Population Build Status

Population is a gem which provides a simple syntax for populating and resetting your database tables.

Installation

Add this line to your application's Gemfile:

gem 'population'

And then execute:

$ bundle

Or install it yourself as:

$ gem install population

Usage

First define some population recipes in lib/populations.rb.

# lib/populations.rb
Population.define do
  populate :users do
    create!(name: "David Tuite", phone: '34893')
    create!(name: "Peter Pan", phone: '093489')
  end

  populate :states do
    create!(name: 'Alabama')
  end
end

Now you can use the Population class to populate and reset your database tables.

Populating

# From the console:
$ rails c
: Population.populate(:users)

# From a task
# lib/tasts/populate.rake
namespace :db do
  desc "Populate the DB with sample data"
  task :populate => :environment do
    tables = [:users, :states]
    Population.populate(*tables)
  end
end

$ rake db:populate

Resetting

Resetting will empty the passed in tables and reset any auto-increment columns to 1.

# From the console:
$ rails c
: Population.reset(:users)

Contributing

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request