diff --git a/Gemfile.lock b/Gemfile.lock index c67213a2..22667591 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -2,7 +2,7 @@ GEM remote: https://rubygems.org/ specs: RedCloth (4.2.9) - aasm (3.0.16) + aasm (3.0.17) actionmailer (3.2.13) actionpack (= 3.2.13) mail (~> 2.5.3) @@ -33,16 +33,18 @@ GEM acts_as_list (0.2.0) activerecord (>= 3.0) arel (3.0.2) - aruba (0.5.1) + aruba (0.5.2) childprocess (~> 0.3.6) cucumber (>= 1.1.1) rspec-expectations (>= 2.7.0) + atomic (1.1.8) bcrypt-ruby (3.0.1) builder (3.0.4) - bullet (4.5.0) + bullet (4.6.0) uniform_notifier - cache_digests (0.2.0) + cache_digests (0.3.0) actionpack (>= 3.2) + thread_safe capybara (2.1.0) mime-types (>= 1.16) nokogiri (>= 1.3.3) @@ -58,10 +60,10 @@ GEM coffee-script-source execjs coffee-script-source (1.6.2) - cucumber (1.2.5) + cucumber (1.3.1) builder (>= 2.1.2) diff-lcs (>= 1.1.3) - gherkin (~> 2.11.7) + gherkin (~> 2.12.0) multi_json (~> 1.3) cucumber-rails (1.3.1) capybara (>= 1.1.2) @@ -69,7 +71,7 @@ GEM nokogiri (>= 1.5.0) rails (~> 3.0) database_cleaner (0.9.1) - diff-lcs (1.2.2) + diff-lcs (1.2.4) erubis (2.7.0) execjs (1.4.0) multi_json (~> 1.0) @@ -78,8 +80,8 @@ GEM factory_girl_rails (4.2.1) factory_girl (~> 4.2.0) railties (>= 3.0.0) - ffi (1.6.0) - gherkin (2.11.8) + ffi (1.8.1) + gherkin (2.12.0) multi_json (~> 1.3) hike (1.2.2) htmlentities (4.3.1) @@ -95,7 +97,7 @@ GEM mime-types (~> 1.16) treetop (~> 1.4.8) metaclass (0.0.1) - mime-types (1.22) + mime-types (1.23) mocha (0.13.3) metaclass (~> 0.0.1) multi_json (1.7.2) @@ -135,15 +137,15 @@ GEM rspec-expectations (2.13.0) diff-lcs (>= 1.1.3, < 2.0) rubyzip (0.9.9) - safe_yaml (0.9.0) + safe_yaml (0.9.1) sanitize (2.0.3) nokogiri (>= 1.4.4, < 1.6) - sass (3.2.7) + sass (3.2.8) sass-rails (3.2.6) railties (~> 3.2.0) sass (>= 3.1.10) tilt (~> 1.3) - selenium-webdriver (2.32.0) + selenium-webdriver (2.32.1) childprocess (>= 0.2.5) multi_json (~> 1.0) rubyzip @@ -165,6 +167,8 @@ GEM libv8 (~> 3.11.8.12) ref thor (0.18.1) + thread_safe (0.1.0) + atomic tilt (1.3.7) timecop (0.6.1) tolk (1.3.9) @@ -182,7 +186,7 @@ GEM will_paginate (3.0.4) xpath (2.0.0) nokogiri (~> 1.3) - yard (0.8.5.2) + yard (0.8.6.1) PLATFORMS ruby diff --git a/app/models/context.rb b/app/models/context.rb index bb02b45b..3c4d732c 100644 --- a/app/models/context.rb +++ b/app/models/context.rb @@ -14,23 +14,24 @@ class Context < ActiveRecord::Base # state machine include AASM - aasm_column :state - aasm_initial_state :active - aasm_state :active - aasm_state :closed - aasm_state :hidden + aasm :column => :state do + + state :active, :initial => true + state :closed + state :hidden - aasm_event :close do - transitions :to => :closed, :from => [:active, :hidden], :guard => :no_active_todos? - end + event :close do + transitions :to => :closed, :from => [:active, :hidden], :guard => :no_active_todos? + end - aasm_event :hide do - transitions :to => :hidden, :from => [:active, :closed] - end + event :hide do + transitions :to => :hidden, :from => [:active, :closed] + end - aasm_event :activate do - transitions :to => :active, :from => [:closed, :hidden] + event :activate do + transitions :to => :active, :from => [:closed, :hidden] + end end attr_protected :user diff --git a/app/models/project.rb b/app/models/project.rb index 1cc84500..5428a7fe 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -20,26 +20,24 @@ class Project < ActiveRecord::Base acts_as_list :scope => 'user_id = #{user_id} AND state = \'#{state}\'', :top_of_list => 0 include AASM - aasm_column :state - aasm_initial_state :active - # extend NamePartFinder - # include Tracks::TodoList + aasm :column => :state do - aasm_state :active - aasm_state :hidden, :enter => :hide_todos, :exit => :unhide_todos - aasm_state :completed, :enter => :set_completed_at_date, :exit => :clear_completed_at_date + state :active, :initial => true + state :hidden, :enter => :hide_todos, :exit => :unhide_todos + state :completed, :enter => :set_completed_at_date, :exit => :clear_completed_at_date - aasm_event :activate do - transitions :to => :active, :from => [:active, :hidden, :completed] - end + event :activate do + transitions :to => :active, :from => [:active, :hidden, :completed] + end - aasm_event :hide do - transitions :to => :hidden, :from => [:active, :completed] - end + event :hide do + transitions :to => :hidden, :from => [:active, :completed] + end - aasm_event :complete do - transitions :to => :completed, :from => [:active, :hidden] + event :complete do + transitions :to => :completed, :from => [:active, :hidden] + end end attr_protected :user diff --git a/app/models/recurring_todo.rb b/app/models/recurring_todo.rb index 444cafa8..31c4e937 100644 --- a/app/models/recurring_todo.rb +++ b/app/models/recurring_todo.rb @@ -13,18 +13,17 @@ class RecurringTodo < ActiveRecord::Base include IsTaggable include AASM - aasm_column :state - aasm_initial_state :active + aasm :column => :state do + state :active, :initial => true, :before_enter => Proc.new { |t| t.occurences_count = 0 } + state :completed, :before_enter => Proc.new { |t| t.completed_at = Time.zone.now }, :before_exit => Proc.new { |t| t.completed_at = nil } - aasm_state :active, :enter => Proc.new { |t| t.occurences_count = 0 } - aasm_state :completed, :enter => Proc.new { |t| t.completed_at = Time.zone.now }, :exit => Proc.new { |t| t.completed_at = nil } + event :complete do + transitions :to => :completed, :from => [:active] + end - aasm_event :complete do - transitions :to => :completed, :from => [:active] - end - - aasm_event :activate do - transitions :to => :active, :from => [:completed] + event :activate do + transitions :to => :active, :from => [:completed] + end end validates_presence_of :description diff --git a/app/models/todo.rb b/app/models/todo.rb index 9f569b37..5cdeed15 100644 --- a/app/models/todo.rb +++ b/app/models/todo.rb @@ -56,43 +56,45 @@ class Todo < ActiveRecord::Base # state machine include AASM - aasm_column :state aasm_initial_state Proc.new { |t| (t.show_from && t.user && (t.show_from > t.user.date)) ? :deferred : :active} - aasm_state :active - aasm_state :project_hidden - aasm_state :completed, :enter => Proc.new { |t| t.completed_at = Time.zone.now }, :exit => Proc.new { |t| t.completed_at = nil} - aasm_state :deferred, :exit => Proc.new { |t| t[:show_from] = nil } - aasm_state :pending + aasm :column => :state do - aasm_event :defer do - transitions :to => :deferred, :from => [:active] - end + state :active + state :project_hidden + state :completed, :enter => Proc.new { |t| t.completed_at = Time.zone.now }, :exit => Proc.new { |t| t.completed_at = nil} + state :deferred, :after_exit => Proc.new { |t| t[:show_from] = nil} + state :pending - aasm_event :complete do - transitions :to => :completed, :from => [:active, :project_hidden, :deferred, :pending] - end + event :defer do + transitions :to => :deferred, :from => [:active] + end - aasm_event :activate do - transitions :to => :active, :from => [:project_hidden, :deferred] - transitions :to => :active, :from => [:completed], :guard => :no_uncompleted_predecessors? - transitions :to => :active, :from => [:pending], :guard => :no_uncompleted_predecessors_or_deferral? - transitions :to => :pending, :from => [:completed], :guard => :uncompleted_predecessors? - transitions :to => :deferred, :from => [:pending], :guard => :no_uncompleted_predecessors? - end + event :complete do + transitions :to => :completed, :from => [:active, :project_hidden, :deferred, :pending] + end - aasm_event :hide do - transitions :to => :project_hidden, :from => [:active, :deferred, :pending] - end + event :activate do + transitions :to => :active, :from => [:project_hidden, :deferred] + transitions :to => :active, :from => [:completed], :guard => :no_uncompleted_predecessors? + transitions :to => :active, :from => [:pending], :guard => :no_uncompleted_predecessors_or_deferral? + transitions :to => :pending, :from => [:completed], :guard => :uncompleted_predecessors? + transitions :to => :deferred, :from => [:pending], :guard => :no_uncompleted_predecessors? + end - aasm_event :unhide do - transitions :to => :deferred, :from => [:project_hidden], :guard => Proc.new{|t| !t.show_from.blank? } - transitions :to => :pending, :from => [:project_hidden], :guard => :uncompleted_predecessors? - transitions :to => :active, :from => [:project_hidden] - end + event :hide do + transitions :to => :project_hidden, :from => [:active, :deferred, :pending] + end - aasm_event :block do - transitions :to => :pending, :from => [:active, :deferred] + event :unhide do + transitions :to => :deferred, :from => [:project_hidden], :guard => Proc.new{|t| !t.show_from.blank? } + transitions :to => :pending, :from => [:project_hidden], :guard => :uncompleted_predecessors? + transitions :to => :active, :from => [:project_hidden] + end + + event :block do + transitions :to => :pending, :from => [:active, :deferred] + end end attr_protected :user diff --git a/test/functional/recurring_todos_controller_test.rb b/test/functional/recurring_todos_controller_test.rb index cf5121f4..fe687ca3 100644 --- a/test/functional/recurring_todos_controller_test.rb +++ b/test/functional/recurring_todos_controller_test.rb @@ -82,8 +82,9 @@ class RecurringTodosControllerTest < ActionController::TestCase # mark as active xhr :post, :toggle_check, :id=>1, :_source_view=>"" - recurring_todo_1.reload - assert recurring_todo_1.active? + + recurring_todo_1 = RecurringTodo.find(1) # reload seems to not work + assert recurring_todo_1.active?, "recurring todo should be active but is #{recurring_todo_1.aasm_current_state}" # by making active, a new todo should be created from the pattern assert_equal todo_count+1, Todo.count diff --git a/test/functional/todos_controller_test.rb b/test/functional/todos_controller_test.rb index 4222d981..6d207ade 100644 --- a/test/functional/todos_controller_test.rb +++ b/test/functional/todos_controller_test.rb @@ -365,7 +365,8 @@ class TodosControllerTest < ActionController::TestCase xhr :post, :update, :id => todo.id, :_source_view => 'todo', "project_name"=>"None", "todo"=>{} assert assigns['project_changed'], "the project of the todo should be changed" - assert todo.reload().active?, "todo should be active" + todo = Todo.find(todo.id) # reload does not seem to work anymore + assert todo.active?, "todo should be active" end def test_change_context_of_todo @@ -708,7 +709,7 @@ class TodosControllerTest < ActionController::TestCase # mark todo complete xhr :post, :toggle_check, :id => @todo.id, :_source_view => 'todo' - @todo.reload + @todo = Todo.find(@todo.id) #reload does not seem to work anymore assert @todo.completed? # check that there is no active todo