diff options
author | Pratik Naik <pratiknaik@gmail.com> | 2010-01-01 22:54:23 +0530 |
---|---|---|
committer | Pratik Naik <pratiknaik@gmail.com> | 2010-01-01 22:54:26 +0530 |
commit | 752813016ed227ecfbe0bf69c92de2e2c3e7a988 (patch) | |
tree | 8253ea85ddd044bfdd3107257308bfd486aa89f8 /spec/arel/engines/sql/unit/relations/table_spec.rb | |
parent | c836c3ed10110d0446c4fce87d36c3f6c39b3cda (diff) | |
download | rails-752813016ed227ecfbe0bf69c92de2e2c3e7a988.tar.gz rails-752813016ed227ecfbe0bf69c92de2e2c3e7a988.tar.bz2 rails-752813016ed227ecfbe0bf69c92de2e2c3e7a988.zip |
Add support for table aliasing
Example :
users = Table(:users, :as => :accounts)
users.to_sql
=> SELECT `accounts`.`id`, `accounts`.`name` FROM `users` AS `accounts`
Diffstat (limited to 'spec/arel/engines/sql/unit/relations/table_spec.rb')
-rw-r--r-- | spec/arel/engines/sql/unit/relations/table_spec.rb | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/spec/arel/engines/sql/unit/relations/table_spec.rb b/spec/arel/engines/sql/unit/relations/table_spec.rb index 92e4549028..977eb343e3 100644 --- a/spec/arel/engines/sql/unit/relations/table_spec.rb +++ b/spec/arel/engines/sql/unit/relations/table_spec.rb @@ -26,6 +26,26 @@ module Arel end end + describe '#as' do + it "manufactures a simple select query using aliases" do + sql = @relation.as(:super_users).to_sql + + adapter_is :mysql do + sql.should be_like(%Q{ + SELECT `super_users`.`id`, `super_users`.`name` + FROM `users` AS `super_users` + }) + end + + adapter_is_not :mysql do + sql.should be_like(%Q{ + SELECT "super_users"."id", "super_users"."name" + FROM "users" AS "super_users" + }) + end + end + end + describe '#column_for' do it "returns the column corresponding to the attribute" do @relation.column_for(@relation[:id]).should == @relation.columns.detect { |c| c.name == 'id' } |