From 6064001d642fdbd18cdfe2aafc1f17e8fb248bd1 Mon Sep 17 00:00:00 2001 From: Nick Kallen Date: Fri, 16 May 2008 14:43:27 -0700 Subject: additional test coverage for some random complex case --- lib/arel/primitives/attribute.rb | 23 ++++++++++++++--------- lib/arel/relations/compound.rb | 4 ++++ lib/arel/relations/recursion.rb | 10 ++++++++++ lib/arel/relations/relation.rb | 2 +- 4 files changed, 29 insertions(+), 10 deletions(-) (limited to 'lib') diff --git a/lib/arel/primitives/attribute.rb b/lib/arel/primitives/attribute.rb index 9d5b98474f..9fb47d56cf 100644 --- a/lib/arel/primitives/attribute.rb +++ b/lib/arel/primitives/attribute.rb @@ -37,16 +37,9 @@ module Arel ancestor == other.ancestor end - module Origin - def original_relation - relation.relation_for(self) - end - - def original_attribute - original_relation[self] - end + def original_relation + relation.relation_for(self) end - include Origin module Transformations def self.included(klass) @@ -76,6 +69,18 @@ module Arel !(history & other.history).empty? end + def descends_from?(other) + history.include?(other) + end + + def root? + relation.root? + end + + def root + @root ||= history.detect(&:root?) + end + def /(other) if other then (history & other.history).size.to_f / Set.new(history + other.history).size else 0 diff --git a/lib/arel/relations/compound.rb b/lib/arel/relations/compound.rb index 1459c163cf..6f230c3f57 100644 --- a/lib/arel/relations/compound.rb +++ b/lib/arel/relations/compound.rb @@ -11,6 +11,10 @@ module Arel @attributes ||= relation.attributes.collect { |a| a.bind(self) } end + def selects + @selects ||= relation.selects.collect { |s| s.bind(self) } + end + # XXX def relation_for(attribute) join? && relation.relation_for(attribute) || self[attribute] && self diff --git a/lib/arel/relations/recursion.rb b/lib/arel/relations/recursion.rb index fa4d9969c9..ea8109d87d 100644 --- a/lib/arel/relations/recursion.rb +++ b/lib/arel/relations/recursion.rb @@ -9,9 +9,19 @@ module Arel formatter.table self end + def root? + true + end + def relation_for(attribute) self[attribute] && self end end end + + class Relation + def root? + false + end + end end \ No newline at end of file diff --git a/lib/arel/relations/relation.rb b/lib/arel/relations/relation.rb index 884b743f20..25dc75e8ea 100644 --- a/lib/arel/relations/relation.rb +++ b/lib/arel/relations/relation.rb @@ -138,7 +138,7 @@ module Arel # 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.original_attribute) <=> (attribute / a2.original_attribute) + (attribute / a1.root) <=> (attribute / a2.root) end end end -- cgit v1.2.3