populate-me 0.6.2 → 0.6.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: dbda9949e894e8d1c77c8ad65e0bfdd2bf037873
4
- data.tar.gz: e7fcb6b304893759a53af5ae065a6674bf2b07bb
3
+ metadata.gz: c2e822a83612d9476257936de177d9f9fa1d2e84
4
+ data.tar.gz: 1c12f75c1b8b16f1ddd815483b5076ae0dfd4b65
5
5
  SHA512:
6
- metadata.gz: e784e1176489b34f3f19331bef9d1800aca5d086eb0f481ea5002e45dfba8d36787b97b8b07c8d7ba2bd3c19f0719b06eb09d810531ce87f92d49d750f913ae5
7
- data.tar.gz: 6a19f005cb13878124042a563eb621f596cf83d1a3fa063a62e99a5b75366a4a05665033ed8168a1f54fd521db8a8500b92f064e98915d656a3391d28e7f5e27
6
+ metadata.gz: 7a6e9cc6229589493feed226de03ed0b1858e69ecbbebeec2521f0e353ca73cc98ca17efdfbc6788e8ecdb6de3774d8e10dc3f15211d010663317589168020a3
7
+ data.tar.gz: 1e799cf84d985714c01229e5b4616e2d84b6ecfbed3242a43751aed6e4ef8ca9007d261ddcee9e9e8dfdb90eba6d7d941b97bffe39b3a0005482fffca06b7045
@@ -15,7 +15,7 @@ module PopulateMe
15
15
  def to_admin_list_item o={}
16
16
  {
17
17
  class_name: self.class.name,
18
- id: self.id,
18
+ id: self.id.to_s,
19
19
  admin_url: to_admin_url,
20
20
  title: WebUtils.truncate(to_s, 60),
21
21
  image_url: admin_image_url,
@@ -70,7 +70,7 @@ module PopulateMe
70
70
  end
71
71
 
72
72
  def set_indexes f, ids=[]
73
- if self.fields[f.to_sym][:direction]==:desc
73
+ if self.fields and self.fields[f.to_sym] and self.fields[f.to_sym][:direction]==:desc
74
74
  ids = ids.dup.reverse
75
75
  end
76
76
  ids.each_with_index do |id,i|
@@ -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, (id, i)|
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=>id},
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 = BSON::ObjectId.from_string(theid) if BSON::ObjectId.legal?(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
@@ -1,4 +1,4 @@
1
1
  module PopulateMe
2
- VERSION = '0.6.2'
2
+ VERSION = '0.6.3'
3
3
  end
4
4
 
@@ -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.2
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-03-07 00:00:00.000000000 Z
11
+ date: 2018-04-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: web-utils