diff --git a/activemodel/lib/active_model/validations/callbacks.rb b/activemodel/lib/active_model/validations/callbacks.rb index afd65d3dd5cc97c336464ead3409e7aef5a7dfc3..858cfda73e2a114a281f546a479c93d22d684b32 100644 --- a/activemodel/lib/active_model/validations/callbacks.rb +++ b/activemodel/lib/active_model/validations/callbacks.rb @@ -40,7 +40,7 @@ def after_validation(*args, &block) 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 f9fc6613f455eba0e9354f097240c115ab301306..1eed0b0c4da50281efc9b0476ea43a3c48bcb1e5 100644 --- a/activemodel/test/cases/validations_test.rb +++ b/activemodel/test/cases/validations_test.rb @@ -25,9 +25,11 @@ def test_single_field_validation 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 f25b774cd768b49eaa920ba5d7f8bb6a81269986..ff34565bdb4d058b2d2302e7e596e8b0fa35712a 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 @@ def condition_is_true def condition_is_true_but_its_not false end + + def perform_after_validation + self.after_validation_performed = true + end + end