From 4cf4ea506def9a3e36cc90a2b0e073cbb8fc43df Mon Sep 17 00:00:00 2001 From: Neeraj Singh Date: Sun, 28 Jul 2013 16:51:55 +0530 Subject: make test not depend on order `NestedThroughAssociationsTest` adds records to `member_details` table. When test performs `@member_details[0]` then the order of record is not guaranteed. Hence it is best to start with a clean slate by deleting unwanted records. --- .../test/cases/associations/has_one_through_associations_test.rb | 1 + 1 file changed, 1 insertion(+) (limited to 'activerecord/test/cases/associations/has_one_through_associations_test.rb') diff --git a/activerecord/test/cases/associations/has_one_through_associations_test.rb b/activerecord/test/cases/associations/has_one_through_associations_test.rb index 90c557e886..01a4137a5d 100644 --- a/activerecord/test/cases/associations/has_one_through_associations_test.rb +++ b/activerecord/test/cases/associations/has_one_through_associations_test.rb @@ -191,6 +191,7 @@ class HasOneThroughAssociationsTest < ActiveRecord::TestCase end def test_preloading_has_one_through_on_belongs_to + MemberDetail.delete_all assert_not_nil @member.member_type @organization = organizations(:nsa) @member_detail = MemberDetail.new -- cgit v1.2.3 From 06ac57776cf9ca75521b1f4dd2a32edb53a572e6 Mon Sep 17 00:00:00 2001 From: Akira Matsuda Date: Fri, 26 Jul 2013 23:22:41 +0900 Subject: Unneeded assertion --- .../test/cases/associations/has_one_through_associations_test.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'activerecord/test/cases/associations/has_one_through_associations_test.rb') diff --git a/activerecord/test/cases/associations/has_one_through_associations_test.rb b/activerecord/test/cases/associations/has_one_through_associations_test.rb index 01a4137a5d..f2723f2e18 100644 --- a/activerecord/test/cases/associations/has_one_through_associations_test.rb +++ b/activerecord/test/cases/associations/has_one_through_associations_test.rb @@ -202,7 +202,7 @@ class HasOneThroughAssociationsTest < ActiveRecord::TestCase end @new_detail = @member_details[0] assert @new_detail.send(:association, :member_type).loaded? - assert_not_nil assert_no_queries { @new_detail.member_type } + assert_no_queries { @new_detail.member_type } end def test_save_of_record_with_loaded_has_one_through -- cgit v1.2.3 From 35fd2d401938df1afc595de9b87dadd4421f44a5 Mon Sep 17 00:00:00 2001 From: Godfrey Chan Date: Fri, 29 Nov 2013 19:21:49 -0800 Subject: Raise `ArgumentError` when `has_one` is used with `counter_cache` Previously, the `has_one` macro incorrectly accepts the `counter_cache` option due to a bug, although that options was never supported nor functional on `has_one` and `has_one ... through` relationships. It now correctly raises an `ArgumentError` when passed that option. For reference, this bug was introduced in 52f8e4b9. --- .../test/cases/associations/has_one_through_associations_test.rb | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'activerecord/test/cases/associations/has_one_through_associations_test.rb') diff --git a/activerecord/test/cases/associations/has_one_through_associations_test.rb b/activerecord/test/cases/associations/has_one_through_associations_test.rb index f2723f2e18..a2725441b3 100644 --- a/activerecord/test/cases/associations/has_one_through_associations_test.rb +++ b/activerecord/test/cases/associations/has_one_through_associations_test.rb @@ -315,4 +315,12 @@ class HasOneThroughAssociationsTest < ActiveRecord::TestCase def test_has_one_through_with_custom_select_on_join_model_default_scope assert_equal clubs(:boring_club), members(:groucho).selected_club end + + def test_has_one_through_relationship_cannot_have_a_counter_cache + assert_raise(ArgumentError) do + Class.new(ActiveRecord::Base) do + has_one :thing, through: :other_thing, counter_cache: true + end + end + end end -- cgit v1.2.3