From f17f299abe0d6a858cac15910c81121beb17b372 Mon Sep 17 00:00:00 2001 From: John Bintz Date: Sun, 24 Feb 2013 16:39:36 -0500 Subject: [PATCH] add ability to seed through code --- README.md | 3 +++ lib/seed-fu-mongoid.rb | 12 ++++++++++++ lib/seed-fu-mongoid/railtie.rb | 6 +----- 3 files changed, 16 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index e45eee8..bb4b0f6 100644 --- a/README.md +++ b/README.md @@ -25,3 +25,6 @@ Simple! `require 'seed-fu-mongoid/capistrano'` to have your data get re-seeded on deploy. +### Cucumber/RSpec + +`SeedFuMongoid.seed` diff --git a/lib/seed-fu-mongoid.rb b/lib/seed-fu-mongoid.rb index a795d90..8e1747c 100644 --- a/lib/seed-fu-mongoid.rb +++ b/lib/seed-fu-mongoid.rb @@ -9,6 +9,18 @@ end # punch the duck out of Mongoid::Document +module SeedFuMongoid + class << self + def seed + Dir['db/fixtures/**/*.rb'].each do |file| + puts "== Seed from #{file}" + + load file + end + end + end +end + module Mongoid::Document module ClassMethods def seed_once(*constraints) diff --git a/lib/seed-fu-mongoid/railtie.rb b/lib/seed-fu-mongoid/railtie.rb index 11d2163..20efc46 100644 --- a/lib/seed-fu-mongoid/railtie.rb +++ b/lib/seed-fu-mongoid/railtie.rb @@ -4,11 +4,7 @@ module SeedFuMongoid namespace :db do desc "Load seed data from db/fixtures" task :seed_fu => :environment do - Dir['db/fixtures/**/*.rb'].each do |file| - puts "== Seed from #{file}" - - load file - end + SeedFuMongoid.seed end end end