Git Product home page Git Product logo

farm_girl's Introduction

FarmGirl

Seed your database using your factory definitions.

Example

Create the directory db/seeds/ in your Rails 2.3 application. Drop any number of files in there that you’d like to use to seed your database. For example, if I have a factory defined as “security_levels”, then:

# db/seeds/security_levels.rb
SecurityLevel.delete_all # Remove any old data

Factory.create(:security_level, :level => 0, :description => "No Access", :id => 1)
Factory.create(:security_level, :level => 1, :description => "Access to modules only", :id => 2)
Factory.create(:security_level, :level => 2, :description => "Access to all modules and reports", :id => 3)
Factory.create(:security_level, :level => 3, :description => "Access to everything", :id => 4)

Then, in my db/seeds.rb file:

# db/seeds.rb
FarmGirl.seed!

Now, I can execute the built-in Rake task for seeding my db in Rails:

$ rake db:seed

Installation

script/plugin install git://github.com/daphonz/farm_girl.git

This plugin needs (of course) FactoryGirl to work. So far I’ve used it in Rails 2.3. Make sure that you properly add the line

config.gem 'factory_girl', :version => '1.2.4'

in your main environment.rb file for the dependencies to load correctly.

Copyright © 2010 Casey Dreier and Singlebrook Technology, released under the MIT license.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.