2010-10-18 19:54:50 -04:00
|
|
|
require 'helper'
|
2010-09-29 04:56:54 -04:00
|
|
|
|
2010-08-23 16:28:08 -04:00
|
|
|
module Arel
|
|
|
|
class FakeCrudder < SelectManager
|
|
|
|
class FakeEngine
|
2010-09-21 12:20:14 -04:00
|
|
|
attr_reader :calls, :connection_pool, :spec, :config
|
2010-08-23 16:28:08 -04:00
|
|
|
|
|
|
|
def initialize
|
|
|
|
@calls = []
|
2010-09-21 12:20:14 -04:00
|
|
|
@connection_pool = self
|
|
|
|
@spec = self
|
|
|
|
@config = { :adapter => 'sqlite3' }
|
2010-08-23 16:28:08 -04:00
|
|
|
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
|
2010-09-28 19:46:06 -04:00
|
|
|
fc.from table
|
2010-12-14 11:47:57 -05:00
|
|
|
im = fc.compile_insert [[table[:id], 'foo']]
|
|
|
|
assert_instance_of Arel::InsertManager, im
|
2010-08-23 16:28:08 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'update' do
|
|
|
|
it 'should call update on the connection' do
|
|
|
|
table = Table.new :users
|
|
|
|
fc = FakeCrudder.new
|
|
|
|
fc.from table
|
2010-12-02 17:31:37 -05:00
|
|
|
stmt = fc.compile_update [[table[:id], 'foo']]
|
|
|
|
assert_instance_of Arel::UpdateManager, stmt
|
2010-08-23 16:28:08 -04:00
|
|
|
end
|
|
|
|
end
|
2010-08-23 16:41:34 -04:00
|
|
|
|
|
|
|
describe 'delete' do
|
|
|
|
it 'should call delete on the connection' do
|
|
|
|
table = Table.new :users
|
|
|
|
fc = FakeCrudder.new
|
|
|
|
fc.from table
|
2010-12-02 18:45:00 -05:00
|
|
|
stmt = fc.compile_delete
|
|
|
|
assert_instance_of Arel::DeleteManager, stmt
|
2010-08-23 16:41:34 -04:00
|
|
|
end
|
|
|
|
end
|
2010-08-23 16:28:08 -04:00
|
|
|
end
|
|
|
|
end
|