Module: TestDummy::TestHelper

Defined in:
lib/test_dummy/test_helper.rb

Instance Method Summary collapse

Instance Method Details

#dummy(scope, *tags) ⇒ Object Also known as: a, an, one_of



2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/test_dummy/test_helper.rb', line 2

def dummy(scope, *tags)
  create_attributes =
    case (tags.last)
    when Hash
      tags.pop
    else
      { }
    end

  instance = scope.respond_to?(:build) ? scope.build(create_attributes) : scope.new(create_attributes)

  if (block_given?)
    yield(instance)
  end

  instance.class.dummy_definition.apply!(instance, create_attributes, tags)

  instance.save!

  instance.class.dummy_definition.apply_after_save!(instance, create_attributes, tags)

  instance
end