diff options
author | Nick Kallen <nkallen@nick-kallens-computer-2.local> | 2008-01-13 17:43:00 -0800 |
---|---|---|
committer | Nick Kallen <nkallen@nick-kallens-computer-2.local> | 2008-01-13 17:43:00 -0800 |
commit | 2e63ac91302e2df397a286fdaf9cea51635071a6 (patch) | |
tree | 5d8eb92b25c45ddbf9bb35655da34bdaecf44f1f /spec | |
parent | 59cc0e235285feeeb652ebc17a128c769e2c9d8c (diff) | |
download | rails-2e63ac91302e2df397a286fdaf9cea51635071a6.tar.gz rails-2e63ac91302e2df397a286fdaf9cea51635071a6.tar.bz2 rails-2e63ac91302e2df397a286fdaf9cea51635071a6.zip |
removed support for scalar select (will return later); added support for aliased tables
Diffstat (limited to 'spec')
-rw-r--r-- | spec/active_relation/primitives/attribute_spec.rb | 4 | ||||
-rw-r--r-- | spec/active_relation/relations/alias_spec.rb | 36 | ||||
-rw-r--r-- | spec/active_relation/relations/base_spec.rb | 8 | ||||
-rw-r--r-- | spec/active_relation/relations/table_spec.rb | 2 |
4 files changed, 41 insertions, 9 deletions
diff --git a/spec/active_relation/primitives/attribute_spec.rb b/spec/active_relation/primitives/attribute_spec.rb index 2aad844659..f1aa404a34 100644 --- a/spec/active_relation/primitives/attribute_spec.rb +++ b/spec/active_relation/primitives/attribute_spec.rb @@ -16,6 +16,10 @@ describe ActiveRelation::Primitives::Attribute do it "manufactures an attribute name prefixed with the relation's name" do @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 diff --git a/spec/active_relation/relations/alias_spec.rb b/spec/active_relation/relations/alias_spec.rb new file mode 100644 index 0000000000..6f25df3ddb --- /dev/null +++ b/spec/active_relation/relations/alias_spec.rb @@ -0,0 +1,36 @@ +require File.join(File.dirname(__FILE__), '..', '..', 'spec_helper') + +describe ActiveRelation::Relations::Alias do + before do + @relation = ActiveRelation::Relations::Table.new(:users) + @alias_relation = @relation.as(:foo) + end + + describe '#name' do + it 'returns the alias' do + @alias_relation.name.should == :foo + end + end + + describe '#attributes' do + it 'manufactures sql deleting a table relation' do + @alias_relation.attributes.should == @relation.attributes.collect { |a| ActiveRelation::Primitives::Attribute.new(@alias_relation, a.name) } + end + end + + describe '[]' do + it 'manufactures attributes associated with the aliased relation' do + @alias_relation[:id].relation.should == @alias_relation + @alias_relation[:does_not_exist].should be_nil + end + end + + describe '#to_sql' do + it "manufactures an aliased select query" do + @alias_relation.to_sql.should be_like(""" + SELECT `foo`.`name`, `foo`.`id` + FROM `users` AS `foo` + """) + end + end +end
\ No newline at end of file diff --git a/spec/active_relation/relations/base_spec.rb b/spec/active_relation/relations/base_spec.rb index db112e679a..18063757df 100644 --- a/spec/active_relation/relations/base_spec.rb +++ b/spec/active_relation/relations/base_spec.rb @@ -99,12 +99,4 @@ describe ActiveRelation::Relations::Base do end end end - - describe '#to_sql' do - it "manufactures sql with scalar selects" do - @relation1.as(:tobias).to_sql(:use_parens => true).should be_like(""" - (SELECT `foo`.`name`, `foo`.`id` FROM `foo`) AS tobias - """) - end - end end
\ No newline at end of file diff --git a/spec/active_relation/relations/table_spec.rb b/spec/active_relation/relations/table_spec.rb index 62b8e44980..1418ac203f 100644 --- a/spec/active_relation/relations/table_spec.rb +++ b/spec/active_relation/relations/table_spec.rb @@ -6,7 +6,7 @@ describe ActiveRelation::Relations::Table do end describe '#to_sql' do - it "returns a simple SELECT query" do + it "manufactures a simple select query" do @relation.to_sql.should be_like(""" SELECT `users`.`name`, `users`.`id` FROM `users` |