Sha256: 592b31ade693b76a38cebd20191883aba43e04968f93fc467f97074dfe5b4faa

Contents?: true

Size: 756 Bytes

Versions: 5

Compression:

Stored size: 756 Bytes

Contents

FactoryGirl.define do
	factory :customer do |f|
		initialize_with {
			Customer.new(account: account)
		}

		f.name "Customer"
	end

	factory :customer_with_dynamic_column_data, parent: :customer do |f|
		transient do
			index 0
		end

		before(:create, :build) do |customer, evaluator|
			hash = {}
			customer.account.activerecord_dynamic_columns.each_with_index { |i,index|
				hash[i.key.to_s] = case i.data_type
				when 'integer'
					evaluator.index
				when 'datetime'
					DateTime.now.change(hour: evaluator.index)
				when 'boolean'
					true
				when 'model'
					nil
				else
					"#{evaluator.index } - #{i.data_type}"
				end

				hash[i.key.to_s] = [hash[i.key.to_s]]if i.multiple
			}
			customer.fields = hash

			customer
		end
	end

end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
has_dynamic_columns-0.3.10 spec/factories/customer.rb
has_dynamic_columns-0.3.9 spec/factories/customer.rb
has_dynamic_columns-0.3.8 spec/factories/customer.rb
has_dynamic_columns-0.3.6 spec/factories/customer.rb
has_dynamic_columns-0.3.5 spec/factories/customer.rb