Class: ActiveCucumber::ActiveRecordBuilder
- Inherits:
-
Object
- Object
- ActiveCucumber::ActiveRecordBuilder
- Defined in:
- lib/active_cucumber/active_record_builder.rb
Overview
Creates ActiveRecord entries with data from given Cucumber tables.
Instance Method Summary collapse
- #attributes_for(attributes) ⇒ Object
-
#create_many(table) ⇒ Object
Creates all entries in the given horizontal table hash.
-
#create_record(attributes) ⇒ Object
Creates a new record with the given attributes in the database.
-
#initialize(activerecord_class, context) ⇒ ActiveRecordBuilder
constructor
A new instance of ActiveRecordBuilder.
Constructor Details
#initialize(activerecord_class, context) ⇒ ActiveRecordBuilder
Returns a new instance of ActiveRecordBuilder.
6 7 8 9 10 |
# File 'lib/active_cucumber/active_record_builder.rb', line 6 def initialize activerecord_class, context @clazz = activerecord_class @creator_class = creator_class @context = context end |
Instance Method Details
#attributes_for(attributes) ⇒ Object
13 14 15 |
# File 'lib/active_cucumber/active_record_builder.rb', line 13 def attributes_for attributes @creator_class.new(attributes, @context).factorygirl_attributes end |
#create_many(table) ⇒ Object
Creates all entries in the given horizontal table hash
19 20 21 22 23 |
# File 'lib/active_cucumber/active_record_builder.rb', line 19 def create_many table table.map do |row| create_record row end end |
#create_record(attributes) ⇒ Object
Creates a new record with the given attributes in the database
27 28 29 30 |
# File 'lib/active_cucumber/active_record_builder.rb', line 27 def create_record attributes creator = @creator_class.new attributes, @context FactoryGirl.create @clazz.name.underscore.to_sym, creator.factorygirl_attributes end |