test_crud.rb 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. require 'helper'
  2. module Arel
  3. class FakeCrudder < SelectManager
  4. class FakeEngine
  5. attr_reader :calls, :connection_pool, :spec, :config
  6. def initialize
  7. @calls = []
  8. @connection_pool = self
  9. @spec = self
  10. @config = { :adapter => 'sqlite3' }
  11. end
  12. def connection; self end
  13. def method_missing name, *args
  14. @calls << [name, args]
  15. end
  16. end
  17. include Crud
  18. attr_reader :engine
  19. attr_accessor :ctx
  20. def initialize engine = FakeEngine.new
  21. super
  22. end
  23. end
  24. describe 'crud' do
  25. describe 'insert' do
  26. it 'should call insert on the connection' do
  27. table = Table.new :users
  28. fc = FakeCrudder.new
  29. fc.from table
  30. im = fc.compile_insert [[table[:id], 'foo']]
  31. assert_instance_of Arel::InsertManager, im
  32. end
  33. end
  34. describe 'update' do
  35. it 'should call update on the connection' do
  36. table = Table.new :users
  37. fc = FakeCrudder.new
  38. fc.from table
  39. stmt = fc.compile_update [[table[:id], 'foo']]
  40. assert_instance_of Arel::UpdateManager, stmt
  41. end
  42. end
  43. describe 'delete' do
  44. it 'should call delete on the connection' do
  45. table = Table.new :users
  46. fc = FakeCrudder.new
  47. fc.from table
  48. stmt = fc.compile_delete
  49. assert_instance_of Arel::DeleteManager, stmt
  50. end
  51. end
  52. end
  53. end