aboutsummaryrefslogblamecommitdiffstats
path: root/test/visitors/test_join_sql.rb
blob: 8253fe5ab4cf69ba0ff7e5958c38dd61c7d8493a (plain) (tree)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
                












                                                                    
                                             










                                                                    
                                             







                                                   
require 'helper'

module Arel
  module Visitors
    describe 'the join_sql visitor' do
      before do
        @visitor = JoinSql.new Table.engine
      end

      describe 'inner join' do
        it 'should visit left if left is a join' do
          t    = Table.new :users
          join = Nodes::InnerJoin.new t, t, Nodes::On.new(t[:id])
          j2   = Nodes::InnerJoin.new join, t, Nodes::On.new(t[:id])
          @visitor.accept(j2).must_be_like %{
            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
          join = Nodes::OuterJoin.new t, t, Nodes::On.new(t[:id])
          j2   = Nodes::OuterJoin.new join, t, Nodes::On.new(t[:id])
          @visitor.accept(j2).must_be_like %{
            LEFT OUTER JOIN "users" ON "users"."id"
            LEFT OUTER JOIN "users" ON "users"."id"
          }
        end
      end
    end
  end
end