Created
September 30, 2008 22:11
-
-
Save qrush/13975 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'populator' | |
module Populate | |
def spawn_models | |
p 'ok, wtf: ' + ENV["RAILS_ENV"] | |
[Post, Category, Page].each(&:delete_all) | |
Category.populate 10 do |category| | |
category.name = Populator.words(1..3).titleize | |
category.featured = [true, false] | |
Post.populate 5..10 do |post| | |
post.title = Populator.words(1..5).titleize | |
post.content = Populator.paragraphs(1..5).titleize | |
post.created_at = 2.years.ago..Time.now | |
post.category_id = category.id | |
post.user_id = random(User) | |
end | |
end | |
Page.populate 10..20 do |page| | |
page.title = Populator.words(1..3).titleize | |
page.permalink = page.title.slugify | |
page.content = Populator.paragraphs(1..5).titleize | |
end | |
end | |
def random(model) | |
ids = ActiveRecord::Base.connection.select_all("SELECT id FROM #{model.to_s.tableize}") | |
model.find(ids[rand(ids.length)]["id"].to_i) unless ids.blank? | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Spec::Runner.configure do |config| | |
include AuthenticatedTestHelper | |
include Populate | |
# If you're not using ActiveRecord you should remove these | |
# lines, delete config/database.yml and disable :active_record | |
# in your config/boot.rb | |
config.use_transactional_fixtures = true | |
config.use_instantiated_fixtures = false | |
config.fixture_path = RAILS_ROOT + '/spec/fixtures/' | |
spawn_models | |
= | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment