Class: ActiveRecordMocks::Mock
- Inherits:
-
Object
- Object
- ActiveRecordMocks::Mock
- Defined in:
- lib/active_record_mocks/mock.rb,
lib/active_record_mocks/mock/table.rb
Defined Under Namespace
Classes: ExtensionsUnsupported, Table
Instance Attribute Summary collapse
-
#tables ⇒ Object
Returns the value of attribute tables.
Instance Method Summary collapse
- #create_table(*args, &block) ⇒ Object
- #delete_tables ⇒ Object
- #enable_extension(ext) ⇒ Object
-
#initialize ⇒ Mock
constructor
A new instance of Mock.
Constructor Details
#initialize ⇒ Mock
Returns a new instance of Mock.
35 36 37 38 |
# File 'lib/active_record_mocks/mock.rb', line 35 def initialize @tables = [ ] end |
Instance Attribute Details
#tables ⇒ Object
Returns the value of attribute tables.
12 13 14 |
# File 'lib/active_record_mocks/mock.rb', line 12 def tables @tables end |
Instance Method Details
#create_table(*args, &block) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/active_record_mocks/mock.rb', line 23 def create_table(*args, &block) Table.new(*args).tap do |o| if block_given? block.call(o) end o.setup_mocking! tables.push(o) return o.model end end |
#delete_tables ⇒ Object
40 41 42 43 44 45 46 |
# File 'lib/active_record_mocks/mock.rb', line 40 def delete_tables tables.each do |t| Object.send(:remove_const, t.model_name) ActiveRecord::Base.connection.drop_table(t.table_name) end nil end |
#enable_extension(ext) ⇒ Object
14 15 16 17 18 19 20 21 |
# File 'lib/active_record_mocks/mock.rb', line 14 def enable_extension(ext) raise_if_extensions_unsupported! ActiveRecord::Migration.tap do |o| o. do o.enable_extension(ext) end end end |