Sha256: 657f8aa440283db002e7b100d1334fb804c398d28d51bdfd3a168b10e1356fb9

Contents?: true

Size: 1.7 KB

Versions: 93

Compression:

Stored size: 1.7 KB

Contents

require 'helper'

module Arel
  module Visitors
    describe 'the mysql visitor' do
      before do
        @visitor = MySQL.new Table.engine.connection
      end

      it 'squashes parenthesis on multiple unions' do
        subnode = Nodes::Union.new 'left', 'right'
        node    = Nodes::Union.new subnode, 'topright'
        assert_equal 1, @visitor.accept(node).scan('(').length

        subnode = Nodes::Union.new 'left', 'right'
        node    = Nodes::Union.new 'topleft', subnode
        assert_equal 1, @visitor.accept(node).scan('(').length
      end

      ###
      # :'(
      # http://dev.mysql.com/doc/refman/5.0/en/select.html#id3482214
      it 'defaults limit to 18446744073709551615' do
        stmt = Nodes::SelectStatement.new
        stmt.offset = Nodes::Offset.new(1)
        sql = @visitor.accept(stmt)
        sql.must_be_like "SELECT FROM DUAL LIMIT 18446744073709551615 OFFSET 1"
      end

      it "should escape LIMIT" do
        sc = Arel::Nodes::UpdateStatement.new
        sc.limit = Nodes::Limit.new("omg")
        assert_equal("UPDATE NULL LIMIT 'omg'", @visitor.accept(sc))
      end

      it 'uses DUAL for empty from' do
        stmt = Nodes::SelectStatement.new
        sql = @visitor.accept(stmt)
        sql.must_be_like "SELECT FROM DUAL"
      end

      describe 'locking' do
        it 'defaults to FOR UPDATE when locking' do
          node = Nodes::Lock.new(Arel.sql('FOR UPDATE'))
          @visitor.accept(node).must_be_like "FOR UPDATE"
        end

        it 'allows a custom string to be used as a lock' do
          node = Nodes::Lock.new(Arel.sql('LOCK IN SHARE MODE'))
          @visitor.accept(node).must_be_like "LOCK IN SHARE MODE"
        end
      end
    end
  end
end

Version data entries

93 entries across 75 versions & 14 rubygems

Version Path
challah-0.9.0 vendor/bundle/gems/arel-3.0.2/test/visitors/test_mysql.rb
challah-rolls-0.2.0 vendor/bundle/gems/arel-3.0.2/test/visitors/test_mysql.rb
challah-rolls-0.2.0 vendor/bundle/gems/challah-0.8.0.pre/vendor/bundle/gems/arel-3.0.2/test/visitors/test_mysql.rb
challah-rolls-0.2.0 vendor/bundle/gems/challah-0.8.3/vendor/bundle/gems/arel-3.0.2/test/visitors/test_mysql.rb
challah-0.8.3 vendor/bundle/gems/arel-3.0.2/test/visitors/test_mysql.rb
challah-0.8.1 vendor/bundle/gems/arel-3.0.2/test/visitors/test_mysql.rb
challah-rolls-0.1.0 vendor/bundle/gems/arel-3.0.2/test/visitors/test_mysql.rb
challah-rolls-0.1.0 vendor/bundle/gems/challah-0.8.0.pre/vendor/bundle/gems/arel-3.0.2/test/visitors/test_mysql.rb
challah-0.8.0.pre vendor/bundle/gems/arel-3.0.2/test/visitors/test_mysql.rb
challah-0.7.1 vendor/bundle/gems/arel-3.0.2/test/visitors/test_mysql.rb
challah-0.7.0 vendor/bundle/gems/arel-3.0.2/test/visitors/test_mysql.rb
challah-0.7.0.pre2 vendor/bundle/gems/arel-3.0.2/test/visitors/test_mysql.rb
challah-0.7.0.pre vendor/bundle/gems/arel-3.0.2/test/visitors/test_mysql.rb
challah-0.6.2 vendor/bundle/gems/arel-3.0.2/test/visitors/test_mysql.rb
sunrise-cms-0.3.3 vendor/bundle/ruby/1.9.1/gems/arel-3.0.2/test/visitors/test_mysql.rb
sunrise-cms-0.3.3 vendor/bundle/ruby/1.9.1/gems/rails-uploader-0.0.1/vendor/bundle/ruby/1.9.1/gems/arel-3.0.2/test/visitors/test_mysql.rb
initforthe-cookies-0.0.1 vendor/bundle/gems/arel-3.0.2/test/visitors/test_mysql.rb
sunrise-cms-0.3.2 vendor/bundle/ruby/1.9.1/gems/arel-3.0.2/test/visitors/test_mysql.rb
sunrise-cms-0.3.2 vendor/bundle/ruby/1.9.1/gems/rails-uploader-0.0.1/vendor/bundle/ruby/1.9.1/gems/arel-3.0.2/test/visitors/test_mysql.rb
sunrise-cms-0.3.1 vendor/bundle/ruby/1.9.1/gems/rails-uploader-0.0.1/vendor/bundle/ruby/1.9.1/gems/arel-3.0.2/test/visitors/test_mysql.rb