diff options
author | Andrew White <andyw@pixeltrix.co.uk> | 2011-05-17 22:15:47 +0100 |
---|---|---|
committer | Andrew White <andyw@pixeltrix.co.uk> | 2011-05-17 22:16:24 +0100 |
commit | 3773aa4fbba86184a1f45feebaf72ed4f2702fe7 (patch) | |
tree | b56d9dc07d96e4d085667a98f53c3878509412c0 /activerecord/test | |
parent | be199a1d53f9ceae5cfaac185bfd0d9c2a28f9d4 (diff) | |
download | rails-3773aa4fbba86184a1f45feebaf72ed4f2702fe7.tar.gz rails-3773aa4fbba86184a1f45feebaf72ed4f2702fe7.tar.bz2 rails-3773aa4fbba86184a1f45feebaf72ed4f2702fe7.zip |
Add block setting of attributes to singular associations
Diffstat (limited to 'activerecord/test')
-rw-r--r-- | activerecord/test/cases/associations/belongs_to_associations_test.rb | 21 | ||||
-rw-r--r-- | activerecord/test/cases/associations/has_one_associations_test.rb | 21 |
2 files changed, 42 insertions, 0 deletions
diff --git a/activerecord/test/cases/associations/belongs_to_associations_test.rb b/activerecord/test/cases/associations/belongs_to_associations_test.rb index ddcc36c841..b993bf6e90 100644 --- a/activerecord/test/cases/associations/belongs_to_associations_test.rb +++ b/activerecord/test/cases/associations/belongs_to_associations_test.rb @@ -626,4 +626,25 @@ class BelongsToAssociationsTest < ActiveRecord::TestCase assert_equal "Bob", firm.name end + + def test_build_with_block + client = Client.create(:name => 'Client Company') + + firm = client.build_firm{ |f| f.name = 'Agency Company' } + assert_equal 'Agency Company', firm.name + end + + def test_create_with_block + client = Client.create(:name => 'Client Company') + + firm = client.create_firm{ |f| f.name = 'Agency Company' } + assert_equal 'Agency Company', firm.name + end + + def test_create_bang_with_block + client = Client.create(:name => 'Client Company') + + firm = client.create_firm!{ |f| f.name = 'Agency Company' } + assert_equal 'Agency Company', firm.name + end end diff --git a/activerecord/test/cases/associations/has_one_associations_test.rb b/activerecord/test/cases/associations/has_one_associations_test.rb index 38e622f90f..f3bf5baa95 100644 --- a/activerecord/test/cases/associations/has_one_associations_test.rb +++ b/activerecord/test/cases/associations/has_one_associations_test.rb @@ -426,4 +426,25 @@ class HasOneAssociationsTest < ActiveRecord::TestCase bulb = car.build_bulb({ :bulb_type => :custom }, :as => :admin) assert_equal CustomBulb, bulb.class end + + def test_build_with_block + car = Car.create(:name => 'honda') + + bulb = car.build_bulb{ |b| b.color = 'Red' } + assert_equal 'RED!', bulb.color + end + + def test_create_with_block + car = Car.create(:name => 'honda') + + bulb = car.create_bulb{ |b| b.color = 'Red' } + assert_equal 'RED!', bulb.color + end + + def test_create_bang_with_block + car = Car.create(:name => 'honda') + + bulb = car.create_bulb!{ |b| b.color = 'Red' } + assert_equal 'RED!', bulb.color + end end |