From b332891b2ab4188e9d39737f4d214812afa3ce2c Mon Sep 17 00:00:00 2001 From: Carlos Antonio da Silva Date: Thu, 22 Mar 2012 11:08:04 -0300 Subject: Add order to tests that rely on db ordering, to fix failing tests on pg Also skip persistente tests related to UPDATE + ORDER BY for postgresql PostgreSQL does not support updates with order by, and these tests are failing randomly depending on the fixture loading order now. --- .../cases/associations/has_many_associations_test.rb | 9 ++++----- .../test/cases/associations/join_model_test.rb | 6 +++--- .../associations/nested_through_associations_test.rb | 18 +++++++++--------- 3 files changed, 16 insertions(+), 17 deletions(-) (limited to 'activerecord/test/cases/associations') diff --git a/activerecord/test/cases/associations/has_many_associations_test.rb b/activerecord/test/cases/associations/has_many_associations_test.rb index ead8eaf342..f7b2b42959 100644 --- a/activerecord/test/cases/associations/has_many_associations_test.rb +++ b/activerecord/test/cases/associations/has_many_associations_test.rb @@ -912,7 +912,7 @@ class HasManyAssociationsTest < ActiveRecord::TestCase end def test_clearing_updates_counter_cache - topic = Topic.first + topic = Topic.order(:id).first assert_difference 'topic.reload.replies_count', -1 do topic.replies.clear @@ -1001,14 +1001,14 @@ class HasManyAssociationsTest < ActiveRecord::TestCase end def test_delete_all_association_with_primary_key_deletes_correct_records - firm = Firm.find(:first) + firm = Firm.order(:id).first # break the vanilla firm_id foreign key assert_equal 2, firm.clients.count firm.clients.first.update_column(:firm_id, nil) assert_equal 1, firm.clients(true).count assert_equal 1, firm.clients_using_primary_key_with_delete_all.count old_record = firm.clients_using_primary_key_with_delete_all.first - firm = Firm.find(:first) + firm = Firm.order(:id).first firm.destroy assert_nil Client.find_by_id(old_record.id) end @@ -1168,13 +1168,12 @@ class HasManyAssociationsTest < ActiveRecord::TestCase core = companies(:rails_core) assert_equal accounts(:rails_core_account), core.account - assert_equal companies(:leetsoft, :jadedpixel), core.companies + assert_equal companies(:leetsoft, :jadedpixel), core.companies.order(:id) core.destroy assert_nil accounts(:rails_core_account).reload.firm_id assert_nil companies(:leetsoft).reload.client_of assert_nil companies(:jadedpixel).reload.client_of - assert_equal num_accounts, Account.count end diff --git a/activerecord/test/cases/associations/join_model_test.rb b/activerecord/test/cases/associations/join_model_test.rb index 995afef796..6f5644ada0 100644 --- a/activerecord/test/cases/associations/join_model_test.rb +++ b/activerecord/test/cases/associations/join_model_test.rb @@ -403,7 +403,7 @@ class AssociationsJoinModelTest < ActiveRecord::TestCase end def test_has_many_through_polymorphic_has_one - assert_equal Tagging.find(1,2).sort_by { |t| t.id }, authors(:david).tagging + assert_equal Tagging.find(1,2).sort_by { |t| t.id }, authors(:david).tagging.order(:id) end def test_has_many_through_polymorphic_has_many @@ -452,7 +452,7 @@ class AssociationsJoinModelTest < ActiveRecord::TestCase end def test_has_many_through_uses_conditions_specified_on_the_has_many_association - author = Author.find(:first) + author = Author.order(:id).first assert_present author.comments assert_blank author.nonexistant_comments end @@ -649,7 +649,7 @@ class AssociationsJoinModelTest < ActiveRecord::TestCase end def test_preload_polymorph_many_types - taggings = Tagging.find :all, :include => :taggable, :conditions => ['taggable_type != ?', 'FakeModel'] + taggings = Tagging.find :all, :include => :taggable, :conditions => ['taggable_type != ?', 'FakeModel'], :order => 'id' assert_no_queries do taggings.first.taggable.id taggings[1].taggable.id diff --git a/activerecord/test/cases/associations/nested_through_associations_test.rb b/activerecord/test/cases/associations/nested_through_associations_test.rb index f920e09410..5b551d8a9a 100644 --- a/activerecord/test/cases/associations/nested_through_associations_test.rb +++ b/activerecord/test/cases/associations/nested_through_associations_test.rb @@ -55,7 +55,7 @@ class NestedThroughAssociationsTest < ActiveRecord::TestCase end def test_has_many_through_has_many_with_has_many_through_source_reflection_preload - authors = assert_queries(5) { Author.includes(:tags).to_a } + authors = assert_queries(5) { Author.includes(:tags).order(:id).to_a } general = tags(:general) assert_no_queries do @@ -84,7 +84,7 @@ class NestedThroughAssociationsTest < ActiveRecord::TestCase def test_has_many_through_has_many_through_with_has_many_source_reflection_preload luke, david = subscribers(:first), subscribers(:second) - authors = assert_queries(4) { Author.includes(:subscribers).to_a } + authors = assert_queries(4) { Author.includes(:subscribers).order(:id).to_a } assert_no_queries do assert_equal [luke, david, david], authors.first.subscribers.sort_by(&:nick) end @@ -106,10 +106,10 @@ class NestedThroughAssociationsTest < ActiveRecord::TestCase end def test_has_many_through_has_one_with_has_one_through_source_reflection_preload - members = assert_queries(4) { Member.includes(:nested_member_types).to_a } + members = assert_queries(4) { Member.includes(:nested_member_types).order(:id).to_a } founding = member_types(:founding) assert_no_queries do - assert_equal [founding], members.first.nested_member_types + assert_equal [founding], members.first.nested_member_types.to_a end end @@ -128,10 +128,10 @@ class NestedThroughAssociationsTest < ActiveRecord::TestCase end def test_has_many_through_has_one_through_with_has_one_source_reflection_preload - members = assert_queries(4) { Member.includes(:nested_sponsors).to_a } + members = assert_queries(4) { Member.includes(:nested_sponsors).order(:id).to_a } mustache = sponsors(:moustache_club_sponsor_for_groucho) assert_no_queries do - assert_equal [mustache], members.first.nested_sponsors + assert_equal [mustache], members.first.nested_sponsors.to_a end end @@ -163,7 +163,7 @@ class NestedThroughAssociationsTest < ActiveRecord::TestCase def test_has_many_through_has_one_with_has_many_through_source_reflection_preload_via_joins assert_includes_and_joins_equal( - Member.where('member_details.id' => member_details(:groucho).id).order('member_details.id'), + Member.where('member_details.id' => member_details(:groucho).id).order('members.id'), [members(:groucho), members(:some_other_guy)], :organization_member_details ) @@ -193,7 +193,7 @@ class NestedThroughAssociationsTest < ActiveRecord::TestCase def test_has_many_through_has_one_through_with_has_many_source_reflection_preload_via_joins assert_includes_and_joins_equal( - Member.where('member_details.id' => member_details(:groucho).id).order('member_details.id'), + Member.where('member_details.id' => member_details(:groucho).id).order('members.id'), [members(:groucho), members(:some_other_guy)], :organization_member_details_2 ) @@ -285,7 +285,7 @@ class NestedThroughAssociationsTest < ActiveRecord::TestCase end def test_has_many_through_has_many_through_with_belongs_to_source_reflection_preload - authors = assert_queries(5) { Author.includes(:tagging_tags).to_a } + authors = assert_queries(5) { Author.includes(:tagging_tags).order(:id).to_a } general = tags(:general) assert_no_queries do -- cgit v1.2.3