aboutsummaryrefslogtreecommitdiffstats
path: root/spec/active_relation/primitives/attribute_spec.rb
diff options
context:
space:
mode:
authorNick Kallen <nkallen@nick-kallens-computer-2.local>2008-01-21 18:22:55 -0800
committerNick Kallen <nkallen@nick-kallens-computer-2.local>2008-01-21 18:22:55 -0800
commitd62ace142ce873c72eb916f5a14aa33a67ecfb86 (patch)
tree049a03b997366e770429c85ced3453bc92c2f3d5 /spec/active_relation/primitives/attribute_spec.rb
parentb47ac80a17d7a74e1b5deac0e63a72960a4da453 (diff)
downloadrails-d62ace142ce873c72eb916f5a14aa33a67ecfb86.tar.gz
rails-d62ace142ce873c72eb916f5a14aa33a67ecfb86.tar.bz2
rails-d62ace142ce873c72eb916f5a14aa33a67ecfb86.zip
completed initial functionality for joining with aggregation (the meaning of which is joining on a subselect/derived table); the big change is the introduction of a #projections protected method; this is a private version of #attributes which preserves implementation information (e.g., the name of the function called)
Diffstat (limited to 'spec/active_relation/primitives/attribute_spec.rb')
-rw-r--r--spec/active_relation/primitives/attribute_spec.rb45
1 files changed, 29 insertions, 16 deletions
diff --git a/spec/active_relation/primitives/attribute_spec.rb b/spec/active_relation/primitives/attribute_spec.rb
index 543217b9cf..7f5d4922b8 100644
--- a/spec/active_relation/primitives/attribute_spec.rb
+++ b/spec/active_relation/primitives/attribute_spec.rb
@@ -7,31 +7,43 @@ module ActiveRelation
@relation2 = Table.new(:bar)
end
- describe '#as' do
- it "manufactures an aliased attributed when provided a parameter" do
- @relation1[:id].as(:alias).should == Attribute.new(@relation1, :id, :alias)
+ describe Attribute::Transformations do
+ before do
+ @attribute = Attribute.new(@relation1, :id)
+ end
+
+ describe '#as' do
+ it "manufactures an aliased attributed" do
+ @attribute.as(:alias).should == Attribute.new(@relation1, @attribute.name, :alias)
+ end
end
- end
- describe '#substitute' do
- it "manufactures an attribute with the relation substituted" do
- @relation1[:id].substitute(@relation2).should == Attribute.new(@relation2, :id)
+ describe '#substitute' do
+ it "manufactures an attribute with the relation substituted" do
+ @attribute.substitute(@relation2).should == Attribute.new(@relation2, @attribute.name)
+ end
+ end
+
+ describe '#qualify' do
+ it "manufactures an attribute aliased with that attributes qualified name" do
+ @attribute.qualify.should == Attribute.new(@attribute.relation, @attribute.name, @attribute.qualified_name)
+ end
+ end
+
+ describe '#to_attribute' do
+ it "returns self" do
+ @attribute.to_attribute.should == @attribute
+ end
end
end
-
+
describe '#qualified_name' do
it "manufactures an attribute name prefixed with the relation's name" do
- @relation1[:id].qualified_name.should == 'foo.id'
+ Attribute.new(@relation1, :id).qualified_name.should == 'foo.id'
end
it "manufactures an attribute name prefixed with the relation's aliased name" do
- @relation1.as(:bar)[:id].qualified_name.should == 'bar.id'
- end
- end
-
- describe '#qualify' do
- it "manufactures an attribute aliased with that attributes qualified name" do
- @relation1[:id].qualify.should == @relation1[:id].qualify
+ Attribute.new(@relation1.as(:bar), :id).qualified_name.should == 'bar.id'
end
end
@@ -40,6 +52,7 @@ module ActiveRelation
Attribute.new(@relation1, :name).should == Attribute.new(@relation1, :name)
Attribute.new(@relation1, :name).should_not == Attribute.new(@relation1, :another_name)
Attribute.new(@relation1, :name).should_not == Attribute.new(@relation2, :name)
+ Attribute.new(@relation1, :name).should_not == Aggregation.new(Attribute.new(@relation1, :name), "SUM")
end
end