mongo_mapper 0.15.5 → 0.15.6
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 +4 -4
- data/lib/mongo_mapper/connection.rb +1 -1
- data/lib/mongo_mapper/plugins/caching.rb +2 -2
- data/lib/mongo_mapper/plugins/embedded_callbacks.rb +2 -2
- data/lib/mongo_mapper/plugins.rb +18 -1
- data/lib/mongo_mapper/version.rb +1 -1
- data/spec/examples.txt +1720 -1719
- data/spec/functional/callbacks_spec.rb +5 -1
- data/spec/functional/shardable_spec.rb +11 -19
- data/spec/support/sharded_model.rb +24 -0
- data/spec/unit/document_spec.rb +1 -1
- data/spec/unit/embedded_document_spec.rb +3 -3
- data/spec/unit/mongo_mapper_spec.rb +10 -5
- metadata +4 -3
@@ -10,10 +10,14 @@ module CallbacksSupport
|
|
10
10
|
:before_save, :after_save,
|
11
11
|
:before_destroy, :after_destroy
|
12
12
|
].each do |callback|
|
13
|
-
base.send(callback) do
|
13
|
+
base.send(callback, if: :always_true) do
|
14
14
|
history << callback.to_sym
|
15
15
|
end
|
16
16
|
end
|
17
|
+
|
18
|
+
base.send(:define_method, :always_true) do
|
19
|
+
true
|
20
|
+
end
|
17
21
|
end
|
18
22
|
|
19
23
|
def history
|
@@ -1,65 +1,57 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe 'Shardable' do
|
4
|
-
let(:sharded_model) {
|
5
|
-
Doc do
|
6
|
-
key :first_name, String
|
7
|
-
key :last_name, String
|
8
|
-
shard_key :first_name, :last_name
|
9
|
-
end
|
10
|
-
}
|
11
|
-
|
12
4
|
describe 'shard_key_fields' do
|
13
5
|
it 'returns declared field names' do
|
14
|
-
|
6
|
+
ShardedModel.shard_key_fields.should == ['first_name']
|
15
7
|
end
|
16
8
|
end
|
17
9
|
|
18
10
|
describe 'shard_key_filter' do
|
19
11
|
context 'new record' do
|
20
|
-
let(:document) {
|
12
|
+
let(:document) { ShardedModel.new(first_name: 'John', last_name: 'Smith') }
|
21
13
|
|
22
14
|
it 'returns current values' do
|
23
|
-
document.shard_key_filter.should == { 'first_name' => 'John'
|
15
|
+
document.shard_key_filter.should == { 'first_name' => 'John' }
|
24
16
|
end
|
25
17
|
end
|
26
18
|
|
27
19
|
context 'persisted record' do
|
28
|
-
let(:document) {
|
20
|
+
let(:document) { ShardedModel.create!(first_name: 'John', last_name: 'Smith') }
|
29
21
|
|
30
22
|
before do
|
31
23
|
document.first_name = 'William'
|
32
24
|
end
|
33
25
|
|
34
26
|
it 'returns persisted values' do
|
35
|
-
document.shard_key_filter.should == { 'first_name' => 'John'
|
27
|
+
document.shard_key_filter.should == { 'first_name' => 'John' }
|
36
28
|
end
|
37
29
|
end
|
38
30
|
end
|
39
31
|
|
40
32
|
context 'creating new document' do
|
41
|
-
let(:document) {
|
33
|
+
let(:document) { ShardedModel.new(first_name: 'John', last_name: 'Smith') }
|
42
34
|
|
43
35
|
it 'inserts new document' do
|
44
|
-
lambda { document.save! }.should change {
|
36
|
+
lambda { document.save! }.should change { ShardedModel.count }.by(1)
|
45
37
|
|
46
|
-
persisted =
|
38
|
+
persisted = ShardedModel.find(document.id)
|
47
39
|
persisted.first_name.should == 'John'
|
48
40
|
persisted.last_name.should == 'Smith'
|
49
41
|
end
|
50
42
|
end
|
51
43
|
|
52
44
|
context 'updating persisted document' do
|
53
|
-
let(:document) {
|
45
|
+
let(:document) { ShardedModel.create!(first_name: 'John', last_name: 'Smith') }
|
54
46
|
|
55
47
|
before do
|
56
48
|
document.first_name = 'William'
|
57
49
|
end
|
58
50
|
|
59
51
|
it 'updates persisted document' do
|
60
|
-
lambda { document.save! }.should_not change {
|
52
|
+
lambda { document.save! }.should_not change { ShardedModel.count }
|
61
53
|
|
62
|
-
persisted =
|
54
|
+
persisted = ShardedModel.find(document.id)
|
63
55
|
persisted.first_name.should == 'William'
|
64
56
|
persisted.last_name.should == 'Smith'
|
65
57
|
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
class ShardedModel
|
2
|
+
include MongoMapper::Document
|
3
|
+
|
4
|
+
key :first_name, String
|
5
|
+
key :last_name, String
|
6
|
+
shard_key :first_name
|
7
|
+
end
|
8
|
+
|
9
|
+
if ENV.fetch("ENABLE_SHARDING", "0") == "1"
|
10
|
+
client = MongoMapper.connection
|
11
|
+
database = MongoMapper.database
|
12
|
+
|
13
|
+
# https://www.mongodb.com/docs/manual/reference/command/enableSharding/#mongodb-dbcommand-dbcmd.enableSharding
|
14
|
+
client.use(:admin).command(enableSharding: database.name)
|
15
|
+
|
16
|
+
# https://www.mongodb.com/docs/manual/reference/command/shardCollection/#mongodb-dbcommand-dbcmd.shardCollection
|
17
|
+
# Note: this command automatically creates the index for the empty collection
|
18
|
+
client.use(:admin).command(
|
19
|
+
shardCollection: [database.name, ShardedModel.collection.name].join("."),
|
20
|
+
key: {
|
21
|
+
first_name: "hashed",
|
22
|
+
},
|
23
|
+
)
|
24
|
+
end
|
data/spec/unit/document_spec.rb
CHANGED
@@ -220,10 +220,10 @@ describe "EmbeddedDocument" do
|
|
220
220
|
end
|
221
221
|
|
222
222
|
it "should be recorded" do
|
223
|
-
Grandparent.direct_descendants.should
|
224
|
-
Grandparent.descendants.to_set.should
|
223
|
+
Grandparent.direct_descendants.should contain_exactly(Parent)
|
224
|
+
Grandparent.descendants.to_set.should contain_exactly(Parent, Child, OtherChild)
|
225
225
|
|
226
|
-
Parent.descendants.should
|
226
|
+
Parent.descendants.should contain_exactly(Child, OtherChild)
|
227
227
|
end
|
228
228
|
end
|
229
229
|
end
|
@@ -71,7 +71,7 @@ describe "MongoMapper" do
|
|
71
71
|
'development' => {'hosts' => ['127.0.0.1:27017'], 'database' => 'test', 'read' => 'primary'}
|
72
72
|
}
|
73
73
|
logger = double('logger')
|
74
|
-
Mongo::Client.should_receive(:new).with(['127.0.0.1:27017'], :logger => logger, :read => :primary, :database => 'test')
|
74
|
+
Mongo::Client.should_receive(:new).with(['127.0.0.1:27017'], { :logger => logger, :read => :primary, :database => 'test' })
|
75
75
|
MongoMapper.connect('development', :logger => logger)
|
76
76
|
end
|
77
77
|
|
@@ -80,7 +80,7 @@ describe "MongoMapper" do
|
|
80
80
|
'development' => {'hosts' => ['192.168.1.1:2222'], 'database' => 'test', 'safe' => true}
|
81
81
|
}
|
82
82
|
logger = double('logger')
|
83
|
-
Mongo::Client.should_receive(:new).with(['192.168.1.1:2222'], :logger => logger, :safe => true, :database => 'test')
|
83
|
+
Mongo::Client.should_receive(:new).with(['192.168.1.1:2222'], { :logger => logger, :safe => true, :database => 'test' })
|
84
84
|
MongoMapper.connect('development', :logger => logger)
|
85
85
|
end
|
86
86
|
|
@@ -89,7 +89,7 @@ describe "MongoMapper" do
|
|
89
89
|
'development' => {'uri' => 'mongodb://127.0.0.1:27017/test', 'options'=> {:foo => 1}}
|
90
90
|
}
|
91
91
|
logger = double('logger')
|
92
|
-
Mongo::Client.should_receive(:new).with('mongodb://127.0.0.1:27017/test', :logger => logger, :foo => 1)
|
92
|
+
Mongo::Client.should_receive(:new).with('mongodb://127.0.0.1:27017/test', { :logger => logger, :foo => 1 })
|
93
93
|
MongoMapper.connect('development', :logger => logger)
|
94
94
|
end
|
95
95
|
|
@@ -97,7 +97,7 @@ describe "MongoMapper" do
|
|
97
97
|
MongoMapper.config = {
|
98
98
|
'development' => {'hosts' => ['127.0.0.1:27017'], 'database' => 'test', 'user' => 'john', 'password' => 'secret'}
|
99
99
|
}
|
100
|
-
Mongo::Client.should_receive(:new).with(['127.0.0.1:27017'], :database => 'test', :user => 'john', :password => 'secret')
|
100
|
+
Mongo::Client.should_receive(:new).with(['127.0.0.1:27017'], { :database => 'test', :user => 'john', :password => 'secret' })
|
101
101
|
MongoMapper.connect('development')
|
102
102
|
end
|
103
103
|
|
@@ -129,9 +129,14 @@ describe "MongoMapper" do
|
|
129
129
|
it "should work as shortcut for setting config, environment and options" do
|
130
130
|
config, logger = double('config'), double('logger')
|
131
131
|
MongoMapper.should_receive(:config=).with(config)
|
132
|
-
MongoMapper.should_receive(:connect).with('development', :logger => logger)
|
132
|
+
MongoMapper.should_receive(:connect).with('development', { :logger => logger })
|
133
133
|
MongoMapper.should_receive(:handle_passenger_forking).once
|
134
134
|
MongoMapper.setup(config, 'development', :logger => logger)
|
135
135
|
end
|
136
|
+
|
137
|
+
it "should use the right reconnect method" do
|
138
|
+
Mongo::Client.instance_methods.should_not include(:connect) # v1
|
139
|
+
Mongo::Client.instance_methods.should include(:reconnect) # v1
|
140
|
+
end
|
136
141
|
end
|
137
142
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mongo_mapper
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.15.
|
4
|
+
version: 0.15.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- John Nunemaker
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2022-
|
13
|
+
date: 2022-06-10 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: mongo
|
@@ -271,6 +271,7 @@ files:
|
|
271
271
|
- spec/spec_helper.rb
|
272
272
|
- spec/support/matchers.rb
|
273
273
|
- spec/support/models.rb
|
274
|
+
- spec/support/sharded_model.rb
|
274
275
|
- spec/unit/associations/base_spec.rb
|
275
276
|
- spec/unit/associations/belongs_to_association_spec.rb
|
276
277
|
- spec/unit/associations/many_association_spec.rb
|
@@ -320,7 +321,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
320
321
|
- !ruby/object:Gem::Version
|
321
322
|
version: '0'
|
322
323
|
requirements: []
|
323
|
-
rubygems_version: 3.
|
324
|
+
rubygems_version: 3.3.7
|
324
325
|
signing_key:
|
325
326
|
specification_version: 4
|
326
327
|
summary: A Ruby Object Mapper for Mongo
|