Merge pull request #61 from github/3-0-github+ar-3-1+fix-broken-where-behaviour

[3.0+AR3.1] Backport broken where merge fix
This commit is contained in:
Charlie Somerville
2014-04-20 12:55:56 +10:00
4 changed files with 19 additions and 22 deletions

View File

@@ -31,22 +31,7 @@ module ActiveRecord
merged_wheres = @where_values + r.where_values
unless @where_values.empty?
# Remove duplicates, last one wins.
seen = Hash.new { |h,table| h[table] = {} }
merged_wheres = merged_wheres.reverse.reject { |w|
nuke = false
if w.respond_to?(:operator) && w.operator == :==
name = w.left.name
table = w.left.relation.name
nuke = seen[table][name]
seen[table][name] = true
end
nuke
}.reverse
end
merged_relation.where_values = merged_wheres
merged_relation.where_values = merged_wheres.uniq
(Relation::SINGLE_VALUE_METHODS - [:lock, :create_with]).each do |method|
value = r.send(:"#{method}_value")

View File

@@ -981,10 +981,16 @@ class EagerAssociationTest < ActiveRecord::TestCase
LazyReader.create! :person => people(:susan), :post => post
assert_equal 1, post.lazy_readers.to_a.size
assert_equal 2, post.lazy_readers_skimmers_or_not.to_a.size
# This test relied on some completely broken and incorrect behaviour in
# ActiveRecord that we've fixed.
#
# assert_equal 2, post.lazy_readers_skimmers_or_not.to_a.size
assert_equal 1, post.lazy_readers_skimmers_or_not.to_a.size
post_with_readers = Post.includes(:lazy_readers_skimmers_or_not).find(post.id)
assert_equal 2, post_with_readers.lazy_readers_skimmers_or_not.to_a.size
assert_equal 1, post_with_readers.lazy_readers_skimmers_or_not.to_a.size
end
def test_include_has_many_using_primary_key

View File

@@ -364,11 +364,11 @@ class NamedScopeTest < ActiveRecord::TestCase
def test_chaining_should_use_latest_conditions_when_searching
# Normal hash conditions
assert_equal Topic.where(:approved => true).to_a, Topic.rejected.approved.all
assert_equal Topic.where(:approved => false).to_a, Topic.approved.rejected.all
assert_equal [], Topic.rejected.approved.all
assert_equal [], Topic.approved.rejected.all
# Nested hash conditions with same keys
assert_equal [posts(:sti_comments)], Post.with_special_comments.with_very_special_comments.all
assert_equal [], Post.with_special_comments.with_very_special_comments.all
# Nested hash conditions with different keys
assert_equal [posts(:sti_comments)], Post.with_special_comments.with_post(4).all.uniq

View File

@@ -278,7 +278,13 @@ class HasManyScopingTest< ActiveRecord::TestCase
def test_should_default_scope_on_associations_is_overriden_by_association_conditions
reference = references(:michael_unicyclist).becomes(BadReference)
assert_equal [reference], people(:michael).fixed_bad_references
# This test relied on some completely broken and incorrect behaviour in
# ActiveRecord that we've fixed.
#
# assert_equal [reference], people(:michael).fixed_bad_references
assert_equal [], people(:michael).fixed_bad_references
end
def test_should_maintain_default_scope_on_eager_loaded_associations