forked from ryanong/mongoid_spacial
/
spec_helper.rb
70 lines (54 loc) · 1.9 KB
/
spec_helper.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
require 'pry'
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
$LOAD_PATH.unshift(File.dirname(__FILE__))
MODELS = File.join(File.dirname(__FILE__), "models")
SUPPORT = File.join(File.dirname(__FILE__), "support")
$LOAD_PATH.unshift(MODELS)
$LOAD_PATH.unshift(SUPPORT)
require "mongoid"
require "mocha"
require "rspec"
require "mongoid_geospatial"
# These environment variables can be set if wanting to test against a database
# that is not on the local machine.
ENV["MONGOID_SPEC_HOST"] ||= "localhost"
ENV["MONGOID_SPEC_PORT"] ||= "27018"
# These are used when creating any connection in the test suite.
HOST = ENV["MONGOID_SPEC_HOST"]
PORT = ENV["MONGOID_SPEC_PORT"].to_i
LOGGER = Logger.new($stdout)
if RUBY_VERSION >= '1.9.2'
YAML::ENGINE.yamler = 'syck'
end
puts "version: #{Mongoid::VERSION}"
require 'mongoid_setup'
Mongoid.configure do |config|
Mongoid::VersionSetup.configure config
end
# Autoload every model for the test suite that sits in spec/app/models.
Dir[ File.join(MODELS, "*.rb") ].sort.each do |file|
name = File.basename(file, ".rb")
autoload name.camelize.to_sym, name
end
Dir[ File.join(SUPPORT, "*.rb") ].each { |file| require File.basename(file) }
def bson_object_id_class
Mongoid::VERSION > '3' ? Moped::BSON:: ObjectId : BSON::ObjectId
end
RSpec.configure do |config|
config.mock_with(:mocha)
config.before(:each) do
Mongoid.purge!
# Mongoid.database.collections.each do |collection|
# unless collection.name =~ /^system\./
# collection.remove
# end
# end
end
# We filter out the specs that require authentication if the database has not
# had the mongoid user set up properly.
# user_configured = Support::Authentication.configured?
# warn(Support::Authentication.message) unless user_configured
# config.filter_run_excluding(:config => lambda { |value|
# return true if value == :user && !user_configured
# })
end