populate-me 0.22.0 → 0.23.0

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
  SHA256:
3
- metadata.gz: 9685bd65706f352405ea07aa4ea887e92b29f1fa13451d37841d4ac77d13426c
4
- data.tar.gz: 996dc804bff57498ed194f482eb8e71022a80150d5c047a51239e120761e4c65
3
+ metadata.gz: 55d30e2228d61d7b09c44f2b10aec8b9f807bac471c93d98891e82dd3e1f4d00
4
+ data.tar.gz: bd4d649fb3a4db45361dff0c7b83cf90978ae1a55223f25419b95b93681c509f
5
5
  SHA512:
6
- metadata.gz: 5ed346ccb8270eb4ad447d2e7dffda0010cb9e27f911a45b6f295a3bd9dbf45e8a22871d4065dbca437db80a7deda8701123bad64bd97744e99d5e2209ebc5e6
7
- data.tar.gz: 829956b8fa1305e8f601297dc16d1686a495f29f475209743bad9fd020a91d6a8b2a90627e6dae2b3d853633edebc373a66d586607d598256eaaec7de93be9a4
6
+ metadata.gz: f6230c8dee48e0540ce3f72a595e710be140d910458ded8b68141885c36eda7f87eba45895da9fc07f40d89d1e4baefdb6dbd9a94efe3a8c25948194fb1f19de
7
+ data.tar.gz: f0d345e9f161ae45a93ccc79697d1419d31474625323ab2d03cc022fa3feb5b4396d56d782214d7ea7e42c53f5b541617f7e741110049a2b23c11c4b67ce995f
@@ -129,9 +129,9 @@
129
129
  </script>
130
130
 
131
131
  <script id="template-string-field" type="x-tmpl-mustache">
