aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/cases/associations
diff options
context:
space:
mode:
authorJon Leighton <j@jonathanleighton.com>2011-01-09 19:09:51 +0000
committerAaron Patterson <aaron.patterson@gmail.com>2011-01-11 13:45:09 -0800
commit552df9b933e05a3c1d2508c316f1f2bd240accc5 (patch)
tree116f9b2bc884e4913859f0baa0b9c28b79d9e76a /activerecord/test/cases/associations
parentd88caa6e4a8f0f64601fc8bf07b61b682263d712 (diff)
downloadrails-552df9b933e05a3c1d2508c316f1f2bd240accc5.tar.gz
rails-552df9b933e05a3c1d2508c316f1f2bd240accc5.tar.bz2
rails-552df9b933e05a3c1d2508c316f1f2bd240accc5.zip
Support for create_association! for has_one associations
Diffstat (limited to 'activerecord/test/cases/associations')
-rw-r--r--activerecord/test/cases/associations/has_one_associations_test.rb18
1 files changed, 18 insertions, 0 deletions
diff --git a/activerecord/test/cases/associations/has_one_associations_test.rb b/activerecord/test/cases/associations/has_one_associations_test.rb
index 925b76b901..d9b6694dd8 100644
--- a/activerecord/test/cases/associations/has_one_associations_test.rb
+++ b/activerecord/test/cases/associations/has_one_associations_test.rb
@@ -173,6 +173,24 @@ class HasOneAssociationsTest < ActiveRecord::TestCase
assert_equal account, firm.reload.account
end
+ def test_create_association_with_bang
+ firm = Firm.create(:name => "GlobalMegaCorp")
+ account = firm.create_account!(:credit_limit => 1000)
+ assert_equal account, firm.reload.account
+ end
+
+ def test_create_association_with_bang_failing
+ firm = Firm.create(:name => "GlobalMegaCorp")
+ assert_raise ActiveRecord::RecordInvalid do
+ firm.create_account!
+ end
+ account = firm.account
+ assert_not_nil account
+ account.credit_limit = 5
+ account.save
+ assert_equal account, firm.reload.account
+ end
+
def test_build
firm = Firm.new("name" => "GlobalMegaCorp")
firm.save