mongo_mapper 0.14.0 → 0.15.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +5 -5
- data/LICENSE +1 -1
- data/README.md +72 -0
- data/examples/keys.rb +1 -1
- data/examples/modifiers/set.rb +1 -1
- data/examples/querying.rb +1 -1
- data/examples/safe.rb +2 -2
- data/examples/scopes.rb +1 -1
- data/lib/mongo_mapper.rb +19 -17
- data/lib/mongo_mapper/connection.rb +16 -38
- data/lib/mongo_mapper/extensions/array.rb +1 -1
- data/lib/mongo_mapper/extensions/binary.rb +1 -1
- data/lib/mongo_mapper/extensions/date.rb +1 -1
- data/lib/mongo_mapper/extensions/float.rb +1 -1
- data/lib/mongo_mapper/extensions/hash.rb +1 -1
- data/lib/mongo_mapper/extensions/nil_class.rb +2 -2
- data/lib/mongo_mapper/extensions/object.rb +1 -1
- data/lib/mongo_mapper/extensions/object_id.rb +6 -2
- data/lib/mongo_mapper/extensions/set.rb +1 -1
- data/lib/mongo_mapper/extensions/string.rb +1 -1
- data/lib/mongo_mapper/plugins/accessible.rb +1 -1
- data/lib/mongo_mapper/plugins/associations/base.rb +10 -2
- data/lib/mongo_mapper/plugins/associations/belongs_to_association.rb +1 -1
- data/lib/mongo_mapper/plugins/associations/many_association.rb +6 -5
- data/lib/mongo_mapper/plugins/associations/{belongs_to_polymorphic_proxy.rb → proxy/belongs_to_polymorphic_proxy.rb} +0 -0
- data/lib/mongo_mapper/plugins/associations/{belongs_to_proxy.rb → proxy/belongs_to_proxy.rb} +6 -0
- data/lib/mongo_mapper/plugins/associations/proxy/collection.rb +55 -0
- data/lib/mongo_mapper/plugins/associations/{embedded_collection.rb → proxy/embedded_collection.rb} +0 -0
- data/lib/mongo_mapper/plugins/associations/{in_array_proxy.rb → proxy/in_array_proxy.rb} +36 -6
- data/lib/mongo_mapper/plugins/associations/proxy/in_foreign_array_proxy.rb +136 -0
- data/lib/mongo_mapper/plugins/associations/{many_documents_as_proxy.rb → proxy/many_documents_as_proxy.rb} +0 -0
- data/lib/mongo_mapper/plugins/associations/{many_documents_proxy.rb → proxy/many_documents_proxy.rb} +0 -4
- data/lib/mongo_mapper/plugins/associations/{many_embedded_polymorphic_proxy.rb → proxy/many_embedded_polymorphic_proxy.rb} +0 -0
- data/lib/mongo_mapper/plugins/associations/{many_embedded_proxy.rb → proxy/many_embedded_proxy.rb} +0 -0
- data/lib/mongo_mapper/plugins/associations/{many_polymorphic_proxy.rb → proxy/many_polymorphic_proxy.rb} +0 -0
- data/lib/mongo_mapper/plugins/associations/{one_as_proxy.rb → proxy/one_as_proxy.rb} +0 -0
- data/lib/mongo_mapper/plugins/associations/{one_embedded_polymorphic_proxy.rb → proxy/one_embedded_polymorphic_proxy.rb} +0 -0
- data/lib/mongo_mapper/plugins/associations/{one_embedded_proxy.rb → proxy/one_embedded_proxy.rb} +3 -1
- data/lib/mongo_mapper/plugins/associations/{one_proxy.rb → proxy/one_proxy.rb} +0 -0
- data/lib/mongo_mapper/plugins/associations/proxy/proxy.rb +164 -0
- data/lib/mongo_mapper/plugins/associations/single_association.rb +5 -13
- data/lib/mongo_mapper/plugins/dirty.rb +29 -37
- data/lib/mongo_mapper/plugins/document.rb +1 -1
- data/lib/mongo_mapper/plugins/dynamic_querying/dynamic_finder.rb +1 -1
- data/lib/mongo_mapper/plugins/embedded_callbacks.rb +1 -0
- data/lib/mongo_mapper/plugins/embedded_document.rb +2 -2
- data/lib/mongo_mapper/plugins/identity_map.rb +3 -1
- data/lib/mongo_mapper/plugins/indexes.rb +13 -6
- data/lib/mongo_mapper/plugins/keys.rb +12 -7
- data/lib/mongo_mapper/plugins/keys/key.rb +21 -13
- data/lib/mongo_mapper/plugins/modifiers.rb +39 -14
- data/lib/mongo_mapper/plugins/persistence.rb +6 -2
- data/lib/mongo_mapper/plugins/querying.rb +9 -3
- data/lib/mongo_mapper/plugins/querying/decorated_plucky_query.rb +6 -6
- data/lib/mongo_mapper/plugins/safe.rb +10 -4
- data/lib/mongo_mapper/plugins/scopes.rb +19 -3
- data/lib/mongo_mapper/plugins/stats.rb +1 -3
- data/lib/mongo_mapper/plugins/strong_parameters.rb +26 -0
- data/lib/mongo_mapper/plugins/validations.rb +1 -1
- data/lib/mongo_mapper/railtie.rb +1 -0
- data/lib/mongo_mapper/utils.rb +2 -2
- data/lib/mongo_mapper/version.rb +1 -1
- data/spec/examples.txt +1731 -0
- data/spec/functional/accessible_spec.rb +7 -1
- data/spec/functional/associations/belongs_to_polymorphic_proxy_spec.rb +2 -2
- data/spec/functional/associations/belongs_to_proxy_spec.rb +55 -5
- data/spec/functional/associations/in_array_proxy_spec.rb +149 -14
- data/spec/functional/associations/in_foreign_array_proxy_spec.rb +321 -0
- data/spec/functional/associations/many_documents_as_proxy_spec.rb +6 -6
- data/spec/functional/associations/many_documents_proxy_spec.rb +22 -22
- data/spec/functional/associations/many_embedded_polymorphic_proxy_spec.rb +2 -2
- data/spec/functional/associations/many_polymorphic_proxy_spec.rb +4 -4
- data/spec/functional/associations/one_as_proxy_spec.rb +8 -8
- data/spec/functional/associations/one_embedded_proxy_spec.rb +28 -0
- data/spec/functional/associations/one_proxy_spec.rb +19 -9
- data/spec/functional/associations_spec.rb +3 -3
- data/spec/functional/binary_spec.rb +2 -2
- data/spec/functional/caching_spec.rb +15 -22
- data/spec/functional/callbacks_spec.rb +2 -2
- data/spec/functional/counter_cache_spec.rb +10 -10
- data/spec/functional/dirty_spec.rb +48 -10
- data/spec/functional/dirty_with_callbacks_spec.rb +59 -0
- data/spec/functional/document_spec.rb +5 -8
- data/spec/functional/dumpable_spec.rb +1 -1
- data/spec/functional/embedded_document_spec.rb +5 -5
- data/spec/functional/identity_map_spec.rb +8 -8
- data/spec/functional/indexes_spec.rb +19 -18
- data/spec/functional/keys_spec.rb +64 -33
- data/spec/functional/logger_spec.rb +2 -2
- data/spec/functional/modifiers_spec.rb +81 -19
- data/spec/functional/partial_updates_spec.rb +8 -8
- data/spec/functional/protected_spec.rb +1 -1
- data/spec/functional/querying_spec.rb +70 -22
- data/spec/functional/safe_spec.rb +23 -27
- data/spec/functional/sci_spec.rb +7 -7
- data/spec/functional/scopes_spec.rb +89 -1
- data/spec/functional/static_keys_spec.rb +2 -2
- data/spec/functional/stats_spec.rb +28 -12
- data/spec/functional/strong_parameters_spec.rb +49 -0
- data/spec/functional/validations_spec.rb +8 -16
- data/spec/quality_spec.rb +1 -1
- data/spec/spec_helper.rb +39 -8
- data/spec/support/matchers.rb +1 -1
- data/spec/unit/associations/proxy_spec.rb +18 -10
- data/spec/unit/clone_spec.rb +1 -1
- data/spec/unit/document_spec.rb +3 -3
- data/spec/unit/embedded_document_spec.rb +4 -5
- data/spec/unit/extensions_spec.rb +12 -7
- data/spec/unit/identity_map_middleware_spec.rb +65 -96
- data/spec/unit/inspect_spec.rb +1 -1
- data/spec/unit/key_spec.rb +23 -18
- data/spec/unit/keys_spec.rb +17 -8
- data/spec/unit/mongo_mapper_spec.rb +41 -88
- data/spec/unit/rails_spec.rb +2 -2
- data/spec/unit/validations_spec.rb +18 -18
- metadata +70 -38
- data/README.rdoc +0 -56
- data/lib/mongo_mapper/extensions/ordered_hash.rb +0 -23
- data/lib/mongo_mapper/plugins/associations/collection.rb +0 -29
- data/lib/mongo_mapper/plugins/associations/proxy.rb +0 -141
data/spec/unit/inspect_spec.rb
CHANGED
@@ -31,7 +31,7 @@ describe "Inspect" do
|
|
31
31
|
klass.many :pets, :class => pets
|
32
32
|
|
33
33
|
doc = klass.new(:pets => [{:name => "Kitten"}])
|
34
|
-
doc.inspect.should =~ /_id:.*, pets:
|
34
|
+
doc.inspect.should =~ /_id:.*, pets: .*\[.*_id.*, name: "Kitten".*\]/
|
35
35
|
end
|
36
36
|
|
37
37
|
it "should include embedded document" do
|
data/spec/unit/key_spec.rb
CHANGED
@@ -1,6 +1,5 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
|
4
3
|
class FooType < Struct.new(:bar)
|
5
4
|
def self.to_mongo(value)
|
6
5
|
'to_mongo'
|
@@ -56,23 +55,24 @@ describe "Key" do
|
|
56
55
|
it "should work with name and options" do
|
57
56
|
key = Key.new(:foo, :required => true)
|
58
57
|
key.name.should == 'foo'
|
58
|
+
key.type.should be_nil
|
59
59
|
key.options[:required].should be_truthy
|
60
60
|
end
|
61
61
|
|
62
62
|
it "should not permit reserved names" do
|
63
|
-
|
63
|
+
lambda { Key.new(:id) }.should raise_error(/reserved/)
|
64
64
|
end
|
65
65
|
|
66
66
|
it "should not permit bad names" do
|
67
|
-
|
67
|
+
lambda { Key.new(:"id.bar") }.should raise_error(/must match/)
|
68
68
|
end
|
69
69
|
|
70
70
|
it "should permit bad names if __dynamic" do
|
71
|
-
|
71
|
+
lambda { Key.new(:"id.bar", :__dynamic => true) }.should_not raise_error
|
72
72
|
end
|
73
73
|
|
74
74
|
it "should permit bad names if it is not to create accessors" do
|
75
|
-
|
75
|
+
lambda { Key.new(:"id.bar", :accessors => :skip) }.should_not raise_error
|
76
76
|
end
|
77
77
|
end
|
78
78
|
|
@@ -112,7 +112,12 @@ describe "Key" do
|
|
112
112
|
subject { @key }
|
113
113
|
|
114
114
|
it "should cast each element correctly" do
|
115
|
-
ids = [
|
115
|
+
ids = [
|
116
|
+
BSON::ObjectId.new,
|
117
|
+
BSON::ObjectId.new,
|
118
|
+
BSON::ObjectId.new.to_s,
|
119
|
+
BSON::ObjectId.new.to_s
|
120
|
+
]
|
116
121
|
subject.set(ids).should == ids.map { |id| ObjectId.to_mongo(id) }
|
117
122
|
end
|
118
123
|
end
|
@@ -149,33 +154,33 @@ describe "Key" do
|
|
149
154
|
context "with :read" do
|
150
155
|
let(:accessor) { :read }
|
151
156
|
|
152
|
-
it {
|
153
|
-
it {
|
154
|
-
it {
|
157
|
+
it { subject.read_accessor?.should be_truthy }
|
158
|
+
it { subject.write_accessor?.should be_falsey }
|
159
|
+
it { subject.predicate_accessor?.should be_falsey }
|
155
160
|
end
|
156
161
|
|
157
162
|
context "with :write" do
|
158
163
|
let(:accessor) { :write }
|
159
164
|
|
160
|
-
it {
|
161
|
-
it {
|
162
|
-
it {
|
165
|
+
it { subject.read_accessor?.should be_falsey }
|
166
|
+
it { subject.write_accessor?.should be_truthy }
|
167
|
+
it { subject.predicate_accessor?.should be_falsey }
|
163
168
|
end
|
164
169
|
|
165
170
|
context "with :predicate" do
|
166
171
|
let(:accessor) { :predicate }
|
167
172
|
|
168
|
-
it {
|
169
|
-
it {
|
170
|
-
it {
|
173
|
+
it { subject.read_accessor?.should be_falsey }
|
174
|
+
it { subject.write_accessor?.should be_falsey }
|
175
|
+
it { subject.predicate_accessor?.should be_truthy }
|
171
176
|
end
|
172
177
|
|
173
178
|
context "with an array of options" do
|
174
179
|
let(:accessor) { [:read, :write] }
|
175
180
|
|
176
|
-
it {
|
177
|
-
it {
|
178
|
-
it {
|
181
|
+
it { subject.read_accessor?.should be_truthy }
|
182
|
+
it { subject.write_accessor?.should be_truthy }
|
183
|
+
it { subject.predicate_accessor?.should be_falsey }
|
179
184
|
end
|
180
185
|
end
|
181
186
|
|
data/spec/unit/keys_spec.rb
CHANGED
@@ -1,6 +1,5 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
|
4
3
|
describe "Key" do
|
5
4
|
context ".new with no id and _id of type integer" do
|
6
5
|
it "should not error" do
|
@@ -9,7 +8,7 @@ describe "Key" do
|
|
9
8
|
key :_id, Integer
|
10
9
|
end
|
11
10
|
# No sensible default id for integer, people better pass them in if they user this
|
12
|
-
|
11
|
+
suppress_stderr { klass.new.id.should be_nil }
|
13
12
|
}.should_not raise_error
|
14
13
|
end
|
15
14
|
end
|
@@ -30,7 +29,7 @@ describe "Key" do
|
|
30
29
|
key :_id, Integer
|
31
30
|
end
|
32
31
|
doc = klass.new
|
33
|
-
|
32
|
+
doc.should_receive(:warn).once
|
34
33
|
doc.assign({:x => :y})
|
35
34
|
end
|
36
35
|
end
|
@@ -82,11 +81,11 @@ describe "Key" do
|
|
82
81
|
end
|
83
82
|
|
84
83
|
it "should use []= for keys instead of public writer" do
|
85
|
-
|
84
|
+
lambda {
|
86
85
|
doc = @klass.first
|
87
86
|
doc.user['id'].should == 1
|
88
87
|
doc.user['name'].should == 'John Nunemaker'
|
89
|
-
}.
|
88
|
+
}.should_not raise_error
|
90
89
|
end
|
91
90
|
end
|
92
91
|
|
@@ -141,15 +140,25 @@ describe "Key" do
|
|
141
140
|
key :value, Integer, :default => lambda { counter += 1 }
|
142
141
|
end
|
143
142
|
|
144
|
-
|
145
|
-
|
143
|
+
lambda { instance = klass.create }.should change { counter }.by(1)
|
144
|
+
lambda {
|
146
145
|
instance.reload.value.should == 1
|
147
146
|
|
148
147
|
instance.value = 10
|
149
148
|
instance.save
|
150
149
|
|
151
150
|
instance.reload.value.should == 10
|
152
|
-
}.
|
151
|
+
}.should_not change { counter }
|
152
|
+
end
|
153
|
+
end
|
154
|
+
|
155
|
+
context "with attributes key" do
|
156
|
+
it "should raise an error" do
|
157
|
+
lambda do
|
158
|
+
klass = Doc do
|
159
|
+
key :attributes, Hash
|
160
|
+
end
|
161
|
+
end.should raise_error("`attributes` is a reserved key name")
|
153
162
|
end
|
154
163
|
end
|
155
164
|
end # KeyTest
|
@@ -3,23 +3,28 @@ require 'spec_helper'
|
|
3
3
|
class Address; end
|
4
4
|
|
5
5
|
describe "MongoMapper" do
|
6
|
-
it "should be able to write and read connection" do
|
7
|
-
conn = Mongo::
|
6
|
+
it "should be able to write and read connection", :without_connection do
|
7
|
+
conn = Mongo::Client.new(['127.0.0.1:27001'])
|
8
8
|
MongoMapper.connection = conn
|
9
9
|
MongoMapper.connection.should == conn
|
10
10
|
end
|
11
11
|
|
12
|
-
it "should default connection to new mongo ruby driver" do
|
12
|
+
it "should default connection to new mongo ruby driver", :without_connection do
|
13
13
|
MongoMapper.connection = nil
|
14
|
-
MongoMapper.connection.should be_instance_of(Mongo::
|
14
|
+
MongoMapper.connection.should be_instance_of(Mongo::Client)
|
15
15
|
end
|
16
16
|
|
17
|
-
it "should be able to
|
18
|
-
MongoMapper.database
|
19
|
-
MongoMapper.database.should be_instance_of(Mongo::DB)
|
17
|
+
it "should be able to read default database" do
|
18
|
+
MongoMapper.database.should be_instance_of(Mongo::Database)
|
20
19
|
MongoMapper.database.name.should == 'test'
|
21
20
|
end
|
22
21
|
|
22
|
+
it "should be able to write default database", :without_connection do
|
23
|
+
MongoMapper.database = 'test-2'
|
24
|
+
MongoMapper.database.should be_instance_of(Mongo::Database)
|
25
|
+
MongoMapper.database.name.should == 'test-2'
|
26
|
+
end
|
27
|
+
|
23
28
|
it "should have document not found error" do
|
24
29
|
lambda {
|
25
30
|
MongoMapper::DocumentNotFound
|
@@ -35,96 +40,64 @@ describe "MongoMapper" do
|
|
35
40
|
MongoMapper.config.should == config
|
36
41
|
end
|
37
42
|
|
38
|
-
context "connecting to environment from config" do
|
39
|
-
it "should work without authentication" do
|
40
|
-
MongoMapper.config = {
|
41
|
-
'development' => {'host' => '127.0.0.1', 'port' => 27017, 'database' => 'test'}
|
42
|
-
}
|
43
|
-
expect(Mongo::MongoClient).to receive(:new).with('127.0.0.1', 27017, {})
|
44
|
-
expect(MongoMapper).to receive(:database=).with('test')
|
45
|
-
expect_any_instance_of(Mongo::DB).to receive(:authenticate).never
|
46
|
-
MongoMapper.connect('development')
|
47
|
-
end
|
43
|
+
context "connecting to environment from config", :without_connection do
|
48
44
|
|
49
45
|
it "should work without authentication using uri" do
|
50
46
|
MongoMapper.config = {
|
51
47
|
'development' => {'uri' => 'mongodb://127.0.0.1:27017/test'}
|
52
48
|
}
|
53
|
-
|
54
|
-
expect(MongoMapper).to receive(:database=).with('test')
|
55
|
-
expect_any_instance_of(Mongo::DB).to receive(:authenticate).never
|
49
|
+
Mongo::Client.should_receive(:new).with('mongodb://127.0.0.1:27017/test', {})
|
56
50
|
MongoMapper.connect('development')
|
57
51
|
end
|
58
52
|
|
59
|
-
it "should work
|
53
|
+
it "should work without authentication using hosts" do
|
60
54
|
MongoMapper.config = {
|
61
|
-
'development' => {'
|
55
|
+
'development' => {'hosts' => ['127.0.0.1:27017']}
|
62
56
|
}
|
63
|
-
|
64
|
-
|
65
|
-
expect_any_instance_of(Mongo::DB).to receive(:authenticate).never
|
66
|
-
MongoMapper.connect(:development)
|
67
|
-
end
|
68
|
-
|
69
|
-
it "should work with options" do
|
70
|
-
MongoMapper.config = {
|
71
|
-
'development' => {'host' => '127.0.0.1', 'port' => 27017, 'database' => 'test'}
|
72
|
-
}
|
73
|
-
connection, logger = double('connection'), double('logger')
|
74
|
-
expect(Mongo::MongoClient).to receive(:new).with('127.0.0.1', 27017, :logger => logger)
|
75
|
-
MongoMapper.connect('development', :logger => logger)
|
76
|
-
end
|
77
|
-
|
78
|
-
it "should pass along ssl when true" do
|
79
|
-
MongoMapper.config = {
|
80
|
-
'development' => {'host' => '127.0.0.1', 'port' => 27017, 'database' => 'test', 'ssl' => true}
|
81
|
-
}
|
82
|
-
connection, logger = double('connection'), double('logger')
|
83
|
-
expect(Mongo::MongoClient).to receive(:new).with('127.0.0.1', 27017, :logger => logger, :ssl => true)
|
84
|
-
MongoMapper.connect('development', :logger => logger)
|
57
|
+
Mongo::Client.should_receive(:new).with(['127.0.0.1:27017'], {})
|
58
|
+
MongoMapper.connect('development')
|
85
59
|
end
|
86
60
|
|
87
|
-
it "should
|
61
|
+
it "should work without authentication using host" do
|
88
62
|
MongoMapper.config = {
|
89
|
-
'development' => {'host' => '127.0.0.1
|
63
|
+
'development' => {'host' => '127.0.0.1:27017'}
|
90
64
|
}
|
91
|
-
|
92
|
-
|
93
|
-
MongoMapper.connect('development', :logger => logger)
|
65
|
+
Mongo::Client.should_receive(:new).with(['127.0.0.1:27017'], {})
|
66
|
+
MongoMapper.connect('development')
|
94
67
|
end
|
95
68
|
|
96
69
|
it "should convert read preferences to symbols" do
|
97
70
|
MongoMapper.config = {
|
98
|
-
'development' => {'
|
71
|
+
'development' => {'hosts' => ['127.0.0.1:27017'], 'database' => 'test', 'read' => 'primary'}
|
99
72
|
}
|
100
|
-
|
101
|
-
|
73
|
+
logger = double('logger')
|
74
|
+
Mongo::Client.should_receive(:new).with(['127.0.0.1:27017'], :logger => logger, :read => :primary, :database => 'test')
|
102
75
|
MongoMapper.connect('development', :logger => logger)
|
103
76
|
end
|
104
77
|
|
105
78
|
it "should work with options from config" do
|
106
79
|
MongoMapper.config = {
|
107
|
-
'development' => {'
|
80
|
+
'development' => {'hosts' => ['192.168.1.1:2222'], 'database' => 'test', 'safe' => true}
|
108
81
|
}
|
109
|
-
|
110
|
-
|
82
|
+
logger = double('logger')
|
83
|
+
Mongo::Client.should_receive(:new).with(['192.168.1.1:2222'], :logger => logger, :safe => true, :database => 'test')
|
111
84
|
MongoMapper.connect('development', :logger => logger)
|
112
85
|
end
|
113
86
|
|
114
87
|
it "should work with options using uri" do
|
115
88
|
MongoMapper.config = {
|
116
|
-
'development' => {'uri' => 'mongodb://127.0.0.1:27017/test'}
|
89
|
+
'development' => {'uri' => 'mongodb://127.0.0.1:27017/test', 'options'=> {:foo => 1}}
|
117
90
|
}
|
118
|
-
|
119
|
-
|
91
|
+
logger = double('logger')
|
92
|
+
Mongo::Client.should_receive(:new).with('mongodb://127.0.0.1:27017/test', :logger => logger, :foo => 1)
|
120
93
|
MongoMapper.connect('development', :logger => logger)
|
121
94
|
end
|
122
95
|
|
123
96
|
it "should work with authentication" do
|
124
97
|
MongoMapper.config = {
|
125
|
-
'development' => {'
|
98
|
+
'development' => {'hosts' => ['127.0.0.1:27017'], 'database' => 'test', 'user' => 'john', 'password' => 'secret'}
|
126
99
|
}
|
127
|
-
|
100
|
+
Mongo::Client.should_receive(:new).with(['127.0.0.1:27017'], :database => 'test', :user => 'john', :password => 'secret')
|
128
101
|
MongoMapper.connect('development')
|
129
102
|
end
|
130
103
|
|
@@ -132,7 +105,7 @@ describe "MongoMapper" do
|
|
132
105
|
MongoMapper.config = {
|
133
106
|
'development' => {'uri' => 'mongodb://john:secret@127.0.0.1:27017/test'}
|
134
107
|
}
|
135
|
-
|
108
|
+
Mongo::Client.should_receive(:new).with('mongodb://john:secret@127.0.0.1:27017/test', {})
|
136
109
|
MongoMapper.connect('development')
|
137
110
|
end
|
138
111
|
|
@@ -140,44 +113,24 @@ describe "MongoMapper" do
|
|
140
113
|
MongoMapper.config = {
|
141
114
|
'development' => {'uri' => 'mysql://127.0.0.1:5336/foo'}
|
142
115
|
}
|
143
|
-
|
116
|
+
lambda { MongoMapper.connect('development') }.should raise_error(Mongo::Error::InvalidURI)
|
144
117
|
end
|
145
118
|
|
146
|
-
it
|
119
|
+
it 'should forbid use of port' do
|
147
120
|
MongoMapper.config = {
|
148
|
-
'development' => {
|
149
|
-
'hosts' => [ ['127.0.0.1', 27017], ['localhost', 27017] ],
|
150
|
-
'database' => 'test'
|
151
|
-
}
|
121
|
+
'development' => {'host' => '192.168.1.1', 'port' => '27017', 'database' => 'test', 'safe' => true}
|
152
122
|
}
|
153
|
-
|
154
|
-
expect(Mongo::MongoReplicaSetClient).to receive(:new).with( ['127.0.0.1', 27017], ['localhost', 27017], {'read_secondary' => true} )
|
155
|
-
expect(MongoMapper).to receive(:database=).with('test')
|
156
|
-
expect_any_instance_of(Mongo::DB).to receive(:authenticate).never
|
157
|
-
MongoMapper.connect('development', 'read_secondary' => true)
|
123
|
+
lambda { MongoMapper.connect('development') }.should raise_error(RuntimeError)
|
158
124
|
end
|
159
125
|
|
160
|
-
it "should create a replica set connection if config contains multiple hosts in the new format" do
|
161
|
-
MongoMapper.config = {
|
162
|
-
'development' => {
|
163
|
-
'hosts' => ['127.0.0.1:27017', 'localhost:27017'],
|
164
|
-
'database' => 'test'
|
165
|
-
}
|
166
|
-
}
|
167
|
-
|
168
|
-
expect(Mongo::MongoReplicaSetClient).to receive(:new).with( ['127.0.0.1:27017', 'localhost:27017'], {'read_secondary' => true} )
|
169
|
-
expect(MongoMapper).to receive(:database=).with('test')
|
170
|
-
expect_any_instance_of(Mongo::DB).to receive(:authenticate).never
|
171
|
-
MongoMapper.connect('development', 'read_secondary' => true)
|
172
|
-
end
|
173
126
|
end
|
174
127
|
|
175
128
|
context "setup" do
|
176
129
|
it "should work as shortcut for setting config, environment and options" do
|
177
130
|
config, logger = double('config'), double('logger')
|
178
|
-
|
179
|
-
|
180
|
-
|
131
|
+
MongoMapper.should_receive(:config=).with(config)
|
132
|
+
MongoMapper.should_receive(:connect).with('development', :logger => logger)
|
133
|
+
MongoMapper.should_receive(:handle_passenger_forking).once
|
181
134
|
MongoMapper.setup(config, 'development', :logger => logger)
|
182
135
|
end
|
183
136
|
end
|
data/spec/unit/rails_spec.rb
CHANGED
@@ -163,7 +163,7 @@ describe "Rails integration" do
|
|
163
163
|
|
164
164
|
it "should array representation of id if persisted" do
|
165
165
|
@klass.new.tap do |doc|
|
166
|
-
|
166
|
+
doc.should_receive(:persisted?).and_return(true)
|
167
167
|
doc.to_param.should == doc.id.to_s
|
168
168
|
end
|
169
169
|
end
|
@@ -178,7 +178,7 @@ describe "Rails integration" do
|
|
178
178
|
|
179
179
|
it "should array representation of id if persisted" do
|
180
180
|
@klass.new.tap do |doc|
|
181
|
-
|
181
|
+
doc.should_receive(:persisted?).and_return(true)
|
182
182
|
doc.to_key.should == [doc.id]
|
183
183
|
end
|
184
184
|
end
|
@@ -157,19 +157,19 @@ describe "Validations" do
|
|
157
157
|
end # numericality of
|
158
158
|
|
159
159
|
context "validating presence of" do
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
160
|
+
it "should work with validates_presence_of macro" do
|
161
|
+
@document.key :name, String
|
162
|
+
@document.validates_presence_of :name
|
163
|
+
doc = @document.new
|
164
|
+
doc.should have_error_on(:name)
|
165
|
+
end
|
166
|
+
|
167
|
+
it "should work with :required shortcut on key definition" do
|
168
|
+
@document.key :name, String, :required => true
|
169
|
+
doc = @document.new
|
170
|
+
doc.should have_error_on(:name)
|
171
|
+
end
|
172
|
+
end
|
173
173
|
|
174
174
|
context "validating exclusion of" do
|
175
175
|
it "should throw error if enumerator not provided" do
|
@@ -436,19 +436,19 @@ describe "Validations" do
|
|
436
436
|
end # numericality of
|
437
437
|
|
438
438
|
context "validating presence of" do
|
439
|
-
|
439
|
+
it "should work with validates_presence_of macro" do
|
440
440
|
@embedded_doc.key :name, String
|
441
441
|
@embedded_doc.validates_presence_of :name
|
442
442
|
doc = @embedded_doc.new
|
443
443
|
doc.should have_error_on(:name)
|
444
|
-
|
444
|
+
end
|
445
445
|
|
446
|
-
|
446
|
+
it "should work with :required shortcut on key definition" do
|
447
447
|
@embedded_doc.key :name, String, :required => true
|
448
448
|
doc = @embedded_doc.new
|
449
449
|
doc.should have_error_on(:name)
|
450
|
-
|
451
|
-
|
450
|
+
end
|
451
|
+
end
|
452
452
|
|
453
453
|
context "validating exclusion of" do
|
454
454
|
it "should throw error if enumerator not provided" do
|