ruby_mongo_utils 0.0.8 → 0.0.9
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/mongo_utils/stripable.rb +5 -1
- data/lib/mongo_utils/version.rb +1 -1
- data/spec/mongo_utils/stripable_spec.rb +4 -26
- metadata +2 -2
@@ -8,11 +8,15 @@ module MongoUtils
|
|
8
8
|
end
|
9
9
|
|
10
10
|
def plain_value_blank?(value)
|
11
|
+
if value.is_a?(Hash)
|
12
|
+
value = value.dup
|
13
|
+
value.reject! { |_, v| plain_value_blank?(v) }
|
14
|
+
end
|
11
15
|
value.blank? || value == 0
|
12
16
|
end
|
13
17
|
|
14
18
|
def blank_and_was_blank_value?(attribute, value)
|
15
|
-
|
19
|
+
plain_value_blank?(value) && respond_to?("#{attribute}_was") && blank_value?(send("#{attribute}_was"))
|
16
20
|
end
|
17
21
|
|
18
22
|
def self.included(base)
|
data/lib/mongo_utils/version.rb
CHANGED
@@ -223,28 +223,6 @@ describe MongoUtils::Stripable do
|
|
223
223
|
page.keys.should include 'likes'
|
224
224
|
end
|
225
225
|
|
226
|
-
it 'should update an empty value to another and stript empties in higher level hashes' do
|
227
|
-
page = Page.first
|
228
|
-
page.likes[:lifetime] = { user777: 77, user555: 0 }
|
229
|
-
page.save!
|
230
|
-
|
231
|
-
page.likes.should eq({ lifetime: { user777: 77 } })
|
232
|
-
|
233
|
-
page = Page.collection.find.first
|
234
|
-
page.keys.should include 'likes'
|
235
|
-
end
|
236
|
-
|
237
|
-
it 'should update an empty value to another and stript empties in higher level hashes' do
|
238
|
-
page = Page.first
|
239
|
-
page.likes[:lifetime] = { user777: 77, user555: 0, total: { by_user: [] } }
|
240
|
-
page.save!
|
241
|
-
|
242
|
-
page.likes.should eq({ lifetime: { user777: 77 } })
|
243
|
-
|
244
|
-
page = Page.collection.find.first
|
245
|
-
page.keys.should include 'likes'
|
246
|
-
end
|
247
|
-
|
248
226
|
context 'after update' do
|
249
227
|
before do
|
250
228
|
page = Page.first
|
@@ -259,7 +237,7 @@ describe MongoUtils::Stripable do
|
|
259
237
|
|
260
238
|
page = Page.first
|
261
239
|
page.likes['totals'].should eq 55
|
262
|
-
page.likes['lifetime'].should eq({ 'user777' => 77 })
|
240
|
+
page.likes['lifetime'].should eq({ 'user777' => 77 , 'user555' => 0, 'total' => { 'by_user' => [] } })
|
263
241
|
end
|
264
242
|
|
265
243
|
it 'should be able to add another key to the second level hash' do
|
@@ -272,13 +250,13 @@ describe MongoUtils::Stripable do
|
|
272
250
|
page.likes['lifetime']['user777'].should eq 77
|
273
251
|
end
|
274
252
|
|
275
|
-
it 'should be able to make existing key inside a hash to empty value' do
|
253
|
+
it 'should be able to make existing key inside a hash to an empty value' do
|
276
254
|
page = Page.first
|
277
255
|
page.likes['lifetime']['user777'] = 0
|
278
256
|
page.save!
|
279
257
|
|
280
258
|
page = Page.first
|
281
|
-
page.likes['lifetime'].should
|
259
|
+
page.likes['lifetime']['user777'].should eq 0
|
282
260
|
end
|
283
261
|
|
284
262
|
it 'should be able to make existing key inside a hash to empty value and set another value' do
|
@@ -288,7 +266,7 @@ describe MongoUtils::Stripable do
|
|
288
266
|
page.save!
|
289
267
|
|
290
268
|
page = Page.first
|
291
|
-
page.likes['lifetime'].should eq({ 'user555' => 55 })
|
269
|
+
page.likes['lifetime'].should eq({ 'user777' => 0, 'user555' => 55, 'total' => { 'by_user' => [] } })
|
292
270
|
end
|
293
271
|
end
|
294
272
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ruby_mongo_utils
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.9
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-05-
|
12
|
+
date: 2013-05-03 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: mongoid
|