Module: RSpec::ActiveRecordMocks
- Defined in:
- lib/rspec/active_record_mocks.rb,
lib/rspec/active_record_mocks/version.rb
Defined Under Namespace
Classes: ExtensionsUnsupportedError
Constant Summary collapse
- VERSION =
"0.1.1"
Instance Method Summary collapse
-
#active_record_tables ⇒ Object
Aliases ActiveRecord::Base.connection.tables to active_record_tables to a geniunely useful method that can be used by anybody doing db testing.
-
#clean_tables_for_active_record_mocking ⇒ Object
Roll through each one of the created tables and destroy them.
-
#mock_active_record_model(opts = {}, &block) ⇒ Object
Allow people to mock ActiveRecord while giving them the flexibility.
Instance Method Details
#active_record_tables ⇒ Object
Aliases ActiveRecord::Base.connection.tables to active_record_tables to a geniunely useful method that can be used by anybody doing db testing.
40 41 42 |
# File 'lib/rspec/active_record_mocks.rb', line 40 def active_record_tables ActiveRecord::Base.connection.tables end |
#clean_tables_for_active_record_mocking ⇒ Object
Roll through each one of the created tables and destroy them.
26 27 28 29 30 31 32 33 34 35 |
# File 'lib/rspec/active_record_mocks.rb', line 26 def clean_tables_for_active_record_mocking if [:mocked_active_record_tables] .delete(:mocked_active_record_tables).each do |tbl| ActiveRecord::Base.connection.drop_table(tbl) if active_record_tables.include?(tbl) if Object.const_defined?(tbl.camelize) Object.send(:remove_const, tbl.camelize) end end end end |
#mock_active_record_model(opts = {}, &block) ⇒ Object
Allow people to mock ActiveRecord while giving them the flexibility.
15 16 17 18 19 20 21 22 |
# File 'lib/rspec/active_record_mocks.rb', line 15 def mock_active_record_model(opts = {}, &block) tbl, ext = opts.delete(:name), opts.delete(:extensions) tbl = create_active_record_table_for_mocking(tbl, ext, &block) Object.const_set(tbl.camelize, Class.new(ActiveRecord::Base)).class_eval do include opts.delete(:include) if opts[:include] self.table_name = tbl and self end end |