Fix a bug where the limit parameter was not respected in the TodosController. This bug affected the Last 15 Actions feed.

git-svn-id: http://www.rousette.org.uk/svn/tracks-repos/trunk@574 a4c988fc-2ded-0310-b66e-134b36920a42
This commit is contained in:
lukemelia 2007-07-25 03:54:26 +00:00
parent 6be1994d8c
commit ad5fbc7147
2 changed files with 31 additions and 8 deletions

View file

@ -341,7 +341,6 @@ class TodosController < ApplicationController
end
condition_builder = FindConditionBuilder.new
options = Hash.new
if params.key?('done')
condition_builder.add 'todos.state = ?', 'completed'
@ -368,7 +367,7 @@ class TodosController < ApplicationController
@title << " actions completed"
@description << " in the last #{done_in_last.to_s} days"
end
Todo.with_scope :find => {:conditions => condition_builder.to_conditions} do
yield
end
@ -393,10 +392,16 @@ class TodosController < ApplicationController
def with_limit_scope(&block)
if params.key?('limit')
Todo.with_scope :find => {:limit => params['limit']} do
Todo.with_scope :find => { :limit => params['limit'] } do
yield
end
#@description = limit ? "Lists the last #{limit} incomplete next actions" : "Lists incomplete next actions"
if TodosController.is_feed_request(request) && @description
if params.key?('limit')
@description << "Lists the last #{params['limit']} incomplete next actions"
else
@description << "Lists incomplete next actions"
end
end
else
yield
end
@ -419,11 +424,13 @@ class TodosController < ApplicationController
else
# Note: these next two finds were previously using @users.todos.find but that broke with_scope for :limit
# Exclude hidden projects from count on home page
@todos = @user.todos.find(:all, :conditions => ['todos.state = ? or todos.state = ?', 'active', 'completed'], :include => [ :project, :context, :tags ])
@todos = Todo.find(:all, :conditions => ['todos.user_id = ? and todos.state = ? or todos.state = ?', @user.id, 'active', 'completed'], :include => [ :project, :context, :tags ])
# Exclude hidden projects from the home page
@not_done_todos = @user.todos.find(:all, :conditions => ['todos.state = ?', 'active'], :order => "todos.due IS NULL, todos.due ASC, todos.created_at ASC", :include => [ :project, :context, :tags ])
@not_done_todos = Todo.find(:all, :conditions => ['todos.user_id = ? and todos.state = ?', @user.id, 'active'], :order => "todos.due IS NULL, todos.due ASC, todos.created_at ASC", :include => [ :project, :context, :tags ])
end

View file

@ -140,8 +140,8 @@ class TodosControllerTest < Test::Rails::TestCase
assert_response :success
assert_equal 3, @tagged
end
def test_find_tagged_withd_content
def test_rss_feed
@request.session['user_id'] = users(:admin_user).id
get :index, { :format => "rss" }
assert_equal 'application/rss+xml; charset=utf-8', @response.headers["Content-Type"]
@ -165,6 +165,22 @@ class TodosControllerTest < Test::Rails::TestCase
end
end
def test_rss_feed_with_limit
@request.session['user_id'] = users(:admin_user).id
get :index, { :format => "rss", :limit => '5' }
assert_xml_select 'rss[version="2.0"]' do
assert_select 'channel' do
assert_select '>title', 'Tracks Actions'
assert_select '>description', "Actions for #{users(:admin_user).display_name}"
assert_select 'item', 5 do
assert_select 'title', /.+/
assert_select 'description', /.*/
end
end
end
end
def test_rss_feed_not_accessible_to_anonymous_user_without_token
@request.session['user_id'] = nil
get :index, { :format => "rss" }