Skip to content

Commit

Permalink
Add order to tests that rely on db ordering, to fix failing tests on pg
Browse files Browse the repository at this point in the history
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.

Conflicts:

	activerecord/test/cases/associations/join_model_test.rb
	activerecord/test/cases/associations/nested_through_associations_test.rb
	activerecord/test/cases/clone_test.rb
	activerecord/test/cases/dup_test.rb
	activerecord/test/cases/relations_test.rb
	activerecord/test/cases/yaml_serialization_test.rb
  • Loading branch information
carlosantoniodasilva committed Mar 23, 2012
1 parent 8645745 commit a9fdefd
Show file tree
Hide file tree
Showing 10 changed files with 22 additions and 22 deletions.
Expand Up @@ -656,7 +656,7 @@ def test_clearing_an_association_collection
end

def test_clearing_updates_counter_cache
topic = Topic.first
topic = Topic.order(:id).first

topic.replies.clear
topic.reload
Expand Down Expand Up @@ -736,14 +736,14 @@ def test_dependent_association_respects_optional_hash_conditions_on_delete
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_attribute(: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
Expand Down Expand Up @@ -909,13 +909,12 @@ def test_depends_and_nullify

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

Expand Down
6 changes: 3 additions & 3 deletions activerecord/test/cases/associations/join_model_test.rb
Expand Up @@ -384,7 +384,7 @@ def test_has_many_through_has_many_find_by_id
end

def test_has_many_through_polymorphic_has_one
assert_equal Tagging.find(1,2).sort_by { |t| t.id }, authors(:david).taggings
assert_equal Tagging.find(1,2).sort_by { |t| t.id }, authors(:david).taggings.order(:id)
end

def test_has_many_through_polymorphic_has_many
Expand Down Expand Up @@ -441,7 +441,7 @@ def test_add_to_self_referential_has_many_through
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
Expand Down Expand Up @@ -634,7 +634,7 @@ def test_preload_polymorphic_has_many_through
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
Expand Down
4 changes: 2 additions & 2 deletions activerecord/test/cases/finder_test.rb
Expand Up @@ -103,8 +103,8 @@ def test_exists_returns_true_with_one_record_and_no_args
def test_exists_with_nil_arg
assert !Topic.exists?(nil)
assert Topic.exists?
assert !Topic.first.replies.exists?(nil)
assert Topic.first.replies.exists?
assert !Topic.order(:id).first.replies.exists?(nil)
assert Topic.order(:id).first.replies.exists?
end

def test_does_not_exist_with_empty_table_and_no_args_given
Expand Down
4 changes: 2 additions & 2 deletions activerecord/test/cases/json_serialization_test.rb
Expand Up @@ -198,7 +198,7 @@ def test_should_allow_includes_for_list_of_authors
['"name":"David"', '"posts":[', '{"id":1}', '{"id":2}', '{"id":4}',
'{"id":5}', '{"id":6}', '"name":"Mary"', '"posts":[{"id":7}]'].each do |fragment|
assert json.include?(fragment), json
end
end
end

def test_should_allow_options_for_hash_of_authors
Expand All @@ -210,7 +210,7 @@ def test_should_allow_options_for_hash_of_authors
end

def test_should_be_able_to_encode_relation
authors_relation = Author.where(:id => [@david.id, @mary.id])
authors_relation = Author.where(:id => [@david.id, @mary.id]).order(:id)

json = ActiveSupport::JSON.encode authors_relation, :only => :name
assert_equal '[{"author":{"name":"David"}},{"author":{"name":"Mary"}}]', json
Expand Down
2 changes: 1 addition & 1 deletion activerecord/test/cases/nested_attributes_test.rb
Expand Up @@ -850,7 +850,7 @@ def setup

def test_should_update_existing_records_with_non_standard_primary_key
@owner.update_attributes(@params)
assert_equal ['Foo', 'Bar'], @owner.pets.map(&:name)
assert_equal %w(Bar Foo), @owner.pets.map(&:name).sort
end

def test_attr_accessor_of_child_should_be_value_provided_during_update_attributes
Expand Down
11 changes: 6 additions & 5 deletions activerecord/test/cases/persistence_test.rb
Expand Up @@ -17,15 +17,16 @@
require 'active_support/core_ext/exception'

class PersistencesTest < ActiveRecord::TestCase
fixtures :topics, :companies, :developers, :projects, :computers, :accounts, :minimalistics,
'warehouse-things', :authors, :categorizations, :categories, :posts, :minivans

fixtures :topics, :companies, :developers, :projects, :computers, :accounts, :minimalistics, 'warehouse-things', :authors, :categorizations, :categories, :posts, :minivans

# Oracle UPDATE does not support ORDER BY
unless current_adapter?(:OracleAdapter)
# Skip databases that don't support UPDATE + ORDER BY
unless current_adapter?(:OracleAdapter, :PostgreSQLAdapter)
def test_update_all_ignores_order_without_limit_from_association
author = authors(:david)
assert_nothing_raised do
assert_equal author.posts_with_comments_and_categories.length, author.posts_with_comments_and_categories.update_all([ "body = ?", "bulk update!" ])
assert_equal author.posts_with_comments_and_categories.length,
author.posts_with_comments_and_categories.update_all([ "body = ?", "bulk update!" ])
end
end

Expand Down
2 changes: 1 addition & 1 deletion activerecord/test/cases/relations_test.rb
Expand Up @@ -570,7 +570,7 @@ def test_relation_merging_with_locks

def test_relation_merging_with_preload
[Post.scoped.merge(Post.preload(:author)), Post.preload(:author).merge(Post.scoped)].each do |posts|
assert_queries(2) { assert posts.first.author }
assert_queries(2) { assert posts.order(:id).first.author }
end
end

Expand Down
2 changes: 1 addition & 1 deletion activerecord/test/cases/timestamp_test.rb
Expand Up @@ -10,7 +10,7 @@ class TimestampTest < ActiveRecord::TestCase
fixtures :developers, :owners, :pets, :toys, :cars, :tasks

def setup
@developer = Developer.first
@developer = Developer.order(:id).first
@developer.update_attribute(:updated_at, Time.now.prev_month)
@previously_updated_at = @developer.updated_at
end
Expand Down
2 changes: 1 addition & 1 deletion activerecord/test/cases/yaml_serialization_test.rb
Expand Up @@ -12,7 +12,7 @@ def test_to_yaml_with_time_with_zone_should_not_raise_exception
end

def test_roundtrip
topic = Topic.first
topic = Topic.order(:id).first
assert topic
t = YAML.load YAML.dump topic
assert_equal topic, t
Expand Down
2 changes: 1 addition & 1 deletion activerecord/test/models/company.rb
Expand Up @@ -92,7 +92,7 @@ class Firm < Company
end

class DependentFirm < Company
has_one :account, :foreign_key => "firm_id", :dependent => :nullify
has_one :account, :foreign_key => "firm_id", :dependent => :nullify, :order => "accounts.id"
has_many :companies, :foreign_key => 'client_of', :dependent => :nullify
end

Expand Down

0 comments on commit a9fdefd

Please sign in to comment.