mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
this is as close as it's been
This commit is contained in:
parent
c96155c4fd
commit
b06d351b70
4 changed files with 42 additions and 2 deletions
|
@ -39,6 +39,11 @@ module Arel
|
|||
|
||||
def original_relation
|
||||
relation.relation_for(self)
|
||||
# root.relation
|
||||
end
|
||||
|
||||
def original_attribute
|
||||
original_relation[self]
|
||||
end
|
||||
|
||||
module Transformations
|
||||
|
@ -85,6 +90,7 @@ module Arel
|
|||
if other then (history & other.history).size.to_f / Set.new(history + other.history).size
|
||||
else 0
|
||||
end
|
||||
# 1 / (history.index(other) || -1)
|
||||
end
|
||||
end
|
||||
include Congruence
|
||||
|
|
|
@ -135,10 +135,9 @@ module Arel
|
|||
attributes.detect { |a| a.named?(name) }
|
||||
end
|
||||
|
||||
# TESTME - added original_attribute because of AR
|
||||
def find_attribute_matching_attribute(attribute)
|
||||
attributes.select { |a| a.match?(attribute) }.max do |a1, a2|
|
||||
(attribute / a1.root) <=> (attribute / a2.root)
|
||||
(a1.original_attribute / attribute) <=> (a2.original_attribute / attribute)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -107,6 +107,13 @@ module Arel
|
|||
.on(@predicate) \
|
||||
.should disambiguate_attributes(@relation1[:id], @relation2[:id])
|
||||
end
|
||||
|
||||
it '' do
|
||||
r0 = @relation1.select(@predicate)
|
||||
r1 = r0.alias
|
||||
r = r0.join(r1).on(@predicate)
|
||||
r.should disambiguate_attributes(r0[:id], r1[:id])
|
||||
end
|
||||
end
|
||||
|
||||
describe 'when the right relation is extremely compound' do
|
||||
|
|
28
spec/matchers/disambiguate_attributes.rb
Normal file
28
spec/matchers/disambiguate_attributes.rb
Normal file
|
@ -0,0 +1,28 @@
|
|||
module DisambiguateAttributesMatcher
|
||||
class DisambiguateAttributes
|
||||
def initialize(attributes)
|
||||
@attributes = attributes
|
||||
end
|
||||
|
||||
def matches?(actual)
|
||||
@actual = actual
|
||||
attribute1, attribute2 = @attributes
|
||||
@actual[attribute1].descends_from?(attribute1) &&
|
||||
!@actual[attribute1].descends_from?(attribute2) &&
|
||||
@actual[attribute2].descends_from?(attribute2)
|
||||
end
|
||||
|
||||
def failure_message
|
||||
""
|
||||
# "expected #{@actual} to disambiguate its attributes"
|
||||
end
|
||||
|
||||
def negative_failure_message
|
||||
"expected #{@actual} to not disambiguate its attributes"
|
||||
end
|
||||
end
|
||||
|
||||
def disambiguate_attributes(*attributes)
|
||||
DisambiguateAttributes.new(attributes)
|
||||
end
|
||||
end
|
Loading…
Reference in a new issue