Allows Rails engines to contain fixtures for their models and for those fixtures to be automatically used in the downstream engines. This is very much in line with Rails engines containing db migrations for their models and for those migrations to be automatically used by the downstream engines.
Add this line to your application's Gemfile
:
gem 'inheritable_fixtures'
And then execute:
$ bundle install
This gem introduces a configuration option called Rails.application.config.fixtures_paths
, which is by default empty. The list of fixtures is determined by traversing all the fixtures_paths
looking for fixture files. Rails.root.join('test/fixtures')
is always prepended to the list, thus it has the highest precedence.
When the application initializes, each engine adds lib/fixtures
to the list (if that path exists).
Tests use fixtures :all
or something like fixtures :users, :addresses
to initial the database with necessary test data. It will now search for the fixtures in all fixtures_paths
.
The fixture_file_upload
is a handy utility provided by Rails for creating Rack::Test::UploadedFile
out of a fixture file. It will now look for the fixture in all fixtures_paths
.
The db:fixtures:load
task is used to populate a database with the fixtures. It will now load all fixtures from fixtures_paths
.
- Fork it ( https://github.com/[my-github-username]/inheritable_fixtures/fork )
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create a new Pull Request