mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
making sure update delegates to update and insert delegates to insert
This commit is contained in:
parent
2579fec805
commit
8966434f2a
3 changed files with 56 additions and 5 deletions
|
@ -6,22 +6,21 @@ module Arel
|
|||
def update values
|
||||
um = UpdateManager.new @engine
|
||||
|
||||
if String === values
|
||||
values = SqlLiteral.new values
|
||||
if Nodes::SqlLiteral === values
|
||||
um.table @ctx.froms.last
|
||||
else
|
||||
um.table values.first.first.relation
|
||||
end
|
||||
um.set values
|
||||
um.wheres = @ctx.wheres
|
||||
@engine.connection.execute um.to_sql
|
||||
@engine.connection.update um.to_sql, 'AREL'
|
||||
end
|
||||
|
||||
# FIXME: this method should go away
|
||||
def insert values
|
||||
im = InsertManager.new @engine
|
||||
im.insert values
|
||||
@engine.connection.execute im.to_sql
|
||||
@engine.connection.insert im.to_sql
|
||||
end
|
||||
|
||||
def delete
|
||||
|
|
51
spec/arel/crud_spec.rb
Normal file
51
spec/arel/crud_spec.rb
Normal file
|
@ -0,0 +1,51 @@
|
|||
module Arel
|
||||
class FakeCrudder < SelectManager
|
||||
class FakeEngine
|
||||
attr_reader :calls
|
||||
|
||||
def initialize
|
||||
@calls = []
|
||||
end
|
||||
|
||||
def connection; self end
|
||||
|
||||
def method_missing name, *args
|
||||
@calls << [name, args]
|
||||
end
|
||||
end
|
||||
|
||||
include Crud
|
||||
|
||||
attr_reader :engine
|
||||
attr_accessor :ctx
|
||||
|
||||
def initialize engine = FakeEngine.new
|
||||
super
|
||||
end
|
||||
end
|
||||
|
||||
describe 'crud' do
|
||||
describe 'insert' do
|
||||
it 'should call insert on the connection' do
|
||||
table = Table.new :users
|
||||
fc = FakeCrudder.new
|
||||
fc.insert [[table[:id], 'foo']]
|
||||
fc.engine.calls.find { |method, _|
|
||||
method == :insert
|
||||
}.should_not be_nil
|
||||
end
|
||||
end
|
||||
|
||||
describe 'update' do
|
||||
it 'should call update on the connection' do
|
||||
table = Table.new :users
|
||||
fc = FakeCrudder.new
|
||||
fc.from table
|
||||
fc.update [[table[:id], 'foo']]
|
||||
fc.engine.calls.find { |method, _|
|
||||
method == :update
|
||||
}.should_not be_nil
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -17,9 +17,10 @@ module Arel
|
|||
def quote_column_name thing; @engine.connection.quote_column_name thing end
|
||||
def quote thing, column; @engine.connection.quote thing, column end
|
||||
|
||||
def execute sql
|
||||
def execute sql, name = nil
|
||||
@executed << sql
|
||||
end
|
||||
alias :update :execute
|
||||
end
|
||||
|
||||
describe 'select manager' do
|
||||
|
|
Loading…
Reference in a new issue