Class: ActiveRecordMocks::Mock

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

Constructor Details

#initializeMock

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

#tablesObject

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_tablesObject



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.suppress_messages do
      o.enable_extension(ext)
    end
  end
end