mongoid-time_with_named_zone 0.2.0 → 0.2.1
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
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0a57b966d50562922af60e9abeb585d031826bc4
|
4
|
+
data.tar.gz: b17f8b520e92bdd9a47e23d38f5b07c69cca4b55
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 385f2dd028b7a8384ce61cea0480fd0410e317102f5ccd1ec549301e40d31df7fda7ac10812c79d7ddfb91787a697dd6b32c7863a12ce60dadd06f7af082b2a3
|
7
|
+
data.tar.gz: e394289fc108e3b6341111ecddcdbea1c7d867643edfa8de9aec8cef3ec741f5a9979fdd78c60a24f0b797969162d99ceb9be827500648ac5962bb0b69080e91
|
@@ -9,8 +9,10 @@ module Mongoid
|
|
9
9
|
class << self
|
10
10
|
# Convert the object from its mongo friendly ruby type to this type
|
11
11
|
def demongoize(object)
|
12
|
-
return nil unless object
|
13
|
-
object
|
12
|
+
return nil unless object.is_a? Hash
|
13
|
+
object.symbolize_keys!
|
14
|
+
return nil unless object[:time] && object[:zone]
|
15
|
+
object[:time].in_time_zone(object[:zone])
|
14
16
|
end
|
15
17
|
|
16
18
|
# Turn the object from the ruby type we deal with to a Mongo friendly type
|
data/spec/time_with_zone_spec.rb
CHANGED
@@ -32,6 +32,12 @@ describe Mongoid::TimeWithNamedZone do
|
|
32
32
|
expect(demongoized_value).to eq(Time.new(2010, 11, 19, '+13:00'))
|
33
33
|
end
|
34
34
|
|
35
|
+
it 'works with symbolized keys' do
|
36
|
+
hash = { time: Time.utc(2010, 11, 19), zone: 'Pacific/Auckland' }
|
37
|
+
demongoized_value = Mongoid::TimeWithNamedZone.demongoize(hash)
|
38
|
+
expect(demongoized_value).to eq(Time.new(2010, 11, 19, '+13:00'))
|
39
|
+
end
|
40
|
+
|
35
41
|
it 'returns nil for blank object' do
|
36
42
|
expect(Mongoid::TimeWithNamedZone.demongoize(nil)).to eq(nil)
|
37
43
|
end
|