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

66 lines
1.4 KiB
Ruby
Raw Normal View History

require 'helper'
module Arel
class FakeCrudder < SelectManager
class FakeEngine
2010-09-21 12:20:14 -04:00
attr_reader :calls, :connection_pool, :spec, :config
def initialize
@calls = []
2010-09-21 12:20:14 -04:00
@connection_pool = self
@spec = self
@config = { :adapter => 'sqlite3' }
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
fc.insert [[table[:id], 'foo']]
fc.engine.calls.find { |method, _|
method == :insert
}.wont_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
stmt = fc.compile_update [[table[:id], 'foo']]
assert_instance_of Arel::UpdateManager, stmt
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
stmt = fc.compile_delete
assert_instance_of Arel::DeleteManager, stmt
2010-08-23 16:41:34 -04:00
end
end
end
end