I'm trying to populate a development database with fixtures for testing purposes.
I am populating a model's data using multiple fixture files in different directories. However, it seems like my fixture loading is not additive. That is, my table gets re-initialized from scratch every time.
This is my code loop:
Dir[Rails.root.join('db', 'seeds', 'dev', '**/*.yml')].each do |file|
puts "Loading #{file}"
ActiveRecord::FixtureSet.create_fixtures(File.dirname(file), File.basename(file, '.yml'))
end
For example, my model Article
has many fixture files that will write to it. i.e. news.yml
, tech.yml
, recipies.yml
... etc.
Every one of those fixture files I have:
_fixture:
model_class: Article
...rest of fixtures...
In the beginning of the file.
When I run my task, only the last Article
fixture data gets retained.
How can I utilize all of the Article
fixtures to initialize the model? (all of news.yml
, tech.yml
, recipies.yml
)
Aucun commentaire:
Enregistrer un commentaire