-
Following is a example: class Company < BaseModel
table do
column name : String
has_many manufactories : Manufactory
end
end
class Manufactory < BaseModel
table do
column name : String
belongs_to company : Company
end
end
class CompanyFactory < Avram::Factory
def initialize
name sequence("Company")
end
end
class ManufactoryFactory < Avram::Factory
def initialize
name sequence("Manufactory")
end
end Is it possible to create a for now, i have to do like this: company = CompanyFactory.create
manufactory = ManufactoryFactory.create do |e|
e.company_id company.id
end
CompanyQuery.new.size.should eq 1 EDIT: I test use https://luckyframework.org/guides/testing/creating-test-data#associations-with-factories too. it works, but, this exists another issue, when i want to use exists company instead create a new company, like following class ManufactoryFactory < Avram::Factory
def initialize
name sequence("Manufactory")
company_id CompanyFactory.create.id
end
end
company = CompanyFactory.create
manufactory = ManufactoryFactory.create do |e|
e.company_id company.id
end
CompanyQuery.new.size.should eq 2 # => true
company.id.should eq manufactory.company.id # => true This will result in two company record created, that not is expected. Thank you. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
Okay, i know the answer. https://luckyframework.org/guides/testing/creating-test-data#factory-callbacks thank you. |
Beta Was this translation helpful? Give feedback.
Okay, i know the answer.
https://luckyframework.org/guides/testing/creating-test-data#factory-callbacks
thank you.