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
12 13 14 |
# File 'lib/active_cucumber/active_record_builder.rb', line 12 def attributes_for(attributes) @creator_class.new(attributes, @context).factorybot_attributes end |
#create_many(table) ⇒ Object
Creates all entries in the given horizontal table hash
17 18 19 20 21 |
# File 'lib/active_cucumber/active_record_builder.rb', line 17 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
24 25 26 27 28 29 |
# File 'lib/active_cucumber/active_record_builder.rb', line 24 def create_record(attributes) creator = @creator_class.new attributes, @context factorybot_attributes = creator.factorybot_attributes factory_name = @clazz.name.underscore.to_sym create_with_factory(factory_name, factorybot_attributes, attributes) end |