diff --git a/History.txt b/History.txt index 50f9ea8a..7234a6a7 100644 --- a/History.txt +++ b/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 diff --git a/README.rdoc b/README.rdoc index 44702924..2349b318 100644 --- a/README.rdoc +++ b/README.rdoc @@ -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 @@ -133,13 +133,11 @@ In: features/support/pickle.rb 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 @@ -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] \ No newline at end of file +* {Chris Flipse}[http://github.com/cflipse] diff --git a/VERSION b/VERSION index c2c0004f..449d7e73 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -0.3.5 +0.3.6 diff --git a/lib/pickle/adapters/mongoid.rb b/lib/pickle/adapters/mongoid.rb new file mode 100644 index 00000000..cd9cbae2 --- /dev/null +++ b/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 diff --git a/lib/pickle/config.rb b/lib/pickle/config.rb index 2c90e949..70418c1b 100644 --- a/lib/pickle/config.rb +++ b/lib/pickle/config.rb @@ -11,7 +11,7 @@ def configure(&block) end def adapters - @adapters ||= [:machinist, :factory_girl, :active_record] + @adapters ||= [:machinist, :factory_girl] end def adapter_classes diff --git a/lib/pickle/world.rb b/lib/pickle/world.rb index ed6138de..2e149251 100644 --- a/lib/pickle/world.rb +++ b/lib/pickle/world.rb @@ -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)