Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Get specs passing in both MongoMapper + Mongoid ;)

  • Loading branch information...
commit a1f5a24039074ea46152b96d83d8fe8ace2dab19 1 parent d20ba2f
@ryw ryw authored
View
10 lib/mongo_followable/followed.rb
@@ -6,8 +6,10 @@ module Followed
included do |base|
if defined?(Mongoid)
base.has_many :followers, :class_name => "Follow", :as => :followable, :dependent => :destroy
+ @db = Mongoid.default_session
elsif defined?(MongoMapper)
base.many :followers, :class_name => "Follow", :as => :followable, :dependent => :destroy
+ @db = MongoMapper.database
end
end
@@ -135,7 +137,13 @@ def all_followers(page = nil, per_page = nil)
pipeline: pipeline
}
- users_hash = Mongoid.default_session.command(command)['result']
+ if defined?(Mongoid)
+ db = Mongoid.default_session
+ elsif defined?(MongoMapper)
+ db = MongoMapper.database
+ end
+
+ users_hash = db.command(command)['result']
ids = users_hash.map {|e| e['f_id']}
View
5 spec/mongo/performance_spec.rb
@@ -1,8 +1,5 @@
-require "benchmark"
-require "rubygems"
-require "bundler/setup"
-require "mongoid"
require "spec_helper"
+require "benchmark"
users = []
1000.times { users << User.create! }
View
2  spec/spec_helper.rb
@@ -9,11 +9,11 @@
if rand > 0.5
puts 'Mongoid'
require 'mongoid'
+ Mongoid.load!(File.expand_path("../mongoid.yml", __FILE__), :test)
require File.expand_path("../../lib/mongo_followable", __FILE__)
require File.expand_path("../mongoid/user", __FILE__)
require File.expand_path("../mongoid/group", __FILE__)
require File.expand_path("../mongoid/childuser", __FILE__)
- Mongoid.load!(File.expand_path("../mongoid.yml", __FILE__), :test)
else
puts 'MongoMapper'
require 'mongo_mapper'
Please sign in to comment.
Something went wrong with that request. Please try again.