In Rails 3.2, is it possible to have multiple fixture files for a given ActiveRecord object?
The client is requiring the test data be written in fixtures but also wants them to be manageable. I'd like to split up the fixtures a bit by introducing a 2nd set that the originals would include/require/render whatever.
I haven't been able to find anything via Google on how to do it and fixtures are not my cup of tea. Thanks in advance.
Seems to me like what you want to do is include a YAML file from another YAML file. Here's a question which covers how to do that: How to include a YAML file inside a YAML file?
Since fixtures already have ERB, it should be as simple as:
<%= IO.read(Rails.root.join "test/other_fixtures/fixture_to_load.yml") %>
Just make sure that the fixtures are outside of the primary fixture directory or the mechanism for loading fixtures will also attempt to map them to a model.
If you need ERB inside of the fixture, wrap it in ERB.new
, such as:
<%= ERB.new(IO.read(Rails.root.join "test/other_fixtures/fixture_to_load.yml")).result %>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With