Module: MongoMapperSweatShop::Model::ClassMethods

Defined in:
lib/mongomapper-sweatshop/model.rb

Constant Summary collapse

@@fixtures =
{}

Instance Method Summary collapse

Instance Method Details

#fix(name = :default, &block) ⇒ Proc Also known as: fixture

Creates a fixture

Parameters:

  • name (Symbol) (defaults to: :default)

    fixture name, :default is default

  • block (Proc)

    the fixture to be lazily evaluated

Returns:

  • (Proc)

    the block passed



12
13
14
15
16
17
18
# File 'lib/mongomapper-sweatshop/model.rb', line 12

def fix name=:default, &block
  if name.is_a? Proc
    block, name = name, :default
  end
  SweatShop[self, name] = block
  #@@fixtures[name] = block
end

#gen(name = :default, overrides = {}) ⇒ Class Also known as: generate

Generates a fixture and saves it to the test db

Parameters:

  • name (Symbol) (defaults to: :default)

    name of fixture, :default is default

  • overrides (Hash) (defaults to: {})

    hash of attributes to override what may be defined in the fixture

Returns:

  • (Class)

    instance of the class this is currently included



25
26
27
# File 'lib/mongomapper-sweatshop/model.rb', line 25

def gen name=:default, overrides={}  
  self.create SweatShop[self, name, overrides]
end

#make(name = :default, overrides = {}) ⇒ Class

Generates a fixture without saving to the db

Parameters:

  • name (Symbol) (defaults to: :default)

    name of fixture, :default is default

  • overrides (Hash) (defaults to: {})

    Hash of attributes to merge into the generated fixture

Returns:

  • (Class)

    instance of the class



35
36
37
# File 'lib/mongomapper-sweatshop/model.rb', line 35

def make name=:default, overrides={}
  self.new SweatShop[self, name, overrides]
end