Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Add specs for Mongoid 3

  • Loading branch information...
commit bf86d91157b3d5d6fa019b083ecac58d69e44238 1 parent da62e52
Andreas Loupasakis alup authored
12 Rakefile
View
@@ -20,7 +20,13 @@ task :default => "spec:all"
task :test => :spec
namespace :spec do
- desc "Run Tests against mongoid"
+ desc "Run Tests against mongoid (version 3)"
+ task :mongoid3 do
+ sh "BUNDLE_GEMFILE='gemfiles/mongoid3.gemfile' bundle --quiet"
+ sh "BUNDLE_GEMFILE='gemfiles/mongoid3.gemfile' bundle exec rake -t spec"
+ end
+
+ desc "Run Tests against mongoid (version 2)"
task :mongoid2 do
sh "BUNDLE_GEMFILE='gemfiles/mongoid2.gemfile' bundle --quiet"
sh "BUNDLE_GEMFILE='gemfiles/mongoid2.gemfile' bundle exec rake -t spec"
@@ -34,6 +40,10 @@ namespace :spec do
desc "Run Tests against all ORMs"
task :all do
+ # Mongoid 3
+ sh "BUNDLE_GEMFILE='gemfiles/mongoid3.gemfile' bundle --quiet"
+ sh "BUNDLE_GEMFILE='gemfiles/mongoid3.gemfile' bundle exec rake -t spec"
+
# Mongoid 2
sh "BUNDLE_GEMFILE='gemfiles/mongoid2.gemfile' bundle --quiet"
sh "BUNDLE_GEMFILE='gemfiles/mongoid2.gemfile' bundle exec rake -t spec"
15 gemfiles/mongoid3.gemfile
View
@@ -0,0 +1,15 @@
+source :rubygems
+
+gem 'mongoid', '>= 3.0.0'
+
+platforms :jruby do
+ gem "activerecord-jdbc-adapter"
+ gem "activerecord-jdbcsqlite3-adapter"
+ gem "jruby-openssl"
+end
+
+platforms :ruby do
+ gem "sqlite3"
+end
+
+gemspec :path => '../'
16 spec/dummy/config/mongoid.yml
View
@@ -1,7 +1,23 @@
development:
+ # For Mongoid 2.x
host: localhost
database: dummy_development
+ # For Mongoid 3.x
+ sessions:
+ default:
+ database: dummy_development
+ hosts:
+ - localhost:27017
+
test:
+ # For Mongoid 2.x
host: localhost
database: dummy_test
+
+ # For Mongoid 3.x
+ sessions:
+ default:
+ database: dummy_test
+ hosts:
+ - localhost:27017
31 spec/mongoid/three_spec.rb
View
@@ -0,0 +1,31 @@
+require 'spec_helper'
+
+if defined?(Mongoid) && ::Mongoid::VERSION =~ /^3(.*)/
+
+ describe Money do
+ let!(:priceable) { Priceable.create(:price => Money.new(100, 'EUR')) }
+
+ context "mongoize" do
+ it "mongoizes correctly a Money object to a hash of cents and currency" do
+ priceable.price.cents.should == 100
+ priceable.price.currency.should == Money::Currency.find('EUR')
+ end
+ end
+
+ context "demongoize" do
+ subject { priceable.price }
+ it { should be_an_instance_of(Money) }
+ it { should == Money.new(100, 'EUR') }
+ it "returns nil if a nil value was stored" do
+ nil_priceable = Priceable.create(:price => nil)
+ nil_priceable.price.should be_nil
+ end
+ end
+
+ context "evolve" do
+ it "transforms correctly a Money object to a Mongo friendly value" do
+ Priceable.where(:price => Money.new(100, 'EUR')).first.should == priceable
+ end
+ end
+ end
+end
2  spec/mongoid/two_spec.rb
View
@@ -1,6 +1,6 @@
require 'spec_helper'
-if defined? Mongoid
+if defined?(Mongoid) && ::Mongoid::VERSION =~ /^2(.*)/
describe Money do
let(:priceable) { Priceable.create(:price => Money.new(100, 'EUR')) }
Please sign in to comment.
Something went wrong with that request. Please try again.