Skip to content

Instantly share code, notes, and snippets.

@samullen
Created January 28, 2010 14:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save samullen/288809 to your computer and use it in GitHub Desktop.
Save samullen/288809 to your computer and use it in GitHub Desktop.
Testing MongoMapper with Machinist
require 'machinist/mongomapper'
require 'sham'
require 'faker'
Sham.define do
username { Faker::Internet.user_name }
email { Faker::Internet.email }
# confirmed_at { ...date... }
# confirmation_sent_at { ...date... }
# remember_token { 'Cj4ja2A3Xp6MEK6rdUej' }
# remember_created_at { date }
end
User.blueprint do
username { Sham.username }
email { Sham.email }
password "foobarbaz"
password_confirmation "foobarbaz"
end
# Install Machinist Gem
# http://github.com/notahat/machinist
sudo gem install machinist --source http://gemcutter.org
# Install Faker Gem - used to fake data for Machinist
# http://faker.rubyforge.org/
sudo gem install faker
# Install machinist_mongo Gem - used to interface Machinist to Mongo
# http://github.com/nmerouze/machinist_mongo
gem install machinist_mongo
ENV["RAILS_ENV"] = "test"
require File.expand_path(File.dirname(__FILE__) + "/../config/environment")
require 'test_help'
require File.expand_path(File.dirname(__FILE__) + "/blueprints")
class ActiveSupport::TestCase
setup { Sham.reset }
def teardown
MongoMapper.database.collections.each do |collection|
collection.remove # remove documents from collection
end
end
# Every Test using this helper incorporates the above teardown to its own
def inherited(base) # applied upon inheritance
base.define_method teardown do
super
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment