aboutsummaryrefslogtreecommitdiffstats
path: root/activemodel
diff options
context:
space:
mode:
authorNeeraj Singh <neerajdotname@gmail.com>2010-08-20 10:17:29 -0400
committerJosé Valim <jose.valim@gmail.com>2010-08-20 11:24:43 -0300
commit2ffa50f5a9fac08e08869687006031b70322497a (patch)
treefd79f4abae332bb2abab2ebba82fc653deaaaec6 /activemodel
parent0d0fbf1e648606c9499e332bad412da005a4e37f (diff)
downloadrails-2ffa50f5a9fac08e08869687006031b70322497a.tar.gz
rails-2ffa50f5a9fac08e08869687006031b70322497a.tar.bz2
rails-2ffa50f5a9fac08e08869687006031b70322497a.zip
after_validation should be called irrespective of the result of validation.
I confirmed that this is the behavior on 2.3.x . [5419 state:resolved] Signed-off-by: José Valim <jose.valim@gmail.com>
Diffstat (limited to 'activemodel')
-rw-r--r--activemodel/lib/active_model/validations/callbacks.rb2
-rw-r--r--activemodel/test/cases/validations_test.rb2
-rw-r--r--activemodel/test/models/topic.rb9
3 files changed, 12 insertions, 1 deletions
diff --git a/activemodel/lib/active_model/validations/callbacks.rb b/activemodel/lib/active_model/validations/callbacks.rb
index afd65d3dd5..858cfda73e 100644
--- a/activemodel/lib/active_model/validations/callbacks.rb
+++ b/activemodel/lib/active_model/validations/callbacks.rb
@@ -40,7 +40,7 @@ module ActiveModel
options = args.extract_options!
options[:prepend] = true
options[:if] = Array.wrap(options[:if])
- options[:if] << "!halted && value != false"
+ options[:if] << "!halted"
options[:if] << "self.validation_context == :#{options[:on]}" if options[:on]
set_callback(:validation, :after, *(args << options), &block)
end
diff --git a/activemodel/test/cases/validations_test.rb b/activemodel/test/cases/validations_test.rb
index f9fc6613f4..1eed0b0c4d 100644
--- a/activemodel/test/cases/validations_test.rb
+++ b/activemodel/test/cases/validations_test.rb
@@ -25,9 +25,11 @@ class ValidationsTest < ActiveModel::TestCase
r = Reply.new
r.title = "There's no content!"
assert r.invalid?, "A reply without content shouldn't be saveable"
+ assert r.after_validation_performed, "after_validation callback should be called"
r.content = "Messa content!"
assert r.valid?, "A reply with content should be saveable"
+ assert r.after_validation_performed, "after_validation callback should be called"
end
def test_single_attr_validation_and_error_msg
diff --git a/activemodel/test/models/topic.rb b/activemodel/test/models/topic.rb
index f25b774cd7..ff34565bdb 100644
--- a/activemodel/test/models/topic.rb
+++ b/activemodel/test/models/topic.rb
@@ -1,7 +1,11 @@
class Topic
include ActiveModel::Validations
+ include ActiveModel::Validations::Callbacks
attr_accessor :title, :author_name, :content, :approved
+ attr_accessor :after_validation_performed
+
+ after_validation :perform_after_validation
def initialize(attributes = {})
attributes.each do |key, value|
@@ -16,4 +20,9 @@ class Topic
def condition_is_true_but_its_not
false
end
+
+ def perform_after_validation
+ self.after_validation_performed = true
+ end
+
end