aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test
diff options
context:
space:
mode:
Diffstat (limited to 'activerecord/test')
-rwxr-xr-xactiverecord/test/associations_test.rb24
-rwxr-xr-xactiverecord/test/validations_test.rb4
2 files changed, 24 insertions, 4 deletions
diff --git a/activerecord/test/associations_test.rb b/activerecord/test/associations_test.rb
index a1ea3f1c23..222cb5dbca 100755
--- a/activerecord/test/associations_test.rb
+++ b/activerecord/test/associations_test.rb
@@ -576,6 +576,26 @@ class HasManyAssociationsTest < Test::Unit::TestCase
assert_equal 3, first_firm.plain_clients.length
assert_equal 3, first_firm.plain_clients.size
end
+
+ def test_create_with_bang_on_has_many_when_parent_is_new_raises
+ assert_raises(ActiveRecord::RecordNotSaved) do
+ firm = Firm.new
+ firm.plain_clients.create! :name=>"Whoever"
+ end
+ end
+
+ def test_regular_create_on_has_many_when_parent_is_new_raises
+ assert_raises(ActiveRecord::RecordNotSaved) do
+ firm = Firm.new
+ firm.plain_clients.create :name=>"Whoever"
+ end
+ end
+
+ def test_create_with_bang_on_habtm_when_parent_is_new_raises
+ assert_raises(ActiveRecord::RecordNotSaved) do
+ Developer.new("name" => "Aredridel").projects.create!
+ end
+ end
def test_adding_a_mismatch_class
assert_raises(ActiveRecord::AssociationTypeMismatch) { companies(:first_firm).clients_of_firm << nil }
@@ -1540,8 +1560,8 @@ class HasAndBelongsToManyAssociationsTest < Test::Unit::TestCase
def test_create_by_new_record
devel = Developer.new(:name => "Marcel", :salary => 75000)
- proj1 = devel.projects.create(:name => "Make bed")
- proj2 = devel.projects.create(:name => "Lie in it")
+ proj1 = devel.projects.build(:name => "Make bed")
+ proj2 = devel.projects.build(:name => "Lie in it")
assert_equal devel.projects.last, proj2
assert proj2.new_record?
devel.save
diff --git a/activerecord/test/validations_test.rb b/activerecord/test/validations_test.rb
index 8c7ef759e6..d0c54d1528 100755
--- a/activerecord/test/validations_test.rb
+++ b/activerecord/test/validations_test.rb
@@ -675,7 +675,7 @@ class ValidationsTest < Test::Unit::TestCase
t = Topic.new('title' => 'noreplies', 'content' => 'whatever')
assert !t.save
assert t.errors.on(:replies)
- t.replies.create('title' => 'areply', 'content' => 'whateveragain')
+ reply = t.replies.build('title' => 'areply', 'content' => 'whateveragain')
assert t.valid?
end
@@ -868,7 +868,7 @@ class ValidationsTest < Test::Unit::TestCase
t = Topic.new('title' => 'あいうえお', 'content' => 'かきくけこ')
assert !t.save
assert t.errors.on(:replies)
- t.replies.create('title' => 'あいうえお', 'content' => 'かきくけこ')
+ t.replies.build('title' => 'あいうえお', 'content' => 'かきくけこ')
assert t.valid?
end
end