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:
parent
1c48bef215
commit
8ed3ab00f1
8 changed files with 8 additions and 18 deletions
|
@ -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'
|
||||
|
|
|
@ -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
|
|
@ -18,6 +18,7 @@ module Arel
|
|||
Offset
|
||||
On
|
||||
Top
|
||||
Lock
|
||||
}.each do |name|
|
||||
const_set(name, Class.new(Unary))
|
||||
end
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue