Skip to content

Commit

Permalink
adapter for Mongoid
Browse files Browse the repository at this point in the history
  • Loading branch information
zuchmanski authored and ianwhite committed Aug 19, 2010
1 parent 4b618f8 commit f58e0dc
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 8 deletions.
3 changes: 3 additions & 0 deletions History.txt
@@ -1,5 +1,8 @@
== master

* 1 major improvment
* adapter for MongoID [Sebastian Zuchmanski]

* 1 minor improvement
* Pickle::Session::ModelNotKnownError is raised instead of a generic RuntimeError

Expand Down
10 changes: 4 additions & 6 deletions README.rdoc
Expand Up @@ -3,7 +3,7 @@
Pickle gives you cucumber steps that create your models easily from factory-girl or
machinist factories/blueprints. You can also just use ActiveRecord as a factory but it's not as cool.

Pickle can make use of different ORMs for finding records. Currently ActiveRecord and DataMapper adapters are
Pickle can make use of different ORMs for finding records. Currently ActiveRecord, DataMapper, MongoID adapters are
provided. More adapters welcome!

References to the models are stored in the current world, not necessarily for the purpose of checking the db
Expand Down Expand Up @@ -133,13 +133,11 @@ In: <tt>features/support/pickle.rb</tt>
require 'pickle/world'

Pickle.configure do |config|
config.adapters = [:machinist, YourOwnAdapterClass]
config.adapters = [:machinist, :active_record, YourOwnAdapterClass]
config.map 'me', 'myself', 'my', 'I', :to => 'user: "me"'
end

Out of the box pickle looks for machinist, then factory-girl, then finally active-record 'factories'.
If you find that your steps aren't working with your factories, it's probably the case that your factory
setup is not being included in your cucumber environment (see comments above regarding machinist and factory-girl).
Out of the box pickle looks for machinist, then factory-girl. If you want to use active-record 'factories' add ":active_record" to adapters. If you find that your steps aren't working with your factories, it's probably the case that your factory setup is not being included in your cucumber environment (see comments above regarding machinist and factory-girl).

== API

Expand Down Expand Up @@ -347,4 +345,4 @@ The following people have made Pickle better:
* {Michael Moen}[http://github.com/UnderpantsGnome]
* {Myron Marston}[http://github.com/myronmarston]
* {Stephan Hagemann}[http://github.com/xing]
* {Chris Flipse}[http://github.com/cflipse]
* {Chris Flipse}[http://github.com/cflipse]
2 changes: 1 addition & 1 deletion VERSION
@@ -1 +1 @@
0.3.5
0.3.6
39 changes: 39 additions & 0 deletions lib/pickle/adapters/mongoid.rb
@@ -0,0 +1,39 @@
require 'mongoid'

module Mongoid
module Document
module PickleAdapter
include Pickle::Adapter::Base

# Do not consider these to be part of the class list
def self.except_classes
@@except_classes ||= []
end

# Gets a list of the available models for this adapter
def self.model_classes
ObjectSpace.each_object(Class).to_a.select {|klass| klass.ancestors.include? Mongoid::Document}
end

# get a list of column names for a given class
def self.column_names(klass)
klass.fields.keys
end

# Get an instance by id of the model
def self.get_model(klass, id)
klass.find(id)
end

# Find the first instance matching conditions
def self.find_first_model(klass, conditions)
klass.first(conditions)
end

# Find all models matching conditions
def self.find_all_models(klass, conditions)
klass.all(conditions)
end
end
end
end
2 changes: 1 addition & 1 deletion lib/pickle/config.rb
Expand Up @@ -11,7 +11,7 @@ def configure(&block)
end

def adapters
@adapters ||= [:machinist, :factory_girl, :active_record]
@adapters ||= [:machinist, :factory_girl]
end

def adapter_classes
Expand Down
1 change: 1 addition & 0 deletions lib/pickle/world.rb
Expand Up @@ -3,6 +3,7 @@
# auto require for active record and datamapper
require 'pickle/adapters/active_record' if defined?(ActiveRecord::Base)
require 'pickle/adapters/data_mapper' if defined?(DataMapper::Resource)
require 'pickle/adapters/mongoid' if defined?(Mongoid::Document)

# make cucumber world pickle aware
World(Pickle::Session)
Expand Down

0 comments on commit f58e0dc

Please sign in to comment.