aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/cases
diff options
context:
space:
mode:
authorCarlos Antonio da Silva <carlosantoniodasilva@gmail.com>2014-03-14 20:17:03 -0300
committerCarlos Antonio da Silva <carlosantoniodasilva@gmail.com>2014-03-14 20:30:55 -0300
commitbae7f1dae90c37b0e02482a1d99f4aeec5d49e24 (patch)
tree92ab9b0a56ba77c804a8601d8537bfeb76c1efb8 /activerecord/test/cases
parenteb31a86f3090b04a7171c4db054ad0ec98cac760 (diff)
downloadrails-bae7f1dae90c37b0e02482a1d99f4aeec5d49e24.tar.gz
rails-bae7f1dae90c37b0e02482a1d99f4aeec5d49e24.tar.bz2
rails-bae7f1dae90c37b0e02482a1d99f4aeec5d49e24.zip
Obey `validate: false` option for habtm
Fixes #14383.
Diffstat (limited to 'activerecord/test/cases')
-rw-r--r--activerecord/test/cases/associations/has_and_belongs_to_many_associations_test.rb24
1 files changed, 24 insertions, 0 deletions
diff --git a/activerecord/test/cases/associations/has_and_belongs_to_many_associations_test.rb b/activerecord/test/cases/associations/has_and_belongs_to_many_associations_test.rb
index bac1cb8e2d..366472c6fd 100644
--- a/activerecord/test/cases/associations/has_and_belongs_to_many_associations_test.rb
+++ b/activerecord/test/cases/associations/has_and_belongs_to_many_associations_test.rb
@@ -11,6 +11,7 @@ require 'models/author'
require 'models/tag'
require 'models/tagging'
require 'models/parrot'
+require 'models/person'
require 'models/pirate'
require 'models/treasure'
require 'models/price_estimate'
@@ -795,4 +796,27 @@ class HasAndBelongsToManyAssociationsTest < ActiveRecord::TestCase
end
end
+ def test_association_with_validate_false_does_not_run_associated_validation_callbacks_on_create
+ rich_person = RichPerson.new
+
+ treasure = Treasure.new
+ treasure.rich_people << rich_person
+ treasure.valid?
+
+ assert_equal 1, treasure.rich_people.size
+ assert_nil rich_person.first_name, 'should not run associated person validation on create when validate: false'
+ end
+
+ def test_association_with_validate_false_does_not_run_associated_validation_callbacks_on_update
+ rich_person = RichPerson.create!
+ person_first_name = rich_person.first_name
+ assert_not_nil person_first_name
+
+ treasure = Treasure.new
+ treasure.rich_people << rich_person
+ treasure.valid?
+
+ assert_equal 1, treasure.rich_people.size
+ assert_equal person_first_name, rich_person.first_name, 'should not run associated person validation on update when validate: false'
+ end
end