fix test failures after the changes and refactorings

This commit is contained in:
Reinier Balt 2011-06-12 04:29:35 +02:00
parent 559a02d6f1
commit 8546ae5dfa
8 changed files with 30 additions and 81 deletions

View file

@ -80,22 +80,12 @@ class ApplicationController < ActionController::Base
# actions or multiple actions
#
def count_undone_todos_phrase(todos_parent, string="actions")
count = count_undone_todos(todos_parent)
count = todos_parent.nil? ? 0 : todos_parent.todos.not_completed.count
# count_undone_todos(todos_parent)
word = count == 1 ? string.singularize : string.pluralize
return count.to_s + "&nbsp;" + word
end
def count_undone_todos(todos_parent)
return 0 if todos_parent.nil?
if (todos_parent.is_a?(Project) && todos_parent.hidden?)
count = eval "@project_project_hidden_todo_counts[#{todos_parent.id}]"
else
count = eval "@#{todos_parent.class.to_s.downcase}_not_done_counts[#{todos_parent.id}]"
end
end
# Convert a date object to the format specified in the user's preferences in
# config/settings.yml
#
@ -248,25 +238,8 @@ class ApplicationController < ActionController::Base
@active_contexts = current_user.contexts.active
@hidden_contexts = current_user.contexts.hidden
init_not_done_counts
if prefs.show_hidden_projects_in_sidebar
init_project_hidden_todo_counts(['project'])
end
end
def init_not_done_counts(parents = ['project','context'])
parents.each do |parent|
eval("@#{parent}_not_done_counts = @#{parent}_not_done_counts || current_user.todos.active.count(:group => :#{parent}_id)")
end
end
def init_project_hidden_todo_counts(parents = ['project','context'])
parents.each do |parent|
eval("@#{parent}_project_hidden_todo_counts = @#{parent}_project_hidden_todo_counts || current_user.todos.count(:conditions => ['state = ? or state = ?', 'project_hidden', 'active'], :group => :#{parent}_id)")
end
end
# Set the contents of the flash message from a controller Usage: notify
# :warning, "This is the message" Sets the flash of type 'warning' to "This is
# the message"

View file

@ -19,8 +19,6 @@ class ContextsController < ApplicationController
@all_contexts = @active_contexts + @hidden_contexts
@count = @all_contexts.size
init_not_done_counts(['context'])
respond_to do |format|
format.html &render_contexts_html
format.m &render_contexts_mobile

View file

@ -14,13 +14,11 @@ class ProjectsController < ApplicationController
projects_and_actions
else
@contexts = current_user.contexts.all
init_not_done_counts(['project'])
if params[:only_active_with_no_next_actions]
@projects = current_user.projects.active.select { |p| count_undone_todos(p) == 0 }
@projects = current_user.projects.active.select { |p| p.todos.count == 0 }
else
@projects = current_user.projects.all
end
init_project_hidden_todo_counts(['project'])
respond_to do |format|
format.html &render_projects_html
format.m &render_projects_mobile
@ -209,16 +207,12 @@ class ProjectsController < ApplicationController
@state = params['state']
@projects = current_user.projects.alphabetize(:state => @state) if @state
@contexts = current_user.contexts
init_not_done_counts(['project'])
init_project_hidden_todo_counts(['project']) if @state == 'hidden'
end
def actionize
@state = params['state']
@projects = current_user.projects.actionize(current_user.id, :state => @state) if @state
@projects = current_user.projects.actionize(:state => @state) if @state
@contexts = current_user.contexts
init_not_done_counts(['project'])
init_project_hidden_todo_counts(['project']) if @state == 'hidden'
end
protected
@ -293,7 +287,6 @@ class ProjectsController < ApplicationController
def render_text_feed
lambda do
init_project_hidden_todo_counts(['project'])
render :action => 'index', :layout => false, :content_type => Mime::TEXT
end
end