populate-me 0.22.1 → 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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 55d30e2228d61d7b09c44f2b10aec8b9f807bac471c93d98891e82dd3e1f4d00
|
4
|
+
data.tar.gz: bd4d649fb3a4db45361dff0c7b83cf90978ae1a55223f25419b95b93681c509f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f6230c8dee48e0540ce3f72a595e710be140d910458ded8b68141885c36eda7f87eba45895da9fc07f40d89d1e4baefdb6dbd9a94efe3a8c25948194fb1f19de
|
7
|
+
data.tar.gz: f0d345e9f161ae45a93ccc79697d1419d31474625323ab2d03cc022fa3feb5b4396d56d782214d7ea7e42c53f5b541617f7e741110049a2b23c11c4b67ce995f
|
@@ -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
|
-
|
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={}
|
data/lib/populate_me/mongo.rb
CHANGED
@@ -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
|
-
|
99
|
-
self.admin_find(o.merge({
|
100
|
-
query: {id_string_key => {'$in' =>
|
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={}
|
data/lib/populate_me/version.rb
CHANGED
@@ -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.
|
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: 2024-
|
11
|
+
date: 2024-09-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: web-utils
|