aboutsummaryrefslogtreecommitdiffstats
path: root/spec/active_relation/relations/projection_spec.rb
diff options
context:
space:
mode:
authorNick Kallen <nkallen@nick-kallens-computer-2.local>2008-02-16 16:37:00 -0800
committerNick Kallen <nkallen@nick-kallens-computer-2.local>2008-02-16 16:37:00 -0800
commitd0ba361c93aa94865ccfe739e9ab65654771e38e (patch)
tree56ac5623fd0b77eeb9642ed752e31d2f5f08cc9c /spec/active_relation/relations/projection_spec.rb
parent28b11fdf4d4e5cd4b98d6c79fc88999a41532103 (diff)
downloadrails-d0ba361c93aa94865ccfe739e9ab65654771e38e.tar.gz
rails-d0ba361c93aa94865ccfe739e9ab65654771e38e.tar.bz2
rails-d0ba361c93aa94865ccfe739e9ab65654771e38e.zip
more test coverage
Diffstat (limited to 'spec/active_relation/relations/projection_spec.rb')
-rw-r--r--spec/active_relation/relations/projection_spec.rb39
1 files changed, 24 insertions, 15 deletions
diff --git a/spec/active_relation/relations/projection_spec.rb b/spec/active_relation/relations/projection_spec.rb
index e792eec3b8..739a16c8ef 100644
--- a/spec/active_relation/relations/projection_spec.rb
+++ b/spec/active_relation/relations/projection_spec.rb
@@ -3,36 +3,45 @@ require File.join(File.dirname(__FILE__), '..', '..', 'spec_helper')
module ActiveRelation
describe Projection do
before do
- @relation1 = Table.new(:foo)
- @relation2 = Table.new(:bar)
- @attribute1 = @relation1[:id]
- @attribute2 = @relation2[:id]
+ @relation = Table.new(:users)
+ @attribute = @relation[:id]
end
-
- it "needs to test that [] is limited" do
- pending
+
+ describe '#attributes' do
+ before do
+ @projection = Projection.new(@relation, @attribute)
+ end
+
+ it "manufactures attributes associated with the projection relation" do
+ @projection.attributes.should == [@attribute].collect { |a| a.bind(@projection) }
+ end
end
describe '==' do
+ before do
+ @another_relation = Table.new(:photos)
+ @another_attribute = @relation[:name]
+ end
+
it "obtains if the relations and attributes are identical" do
- Projection.new(@relation1, @attribute1, @attribute2).should == Projection.new(@relation1, @attribute1, @attribute2)
- Projection.new(@relation1, @attribute1).should_not == Projection.new(@relation2, @attribute1)
- Projection.new(@relation1, @attribute1).should_not == Projection.new(@relation1, @attribute2)
+ Projection.new(@relation, @attribute).should == Projection.new(@relation, @attribute)
+ Projection.new(@relation, @attribute).should_not == Projection.new(@another_relation, @attribute)
+ Projection.new(@relation, @attribute).should_not == Projection.new(@relation, @another_attribute)
end
end
describe '#qualify' do
it "distributes over the relation and attributes" do
- Projection.new(@relation1, @attribute1).qualify. \
- should == Projection.new(@relation1.qualify, @attribute1.qualify)
+ Projection.new(@relation, @attribute).qualify. \
+ should == Projection.new(@relation.qualify, @attribute.qualify)
end
end
describe '#to_sql' do
it "manufactures sql with a limited select clause" do
- Projection.new(@relation1, @attribute1).to_sql.should be_like("""
- SELECT `foo`.`id`
- FROM `foo`
+ Projection.new(@relation, @attribute).to_sql.should be_like("""
+ SELECT `users`.`id`
+ FROM `users`
""")
end
end