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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0856ee3834afef77888546b862d8cb200ccf6d38
4
- data.tar.gz: 35153d7985332e50a55f1183cd7afbf578e182ff
3
+ metadata.gz: f3bf558f623bcacd7344a073a79c0c3df320e68e
4
+ data.tar.gz: f8b78e8dd441a0d9535072a0d271e80251a5ac96
5
5
  SHA512:
6
- metadata.gz: 2e7c8be8ae3df1bbbefe8b1805ed0c78ae1e90eb26c1af053c29411e05774f1f3fc538ee29d1d8a25c608b658e35699551bb21b79aef37a47c9d55355b68d50a
7
- data.tar.gz: b36bc482f7df0a01767174f08ba3ec0eaf68bf7e3889ff50dcb61f944c37dc1e27a7c8ccb3b6b8c944270badd9c5704400baef728d6d20551651bf9d4e5a0e17
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
- amounts_json['amounts'][name.to_s] = {'cents' => value.fractional, 'currency' => value.currency.iso_code}
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)
@@ -1,5 +1,5 @@
1
1
  # Copyright 2015-2016, Instacart
2
2
 
3
3
  module Amountable
4
- VERSION = '0.2.2'
4
+ VERSION = '0.2.3'
5
5
  end
@@ -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.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-24 00:00:00.000000000 Z
11
+ date: 2016-10-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord