ToFixture

Add to_fixture method to Active Record object. Result of to_fixture can directly use the fixture files.

Build Status Gem Version

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: '[email protected]')
puts user.to_fixture
# =>
# users_1:
#   name: to_fixture
#   email: [email protected]

If you want to specify a label, pass the label name as an argument.

puts user.to_fixture("label")
# =>
# label:
#   name: to_fixture
#   email: [email protected]

You can also use to ActiveRecord::Relation.

User.create!(name: 'to_fixture_1', email: '[email protected]')
User.create!(name: 'to_fixture_2', email: '[email protected]')
puts User.all.to_fixture
# =>
# users_980190968:
#   name: to_fixture_1
#   email: [email protected]
#
# users_980190969:
#   name: to_fixture_2
#   email: [email protected]

License

The gem is available as open source under the terms of the MIT License.