ToFixture
Add to_fixture method to Active Record object. Result of to_fixture can directly use the fixture files.
Installation
Add this line to your application's Gemfile:
gem 'to_fixture'And then execute:
$ bundle
Or install it yourself as:
$ gem install to_fixture
Usage
user = User.create!(name: 'to_fixture', email: 'to_fixture@example.com')
puts user.to_fixture
# =>
# users_1:
# name: to_fixture
# email: to_fixture@example.comIf you want to specify a label, pass the label name as an argument.
puts user.to_fixture("label")
# =>
# label:
# name: to_fixture
# email: to_fixture@example.comYou can also use to ActiveRecord::Relation.
User.create!(name: 'to_fixture_1', email: 'to_fixture1@example.com')
User.create!(name: 'to_fixture_2', email: 'to_fixture2@example.com')
puts User.all.to_fixture
# =>
# users_980190968:
# name: to_fixture_1
# email: to_fixture1@example.com
#
# users_980190969:
# name: to_fixture_2
# email: to_fixture2@example.comLicense
The gem is available as open source under the terms of the MIT License.