mongo_mapper 0.15.4 → 0.15.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +4 -0
- data/lib/mongo_mapper/document.rb +1 -0
- data/lib/mongo_mapper/plugins/associations/proxy/proxy.rb +1 -0
- data/lib/mongo_mapper/plugins/keys.rb +14 -2
- data/lib/mongo_mapper/plugins/querying.rb +2 -2
- data/lib/mongo_mapper/plugins/shardable.rb +30 -0
- data/lib/mongo_mapper/version.rb +1 -1
- data/lib/mongo_mapper.rb +1 -0
- data/spec/examples.txt +1698 -1691
- data/spec/functional/shardable_spec.rb +67 -0
- data/spec/unit/associations/proxy_spec.rb +13 -0
- metadata +4 -2
@@ -0,0 +1,67 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
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
|
+
describe 'shard_key_fields' do
|
13
|
+
it 'returns declared field names' do
|
14
|
+
sharded_model.shard_key_fields.should == ['first_name', 'last_name']
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
describe 'shard_key_filter' do
|
19
|
+
context 'new record' do
|
20
|
+
let(:document) { sharded_model.new(first_name: 'John', last_name: 'Smith') }
|
21
|
+
|
22
|
+
it 'returns current values' do
|
23
|
+
document.shard_key_filter.should == { 'first_name' => 'John', 'last_name' => 'Smith' }
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
context 'persisted record' do
|
28
|
+
let(:document) { sharded_model.create!(first_name: 'John', last_name: 'Smith') }
|
29
|
+
|
30
|
+
before do
|
31
|
+
document.first_name = 'William'
|
32
|
+
end
|
33
|
+
|
34
|
+
it 'returns persisted values' do
|
35
|
+
document.shard_key_filter.should == { 'first_name' => 'John', 'last_name' => 'Smith' }
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
context 'creating new document' do
|
41
|
+
let(:document) { sharded_model.new(first_name: 'John', last_name: 'Smith') }
|
42
|
+
|
43
|
+
it 'inserts new document' do
|
44
|
+
lambda { document.save! }.should change { sharded_model.count }.by(1)
|
45
|
+
|
46
|
+
persisted = sharded_model.find(document.id)
|
47
|
+
persisted.first_name.should == 'John'
|
48
|
+
persisted.last_name.should == 'Smith'
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
context 'updating persisted document' do
|
53
|
+
let(:document) { sharded_model.create!(first_name: 'John', last_name: 'Smith') }
|
54
|
+
|
55
|
+
before do
|
56
|
+
document.first_name = 'William'
|
57
|
+
end
|
58
|
+
|
59
|
+
it 'updates persisted document' do
|
60
|
+
lambda { document.save! }.should_not change { sharded_model.count }
|
61
|
+
|
62
|
+
persisted = sharded_model.find(document.id)
|
63
|
+
persisted.first_name.should == 'William'
|
64
|
+
persisted.last_name.should == 'Smith'
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
@@ -108,4 +108,17 @@ describe "Proxy" do
|
|
108
108
|
lambda { @proxy.private_foo }.should raise_error(NoMethodError, /private method `private_foo' called/)
|
109
109
|
end
|
110
110
|
end
|
111
|
+
|
112
|
+
context "hash" do
|
113
|
+
it "should return the same value for the same proxy" do
|
114
|
+
proxy_a = FakeProxy.new(@owner, @association)
|
115
|
+
proxy_b = FakeProxy.new(@owner, @association)
|
116
|
+
|
117
|
+
proxy_a.hash.should == proxy_b.hash
|
118
|
+
end
|
119
|
+
|
120
|
+
it "should return different values for different proxies" do
|
121
|
+
@proxy.hash.should_not == @nil_proxy.hash
|
122
|
+
end
|
123
|
+
end
|
111
124
|
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.5
|
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:
|
13
|
+
date: 2022-02-18 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: mongo
|
@@ -202,6 +202,7 @@ files:
|
|
202
202
|
- lib/mongo_mapper/plugins/sci.rb
|
203
203
|
- lib/mongo_mapper/plugins/scopes.rb
|
204
204
|
- lib/mongo_mapper/plugins/serialization.rb
|
205
|
+
- lib/mongo_mapper/plugins/shardable.rb
|
205
206
|
- lib/mongo_mapper/plugins/stats.rb
|
206
207
|
- lib/mongo_mapper/plugins/strong_parameters.rb
|
207
208
|
- lib/mongo_mapper/plugins/timestamps.rb
|
@@ -258,6 +259,7 @@ files:
|
|
258
259
|
- spec/functional/safe_spec.rb
|
259
260
|
- spec/functional/sci_spec.rb
|
260
261
|
- spec/functional/scopes_spec.rb
|
262
|
+
- spec/functional/shardable_spec.rb
|
261
263
|
- spec/functional/static_keys_spec.rb
|
262
264
|
- spec/functional/stats_spec.rb
|
263
265
|
- spec/functional/strong_parameters_spec.rb
|