diff --git a/Gemfile.lock b/Gemfile.lock index 22ef61ba..9ae216c1 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -83,16 +83,16 @@ GEM actionpack (~> 3.0) bluecloth (~> 2.2) gem_plugin (0.2.3) - gherkin (2.11.1) + gherkin (2.11.2) json (>= 1.4.6) hike (1.2.1) htmlentities (4.3.1) i18n (0.6.0) journey (1.0.4) - jquery-rails (2.0.2) - railties (>= 3.2.0, < 5.0) + jquery-rails (2.1.1) + railties (>= 3.1.0, < 5.0) thor (~> 0.14) - json (1.7.4) + json (1.7.5) libv8 (3.3.10.4) libwebsocket (0.1.5) addressable @@ -142,11 +142,11 @@ GEM rspec-core (2.11.1) rspec-expectations (2.11.2) diff-lcs (~> 1.1.3) - rspec-mocks (2.11.1) + rspec-mocks (2.11.2) rubyzip (0.9.9) sanitize (2.0.3) nokogiri (>= 1.4.4, < 1.6) - sass (3.1.20) + sass (3.2.1) sass-rails (3.2.5) railties (~> 3.2.0) sass (>= 3.1.10) @@ -166,7 +166,7 @@ GEM rails (>= 3.1) therubyracer (0.10.2) libv8 (~> 3.3.10) - thor (0.15.4) + thor (0.16.0) tilt (1.3.3) tolk (1.3.2) will_paginate diff --git a/app/models/todo.rb b/app/models/todo.rb index 18219a34..655f6129 100644 --- a/app/models/todo.rb +++ b/app/models/todo.rb @@ -108,8 +108,10 @@ class Todo < ActiveRecord::Base validate :check_circular_dependencies def check_show_from_in_future - if !show_from.blank? && show_from < user.date - errors.add("show_from", I18n.t('models.todo.error_date_must_be_future')) + if show_from_changed? # only check on change of show_from + if !show_from.blank? && (show_from < user.date) + errors.add("show_from", I18n.t('models.todo.error_date_must_be_future')) + end end end diff --git a/test/unit/todo_test.rb b/test/unit/todo_test.rb index b025b3c8..7c792132 100644 --- a/test/unit/todo_test.rb +++ b/test/unit/todo_test.rb @@ -67,9 +67,9 @@ class TodoTest < ActiveSupport::TestCase def test_validate_show_from_must_be_a_date_in_the_future t = @not_completed2 - t[:show_from] = 1.week.ago # we have to set this via the indexer because show_from=() updates the state - # and actual show_from value appropriately based on the date - assert !t.save + t.show_from = 1.week.ago + + assert !t.save, "todo should not be saved without validation errors" assert_equal 1, t.errors.count assert_equal "must be a date in the future", t.errors[:show_from][0] end @@ -128,6 +128,24 @@ class TodoTest < ActiveSupport::TestCase t.toggle_completion! assert_equal :active, t.aasm_current_state end + + def test_toggle_completion_with_show_from_in_future + t = @not_completed1 + t.show_from= 1.week.from_now + t.save! + assert_equal :deferred, t.aasm_current_state + t.toggle_completion! + assert_equal :completed, t.aasm_current_state + end + + def test_toggle_completion_with_show_from_in_past + t = @not_completed1 + t.update_attribute(:show_from, 1.week.ago) + assert_equal :active, t.aasm_current_state + + assert t.toggle_completion!, "shoud be able to mark active todo complete even if show_from is set in the past" + assert_equal :completed, t.aasm_current_state + end def test_activate_also_saves t = @not_completed1