mirror of
https://github.com/TracksApp/tracks.git
synced 2025-12-16 15:20:13 +01:00
Merge branch '2.3_branch'
This commit is contained in:
commit
1ba829e960
7 changed files with 241 additions and 75 deletions
|
|
@ -705,9 +705,9 @@ class TodosController < ApplicationController
|
||||||
|
|
||||||
def tags
|
def tags
|
||||||
# TODO: limit to current_user
|
# TODO: limit to current_user
|
||||||
tags_beginning = Tag.where('name like ?', params[:term]+'%')
|
tags_beginning = Tag.where(Tag.arel_table[:name].matches("#{params[:term]}%"))
|
||||||
tags_all = Tag.where('name like ?', '%'+params[:term]+'%')
|
tags_all = Tag.where(Tag.arel_table[:name].matches("%#{params[:term]}%"))
|
||||||
tags_all= tags_all - tags_beginning
|
tags_all = tags_all - tags_beginning
|
||||||
|
|
||||||
respond_to do |format|
|
respond_to do |format|
|
||||||
format.autocomplete { render :text => for_autocomplete(tags_beginning+tags_all, params[:term]) }
|
format.autocomplete { render :text => for_autocomplete(tags_beginning+tags_all, params[:term]) }
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,9 @@
|
||||||
atom_feed do |feed|
|
atom_feed do |feed|
|
||||||
feed.title(@feed_title)
|
feed.title(@feed_title)
|
||||||
feed.subtitle(@feed_description)
|
feed.subtitle(@feed_description)
|
||||||
feed.updated(@todos.last.updated_at)
|
feed.updated(@not_done_todos.last.updated_at)
|
||||||
|
|
||||||
@todos.each do |todo|
|
@not_done_todos.each do |todo|
|
||||||
feed.entry(todo) do |entry|
|
feed.entry(todo) do |entry|
|
||||||
entry.title(h(todo.description))
|
entry.title(h(todo.description))
|
||||||
entry.link(todo.project ? project_url(todo.project) : context_url(todo.context))
|
entry.link(todo.project ? project_url(todo.project) : context_url(todo.context))
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,7 @@ TZID:<%= ENV['TZ'] || 'GMT' %>
|
||||||
LAST-MODIFIED:<%= Time.now.strftime("%Y%m%dT%H%M%SZ") %>
|
LAST-MODIFIED:<%= Time.now.strftime("%Y%m%dT%H%M%SZ") %>
|
||||||
TZNAME:<%= ENV['TZ'] %>
|
TZNAME:<%= ENV['TZ'] %>
|
||||||
END:VTIMEZONE
|
END:VTIMEZONE
|
||||||
<% for @todo in @todos -%>
|
<% for @todo in @not_done_todos -%>
|
||||||
BEGIN:VTODO
|
BEGIN:VTODO
|
||||||
DTSTAMP:<%= @todo.created_at.strftime("%Y%m%dT%H%M%SZ") %>
|
DTSTAMP:<%= @todo.created_at.strftime("%Y%m%dT%H%M%SZ") %>
|
||||||
DTSTART;VALUE=DATE:<%= @todo.created_at.strftime("%Y%m%d") %>
|
DTSTART;VALUE=DATE:<%= @todo.created_at.strftime("%Y%m%d") %>
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,7 @@ xml.rss :version => "2.0" do
|
||||||
xml.language 'en-us'
|
xml.language 'en-us'
|
||||||
xml.ttl 40
|
xml.ttl 40
|
||||||
|
|
||||||
@todos.each do |todo|
|
@not_done_todos.each do |todo|
|
||||||
xml.item do
|
xml.item do
|
||||||
xml.title h(todo.description)
|
xml.title h(todo.description)
|
||||||
xml.description feed_content_for_todo(todo)
|
xml.description feed_content_for_todo(todo)
|
||||||
|
|
|
||||||
|
|
@ -27,10 +27,11 @@ module I18n::Backend::Pluralization
|
||||||
n==1 ? :one : :other # default :en
|
n==1 ? :one : :other # default :en
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
key = :other if key == :few && !entry.has_key?(key) #fallback to :other if :few is missing
|
||||||
raise InvalidPluralizationData.new(entry, n) unless entry.has_key?(key)
|
raise InvalidPluralizationData.new(entry, n) unless entry.has_key?(key)
|
||||||
entry[key]
|
entry[key]
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
I18n::Backend::Simple.send(:include, I18n::Backend::Pluralization)
|
I18n::Backend::Simple.send(:include, I18n::Backend::Pluralization)
|
||||||
I18n::Backend::Simple.send(:include, I18n::Backend::Fallbacks)
|
I18n::Backend::Simple.send(:include, I18n::Backend::Fallbacks)
|
||||||
|
|
|
||||||
|
|
@ -460,7 +460,7 @@ class TodosControllerTest < ActionController::TestCase
|
||||||
# feeds
|
# feeds
|
||||||
#######
|
#######
|
||||||
|
|
||||||
def test_rss_feed
|
def test_rss_feed_not_completed
|
||||||
login_as(:admin_user)
|
login_as(:admin_user)
|
||||||
get :index, { :format => "rss" }
|
get :index, { :format => "rss" }
|
||||||
assert_equal 'application/rss+xml', @response.content_type
|
assert_equal 'application/rss+xml', @response.content_type
|
||||||
|
|
@ -472,31 +472,187 @@ class TodosControllerTest < ActionController::TestCase
|
||||||
assert_select '>description', "Actions for #{users(:admin_user).display_name}"
|
assert_select '>description', "Actions for #{users(:admin_user).display_name}"
|
||||||
assert_select 'language', 'en-us'
|
assert_select 'language', 'en-us'
|
||||||
assert_select 'ttl', '40'
|
assert_select 'ttl', '40'
|
||||||
assert_select 'item', 17 do
|
assert_select 'item', 11 do
|
||||||
assert_select 'title', /.+/
|
assert_select 'title', /.+/
|
||||||
assert_select 'description', /.*/
|
assert_select 'description', /.*/
|
||||||
assert_select 'link', %r{http://test.host/contexts/.+}
|
assert_select 'link', %r{http://test.host/contexts/.+}
|
||||||
assert_select 'guid', %r{http://test.host/todos/.+}
|
assert_select 'guid', %r{http://test.host/todos/.+}
|
||||||
assert_select 'pubDate', todos(:book).updated_at.to_s(:rfc822)
|
assert_select 'pubDate', todos(:call_bill_gates_every_day).created_at.to_s(:rfc822)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_atom_feed_not_completed
|
||||||
|
login_as :admin_user
|
||||||
|
get :index, { :format => "atom" }
|
||||||
|
assert_equal 'application/atom+xml', @response.content_type
|
||||||
|
assert_equal 'http://www.w3.org/2005/Atom', html_document.children[0].namespace.href
|
||||||
|
assert_select 'feed' do
|
||||||
|
assert_select '>title', 'Tracks Actions'
|
||||||
|
assert_select '>subtitle', "Actions for #{users(:admin_user).display_name}"
|
||||||
|
assert_select 'entry', 11 do
|
||||||
|
assert_select 'title', /.+/
|
||||||
|
assert_select 'content[type="html"]', /.*/
|
||||||
|
assert_select 'published', /(#{Regexp.escape(todos(:book).updated_at.xmlschema)}|#{Regexp.escape(projects(:moremoney).updated_at.xmlschema)})/
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_text_feed_not_completed
|
||||||
|
login_as(:admin_user)
|
||||||
|
get :index, { :format => "txt" }
|
||||||
|
assert_equal 'text/plain', @response.content_type
|
||||||
|
assert !(/ /.match(@response.body))
|
||||||
|
assert_number_of_items_in_text_feed 11
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_ical_feed_not_completed
|
||||||
|
login_as :admin_user
|
||||||
|
get :index, { :format => "ics" }
|
||||||
|
assert_equal 'text/calendar', @response.content_type
|
||||||
|
assert !(/ /.match(@response.body))
|
||||||
|
assert_number_of_items_in_ical_feed 11
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_rss_feed_completed_in_last_week
|
||||||
|
login_as(:admin_user)
|
||||||
|
get :index, { :format => "rss", :done => '7' }
|
||||||
|
|
||||||
|
assert_number_of_items_in_rss_feed 3
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_atom_feed_completed_in_last_week
|
||||||
|
login_as(:admin_user)
|
||||||
|
get :index, { :format => "atom", :done => '7' }
|
||||||
|
|
||||||
|
assert_number_of_items_in_atom_feed 3
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_text_feed_completed_in_last_week
|
||||||
|
login_as(:admin_user)
|
||||||
|
get :index, { :format => "text", :done => '7' }
|
||||||
|
|
||||||
|
assert_number_of_items_in_text_feed 3
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_ical_feed_completed_in_last_week
|
||||||
|
login_as(:admin_user)
|
||||||
|
get :index, { :format => "ics", :done => '7' }
|
||||||
|
|
||||||
|
assert_number_of_items_in_ical_feed 3
|
||||||
|
end
|
||||||
|
|
||||||
def test_rss_feed_with_limit
|
def test_rss_feed_with_limit
|
||||||
login_as(:admin_user)
|
login_as(:admin_user)
|
||||||
get :index, { :format => "rss", :limit => '5' }
|
get :index, { :format => "rss", :limit => '5' }
|
||||||
|
|
||||||
assert_select 'rss[version="2.0"]' do
|
assert_number_of_items_in_rss_feed 5
|
||||||
assert_select 'channel' do
|
end
|
||||||
assert_select '>title', 'Tracks Actions'
|
|
||||||
assert_select '>description', "Actions for #{users(:admin_user).display_name}"
|
def test_atom_feed_with_limit
|
||||||
assert_select 'item', 5 do
|
login_as(:admin_user)
|
||||||
assert_select 'title', /.+/
|
get :index, { :format => "atom", :limit => '5' }
|
||||||
assert_select 'description', /.*/
|
|
||||||
end
|
assert_number_of_items_in_atom_feed 5
|
||||||
end
|
end
|
||||||
end
|
|
||||||
|
def test_text_feed_with_limit
|
||||||
|
login_as(:admin_user)
|
||||||
|
get :index, { :format => "text", :limit => '5' }
|
||||||
|
|
||||||
|
assert_number_of_items_in_text_feed 5
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_ical_feed_with_limit
|
||||||
|
login_as(:admin_user)
|
||||||
|
get :index, { :format => "ics", :limit => '5' }
|
||||||
|
|
||||||
|
assert_number_of_items_in_ical_feed 5
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_rss_feed_filter_by_context
|
||||||
|
login_as(:admin_user)
|
||||||
|
get :index, { :format => "rss", :context_id => 2 }
|
||||||
|
|
||||||
|
assert_number_of_items_in_rss_feed 3
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_atom_feed_filter_by_context
|
||||||
|
login_as(:admin_user)
|
||||||
|
get :index, { :format => "atom", :context_id => 2 }
|
||||||
|
|
||||||
|
assert_number_of_items_in_atom_feed 3
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_text_feed_filter_by_context
|
||||||
|
login_as(:admin_user)
|
||||||
|
get :index, { :format => "text", :context_id => 2 }
|
||||||
|
|
||||||
|
assert_number_of_items_in_text_feed 3
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_ical_feed_filter_by_context
|
||||||
|
login_as(:admin_user)
|
||||||
|
get :index, { :format => "ics", :context_id => 2 }
|
||||||
|
|
||||||
|
assert_number_of_items_in_ical_feed 3
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_rss_feed_filter_by_project
|
||||||
|
login_as(:admin_user)
|
||||||
|
get :index, { :format => "rss", :project_id => 2 }
|
||||||
|
|
||||||
|
assert_number_of_items_in_rss_feed 4
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_atom_feed_filter_by_project
|
||||||
|
login_as(:admin_user)
|
||||||
|
get :index, { :format => "atom", :project_id => 2 }
|
||||||
|
|
||||||
|
assert_number_of_items_in_atom_feed 4
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_text_feed_filter_by_project
|
||||||
|
login_as(:admin_user)
|
||||||
|
get :index, { :format => "text", :project_id => 2 }
|
||||||
|
|
||||||
|
assert_number_of_items_in_text_feed 4
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_ical_feed_filter_by_project
|
||||||
|
login_as(:admin_user)
|
||||||
|
get :index, { :format => "ics", :project_id => 2 }
|
||||||
|
|
||||||
|
assert_number_of_items_in_ical_feed 4
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_rss_feed_filter_by_project_and_context
|
||||||
|
login_as(:admin_user)
|
||||||
|
get :index, { :format => "rss", :project_id => 2, :context_id => 2 }
|
||||||
|
|
||||||
|
assert_number_of_items_in_rss_feed 1
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_atom_feed_filter_by_project_and_context
|
||||||
|
login_as(:admin_user)
|
||||||
|
get :index, { :format => "atom", :project_id => 2, :context_id => 2 }
|
||||||
|
|
||||||
|
assert_number_of_items_in_atom_feed 1
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_text_feed_filter_by_project_and_context
|
||||||
|
login_as(:admin_user)
|
||||||
|
get :index, { :format => "text", :project_id => 2, :context_id => 2 }
|
||||||
|
|
||||||
|
assert_number_of_items_in_text_feed 1
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_ical_feed_filter_by_project_and_context
|
||||||
|
login_as(:admin_user)
|
||||||
|
get :index, { :format => "ics", :project_id => 2, :context_id => 2 }
|
||||||
|
|
||||||
|
assert_number_of_items_in_ical_feed 1
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_rss_feed_not_accessible_to_anonymous_user_without_token
|
def test_rss_feed_not_accessible_to_anonymous_user_without_token
|
||||||
|
|
@ -505,84 +661,70 @@ class TodosControllerTest < ActionController::TestCase
|
||||||
assert_response 401
|
assert_response 401
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_atom_feed_not_accessible_to_anonymous_user_without_token
|
||||||
|
login_as nil
|
||||||
|
get :index, { :format => "atom" }
|
||||||
|
assert_response 401
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_text_feed_not_accessible_to_anonymous_user_without_token
|
||||||
|
login_as nil
|
||||||
|
get :index, { :format => "txt" }
|
||||||
|
assert_response 401
|
||||||
|
end
|
||||||
|
|
||||||
def test_rss_feed_not_accessible_to_anonymous_user_with_invalid_token
|
def test_rss_feed_not_accessible_to_anonymous_user_with_invalid_token
|
||||||
login_as nil
|
login_as nil
|
||||||
get :index, { :format => "rss", :token => 'foo' }
|
get :index, { :format => "rss", :token => 'foo' }
|
||||||
assert_response 401
|
assert_response 401
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_rss_feed_accessible_to_anonymous_user_with_valid_token
|
|
||||||
login_as nil
|
|
||||||
get :index, { :format => "rss", :token => users(:admin_user).token }
|
|
||||||
assert_response :ok
|
|
||||||
end
|
|
||||||
|
|
||||||
def test_atom_feed_content
|
|
||||||
login_as :admin_user
|
|
||||||
get :index, { :format => "atom" }
|
|
||||||
assert_equal 'application/atom+xml', @response.content_type
|
|
||||||
assert_equal 'http://www.w3.org/2005/Atom', html_document.children[0].namespace.href
|
|
||||||
assert_select 'feed' do
|
|
||||||
assert_select '>title', 'Tracks Actions'
|
|
||||||
assert_select '>subtitle', "Actions for #{users(:admin_user).display_name}"
|
|
||||||
assert_select 'entry', 17 do
|
|
||||||
assert_select 'title', /.+/
|
|
||||||
assert_select 'content[type="html"]', /.*/
|
|
||||||
assert_select 'published', /(#{Regexp.escape(todos(:book).updated_at.xmlschema)}|#{Regexp.escape(projects(:moremoney).updated_at.xmlschema)})/
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def test_atom_feed_not_accessible_to_anonymous_user_without_token
|
|
||||||
login_as nil
|
|
||||||
get :index, { :format => "atom" }
|
|
||||||
assert_response 401
|
|
||||||
end
|
|
||||||
|
|
||||||
def test_atom_feed_not_accessible_to_anonymous_user_with_invalid_token
|
def test_atom_feed_not_accessible_to_anonymous_user_with_invalid_token
|
||||||
login_as nil
|
login_as nil
|
||||||
get :index, { :format => "atom", :token => 'foo' }
|
get :index, { :format => "atom", :token => 'foo' }
|
||||||
assert_response 401
|
assert_response 401
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_atom_feed_accessible_to_anonymous_user_with_valid_token
|
|
||||||
login_as nil
|
|
||||||
get :index, { :format => "atom", :token => users(:admin_user).token }
|
|
||||||
assert_response :ok
|
|
||||||
end
|
|
||||||
|
|
||||||
def test_text_feed_content
|
|
||||||
login_as(:admin_user)
|
|
||||||
get :index, { :format => "txt" }
|
|
||||||
assert_equal 'text/plain', @response.content_type
|
|
||||||
assert !(/ /.match(@response.body))
|
|
||||||
# #puts @response.body
|
|
||||||
end
|
|
||||||
|
|
||||||
def test_text_feed_not_accessible_to_anonymous_user_without_token
|
|
||||||
login_as nil
|
|
||||||
get :index, { :format => "txt" }
|
|
||||||
assert_response 401
|
|
||||||
end
|
|
||||||
|
|
||||||
def test_text_feed_not_accessible_to_anonymous_user_with_invalid_token
|
def test_text_feed_not_accessible_to_anonymous_user_with_invalid_token
|
||||||
login_as nil
|
login_as nil
|
||||||
get :index, { :format => "txt", :token => 'foo' }
|
get :index, { :format => "txt", :token => 'foo' }
|
||||||
assert_response 401
|
assert_response 401
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_rss_feed_accessible_to_anonymous_user_with_valid_token
|
||||||
|
login_as nil
|
||||||
|
get :index, { :format => "rss", :token => users(:admin_user).token }
|
||||||
|
assert_response :ok
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_atom_feed_accessible_to_anonymous_user_with_valid_token
|
||||||
|
login_as nil
|
||||||
|
get :index, { :format => "atom", :token => users(:admin_user).token }
|
||||||
|
assert_response :ok
|
||||||
|
end
|
||||||
|
|
||||||
def test_text_feed_accessible_to_anonymous_user_with_valid_token
|
def test_text_feed_accessible_to_anonymous_user_with_valid_token
|
||||||
login_as nil
|
login_as nil
|
||||||
get :index, { :format => "txt", :token => users(:admin_user).token }
|
get :index, { :format => "txt", :token => users(:admin_user).token }
|
||||||
assert_response :ok
|
assert_response :ok
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_ical_feed_content
|
def test_ical_feed_accessible_to_anonymous_user_with_valid_token
|
||||||
login_as :admin_user
|
login_as nil
|
||||||
get :index, { :format => "ics" }
|
get :index, { :format => "ics", :token => users(:admin_user).token }
|
||||||
assert_equal 'text/calendar', @response.content_type
|
assert_response :ok
|
||||||
assert !(/ /.match(@response.body))
|
end
|
||||||
# #puts @response.body
|
|
||||||
|
def test_tag_rss_feed_not_accessible_to_anonymous_user_without_token
|
||||||
|
login_as nil
|
||||||
|
get :tag, {:name => "foo", :format => "rss" }
|
||||||
|
assert_response 401
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_tag_atom_feed_not_accessible_to_anonymous_user_without_token
|
||||||
|
login_as nil
|
||||||
|
get :tag, {:name => "foo", :format => "atom" }
|
||||||
|
assert_response 401
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_tag_text_feed_not_accessible_to_anonymous_user_without_token
|
def test_tag_text_feed_not_accessible_to_anonymous_user_without_token
|
||||||
|
|
|
||||||
|
|
@ -81,6 +81,29 @@ class ActionController::TestCase
|
||||||
xhr :post, :create, get_model_class.downcase => {:name => name}
|
xhr :post, :create, get_model_class.downcase => {:name => name}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def assert_number_of_items_in_rss_feed(expected)
|
||||||
|
assert_select 'rss[version="2.0"]' do
|
||||||
|
assert_select 'channel' do
|
||||||
|
assert_select 'item', expected
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def assert_number_of_items_in_atom_feed(expected)
|
||||||
|
assert_equal 'http://www.w3.org/2005/Atom', html_document.children[0].namespace.href
|
||||||
|
assert_select 'feed' do
|
||||||
|
assert_select 'entry', expected
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def assert_number_of_items_in_text_feed(expected)
|
||||||
|
assert_equal expected, @response.body.scan(/^ \- /).size
|
||||||
|
end
|
||||||
|
|
||||||
|
def assert_number_of_items_in_ical_feed(expected)
|
||||||
|
assert_equal expected, @response.body.scan(/^BEGIN:VTODO/).size
|
||||||
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def get_model_class
|
def get_model_class
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue