amountable 0.2.2 → 0.2.3
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 +4 -4
- data/lib/amountable/jsonb_methods.rb +6 -2
- data/lib/amountable/version.rb +1 -1
- data/spec/amountable/amountable_spec.rb +4 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f3bf558f623bcacd7344a073a79c0c3df320e68e
|
4
|
+
data.tar.gz: f8b78e8dd441a0d9535072a0d271e80251a5ac96
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 95227423a46d60a54c75c4ca5c4b130295ba8f4641c548c6e1864730133c44e3f52f7a2d678e1fbe01dce4c3ec1bd5876c886ab9ce35f785169acbbb8c7f4034
|
7
|
+
data.tar.gz: 0547e0fdf70ffcdd1c3751622fa77e390fa7ab70b7b9b89c749e92ad0704ebab1debe393135b1c8861f16e667b871257b35cf35f15405e83bbd08f32669ad11c
|
@@ -12,11 +12,14 @@ module Amountable
|
|
12
12
|
|
13
13
|
def set_amount(name, value)
|
14
14
|
value = value.to_money
|
15
|
-
return value if value.zero?
|
16
15
|
initialize_column
|
17
16
|
amounts_json = attribute(amounts_column_name)
|
18
17
|
amounts_json['amounts'] ||= {}
|
19
|
-
|
18
|
+
if value.zero?
|
19
|
+
amounts_json['amounts'].delete(name.to_s)
|
20
|
+
else
|
21
|
+
amounts_json['amounts'][name.to_s] = {'cents' => value.fractional, 'currency' => value.currency.iso_code}
|
22
|
+
end
|
20
23
|
set_json(amounts_json)
|
21
24
|
@_amounts = nil
|
22
25
|
@amounts_by_name = nil
|
@@ -30,6 +33,7 @@ module Amountable
|
|
30
33
|
amounts_json['sets'] = {}
|
31
34
|
amount_sets.each do |name, amount_names|
|
32
35
|
sum = find_amounts(amount_names).sum(Money.zero, &:value)
|
36
|
+
next if sum.zero?
|
33
37
|
amounts_json['sets'][name.to_s] = {'cents' => sum.fractional, 'currency' => sum.currency.iso_code}
|
34
38
|
end
|
35
39
|
set_json(amounts_json)
|
data/lib/amountable/version.rb
CHANGED
@@ -82,6 +82,10 @@ describe Amountable do
|
|
82
82
|
subscription.update_attributes(sub_total: Money.new(200))
|
83
83
|
expect(subscription.sub_total).to eq(Money.new(200))
|
84
84
|
expect(subscription.total).to eq(Money.new(200))
|
85
|
+
subscription.sub_total = Money.zero
|
86
|
+
expect(subscription.sub_total).to eq(Money.zero)
|
87
|
+
expect(subscription.total).to eq(Money.zero)
|
88
|
+
expect(subscription.attributes['amounts']).to eq({'amounts' => {}, 'sets' => {}})
|
85
89
|
end
|
86
90
|
end
|
87
91
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: amountable
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Emmanuel Turlay
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-10-
|
11
|
+
date: 2016-10-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|