Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to have multiple fixture files per model in rails 3.2?

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.

like image 564
Chance Avatar asked Oct 23 '12 18:10

Chance


1 Answers

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 %>
like image 155
alexpls Avatar answered Nov 20 '22 22:11

alexpls