aboutsummaryrefslogtreecommitdiffstats
path: root/spec
diff options
context:
space:
mode:
authorNick Kallen <nkallen@nick-kallens-computer-2.local>2008-05-05 11:22:48 -0700
committerNick Kallen <nkallen@nick-kallens-computer-2.local>2008-05-05 11:22:48 -0700
commitb9e90e4e55290172d7c5918319fd5fe35aa6a10e (patch)
treeef63a7974dd97012fc72dc3d33ec25f0884620e7 /spec
parentcd428ee66498146d3dc14f58c6534d79ab124b45 (diff)
downloadrails-b9e90e4e55290172d7c5918319fd5fe35aa6a10e.tar.gz
rails-b9e90e4e55290172d7c5918319fd5fe35aa6a10e.tar.bz2
rails-b9e90e4e55290172d7c5918319fd5fe35aa6a10e.zip
better column disambiguation
Diffstat (limited to 'spec')
-rw-r--r--spec/arel/unit/primitives/attribute_spec.rb29
-rw-r--r--spec/arel/unit/relations/join_spec.rb17
2 files changed, 46 insertions, 0 deletions
diff --git a/spec/arel/unit/primitives/attribute_spec.rb b/spec/arel/unit/primitives/attribute_spec.rb
index 561c47da16..b253892b58 100644
--- a/spec/arel/unit/primitives/attribute_spec.rb
+++ b/spec/arel/unit/primitives/attribute_spec.rb
@@ -57,6 +57,35 @@ module Arel
end
end
+ describe '/' do
+ before do
+ @aliased_relation = @relation.alias
+ @doubly_aliased_relation = @aliased_relation.alias.alias.alias.alias
+ end
+
+ describe 'when dividing two identical attributes' do
+ it "returns 1.0" do
+ (@relation[:id] / @relation[:id]).should == 1.0
+ (@aliased_relation[:id] / @aliased_relation[:id]).should == 1.0
+ end
+ end
+
+ describe 'when dividing two unrelated attributes' do
+ it "returns 0.0" do
+ (@relation[:id] / @relation[:name]).should == 0.0
+ end
+ end
+
+ describe 'when dividing two similar attributes' do
+ it 'returns a the highest score for the most similar attributes' do
+ (@aliased_relation[:id] / @relation[:id]) \
+ .should == (@aliased_relation[:id] / @relation[:id])
+ (@aliased_relation[:id] / @relation[:id]) \
+ .should < (@aliased_relation[:id] / @aliased_relation[:id])
+ end
+ end
+ end
+
describe 'hashing' do
it "implements hash equality" do
Attribute.new(@relation, 'name').should hash_the_same_as(Attribute.new(@relation, 'name'))
diff --git a/spec/arel/unit/relations/join_spec.rb b/spec/arel/unit/relations/join_spec.rb
index d517da8c1f..a538c8af68 100644
--- a/spec/arel/unit/relations/join_spec.rb
+++ b/spec/arel/unit/relations/join_spec.rb
@@ -203,6 +203,23 @@ module Arel
end
end
end
+
+ describe 'something really really complex' do
+ it '' do
+ users = @relation1
+ photos = @relation2
+ users_2 = users.alias
+ photos_2 = photos.alias
+ r = users \
+ .join(photos) \
+ .on(photos[:user_id].eq users[:id]) \
+ .join(users_2) \
+ .on(users_2[:id].eq photos[:user_id]) \
+ .join(photos_2) \
+ .on(users_2[:id].eq photos_2[:user_id])
+ r.relation_for(photos[:user_id]).should == photos
+ end
+ end
describe '[]' do
describe 'when given an attribute belonging to both sub-relations' do