diff options
author | Aditya Sanghi <asanghi@me.com> | 2011-04-29 02:54:37 +0530 |
---|---|---|
committer | Aditya Sanghi <asanghi@me.com> | 2011-04-29 02:54:37 +0530 |
commit | bf5cf5db86fa0aeb818d32541a35310de992f426 (patch) | |
tree | b5a1f7f1fb2cbc660b924faa8272a6fb4a06a5a7 /activemodel/test | |
parent | e59491355e921c2275980fba5a85dfc8b5ed25f7 (diff) | |
download | rails-bf5cf5db86fa0aeb818d32541a35310de992f426.tar.gz rails-bf5cf5db86fa0aeb818d32541a35310de992f426.tar.bz2 rails-bf5cf5db86fa0aeb818d32541a35310de992f426.zip |
:if should not fire on validations when not in context with :on
Diffstat (limited to 'activemodel/test')
-rw-r--r-- | activemodel/test/cases/validations_test.rb | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/activemodel/test/cases/validations_test.rb b/activemodel/test/cases/validations_test.rb index 2f36195627..0b50acf913 100644 --- a/activemodel/test/cases/validations_test.rb +++ b/activemodel/test/cases/validations_test.rb @@ -212,6 +212,20 @@ class ValidationsTest < ActiveModel::TestCase assert_equal 'is too short (minimum is 2 characters)', t.errors[key][0] end + def test_validaton_with_if_and_on + Topic.validates_presence_of :title, :if => Proc.new{|x| x.author_name = "bad"; true }, :on => :update + + t = Topic.new(:title => "") + + # If block should not fire + assert t.valid? + assert t.author_name.nil? + + # If block should fire + assert t.invalid?(:update) + assert t.author_name == "bad" + end + def test_invalid_should_be_the_opposite_of_valid Topic.validates_presence_of :title |