aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord
diff options
context:
space:
mode:
authorPratik Naik <pratiknaik@gmail.com>2009-08-11 02:36:50 +0100
committerPratik Naik <pratiknaik@gmail.com>2009-08-11 02:37:04 +0100
commit0a558b36eb3858ceeb926ada1388b0bd41da11f7 (patch)
tree6726226026e52fc4309d4bd6ce32baa9f574ad22 /activerecord
parentd15ddf04ec6fb0cd6d350ba57d9981ebee3eddd0 (diff)
downloadrails-0a558b36eb3858ceeb926ada1388b0bd41da11f7.tar.gz
rails-0a558b36eb3858ceeb926ada1388b0bd41da11f7.tar.bz2
rails-0a558b36eb3858ceeb926ada1388b0bd41da11f7.zip
Add tests for hm:t#push failures
Diffstat (limited to 'activerecord')
-rw-r--r--activerecord/test/cases/associations/has_many_through_associations_test.rb18
1 files changed, 18 insertions, 0 deletions
diff --git a/activerecord/test/cases/associations/has_many_through_associations_test.rb b/activerecord/test/cases/associations/has_many_through_associations_test.rb
index a9d4d88148..5f13b66d11 100644
--- a/activerecord/test/cases/associations/has_many_through_associations_test.rb
+++ b/activerecord/test/cases/associations/has_many_through_associations_test.rb
@@ -199,6 +199,24 @@ class HasManyThroughAssociationsTest < ActiveRecord::TestCase
assert_difference('firm.developers.count', 1) { firm.developers.create!(:name => 'developer') }
end
+ def test_push_with_invalid_record
+ firm = companies(:first_firm)
+ assert_raises(ActiveRecord::RecordInvalid) { firm.developers << Developer.new(:name => '0') }
+ end
+
+ def test_push_with_invalid_join_record
+ repair_validations(Contract) do
+ Contract.validate {|r| r.errors[:base] << 'Invalid Contract' }
+
+ firm = companies(:first_firm)
+ lifo = Developer.new(:name => 'lifo')
+ assert_raises(ActiveRecord::RecordInvalid) { firm.developers << lifo }
+
+ lifo = Developer.create!(:name => 'lifo')
+ assert_raises(ActiveRecord::RecordInvalid) { firm.developers << lifo }
+ end
+ end
+
def test_clear_associations
assert_queries(2) { posts(:welcome);posts(:welcome).people(true) }