132
- <input name='{{input_name}}' value='{{input_value}}' {{#required}}required{{/required}}{{{build_input_attributes}}} {{#autocomplete.length}}list='datalist-{{id}}'{{/autocomplete.length}} />
132
+ <input name='{{input_name}}' value='{{input_value}}' {{#required}}required{{/required}}{{{build_input_attributes}}} {{#autocomplete.length}}list='datalist-{{field_name}}'{{/autocomplete.length}} />
133
133
  {{#autocomplete.length}}
134
- <datalist id='datalist-{{id}}'>
134
+ <datalist id='datalist-{{field_name}}'>
135
135
  {{#autocomplete}}
136
136
  <option value='{{.}}' />
137
137
  {{/autocomplete}}
@@ -85,9 +85,16 @@ module PopulateMe
85
85
  documents.find{|doc| doc[id_string_key] == id }
86
86
  end
87
87
  end
88
+ alias_method :[], :admin_get
88
89
 
89
90
  def admin_get_multiple ids, o={sort: nil}
90
- self.admin_find(o.merge(query: {id_string_key => {'$in' => ids.uniq.compact}}))
91
+ clean_ids = ids.uniq.compact
92
+ items = self.cast do
93
+ documents.select{|doc| clean_ids.include?(doc[id_string_key]) }
94
+ end
95
+ clean_ids.map do |id|
96
+ items.find{|item| item.id == id}
97
+ end.compact
91
98
  end
92
99
 
93
100
  def admin_find o={}
@@ -6,7 +6,7 @@ module PopulateMe
6
6
  class MissingMongoDBError < StandardError; end
7
7
 
8
8
  class Mongo < Document
9
-
9
+
10
10
  self.settings.instance_eval do
11
11
  def collection_name
12
12
  puts 'yo'
@@ -95,10 +95,13 @@ module PopulateMe
95
95
  alias_method :[], :admin_get
96
96
 
97
97
  def admin_get_multiple theids, o={sort: nil}
98
- theids = theids.uniq.compact.map{|theid| string_or_object_id(theid) }
99
- self.admin_find(o.merge({
100
- query: {id_string_key => {'$in' => theids} }
98
+ clean_ids = theids.uniq.compact.map{|theid| string_or_object_id(theid) }
99
+ items = self.admin_find(o.merge({
100
+ query: {id_string_key => {'$in' => clean_ids} }
101
101
  }))
102
+ clean_ids.map do |id|
103
+ items.find{|item| item.id == id}
104
+ end.compact
102
105
  end
103
106
 
104
107
  def admin_find o={}
@@ -1,4 +1,4 @@
1
1
  module PopulateMe
2
- VERSION = '0.22.0'
2
+ VERSION = '0.23.0'
3
3
  end
4
4
 
data/populate-me.gemspec CHANGED
@@ -25,7 +25,7 @@ Gem::Specification.new do |s|
25
25
  s.add_development_dependency 'minitest', '~> 5.8'
26
26
  s.add_development_dependency 'rack-test', '~> 2'
27
27
  s.add_development_dependency 'rack-cerberus', '~> 1.0'
28
- s.add_development_dependency 'mongo', '~> 2.18'
28
+ s.add_development_dependency 'mongo', '~> 2.19'
29
29
  s.add_development_dependency 'rack-grid-serve', '~> 0.0.8'
30
30
  s.add_development_dependency 'aws-sdk-s3', '~> 1'
31
31
  s.add_development_dependency 'racksh', '~> 1.0'
@@ -97,12 +97,12 @@ describe PopulateMe::Document, 'AdminAdapter' do
97
97
  end
98
98
 
99
99
  describe '::admin_find ::admin_find_first' do
100
-
100
+
101
101
  class FindablePerson < PopulateMe::Document
102
102
  field :first_name
103
103
  field :last_name
104
104
  end
105
-
105
+
106
106
  before do
107
107
  FindablePerson.documents = []
108
108
  FindablePerson.new(first_name: 'Bobby', last_name: 'Peru').save
@@ -136,6 +136,46 @@ describe PopulateMe::Document, 'AdminAdapter' do
136
136
 
137
137
  end
138
138
 
139
+ describe '::admin_get' do
140
+
141
+ class GetablePerson < PopulateMe::Document
142
+ field :name
143
+ field :lastname
144
+ end
145
+
146
+ before do
147
+ GetablePerson.documents = []
148
+ end
149
+
150
+ it "Should get correct item" do
151
+ jackson_id = GetablePerson.new(name: "jackson").save
152
+ assert_equal "jackson", GetablePerson.admin_get(jackson_id).name
153
+ assert_equal "jackson", GetablePerson.admin_get(jackson_id.to_s).name
154
+ assert_nil GetablePerson.admin_get("nonexistentid")
155
+
156
+ regular_id = GetablePerson.new(id: 87, name: "regular").save
157
+ # need to test with .to_s
158
+ assert_equal "regular", GetablePerson.admin_get(regular_id).name
159
+ end
160
+
161
+ it "Should get multiple items" do
162
+ # Order is not respected
163
+ alpha_id = GetablePerson.new(name: "alpha").save
164
+ beta_id = GetablePerson.new(name: "beta").save
165
+ gamma_id = GetablePerson.new(name: "gamma").save
166
+ items = GetablePerson.admin_get([beta_id, "nonexistentid", alpha_id, beta_id, nil, alpha_id])
167
+ assert items.is_a?(Array)
168
+ assert_equal 2, items.count
169
+ refute_nil items.find{|i| i.id == alpha_id}
170
+ refute_nil items.find{|i| i.id == beta_id}
171
+ assert_nil items.find{|i| i.id == gamma_id}
172
+ # respects natural order of uniq compact elements
173
+ assert_equal beta_id, items[0].id
174
+ assert_equal alpha_id, items[1].id
175
+ end
176
+
177
+ end
178
+
139
179
  describe '::admin_distinct' do
140
180
 
141
181
  class Distinction < PopulateMe::Document
data/test/test_mongo.rb CHANGED
@@ -131,12 +131,15 @@ describe 'PopulateMe::Mongo' do
131
131
  alpha_id = LowFish.new(name: "alpha").perform_create
132
132
  beta_id = LowFish.new(name: "beta").perform_create
133
133
  gamma_id = LowFish.new(name: "gamma").perform_create
134
- items = LowFish.admin_get([alpha_id, beta_id, nil, alpha_id])
134
+ items = LowFish.admin_get([beta_id, "nonexistentid", alpha_id, beta_id, nil, alpha_id])
135
135
  assert items.is_a?(Array)
136
136
  assert_equal 2, items.count
137
137
  refute_nil items.find{|i| i.id == alpha_id}
138
138
  refute_nil items.find{|i| i.id == beta_id}
139
139
  assert_nil items.find{|i| i.id == gamma_id}
140
+ # respects natural order of uniq compact elements
141
+ assert_equal beta_id, items[0].id
142
+ assert_equal alpha_id, items[1].id
140
143
  end
141
144
 
142
145
  it 'Should have the [] shortcut for admin_get' 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.22.0
4
+ version: 0.23.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mickael Riga
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-09-04 00:00:00.000000000 Z
11
+ date: 2024-09-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: web-utils
@@ -114,14 +114,14 @@ dependencies:
114
114
  requirements:
115
115
  - - "~>"
116
116
  - !ruby/object:Gem::Version
117
- version: '2.18'
117
+ version: '2.19'
118
118
  type: :development
119
119
  prerelease: false
120
120
  version_requirements: !ruby/object:Gem::Requirement
121
121
  requirements:
122
122
  - - "~>"
123
123
  - !ruby/object:Gem::Version
124
- version: '2.18'
124
+ version: '2.19'
125
125
  - !ruby/object:Gem::Dependency
126
126
  name: rack-grid-serve
127
127
  requirement: !ruby/object:Gem::Requirement