mirror of
https://github.com/TracksApp/tracks.git
synced 2026-02-05 15:31:47 +01:00
fix test failures after the changes and refactorings
This commit is contained in:
parent
559a02d6f1
commit
8546ae5dfa
8 changed files with 30 additions and 81 deletions
|
|
@ -54,7 +54,7 @@ class Todo < ActiveRecord::Base
|
|||
|
||||
include AASM
|
||||
aasm_column :state
|
||||
aasm_initial_state Proc.new { |todo| (todo.show_from && (todo.show_from > todo.user.date)) ? :deferred : :active}
|
||||
aasm_initial_state Proc.new { |t| (t.show_from && t.user && (t.show_from > t.user.date)) ? :deferred : :active}
|
||||
|
||||
# when entering active state, also remove completed_at date. Looks like :exit
|
||||
# of state completed is not run, see #679
|
||||
|
|
@ -221,9 +221,9 @@ class Todo < ActiveRecord::Base
|
|||
def show_from=(date)
|
||||
# parse Date objects into the proper timezone
|
||||
date = user.at_midnight(date) if (date.is_a? Date)
|
||||
|
||||
|
||||
# show_from needs to be set before state_change because of "bug" in aasm.
|
||||
# If show_From is not set, the todo will not validate and thus aasm will not save
|
||||
# If show_from is not set, the todo will not validate and thus aasm will not save
|
||||
# (see http://stackoverflow.com/questions/682920/persisting-the-state-column-on-transition-using-rubyist-aasm-acts-as-state-machi)
|
||||
self[:show_from] = date
|
||||
|
||||
|
|
@ -338,4 +338,5 @@ class Todo < ActiveRecord::Base
|
|||
todo.project_id = project_id unless project_id.nil?
|
||||
return todo
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
|||
|
|
@ -59,22 +59,16 @@ class User < ActiveRecord::Base
|
|||
self.update_positions(projects.map{ |p| p.id })
|
||||
return projects
|
||||
end
|
||||
def actionize(user_id, scope_conditions = {})
|
||||
query_state = scope_conditions[:state] ? "AND projects.state = '#{scope_conditions[:state]}' " : ""
|
||||
projects_with_active_todos = Project.find_by_sql([
|
||||
"SELECT projects.id, count(todos.id) as p_count " +
|
||||
"FROM projects " +
|
||||
"LEFT OUTER JOIN todos ON todos.project_id = projects.id "+
|
||||
"WHERE projects.user_id = ? AND " +
|
||||
"NOT (todos.state='completed' OR todos.state='deferred' OR todos.state='pending') " +
|
||||
query_state +
|
||||
" GROUP BY projects.id ORDER by p_count DESC",user_id])
|
||||
all_project_ids = Project.find_by_sql([
|
||||
"SELECT id FROM projects WHERE projects.user_id = ? " + query_state, user_id
|
||||
])
|
||||
ids_in_new_positions = projects_with_active_todos.map{|p| p.id}
|
||||
ids_of_unselected_projects = all_project_ids.map{|p| p.id} - ids_in_new_positions
|
||||
self.update_positions(ids_in_new_positions + ids_of_unselected_projects)
|
||||
def actionize(scope_conditions = {})
|
||||
todos_in_project = find(:all, :conditions => scope_conditions, :include => [:todos])
|
||||
todos_in_project.sort!{ |x, y| -(x.todos.active.count <=> y.todos.active.count) }
|
||||
todos_in_project.reject{ |p| p.todos.active.count > 0 }
|
||||
sorted_project_ids = todos_in_project.map {|p| p.id}
|
||||
|
||||
all_project_ids = find(:all).map {|p| p.id}
|
||||
other_project_ids = all_project_ids - sorted_project_ids
|
||||
|
||||
update_positions(sorted_project_ids + other_project_ids)
|
||||
|
||||
return find(:all, :conditions => scope_conditions)
|
||||
end
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue