aboutsummaryrefslogtreecommitdiffstats
path: root/activemodel/test/cases
diff options
context:
space:
mode:
authorJosé Valim <jose.valim@gmail.com>2011-04-28 23:24:40 -0700
committerJosé Valim <jose.valim@gmail.com>2011-04-28 23:24:40 -0700
commit3331166b48281be27d10b59e2441cb06dc3fc740 (patch)
tree6c60edb7c01a80a27383790628cbce10f08a810d /activemodel/test/cases
parente59491355e921c2275980fba5a85dfc8b5ed25f7 (diff)
parent36ee2bafec9f38fc3de404d7708f27a66960ee10 (diff)
downloadrails-3331166b48281be27d10b59e2441cb06dc3fc740.tar.gz
rails-3331166b48281be27d10b59e2441cb06dc3fc740.tar.bz2
rails-3331166b48281be27d10b59e2441cb06dc3fc740.zip
Merged pull request #344 from asanghi/callback_if.
:if should not fire on validations when not in context with :on
Diffstat (limited to 'activemodel/test/cases')
-rw-r--r--activemodel/test/cases/validations_test.rb14
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