protip 0.30.3 → 0.30.4
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
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 60f4f6ab18acf00fa48b6470c88de46102dddece
|
4
|
+
data.tar.gz: bd54eb88c9e5cb05eb9b1d786a49bd698b10fac8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4a99f855daf4836fbad234c9c3a61f30b449003451c3de41631b04fd24e9458726ff11251bc9409b50175f8e6b459e7dbed4ccf25c17ba716191c40ecc794d99
|
7
|
+
data.tar.gz: c01896ba4aa0b9094e1fe90f0ea2f3b70570b0592c42b0d06228181e0dcf79ebbc522cff40c3db24c634ffbb61b14f2f5f267821b4ad89c90a2a5afb4208109b
|
@@ -35,10 +35,10 @@ module Protip
|
|
35
35
|
::Money.new(message.amount_cents, message.currency.currency_code)
|
36
36
|
end
|
37
37
|
def to_message(object, field)
|
38
|
-
|
39
|
-
currency = Protip::Messages::Currency.new(currency_code:
|
38
|
+
money = object.to_money
|
39
|
+
currency = Protip::Messages::Currency.new(currency_code: money.currency.iso_code.to_sym)
|
40
40
|
field.subtype.msgclass.new(
|
41
|
-
amount_cents:
|
41
|
+
amount_cents: money.fractional,
|
42
42
|
currency: currency,
|
43
43
|
)
|
44
44
|
end
|
@@ -16,15 +16,32 @@ describe Protip::Transformers::BigDecimalTransformer do
|
|
16
16
|
# Since we're just serializing/deserializing values, we test both
|
17
17
|
# transformer methods in tandem.
|
18
18
|
describe 'transformation' do
|
19
|
-
|
19
|
+
# Assumes expected_value = value unless it is explicitly provided
|
20
|
+
def self.it_transforms(name, value, expected_value = nil)
|
21
|
+
expected_value ||= value
|
20
22
|
it "transforms #{name} values" do
|
21
23
|
message = transformer.to_message(value, field)
|
22
|
-
assert_equal
|
24
|
+
assert_equal expected_value, transformer.to_object(message, field)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
describe 'for BigDecimal arguments' do
|
28
|
+
it_transforms 'integer', BigDecimal.new(104, 1)
|
29
|
+
it_transforms 'infinity', (BigDecimal.new(1, 1) / 0)
|
30
|
+
it_transforms 'fractions', BigDecimal.new(100.5, 5)
|
31
|
+
it_transforms 'rational numbers', BigDecimal.new(Rational(2, 3), 3)
|
32
|
+
end
|
33
|
+
|
34
|
+
describe 'for non-BigDecimal arguments' do
|
35
|
+
it_transforms 'integer', 3, BigDecimal.new(3, 1)
|
36
|
+
it_transforms 'string', '3.3', BigDecimal.new(3.3, 2)
|
37
|
+
|
38
|
+
# Match standard BigDecimal behavior for floats
|
39
|
+
it 'raises an argument error for floats' do
|
40
|
+
exception = assert_raises ArgumentError do
|
41
|
+
transformer.to_message(5.5, field)
|
42
|
+
end
|
43
|
+
assert_equal "can't omit precision for a Float.", exception.message
|
23
44
|
end
|
24
45
|
end
|
25
|
-
it_transforms 'integer', BigDecimal.new(104, 1)
|
26
|
-
it_transforms 'infinity', (BigDecimal.new(1, 1) / 0)
|
27
|
-
it_transforms 'fractions', BigDecimal.new(100.5, 5)
|
28
|
-
it_transforms 'rational numbers', BigDecimal.new(Rational(2, 3), 3)
|
29
46
|
end
|
30
47
|
end
|
@@ -109,6 +109,18 @@ describe Protip::Transformers::DeprecatedTransformer do
|
|
109
109
|
)),
|
110
110
|
message
|
111
111
|
end
|
112
|
+
|
113
|
+
it 'converts other objects via #to_money' do
|
114
|
+
obj = mock
|
115
|
+
obj.stubs(:to_money).returns ::Money.new(250, 'CAD')
|
116
|
+
message = transformer.to_message(obj, field)
|
117
|
+
assert_equal message_class.new(
|
118
|
+
amount_cents: 250,
|
119
|
+
currency: Protip::Messages::Currency.new(
|
120
|
+
currency_code: :CAD
|
121
|
+
)),
|
122
|
+
message
|
123
|
+
end
|
112
124
|
end
|
113
125
|
|
114
126
|
describe 'ActiveSupport::TimeWithZone' do
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: protip
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.30.
|
4
|
+
version: 0.30.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- AngelList
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-06-
|
11
|
+
date: 2016-06-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activemodel
|