sps_king 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +9 -0
- data/.rspec +2 -0
- data/.travis.yml +32 -0
- data/CONTRIBUTING.md +38 -0
- data/Gemfile +2 -0
- data/LICENSE.txt +24 -0
- data/README.md +246 -0
- data/Rakefile +6 -0
- data/gemfiles/Gemfile-activemodel-3.1.x +5 -0
- data/gemfiles/Gemfile-activemodel-3.2.x +5 -0
- data/gemfiles/Gemfile-activemodel-4.0.x +5 -0
- data/gemfiles/Gemfile-activemodel-4.1.x +5 -0
- data/gemfiles/Gemfile-activemodel-4.2.x +5 -0
- data/gemfiles/Gemfile-activemodel-5.0.x +5 -0
- data/gemfiles/Gemfile-activemodel-5.1.x +5 -0
- data/gemfiles/Gemfile-activemodel-5.2.x +5 -0
- data/lib/schema/pain.001.001.03.ch.02.xsd +1212 -0
- data/lib/schema/pain.008.001.02.ch.03.xsd +784 -0
- data/lib/sps_king.rb +22 -0
- data/lib/sps_king/account.rb +24 -0
- data/lib/sps_king/account/creditor_account.rb +11 -0
- data/lib/sps_king/account/creditor_address.rb +37 -0
- data/lib/sps_king/account/debtor_account.rb +5 -0
- data/lib/sps_king/account/debtor_address.rb +34 -0
- data/lib/sps_king/converter.rb +53 -0
- data/lib/sps_king/error.rb +4 -0
- data/lib/sps_king/message.rb +163 -0
- data/lib/sps_king/message/credit_transfer.rb +140 -0
- data/lib/sps_king/message/direct_debit.rb +177 -0
- data/lib/sps_king/structured_remittance_information.rb +20 -0
- data/lib/sps_king/transaction.rb +59 -0
- data/lib/sps_king/transaction/credit_transfer_transaction.rb +19 -0
- data/lib/sps_king/transaction/direct_debit_transaction.rb +58 -0
- data/lib/sps_king/validator.rb +55 -0
- data/lib/sps_king/version.rb +3 -0
- data/spec/examples/pain.001.001.03.ch.02.xml +172 -0
- data/spec/examples/pain.008.001.02.ch.03.xml +240 -0
- data/spec/lib/sps_king/account/creditor_account_spec.rb +52 -0
- data/spec/lib/sps_king/account/creditor_address_spec.rb +14 -0
- data/spec/lib/sps_king/account/debtor_account_spec.rb +14 -0
- data/spec/lib/sps_king/account/debtor_address_spec.rb +14 -0
- data/spec/lib/sps_king/account_spec.rb +42 -0
- data/spec/lib/sps_king/converter_spec.rb +88 -0
- data/spec/lib/sps_king/message/credit_transfer_spec.rb +350 -0
- data/spec/lib/sps_king/message/direct_debit_spec.rb +483 -0
- data/spec/lib/sps_king/message_spec.rb +128 -0
- data/spec/lib/sps_king/structured_remittance_information_spec.rb +32 -0
- data/spec/lib/sps_king/transaction/credit_transfer_transaction_spec.rb +53 -0
- data/spec/lib/sps_king/transaction/direct_debit_transaction_spec.rb +56 -0
- data/spec/lib/sps_king/transaction_spec.rb +133 -0
- data/spec/lib/sps_king/validation_spec.rb +23 -0
- data/spec/lib/sps_king/validator_spec.rb +78 -0
- data/spec/spec_helper.rb +33 -0
- data/spec/support/active_model.rb +30 -0
- data/spec/support/custom_matcher.rb +60 -0
- data/spec/support/factories.rb +33 -0
- data/spec/support/validations.rb +27 -0
- data/sps_king.gemspec +31 -0
- metadata +237 -0
@@ -0,0 +1,240 @@
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
2
|
+
<!--
|
3
|
+
(C) Copyright 2015, SIX Interbank Clearing AG, www.iso-payments.ch
|
4
|
+
|
5
|
+
Anregungen und Fragen zu diesem Dokument können an das jeweilige Finanzinstitut gerichtet werden.
|
6
|
+
Allgemeine Anregungen können auch bei der SIX Interbank Clearing AG unter folgender Adresse angebracht werden:
|
7
|
+
pm@six-group.com
|
8
|
+
-->
|
9
|
+
<Document xmlns="http://www.six-interbank-clearing.com/de/pain.008.001.02.ch.03.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.six-interbank-clearing.com/de/pain.008.001.02.ch.03.xsd pain.008.001.02.ch.03.xsd">
|
10
|
+
<CstmrDrctDbtInitn>
|
11
|
+
<GrpHdr>
|
12
|
+
<MsgId>MSG-01</MsgId>
|
13
|
+
<CreDtTm>2015-03-23T07:30:00</CreDtTm>
|
14
|
+
<NbOfTxs>3</NbOfTxs>
|
15
|
+
<CtrlSum>4372.50</CtrlSum>
|
16
|
+
<InitgPty>
|
17
|
+
<Nm>MUSTER AG</Nm>
|
18
|
+
<Id>
|
19
|
+
<OrgId>
|
20
|
+
<Othr>
|
21
|
+
<Id>ABC1W</Id>
|
22
|
+
</Othr>
|
23
|
+
</OrgId>
|
24
|
+
</Id>
|
25
|
+
</InitgPty>
|
26
|
+
</GrpHdr>
|
27
|
+
<PmtInf>
|
28
|
+
<PmtInfId>PMTINF-01</PmtInfId>
|
29
|
+
<PmtMtd>DD</PmtMtd>
|
30
|
+
<PmtTpInf>
|
31
|
+
<SvcLvl>
|
32
|
+
<Prtry>CHTA</Prtry>
|
33
|
+
</SvcLvl>
|
34
|
+
<LclInstrm>
|
35
|
+
<Prtry>LSV+</Prtry>
|
36
|
+
</LclInstrm>
|
37
|
+
</PmtTpInf>
|
38
|
+
<ReqdColltnDt>2015-03-30</ReqdColltnDt>
|
39
|
+
<Cdtr>
|
40
|
+
<Nm>MUSTER AG</Nm>
|
41
|
+
<PstlAdr>
|
42
|
+
<Ctry>CH</Ctry>
|
43
|
+
<AdrLine>SELDWYLA</AdrLine>
|
44
|
+
</PstlAdr>
|
45
|
+
</Cdtr>
|
46
|
+
<CdtrAcct>
|
47
|
+
<Id>
|
48
|
+
<IBAN>CH7081232000001998736</IBAN>
|
49
|
+
</Id>
|
50
|
+
</CdtrAcct>
|
51
|
+
<CdtrAgt>
|
52
|
+
<FinInstnId>
|
53
|
+
<ClrSysMmbId>
|
54
|
+
<MmbId>81232</MmbId>
|
55
|
+
</ClrSysMmbId>
|
56
|
+
<Othr>
|
57
|
+
<Id>010001456</Id>
|
58
|
+
</Othr>
|
59
|
+
</FinInstnId>
|
60
|
+
</CdtrAgt>
|
61
|
+
<CdtrSchmeId>
|
62
|
+
<Id>
|
63
|
+
<PrvtId>
|
64
|
+
<Othr>
|
65
|
+
<Id>ABC1W</Id>
|
66
|
+
<SchmeNm>
|
67
|
+
<Prtry>CHLS</Prtry>
|
68
|
+
</SchmeNm>
|
69
|
+
</Othr>
|
70
|
+
</PrvtId>
|
71
|
+
</Id>
|
72
|
+
</CdtrSchmeId>
|
73
|
+
<DrctDbtTxInf>
|
74
|
+
<PmtId>
|
75
|
+
<InstrId>INSTRID-01-01</InstrId>
|
76
|
+
<EndToEndId>NOTPROVIDED</EndToEndId>
|
77
|
+
</PmtId>
|
78
|
+
<InstdAmt Ccy="CHF">3421.00</InstdAmt>
|
79
|
+
<DbtrAgt>
|
80
|
+
<FinInstnId>
|
81
|
+
<ClrSysMmbId>
|
82
|
+
<MmbId>4835</MmbId>
|
83
|
+
</ClrSysMmbId>
|
84
|
+
</FinInstnId>
|
85
|
+
</DbtrAgt>
|
86
|
+
<Dbtr>
|
87
|
+
<Nm>HERR PETER HALLER</Nm>
|
88
|
+
<PstlAdr>
|
89
|
+
<Ctry>CH</Ctry>
|
90
|
+
<AdrLine>ROSENAUWEG 4</AdrLine>
|
91
|
+
<AdrLine>8004 ZÜRICH</AdrLine>
|
92
|
+
</PstlAdr>
|
93
|
+
</Dbtr>
|
94
|
+
<DbtrAcct>
|
95
|
+
<Id>
|
96
|
+
<IBAN>CH9804835011062385295</IBAN>
|
97
|
+
</Id>
|
98
|
+
</DbtrAcct>
|
99
|
+
<RmtInf>
|
100
|
+
<Strd>
|
101
|
+
<CdtrRefInf>
|
102
|
+
<Tp>
|
103
|
+
<CdOrPrtry>
|
104
|
+
<Prtry>ESR</Prtry>
|
105
|
+
</CdOrPrtry>
|
106
|
+
</Tp>
|
107
|
+
<Ref>200002000000004443332000061</Ref>
|
108
|
+
</CdtrRefInf>
|
109
|
+
</Strd>
|
110
|
+
</RmtInf>
|
111
|
+
</DrctDbtTxInf>
|
112
|
+
</PmtInf>
|
113
|
+
<PmtInf>
|
114
|
+
<PmtInfId>PMTINF-02</PmtInfId>
|
115
|
+
<PmtMtd>DD</PmtMtd>
|
116
|
+
<PmtTpInf>
|
117
|
+
<SvcLvl>
|
118
|
+
<Prtry>CHTA</Prtry>
|
119
|
+
</SvcLvl>
|
120
|
+
<LclInstrm>
|
121
|
+
<Prtry>LSV+</Prtry>
|
122
|
+
</LclInstrm>
|
123
|
+
</PmtTpInf>
|
124
|
+
<ReqdColltnDt>2015-03-25</ReqdColltnDt>
|
125
|
+
<Cdtr>
|
126
|
+
<Nm>MUSTER AG</Nm>
|
127
|
+
<PstlAdr>
|
128
|
+
<Ctry>CH</Ctry>
|
129
|
+
<AdrLine>SELDWYLA</AdrLine>
|
130
|
+
</PstlAdr>
|
131
|
+
</Cdtr>
|
132
|
+
<CdtrAcct>
|
133
|
+
<Id>
|
134
|
+
<IBAN>CH7081232000001998736</IBAN>
|
135
|
+
</Id>
|
136
|
+
</CdtrAcct>
|
137
|
+
<CdtrAgt>
|
138
|
+
<FinInstnId>
|
139
|
+
<ClrSysMmbId>
|
140
|
+
<MmbId>81232</MmbId>
|
141
|
+
</ClrSysMmbId>
|
142
|
+
<Othr>
|
143
|
+
<Id>010001456</Id>
|
144
|
+
</Othr>
|
145
|
+
</FinInstnId>
|
146
|
+
</CdtrAgt>
|
147
|
+
<CdtrSchmeId>
|
148
|
+
<Id>
|
149
|
+
<PrvtId>
|
150
|
+
<Othr>
|
151
|
+
<Id>ABC1W</Id>
|
152
|
+
<SchmeNm>
|
153
|
+
<Prtry>CHLS</Prtry>
|
154
|
+
</SchmeNm>
|
155
|
+
</Othr>
|
156
|
+
</PrvtId>
|
157
|
+
</Id>
|
158
|
+
</CdtrSchmeId>
|
159
|
+
<DrctDbtTxInf>
|
160
|
+
<PmtId>
|
161
|
+
<InstrId>INSTRID-02-01</InstrId>
|
162
|
+
<EndToEndId>NOTPROVIDED</EndToEndId>
|
163
|
+
</PmtId>
|
164
|
+
<InstdAmt Ccy="CHF">885.50</InstdAmt>
|
165
|
+
<DbtrAgt>
|
166
|
+
<FinInstnId>
|
167
|
+
<ClrSysMmbId>
|
168
|
+
<MmbId>4835</MmbId>
|
169
|
+
</ClrSysMmbId>
|
170
|
+
</FinInstnId>
|
171
|
+
</DbtrAgt>
|
172
|
+
<Dbtr>
|
173
|
+
<Nm>HANS TESTER</Nm>
|
174
|
+
<PstlAdr>
|
175
|
+
<Ctry>CH</Ctry>
|
176
|
+
<AdrLine>PROBEWEG 88</AdrLine>
|
177
|
+
<AdrLine>9998 IRGENDWO</AdrLine>
|
178
|
+
</PstlAdr>
|
179
|
+
</Dbtr>
|
180
|
+
<DbtrAcct>
|
181
|
+
<Id>
|
182
|
+
<IBAN>CH9804835011062385295</IBAN>
|
183
|
+
</Id>
|
184
|
+
</DbtrAcct>
|
185
|
+
<RmtInf>
|
186
|
+
<Ustrd>Gemäss Rechnung 4712</Ustrd>
|
187
|
+
<Strd>
|
188
|
+
<CdtrRefInf>
|
189
|
+
<Tp>
|
190
|
+
<CdOrPrtry>
|
191
|
+
<Prtry>ESR</Prtry>
|
192
|
+
</CdOrPrtry>
|
193
|
+
</Tp>
|
194
|
+
<Ref>185744810000000000200800628</Ref>
|
195
|
+
</CdtrRefInf>
|
196
|
+
</Strd>
|
197
|
+
</RmtInf>
|
198
|
+
</DrctDbtTxInf>
|
199
|
+
<DrctDbtTxInf>
|
200
|
+
<PmtId>
|
201
|
+
<InstrId>INSTRID-02-02</InstrId>
|
202
|
+
<EndToEndId>NOTPROVIDED</EndToEndId>
|
203
|
+
</PmtId>
|
204
|
+
<InstdAmt Ccy="CHF">66.00</InstdAmt>
|
205
|
+
<DbtrAgt>
|
206
|
+
<FinInstnId>
|
207
|
+
<ClrSysMmbId>
|
208
|
+
<MmbId>700</MmbId>
|
209
|
+
</ClrSysMmbId>
|
210
|
+
</FinInstnId>
|
211
|
+
</DbtrAgt>
|
212
|
+
<Dbtr>
|
213
|
+
<Nm>PETER ERROR</Nm>
|
214
|
+
<PstlAdr>
|
215
|
+
<Ctry>CH</Ctry>
|
216
|
+
<AdrLine>Rudolfsweg 11</AdrLine>
|
217
|
+
<AdrLine>Sion</AdrLine>
|
218
|
+
</PstlAdr>
|
219
|
+
</Dbtr>
|
220
|
+
<DbtrAcct>
|
221
|
+
<Id>
|
222
|
+
<IBAN>CH2007000031023502601</IBAN>
|
223
|
+
</Id>
|
224
|
+
</DbtrAcct>
|
225
|
+
<RmtInf>
|
226
|
+
<Strd>
|
227
|
+
<CdtrRefInf>
|
228
|
+
<Tp>
|
229
|
+
<CdOrPrtry>
|
230
|
+
<Prtry>ESR</Prtry>
|
231
|
+
</CdOrPrtry>
|
232
|
+
</Tp>
|
233
|
+
<Ref>215703000075200334559000126</Ref>
|
234
|
+
</CdtrRefInf>
|
235
|
+
</Strd>
|
236
|
+
</RmtInf>
|
237
|
+
</DrctDbtTxInf>
|
238
|
+
</PmtInf>
|
239
|
+
</CstmrDrctDbtInitn>
|
240
|
+
</Document>
|
@@ -0,0 +1,52 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'spec_helper'
|
3
|
+
|
4
|
+
describe SPS::CreditorAccount do
|
5
|
+
it 'should initialize a new account' do
|
6
|
+
expect(
|
7
|
+
SPS::CreditorAccount.new(
|
8
|
+
name: 'Gläubiger GmbH',
|
9
|
+
bic: 'BANKDEFFXXX',
|
10
|
+
iban: 'DE87200500001234567890',
|
11
|
+
creditor_identifier: 'DE98ZZZ09999999999'
|
12
|
+
)
|
13
|
+
).to be_valid
|
14
|
+
end
|
15
|
+
|
16
|
+
describe :creditor_identifier do
|
17
|
+
it 'should accept valid value' do
|
18
|
+
expect(SPS::CreditorAccount)
|
19
|
+
.to accept(
|
20
|
+
'DE98ZZZ09999999999',
|
21
|
+
'AT12ZZZ00000000001',
|
22
|
+
'IT97ZZZA1B2C3D4E5F6G7H8',
|
23
|
+
'NL97ZZZ123456780001',
|
24
|
+
'FR12ZZZ123456',
|
25
|
+
for: :creditor_identifier
|
26
|
+
)
|
27
|
+
end
|
28
|
+
|
29
|
+
it 'should not accept invalid value' do
|
30
|
+
expect(SPS::CreditorAccount)
|
31
|
+
.not_to accept(
|
32
|
+
'',
|
33
|
+
'invalid',
|
34
|
+
'DE98ZZZ099999999990',
|
35
|
+
'DEAAAAAAAAAAAAAAAA',
|
36
|
+
for: :creditor_identifier
|
37
|
+
)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
describe :isr_participant_number do
|
42
|
+
it 'should accept valid value' do
|
43
|
+
expect(SPS::CreditorAccount)
|
44
|
+
.to accept('123123123', '554544543', nil, for: :isr_participant_number)
|
45
|
+
end
|
46
|
+
|
47
|
+
it 'should not accept invalid value' do
|
48
|
+
expect(SPS::CreditorAccount)
|
49
|
+
.not_to accept('32423432', 'a89898989', for: :isr_participant_number)
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'spec_helper'
|
3
|
+
|
4
|
+
describe SPS::CreditorAddress do
|
5
|
+
it 'should initialize a new address' do
|
6
|
+
expect(
|
7
|
+
SPS::CreditorAddress.new(
|
8
|
+
country_code: 'CH',
|
9
|
+
address_line1: 'Mustergasse 123',
|
10
|
+
address_line2: '12345 Musterstadt'
|
11
|
+
)
|
12
|
+
).to be_valid
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'spec_helper'
|
3
|
+
|
4
|
+
describe SPS::DebtorAccount do
|
5
|
+
it 'should initialize a new account' do
|
6
|
+
expect(
|
7
|
+
SPS::DebtorAccount.new(
|
8
|
+
name: 'Gläubiger GmbH',
|
9
|
+
bic: 'BANKDEFFXXX',
|
10
|
+
iban: 'DE87200500001234567890'
|
11
|
+
)
|
12
|
+
).to be_valid
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'spec_helper'
|
3
|
+
|
4
|
+
describe SPS::DebtorAddress do
|
5
|
+
it 'should initialize a new address' do
|
6
|
+
expect(
|
7
|
+
SPS::DebtorAddress.new(
|
8
|
+
country_code: 'CH',
|
9
|
+
address_line1: 'Mustergasse 123',
|
10
|
+
address_line2: '12345 Musterstadt'
|
11
|
+
)
|
12
|
+
).to be_valid
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'spec_helper'
|
3
|
+
|
4
|
+
describe SPS::Account do
|
5
|
+
describe :new do
|
6
|
+
it 'should not accept unknown keys' do
|
7
|
+
expect {
|
8
|
+
SPS::Account.new foo: 'bar'
|
9
|
+
}.to raise_error(NoMethodError)
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
describe :name do
|
14
|
+
it 'should accept valid value' do
|
15
|
+
expect(SPS::Account).to accept('Gläubiger GmbH', 'Zahlemann & Söhne GbR', 'X' * 70, for: :name)
|
16
|
+
end
|
17
|
+
|
18
|
+
it 'should not accept invalid value' do
|
19
|
+
expect(SPS::Account).not_to accept(nil, '', 'X' * 71, for: :name)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
describe :iban do
|
24
|
+
it 'should accept valid value' do
|
25
|
+
expect(SPS::Account).to accept('DE21500500009876543210', 'PL61109010140000071219812874', for: :iban)
|
26
|
+
end
|
27
|
+
|
28
|
+
it 'should not accept invalid value' do
|
29
|
+
expect(SPS::Account).not_to accept(nil, '', 'invalid', for: :iban)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
describe :bic do
|
34
|
+
it 'should accept valid value' do
|
35
|
+
expect(SPS::Account).to accept('DEUTDEFF', 'DEUTDEFF500', 'SPUEDE2UXXX', for: :bic)
|
36
|
+
end
|
37
|
+
|
38
|
+
it 'should not accept invalid value' do
|
39
|
+
expect(SPS::Account).not_to accept('', 'invalid', for: :bic)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,88 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'spec_helper'
|
3
|
+
|
4
|
+
describe SPS::Converter do
|
5
|
+
include SPS::Converter::InstanceMethods
|
6
|
+
|
7
|
+
describe :convert do
|
8
|
+
context 'when the conversion method does not exist' do
|
9
|
+
it 'raises an ArgumentError' do
|
10
|
+
class DummyForConverter
|
11
|
+
extend SPS::Converter
|
12
|
+
end
|
13
|
+
|
14
|
+
expect {
|
15
|
+
DummyForConverter.convert(:anything, to: :unknown)
|
16
|
+
}.to raise_error(ArgumentError, "Converter 'unknown' does not exist!")
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
describe :convert_text do
|
22
|
+
it 'should convert special chars' do
|
23
|
+
expect(convert_text('10€')).to eq('10E')
|
24
|
+
expect(convert_text('info@bundesbank.de')).to eq('info(at)bundesbank.de')
|
25
|
+
expect(convert_text('abc_def')).to eq('abc-def')
|
26
|
+
end
|
27
|
+
|
28
|
+
it 'should not change allowed special character' do
|
29
|
+
expect(convert_text('üöäÜÖÄß')).to eq('üöäÜÖÄß')
|
30
|
+
expect(convert_text('&*$%')).to eq('&*$%')
|
31
|
+
end
|
32
|
+
|
33
|
+
it 'should convert line breaks' do
|
34
|
+
expect(convert_text("one\ntwo")) .to eq('one two')
|
35
|
+
expect(convert_text("one\ntwo\n")) .to eq('one two')
|
36
|
+
expect(convert_text("\none\ntwo\n")).to eq('one two')
|
37
|
+
expect(convert_text("one\n\ntwo")) .to eq('one two')
|
38
|
+
end
|
39
|
+
|
40
|
+
it 'should convert number' do
|
41
|
+
expect(convert_text(1234)).to eq('1234')
|
42
|
+
end
|
43
|
+
|
44
|
+
it 'should remove invalid chars' do
|
45
|
+
expect(convert_text('"=<>!')).to eq('')
|
46
|
+
end
|
47
|
+
|
48
|
+
it 'should not touch valid chars' do
|
49
|
+
expect(convert_text("abc-ABC-0123- ':?,-(+.)/")).to eq("abc-ABC-0123- ':?,-(+.)/")
|
50
|
+
end
|
51
|
+
|
52
|
+
it 'should not touch nil' do
|
53
|
+
expect(convert_text(nil)).to eq(nil)
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
describe :convert_decimal do
|
58
|
+
it "should convert Integer to BigDecimal" do
|
59
|
+
expect(convert_decimal(42)).to eq(BigDecimal('42.00'))
|
60
|
+
end
|
61
|
+
|
62
|
+
it "should convert Float to BigDecimal" do
|
63
|
+
expect(convert_decimal(42.12)).to eq(BigDecimal('42.12'))
|
64
|
+
end
|
65
|
+
|
66
|
+
it 'should round' do
|
67
|
+
expect(convert_decimal(1.345)).to eq(BigDecimal('1.35'))
|
68
|
+
end
|
69
|
+
|
70
|
+
it 'should not touch nil' do
|
71
|
+
expect(convert_decimal(nil)).to eq(nil)
|
72
|
+
end
|
73
|
+
|
74
|
+
it 'should not convert zero value' do
|
75
|
+
expect(convert_decimal(0)).to eq(nil)
|
76
|
+
end
|
77
|
+
|
78
|
+
it 'should not convert negative value' do
|
79
|
+
expect(convert_decimal(-3)).to eq(nil)
|
80
|
+
end
|
81
|
+
|
82
|
+
it 'should not convert invalid value' do
|
83
|
+
expect(convert_decimal('xyz')).to eq(nil)
|
84
|
+
expect(convert_decimal('NaN')).to eq(nil)
|
85
|
+
expect(convert_decimal('Infinity')).to eq(nil)
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|