diff options
author | Jon Leighton <j@jonathanleighton.com> | 2011-01-16 18:25:50 +0000 |
---|---|---|
committer | Aaron Patterson <aaron.patterson@gmail.com> | 2011-01-16 13:43:53 -0800 |
commit | 52c47556b7cf55549f97f3cfd5f69b2563198eac (patch) | |
tree | c43cfba16b8e7c0944d42bbc4224b9a178ec7a7f /activerecord/test/cases | |
parent | 8f88a2841682d95c7bcce7ee76c156ec24bf82d8 (diff) | |
download | rails-52c47556b7cf55549f97f3cfd5f69b2563198eac.tar.gz rails-52c47556b7cf55549f97f3cfd5f69b2563198eac.tar.bz2 rails-52c47556b7cf55549f97f3cfd5f69b2563198eac.zip |
Add create_association! for belongs_to
Diffstat (limited to 'activerecord/test/cases')
-rw-r--r-- | activerecord/test/cases/associations/belongs_to_associations_test.rb | 17 |
1 files changed, 17 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 4c4891dcaf..ef6c482f67 100644 --- a/activerecord/test/cases/associations/belongs_to_associations_test.rb +++ b/activerecord/test/cases/associations/belongs_to_associations_test.rb @@ -120,6 +120,23 @@ class BelongsToAssociationsTest < ActiveRecord::TestCase assert_equal apple.name, client.firm_name end + def test_create! + client = Client.create!(:name => "Jimmy") + account = client.create_account!(:credit_limit => 10) + assert_equal account, client.account + assert account.persisted? + client.save + client.reload + assert_equal account, client.account + end + + def test_failing_create! + client = Client.create!(:name => "Jimmy") + assert_raise(ActiveRecord::RecordInvalid) { client.create_account! } + assert_not_nil client.account + assert client.account.new_record? + end + def test_natural_assignment_to_nil client = Client.find(3) client.firm = nil |