I have two classes PublisherLevel and Publisher. If we create a publisher, the PublisherLevel count should be equal to 14 - the count of different publisher level types. In our db, we have a foreign key constraint. This is just a lookup table. I'd like to do someithing like this:
FactoryGirl.define do
if PublisherLevel.count == 0
puts "you have 0 publisher_levels and should seed it"
seed_publisher_levels
end
factory :company do
name { Faker::Company.name }
display_name "Sample Company"
publisher_level
end
end
but the first if statement doesn't get called. I have seen this Using factory_girl in Rails with associations that have unique constraints. Getting duplicate errors but is 8 years old and suspect there is a more elegant solution. What is the canonical way to do this?