aboutsummaryrefslogtreecommitdiffstats
path: root/spec/active_relation/relations/alias_spec.rb
diff options
context:
space:
mode:
authorNick Kallen <nkallen@nick-kallens-computer-2.local>2008-01-13 17:43:00 -0800
committerNick Kallen <nkallen@nick-kallens-computer-2.local>2008-01-13 17:43:00 -0800
commit2e63ac91302e2df397a286fdaf9cea51635071a6 (patch)
tree5d8eb92b25c45ddbf9bb35655da34bdaecf44f1f /spec/active_relation/relations/alias_spec.rb
parent59cc0e235285feeeb652ebc17a128c769e2c9d8c (diff)
downloadrails-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/active_relation/relations/alias_spec.rb')
-rw-r--r--spec/active_relation/relations/alias_spec.rb36
1 files changed, 36 insertions, 0 deletions
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