From 076ca48bd649ddea4dd1a320879c03a9fe7a0a6d Mon Sep 17 00:00:00 2001 From: railsbob Date: Sun, 9 Aug 2009 13:01:42 +0100 Subject: Ensure hm:t#find does not assign nil to :include [#1845 state:resolved] Signed-off-by: Pratik Naik --- .../test/cases/associations/has_many_through_associations_test.rb | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'activerecord/test/cases/associations/has_many_through_associations_test.rb') 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 f6b4a42377..799ab52025 100644 --- a/activerecord/test/cases/associations/has_many_through_associations_test.rb +++ b/activerecord/test/cases/associations/has_many_through_associations_test.rb @@ -299,4 +299,9 @@ class HasManyThroughAssociationsTest < ActiveRecord::TestCase def test_has_many_association_through_a_has_many_association_with_nonstandard_primary_keys assert_equal 1, owners(:blackbeard).toys.count end + + def test_find_on_has_many_association_collection_with_include_and_conditions + post_with_no_comments = people(:michael).posts_with_no_comments.first + assert_equal post_with_no_comments, posts(:authorless) + end end -- cgit v1.2.3 From 00d6c766608f90ce64f11feb98786cbc7f71b89d Mon Sep 17 00:00:00 2001 From: Gabe da Silveira Date: Sun, 9 Aug 2009 12:53:22 -0700 Subject: Enable has_many :through for going through a has_one association on the join model [#2719 state:resolved] Signed-off-by: Pratik Naik --- .../cases/associations/has_many_through_associations_test.rb | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'activerecord/test/cases/associations/has_many_through_associations_test.rb') 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 799ab52025..58ce2ca3a5 100644 --- a/activerecord/test/cases/associations/has_many_through_associations_test.rb +++ b/activerecord/test/cases/associations/has_many_through_associations_test.rb @@ -304,4 +304,16 @@ class HasManyThroughAssociationsTest < ActiveRecord::TestCase post_with_no_comments = people(:michael).posts_with_no_comments.first assert_equal post_with_no_comments, posts(:authorless) end + + def test_has_many_through_has_one_reflection + assert_equal [comments(:eager_sti_on_associations_vs_comment)], authors(:david).very_special_comments + end + + def test_modifying_has_many_through_has_one_reflection_should_raise + [ + lambda { authors(:david).very_special_comments = [VerySpecialComment.create!(:body => "Gorp!", :post_id => 1011), VerySpecialComment.create!(:body => "Eep!", :post_id => 1012)] }, + lambda { authors(:david).very_special_comments << VerySpecialComment.create!(:body => "Hoohah!", :post_id => 1013) }, + lambda { authors(:david).very_special_comments.delete(authors(:david).very_special_comments.first) }, + ].each {|block| assert_raise(ActiveRecord::HasManyThroughCantAssociateThroughHasOneOrManyReflection, &block) } + end end -- cgit v1.2.3 From e06a0b03c8ba29f4b05a35560645814ac88aefbe Mon Sep 17 00:00:00 2001 From: railsbob Date: Sat, 8 Aug 2009 23:48:11 +0100 Subject: has_many :through create should not raise validation errors [#2934 state:committed] Signed-off-by: Jeremy Kemper --- .../has_many_through_associations_test.rb | 29 +++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) (limited to 'activerecord/test/cases/associations/has_many_through_associations_test.rb') 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 58ce2ca3a5..59985374d3 100644 --- a/activerecord/test/cases/associations/has_many_through_associations_test.rb +++ b/activerecord/test/cases/associations/has_many_through_associations_test.rb @@ -11,9 +11,12 @@ require 'models/author' require 'models/owner' require 'models/pet' require 'models/toy' +require 'models/contract' +require 'models/company' +require 'models/developer' class HasManyThroughAssociationsTest < ActiveRecord::TestCase - fixtures :posts, :readers, :people, :comments, :authors, :owners, :pets, :toys, :jobs, :references + fixtures :posts, :readers, :people, :comments, :authors, :owners, :pets, :toys, :jobs, :references, :companies def test_associate_existing assert_queries(2) { posts(:thinking);people(:david) } @@ -176,6 +179,30 @@ class HasManyThroughAssociationsTest < ActiveRecord::TestCase assert_raises(ActiveRecord::RecordNotSaved) { p.people.create!(:first_name => "snow") } end + def test_associate_with_create_and_invalid_options + peeps = companies(:first_firm).developers.count + assert_nothing_raised { companies(:first_firm).developers.create(:name => '0') } + assert_equal peeps, companies(:first_firm).developers.count + end + + def test_associate_with_create_and_valid_options + peeps = companies(:first_firm).developers.count + assert_nothing_raised { companies(:first_firm).developers.create(:name => 'developer') } + assert_equal peeps + 1, companies(:first_firm).developers.count + end + + def test_associate_with_create_bang_and_invalid_options + peeps = companies(:first_firm).developers.count + assert_raises(ActiveRecord::RecordInvalid) { companies(:first_firm).developers.create!(:name => '0') } + assert_equal peeps, companies(:first_firm).developers.count + end + + def test_associate_with_create_bang_and_valid_options + peeps = companies(:first_firm).developers.count + assert_nothing_raised { companies(:first_firm).developers.create!(:name => 'developer') } + assert_equal peeps + 1, companies(:first_firm).developers.count + end + def test_clear_associations assert_queries(2) { posts(:welcome);posts(:welcome).people(true) } -- cgit v1.2.3