Module: Blueprints::Helper
- Included in:
- ActiveSupport::TestCase
- Defined in:
- lib/blueprints/helper.rb
Overview
A helper module that should be included in test framework. Adds methods build
and demolish
Instance Method Summary collapse
-
#build_attributes(name) ⇒ Object
Returns attributes that are used to build blueprint.
-
#build_blueprint(*names) ⇒ Object
(also: #build)
Builds one or more blueprints by their names.
-
#build_blueprint!(*names) ⇒ Object
(also: #build!)
Same as #build_blueprint except that you can use it to build same blueprint several times.
-
#demolish(*names) ⇒ Object
Demolishes built blueprints (by default simply calls destroy method on result of blueprint, but can be customized).
Instance Method Details
#build_attributes(name) ⇒ Object
Returns attributes that are used to build blueprint. To set what attributes are used you need to call attributes method when defining blueprint like this:
blueprint :apple do
Fruit.build attributes
end.attributes(:name => 'apple')
28 29 30 31 |
# File 'lib/blueprints/helper.rb', line 28 def build_attributes(name) Namespace.root[name].build_parents Namespace.root[name].normalized_attributes.tap { Blueprints::Namespace.root.copy_ivars(self) } end |
#build_blueprint(*names) ⇒ Object Also known as: build
Builds one or more blueprints by their names. You can pass names as symbols or strings. You can also pass additional options hash which will be available by calling options
in blueprint block. Returns result of blueprint block.
# build :apple and orange blueprints
build :apple, :orange
# build :apple scenario with additional options
build :apple => {:color => 'red'}
# options can also be passed for several blueprints
build :pear, :apple => {:color => 'red'}, :orange => {:color => 'orange'}
14 15 16 |
# File 'lib/blueprints/helper.rb', line 14 def build_blueprint(*names) Namespace.root.build(names, self, true) end |