2010-10-18 19:54:50 -04:00
|
|
|
require 'helper'
|
2010-09-15 13:50:20 -04:00
|
|
|
|
|
|
|
module Arel
|
|
|
|
module Visitors
|
|
|
|
describe 'the join_sql visitor' do
|
|
|
|
before do
|
2010-12-03 18:24:30 -05:00
|
|
|
@visitor = ToSql.new Table.engine
|
|
|
|
@visitor.extend(JoinSql)
|
2010-09-15 13:50:20 -04:00
|
|
|
end
|
|
|
|
|
2010-12-14 14:04:08 -05:00
|
|
|
it 'should visit string join' do
|
|
|
|
sql = @visitor.accept Nodes::StringJoin.new('omg')
|
|
|
|
sql.must_be_like "'omg'"
|
|
|
|
end
|
|
|
|
|
2010-09-15 13:50:20 -04:00
|
|
|
describe 'inner join' do
|
|
|
|
it 'should visit left if left is a join' do
|
|
|
|
t = Table.new :users
|
2010-12-14 12:43:19 -05:00
|
|
|
sm = t.select_manager
|
|
|
|
sm.join(t).on(t[:id]).join(t).on(t[:id])
|
|
|
|
sm.join_sql.must_be_like %{
|
2010-09-15 13:50:20 -04:00
|
|
|
INNER JOIN "users" ON "users"."id"
|
|
|
|
INNER JOIN "users" ON "users"."id"
|
|
|
|
}
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'outer join' do
|
|
|
|
it 'should visit left if left is a join' do
|
|
|
|
t = Table.new :users
|
2010-12-14 12:43:19 -05:00
|
|
|
sm = t.select_manager
|
|
|
|
sm.join(t, Nodes::OuterJoin).on(t[:id]).join(
|
|
|
|
t, Nodes::OuterJoin).on(t[:id])
|
|
|
|
sm.join_sql.must_be_like %{
|
2010-09-15 13:50:20 -04:00
|
|
|
LEFT OUTER JOIN "users" ON "users"."id"
|
|
|
|
LEFT OUTER JOIN "users" ON "users"."id"
|
|
|
|
}
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|