1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Lock should be a unary node

This commit is contained in:
Aaron Patterson 2011-02-21 15:14:29 -08:00
parent 1c48bef215
commit 8ed3ab00f1
8 changed files with 8 additions and 18 deletions

View file

@ -1,6 +1,5 @@
# node
require 'arel/nodes/node'
require 'arel/nodes/lock'
require 'arel/nodes/select_statement'
require 'arel/nodes/select_core'
require 'arel/nodes/insert_statement'

View file

@ -1,10 +0,0 @@
module Arel
module Nodes
class Lock < Arel::Nodes::Node
attr_reader :locking
def initialize locking = true
@locking = locking
end
end
end
end

View file

@ -18,6 +18,7 @@ module Arel
Offset
On
Top
Lock
}.each do |name|
const_set(name, Class.new(Unary))
end

View file

@ -3,8 +3,8 @@ module Arel
class MySQL < Arel::Visitors::ToSql
private
def visit_Arel_Nodes_Lock o
if o.locking.is_a?(String)
o.locking
if o.expr.is_a?(String)
o.expr
else
"FOR UPDATE"
end

View file

@ -3,8 +3,8 @@ module Arel
class PostgreSQL < Arel::Visitors::ToSql
private
def visit_Arel_Nodes_Lock o
if o.locking.is_a?(String)
o.locking
if o.expr.is_a?(String)
o.expr
else
"FOR UPDATE"
end

View file

@ -63,7 +63,7 @@ module Arel
end
def test_lock
lock = Nodes::Lock.new
lock = Nodes::Lock.new true
@visitor.accept lock
assert_equal [lock], @collector.calls
end

View file

@ -31,7 +31,7 @@ module Arel
describe 'locking' do
it 'defaults to FOR UPDATE when locking' do
node = Nodes::Lock.new
node = Nodes::Lock.new true
@visitor.accept(node).must_be_like "FOR UPDATE"
end

View file

@ -9,7 +9,7 @@ module Arel
describe 'locking' do
it 'defaults to FOR UPDATE' do
@visitor.accept(Nodes::Lock.new).must_be_like %{
@visitor.accept(Nodes::Lock.new(true)).must_be_like %{
FOR UPDATE
}
end