Project

to_fixture

0.0
No commit activity in last 3 years
No release in over 3 years
Add to_fixture method to Active Record object
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 1.12
~> 5.0
~> 10.0

Runtime

 Project Readme

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.