diff options
author | Nick Kallen <nkallen@nick-kallens-computer-2.local> | 2008-05-16 12:12:30 -0700 |
---|---|---|
committer | Nick Kallen <nkallen@nick-kallens-computer-2.local> | 2008-05-16 12:12:30 -0700 |
commit | 71bb593fb240f8e49931b3e3415a827900a032fd (patch) | |
tree | afc00c01b400135b195b41f22dc463017e4a0c0d /spec/arel/integration/joins/with_compounds_spec.rb | |
parent | e4ee2a35c8dc62efed965bf0023a517c65f1c9e7 (diff) | |
download | rails-71bb593fb240f8e49931b3e3415a827900a032fd.tar.gz rails-71bb593fb240f8e49931b3e3415a827900a032fd.tar.bz2 rails-71bb593fb240f8e49931b3e3415a827900a032fd.zip |
reorganized integration join specs
Diffstat (limited to 'spec/arel/integration/joins/with_compounds_spec.rb')
-rw-r--r-- | spec/arel/integration/joins/with_compounds_spec.rb | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/spec/arel/integration/joins/with_compounds_spec.rb b/spec/arel/integration/joins/with_compounds_spec.rb new file mode 100644 index 0000000000..49f0132190 --- /dev/null +++ b/spec/arel/integration/joins/with_compounds_spec.rb @@ -0,0 +1,49 @@ +require File.join(File.dirname(__FILE__), '..', '..', '..', 'spec_helper') + +module Arel + describe Join do + before do + @relation1 = Table.new(:users) + @relation2 = Table.new(:photos) + @predicate = @relation1[:id].eq(@relation2[:user_id]) + end + + describe 'when a compound contains a join' do + describe '#to_sql' do + describe 'when the compound is a select' do + it 'manufactures sql disambiguating the tables' do + @relation1 \ + .select(@relation1[:id].eq(1)) \ + .join(@relation2) \ + .on(@predicate) \ + .select(@relation1[:id].eq(1)) \ + .to_sql.should be_like(" + SELECT `users`.`id`, `users`.`name`, `photos`.`id`, `photos`.`user_id`, `photos`.`camera_id` + FROM `users` + INNER JOIN `photos` + ON `users`.`id` = `photos`.`user_id` + WHERE `users`.`id` = 1 + AND `users`.`id` = 1 + ") + end + end + + describe 'when the compound is a group' do + it 'manufactures sql disambiguating the tables' do + @relation1 \ + .join(@relation2) \ + .on(@predicate) \ + .group(@relation1[:id]) \ + .to_sql.should be_like(" + SELECT `users`.`id`, `users`.`name`, `photos`.`id`, `photos`.`user_id`, `photos`.`camera_id` + FROM `users` + INNER JOIN `photos` + ON `users`.`id` = `photos`.`user_id` + GROUP BY `users`.`id` + ") + end + end + end + end + end +end
\ No newline at end of file |