diff options
author | Nick Kallen <nkallen@nick-kallens-computer-2.local> | 2008-05-26 21:02:23 -0700 |
---|---|---|
committer | Bryan Helmkamp <bryan@brynary.com> | 2009-05-17 15:36:05 -0400 |
commit | a7aacd29460aa137c3b06ee214ff8ffdff8ee365 (patch) | |
tree | e88f8894c830b4f95822ecb970294ca4c793a722 /spec/arel/engines/sql/unit/relations/alias_spec.rb | |
parent | 9d77c08cf8a75636b058c1b85af52ef96e07cee5 (diff) | |
download | rails-a7aacd29460aa137c3b06ee214ff8ffdff8ee365.tar.gz rails-a7aacd29460aa137c3b06ee214ff8ffdff8ee365.tar.bz2 rails-a7aacd29460aa137c3b06ee214ff8ffdff8ee365.zip |
reorganizing tests
Diffstat (limited to 'spec/arel/engines/sql/unit/relations/alias_spec.rb')
-rw-r--r-- | spec/arel/engines/sql/unit/relations/alias_spec.rb | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/spec/arel/engines/sql/unit/relations/alias_spec.rb b/spec/arel/engines/sql/unit/relations/alias_spec.rb new file mode 100644 index 0000000000..83b9113f6d --- /dev/null +++ b/spec/arel/engines/sql/unit/relations/alias_spec.rb @@ -0,0 +1,50 @@ +require File.join(File.dirname(__FILE__), '..', '..', '..', '..', '..', 'spec_helper') + +module Arel + describe Alias do + before do + @relation = Table.new(:users) + end + + describe '==' do + it "obtains if the objects are the same" do + Alias.new(@relation).should_not == Alias.new(@relation) + (aliaz = Alias.new(@relation)).should == aliaz + end + end + + describe '#to_sql' do + describe 'when there is no ambiguity' do + it 'does not alias table names anywhere a table name can appear' do + sql = @relation \ + .where(@relation[:id].eq(1)) \ + .order(@relation[:id]) \ + .project(@relation[:id]) \ + .group(@relation[:id]) \ + .alias \ + .to_sql + + adapter_is :mysql do + sql.should be_like(%Q{ + SELECT `users`.`id` + FROM `users` + WHERE `users`.`id` = 1 + GROUP BY `users`.`id` + ORDER BY `users`.`id` ASC + }) + end + + adapter_is_not :mysql do + sql.should be_like(%Q{ + SELECT "users"."id" + FROM "users" + WHERE "users"."id" = 1 + GROUP BY "users"."id" + ORDER BY "users"."id" ASC + }) + end + end + end + end + end +end |