Files
openfoodnetwork/spec/support/spree/init.rb
Daniel Dominguez 9d9a974295 Switched gem FactoryGirl to FactoryBot as FactoryGirl is deprecated.
- Change FactoryGirl to FactoryBot everywhere on code.
2018-05-04 11:52:08 -03:00

11 lines
456 B
Ruby

# Initialise enterprise fee when created without one, like this:
# create(:product, :distributors => [...])
# In this case, we don't care what the fee is, but we need one for validations to pass.
ProductDistribution.class_eval do
before_validation :init_enterprise_fee
def init_enterprise_fee
self.enterprise_fee ||= EnterpriseFee.where(enterprise_id: distributor).first || FactoryBot.create(:enterprise_fee, enterprise_id: distributor)
end
end