populate-me 0.6.2 → 0.6.3
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/populate_me/document_mixins/admin_adapter.rb +1 -1
- data/lib/populate_me/document_mixins/persistence.rb +1 -1
- data/lib/populate_me/mongo.rb +12 -3
- data/lib/populate_me/version.rb +1 -1
- data/test/test_document_admin_adapter.rb +4 -0
- data/test/test_mongo.rb +11 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c2e822a83612d9476257936de177d9f9fa1d2e84
|
4
|
+
data.tar.gz: 1c12f75c1b8b16f1ddd815483b5076ae0dfd4b65
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7a6e9cc6229589493feed226de03ed0b1858e69ecbbebeec2521f0e353ca73cc98ca17efdfbc6788e8ecdb6de3774d8e10dc3f15211d010663317589168020a3
|
7
|
+
data.tar.gz: 1e799cf84d985714c01229e5b4616e2d84b6ecfbed3242a43751aed6e4ef8ca9007d261ddcee9e9e8dfdb90eba6d7d941b97bffe39b3a0005482fffca06b7045
|
data/lib/populate_me/mongo.rb
CHANGED
@@ -49,10 +49,11 @@ module PopulateMe
|
|
49
49
|
if self.fields[f.to_sym][:direction]==:desc
|
50
50
|
ids = ids.dup.reverse
|
51
51
|
end
|
52
|
-
requests = ids.each_with_index.inject([]) do |list, (
|
52
|
+
requests = ids.each_with_index.inject([]) do |list, (theid, i)|
|
53
|
+
theid = string_or_object_id theid
|
53
54
|
list << {update_one:
|
54
55
|
{
|
55
|
-
filter: {self.id_string_key=>
|
56
|
+
filter: {self.id_string_key=>theid},
|
56
57
|
update: {'$set'=>{f=>i}}
|
57
58
|
}
|
58
59
|
}
|
@@ -61,7 +62,7 @@ module PopulateMe
|
|
61
62
|
end
|
62
63
|
|
63
64
|
def admin_get theid
|
64
|
-
theid =
|
65
|
+
theid = string_or_object_id theid
|
65
66
|
self.cast{ collection.find({id_string_key => theid}).first }
|
66
67
|
end
|
67
68
|
alias_method :[], :admin_get
|
@@ -88,6 +89,14 @@ module PopulateMe
|
|
88
89
|
self.collection.distinct field, query, o
|
89
90
|
end
|
90
91
|
|
92
|
+
def string_or_object_id theid
|
93
|
+
if BSON::ObjectId.legal?(theid)
|
94
|
+
BSON::ObjectId.from_string(theid)
|
95
|
+
else
|
96
|
+
theid
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
91
100
|
end
|
92
101
|
|
93
102
|
attr_accessor :_id
|
data/lib/populate_me/version.rb
CHANGED
@@ -45,6 +45,10 @@ describe PopulateMe::Document, 'AdminAdapter' do
|
|
45
45
|
class ContentTitle < PopulateMe::Document
|
46
46
|
field :content
|
47
47
|
end
|
48
|
+
it 'Sets ID as a string version' do
|
49
|
+
doc = ContentTitle.new id: 3
|
50
|
+
assert_equal '3', doc.to_admin_list_item[:id]
|
51
|
+
end
|
48
52
|
describe 'When title is long' do
|
49
53
|
it 'Is truncated' do
|
50
54
|
doc = ContentTitle.new
|
data/test/test_mongo.rb
CHANGED
@@ -245,6 +245,17 @@ describe 'PopulateMe::Mongo' do
|
|
245
245
|
assert_equal 2, MongoChampion.admin_get('b').reversed
|
246
246
|
assert_equal 0, MongoChampion.admin_get('c').reversed
|
247
247
|
end
|
248
|
+
|
249
|
+
it 'Sets the indexes correctly even if some ids are not string' do
|
250
|
+
MongoChampion.collection.drop
|
251
|
+
MongoChampion.new(id: 'a').perform_create
|
252
|
+
MongoChampion.new(id: BSON::ObjectId.from_string("507f1f77bcf86cd799439011")).perform_create
|
253
|
+
MongoChampion.new(id: BSON::ObjectId.from_string("507f191e810c19729de860ea")).perform_create
|
254
|
+
MongoChampion.set_indexes(:position,["507f1f77bcf86cd799439011",'a',"507f191e810c19729de860ea"])
|
255
|
+
assert_equal 0, MongoChampion.admin_get("507f1f77bcf86cd799439011").position
|
256
|
+
assert_equal 1, MongoChampion.admin_get('a').position
|
257
|
+
assert_equal 2, MongoChampion.admin_get("507f191e810c19729de860ea").position
|
258
|
+
end
|
248
259
|
end
|
249
260
|
|
250
261
|
describe '::admin_distinct' do
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: populate-me
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.6.
|
4
|
+
version: 0.6.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mickael Riga
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-
|
11
|
+
date: 2018-04-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: web-utils
|