Sha256: c4fbe8830a7bea4e25882b0dc6f0bec6d1583d135fb1c6cba4448df45b3dab1a

Contents?: true

Size: 1 KB

Versions: 5

Compression:

Stored size: 1 KB

Contents

module ActiveCucumber

  # Creates ActiveRecord entries with data from given Cucumber tables.
  class ActiveRecordBuilder

    def initialize activerecord_class, context
      @clazz = activerecord_class
      @creator_class = creator_class
      @context = context
    end


    # Creates all entries in the given horizontal table hash
    def create_many table
      table.map do |row|
        create_record row
      end
    end


    # Creates a new record with the given attributes in the database
    def create_record attributes
      creator = @creator_class.new attributes, @context
      FactoryGirl.create @clazz, creator.factorygirl_attributes
    end


  private

    # Returns the Cucumberator subclass to be used by this Cucumparer instance
    def creator_class
      creator_class_name.constantize
    rescue NameError
      Creator
    end


    # Returns the name of the Cucumberator subclass to be used by this Cucumparer instance.
    def creator_class_name
      "#{@clazz.name}Creator"
    end

  end

end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
active_cucumber-0.1.0 lib/active_cucumber/active_record_builder.rb
active_cucumber-0.0.10 lib/active_cucumber/active_record_builder.rb
active_cucumber-0.0.9 lib/active_cucumber/active_record_builder.rb
active_cucumber-0.0.8 lib/active_cucumber/active_record_builder.rb
active_cucumber-0.0.7 lib/active_cucumber/active_record_builder.rb