diff options
author | Aaron Patterson <aaron.patterson@gmail.com> | 2014-02-20 11:25:48 -0800 |
---|---|---|
committer | Aaron Patterson <aaron.patterson@gmail.com> | 2014-02-20 11:26:07 -0800 |
commit | 7eaebd85798c8f56baea4a09d7e08b17d5dcc02c (patch) | |
tree | 83e9e2ee40abc2948a34ef10c8e678477c43541e /activerecord | |
parent | 358802b850df595e071abe3b9d392225a0481d6b (diff) | |
download | rails-7eaebd85798c8f56baea4a09d7e08b17d5dcc02c.tar.gz rails-7eaebd85798c8f56baea4a09d7e08b17d5dcc02c.tar.bz2 rails-7eaebd85798c8f56baea4a09d7e08b17d5dcc02c.zip |
adding a test for #14106
Diffstat (limited to 'activerecord')
-rw-r--r-- | activerecord/test/cases/autosave_association_test.rb | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/activerecord/test/cases/autosave_association_test.rb b/activerecord/test/cases/autosave_association_test.rb index c55dd685a1..d2f97df0fc 100644 --- a/activerecord/test/cases/autosave_association_test.rb +++ b/activerecord/test/cases/autosave_association_test.rb @@ -21,6 +21,31 @@ require 'models/electron' require 'models/molecule' class TestAutosaveAssociationsInGeneral < ActiveRecord::TestCase + def test_autosave_validation + person = Class.new(ActiveRecord::Base) { + self.table_name = 'people' + validate :should_be_cool, :on => :create + def self.name; 'Person'; end + + private + + def should_be_cool + unless self.first_name == 'cool' + errors.add :first_name, "not cool" + end + end + } + reference = Class.new(ActiveRecord::Base) { + self.table_name = "references" + def self.name; 'Reference'; end + belongs_to :person, autosave: true, class: person + } + + u = person.create!(first_name: 'cool') + u.update_attributes!(first_name: 'nah') # still valid because validation only applies on 'create' + assert reference.create!(person: u).persisted? + end + def test_should_not_add_the_same_callbacks_multiple_times_for_has_one assert_no_difference_when_adding_callbacks_twice_for Pirate, :ship end |