to_fixture

Add to_fixture method to Active Record object


License
MIT
Install
gem install to_fixture -v 0.3.0

Documentation

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: 'to_fixture@example.com')
puts user.to_fixture
# =>
# users_1:
#   name: to_fixture
#   email: to_fixture@example.com

If 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.com

You 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.com

License

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