sepa_king 0.3.0 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +7 -1
- data/README.md +4 -0
- data/gemfiles/Gemfile-activemodel-3.0.x +5 -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/lib/sepa_king/converter.rb +1 -11
- data/lib/sepa_king/message/credit_transfer.rb +3 -0
- data/lib/sepa_king/transaction.rb +3 -2
- data/lib/sepa_king/version.rb +1 -1
- data/sepa_king.gemspec +3 -3
- data/spec/account_spec.rb +6 -6
- data/spec/converter_spec.rb +13 -13
- data/spec/credit_transfer_spec.rb +43 -43
- data/spec/credit_transfer_transaction_spec.rb +6 -6
- data/spec/creditor_account_spec.rb +2 -2
- data/spec/direct_debit_spec.rb +55 -55
- data/spec/direct_debit_transaction_spec.rb +8 -8
- data/spec/message_spec.rb +8 -8
- data/spec/spec_helper.rb +0 -1
- data/spec/support/active_model.rb +30 -0
- data/spec/support/custom_matcher.rb +11 -11
- data/spec/transaction_spec.rb +15 -15
- data/spec/validation_spec.rb +8 -8
- data/spec/validator_spec.rb +8 -8
- metadata +19 -12
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: eb96b170a8acd00636509ac62a5bccc71a021c51
|
4
|
+
data.tar.gz: 7891df444dd4d48f880c00de9726ab9d15aeee02
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cb894f09d419a8b8343d54d901ae90c051340aecaed797895d89f61d0e90cfeb18917b33289a1dd90dfb6b51934835b00e6142f69278e2d51731f2c12f4f29e7
|
7
|
+
data.tar.gz: ce5d81ca206169d78e046f2dc7bac69029989e348e29eb83e709c3af3f6140e1fe11a7d05916711afde575aa82787cafde0202f605580817f8c3466a09177885
|
data/.travis.yml
CHANGED
data/README.md
CHANGED
@@ -73,6 +73,10 @@ sdd.add_transaction(
|
|
73
73
|
# Number with two decimal digit
|
74
74
|
amount: 39.99,
|
75
75
|
|
76
|
+
# OPTIONAL: Instruction Identification, will not be submitted to the debtor
|
77
|
+
# String, max. 35 char
|
78
|
+
instruction: '12345',
|
79
|
+
|
76
80
|
# OPTIONAL: End-To-End-Identification, will be submitted to the debtor
|
77
81
|
# String, max. 35 char
|
78
82
|
reference: 'XYZ/2013-08-ABO/6789',
|
data/lib/sepa_king/converter.rb
CHANGED
@@ -18,17 +18,7 @@ module SEPA
|
|
18
18
|
def convert_text(value)
|
19
19
|
return unless value
|
20
20
|
|
21
|
-
|
22
|
-
# Convert german umlauts
|
23
|
-
gsub('Ä', 'AE').
|
24
|
-
gsub('Ü', 'UE').
|
25
|
-
gsub('Ö', 'OE').
|
26
|
-
gsub('ä', 'ae').
|
27
|
-
gsub('ü', 'ue').
|
28
|
-
gsub('ö', 'oe').
|
29
|
-
gsub('ß', 'ss')
|
30
|
-
|
31
|
-
I18n.transliterate(text).
|
21
|
+
I18n.transliterate(value.to_s).
|
32
22
|
# Change linebreaks to whitespaces
|
33
23
|
gsub(/\n+/,' ').
|
34
24
|
# Remove all invalid characters
|
@@ -63,6 +63,9 @@ module SEPA
|
|
63
63
|
def build_transaction(builder, transaction)
|
64
64
|
builder.CdtTrfTxInf do
|
65
65
|
builder.PmtId do
|
66
|
+
if transaction.instruction.present?
|
67
|
+
builder.InstrId(transaction.instruction)
|
68
|
+
end
|
66
69
|
builder.EndToEndId(transaction.reference)
|
67
70
|
end
|
68
71
|
builder.Amt do
|
@@ -4,11 +4,12 @@ module SEPA
|
|
4
4
|
include ActiveModel::Validations
|
5
5
|
extend Converter
|
6
6
|
|
7
|
-
attr_accessor :name, :iban, :bic, :amount, :reference, :remittance_information, :requested_date, :batch_booking
|
8
|
-
convert :name, :reference, :remittance_information, to: :text
|
7
|
+
attr_accessor :name, :iban, :bic, :amount, :instruction, :reference, :remittance_information, :requested_date, :batch_booking
|
8
|
+
convert :name, :instruction, :reference, :remittance_information, to: :text
|
9
9
|
convert :amount, to: :decimal
|
10
10
|
|
11
11
|
validates_length_of :name, within: 1..70
|
12
|
+
validates_length_of :instruction, within: 1..35, allow_nil: true
|
12
13
|
validates_length_of :reference, within: 1..35, allow_nil: true
|
13
14
|
validates_length_of :remittance_information, within: 1..140, allow_nil: true
|
14
15
|
validates_numericality_of :amount, greater_than: 0
|
data/lib/sepa_king/version.rb
CHANGED
data/sepa_king.gemspec
CHANGED
@@ -20,13 +20,13 @@ Gem::Specification.new do |s|
|
|
20
20
|
|
21
21
|
s.required_ruby_version = '>= 1.9.3'
|
22
22
|
|
23
|
-
s.add_runtime_dependency 'activemodel'
|
23
|
+
s.add_runtime_dependency 'activemodel', '>= 3.0.0'
|
24
24
|
s.add_runtime_dependency 'i18n'
|
25
25
|
s.add_runtime_dependency 'builder'
|
26
26
|
s.add_runtime_dependency 'iban-tools'
|
27
27
|
|
28
|
-
s.add_development_dependency 'bundler'
|
29
|
-
s.add_development_dependency 'rspec', '
|
28
|
+
s.add_development_dependency 'bundler'
|
29
|
+
s.add_development_dependency 'rspec', '~> 3.0'
|
30
30
|
s.add_development_dependency 'coveralls'
|
31
31
|
s.add_development_dependency 'simplecov'
|
32
32
|
s.add_development_dependency 'rake'
|
data/spec/account_spec.rb
CHANGED
@@ -12,31 +12,31 @@ describe SEPA::Account do
|
|
12
12
|
|
13
13
|
describe :name do
|
14
14
|
it 'should accept valid value' do
|
15
|
-
SEPA::Account.
|
15
|
+
expect(SEPA::Account).to accept('Gläubiger GmbH', 'Zahlemann & Söhne GbR', 'X' * 70, for: :name)
|
16
16
|
end
|
17
17
|
|
18
18
|
it 'should not accept invalid value' do
|
19
|
-
SEPA::Account.
|
19
|
+
expect(SEPA::Account).not_to accept(nil, '', 'X' * 71, for: :name)
|
20
20
|
end
|
21
21
|
end
|
22
22
|
|
23
23
|
describe :iban do
|
24
24
|
it 'should accept valid value' do
|
25
|
-
SEPA::Account.
|
25
|
+
expect(SEPA::Account).to accept('DE21500500009876543210', 'PL61109010140000071219812874', for: :iban)
|
26
26
|
end
|
27
27
|
|
28
28
|
it 'should not accept invalid value' do
|
29
|
-
SEPA::Account.
|
29
|
+
expect(SEPA::Account).not_to accept(nil, '', 'invalid', for: :iban)
|
30
30
|
end
|
31
31
|
end
|
32
32
|
|
33
33
|
describe :bic do
|
34
34
|
it 'should accept valid value' do
|
35
|
-
SEPA::Account.
|
35
|
+
expect(SEPA::Account).to accept('DEUTDEFF', 'DEUTDEFF500', 'SPUEDE2UXXX', for: :bic)
|
36
36
|
end
|
37
37
|
|
38
38
|
it 'should not accept invalid value' do
|
39
|
-
SEPA::Account.
|
39
|
+
expect(SEPA::Account).not_to accept('', 'invalid', for: :bic)
|
40
40
|
end
|
41
41
|
end
|
42
42
|
end
|
data/spec/converter_spec.rb
CHANGED
@@ -6,48 +6,48 @@ describe SEPA::Converter do
|
|
6
6
|
|
7
7
|
describe :convert_text do
|
8
8
|
it 'should remove invalid chars' do
|
9
|
-
convert_text('&@"=<>!').
|
9
|
+
expect(convert_text('&@"=<>!')).to eq('')
|
10
10
|
end
|
11
11
|
|
12
12
|
it 'should not touch valid chars' do
|
13
|
-
convert_text("abc-ABC-0123- ':?,-(+.)/").
|
13
|
+
expect(convert_text("abc-ABC-0123- ':?,-(+.)/")).to eq("abc-ABC-0123- ':?,-(+.)/")
|
14
14
|
end
|
15
15
|
|
16
16
|
it 'should convert umlaute' do
|
17
|
-
convert_text('üöäÜÖÄß').
|
17
|
+
expect(convert_text('üöäÜÖÄß')).to eq('uoaUOAss')
|
18
18
|
end
|
19
19
|
|
20
20
|
it 'should convert line breaks' do
|
21
|
-
convert_text("one\ntwo") .
|
22
|
-
convert_text("one\ntwo\n") .
|
23
|
-
convert_text("\none\ntwo\n").
|
24
|
-
convert_text("one\n\ntwo") .
|
21
|
+
expect(convert_text("one\ntwo")) .to eq('one two')
|
22
|
+
expect(convert_text("one\ntwo\n")) .to eq('one two')
|
23
|
+
expect(convert_text("\none\ntwo\n")).to eq('one two')
|
24
|
+
expect(convert_text("one\n\ntwo")) .to eq('one two')
|
25
25
|
end
|
26
26
|
|
27
27
|
it 'should convert number' do
|
28
|
-
convert_text(1234).
|
28
|
+
expect(convert_text(1234)).to eq('1234')
|
29
29
|
end
|
30
30
|
|
31
31
|
it 'should not touch nil' do
|
32
|
-
convert_text(nil).
|
32
|
+
expect(convert_text(nil)).to eq(nil)
|
33
33
|
end
|
34
34
|
end
|
35
35
|
|
36
36
|
describe :convert_decimal do
|
37
37
|
it "should convert Integer to BigDecimal" do
|
38
|
-
convert_decimal(42).
|
38
|
+
expect(convert_decimal(42)).to eq(BigDecimal('42.00'))
|
39
39
|
end
|
40
40
|
|
41
41
|
it "should convert Float to BigDecimal" do
|
42
|
-
convert_decimal(42.12).
|
42
|
+
expect(convert_decimal(42.12)).to eq(BigDecimal('42.12'))
|
43
43
|
end
|
44
44
|
|
45
45
|
it 'should round' do
|
46
|
-
convert_decimal(1.345).
|
46
|
+
expect(convert_decimal(1.345)).to eq(BigDecimal('1.35'))
|
47
47
|
end
|
48
48
|
|
49
49
|
it 'should not touch nil' do
|
50
|
-
convert_decimal(nil).
|
50
|
+
expect(convert_decimal(nil)).to eq(nil)
|
51
51
|
end
|
52
52
|
end
|
53
53
|
end
|
@@ -22,7 +22,7 @@ describe SEPA::CreditTransfer do
|
|
22
22
|
credit_transfer.add_transaction(credit_transfer_transaction)
|
23
23
|
end
|
24
24
|
|
25
|
-
expect(credit_transfer).to
|
25
|
+
expect(credit_transfer.transactions.size).to eq(3)
|
26
26
|
end
|
27
27
|
|
28
28
|
it 'should fail for invalid transaction' do
|
@@ -120,73 +120,73 @@ describe SEPA::CreditTransfer do
|
|
120
120
|
end
|
121
121
|
|
122
122
|
it 'should have message_identification' do
|
123
|
-
subject.
|
123
|
+
expect(subject).to have_xml('//Document/CstmrCdtTrfInitn/GrpHdr/MsgId', /SEPA-KING\/[0-9]+/)
|
124
124
|
end
|
125
125
|
|
126
126
|
it 'should contain <PmtInfId>' do
|
127
|
-
subject.
|
127
|
+
expect(subject).to have_xml('//Document/CstmrCdtTrfInitn/PmtInf/PmtInfId', /SEPA-KING\/[0-9]+\/1/)
|
128
128
|
end
|
129
129
|
|
130
130
|
it 'should contain <ReqdExctnDt>' do
|
131
|
-
subject.
|
131
|
+
expect(subject).to have_xml('//Document/CstmrCdtTrfInitn/PmtInf/ReqdExctnDt', Date.today.next.iso8601)
|
132
132
|
end
|
133
133
|
|
134
134
|
it 'should contain <PmtMtd>' do
|
135
|
-
subject.
|
135
|
+
expect(subject).to have_xml('//Document/CstmrCdtTrfInitn/PmtInf/PmtMtd', 'TRF')
|
136
136
|
end
|
137
137
|
|
138
138
|
it 'should contain <BtchBookg>' do
|
139
|
-
subject.
|
139
|
+
expect(subject).to have_xml('//Document/CstmrCdtTrfInitn/PmtInf/BtchBookg', 'true')
|
140
140
|
end
|
141
141
|
|
142
142
|
it 'should contain <NbOfTxs>' do
|
143
|
-
subject.
|
143
|
+
expect(subject).to have_xml('//Document/CstmrCdtTrfInitn/PmtInf/NbOfTxs', '2')
|
144
144
|
end
|
145
145
|
|
146
146
|
it 'should contain <CtrlSum>' do
|
147
|
-
subject.
|
147
|
+
expect(subject).to have_xml('//Document/CstmrCdtTrfInitn/PmtInf/CtrlSum', '161.50')
|
148
148
|
end
|
149
149
|
|
150
150
|
it 'should contain <Dbtr>' do
|
151
|
-
subject.
|
151
|
+
expect(subject).to have_xml('//Document/CstmrCdtTrfInitn/PmtInf/Dbtr/Nm', 'Schuldner GmbH')
|
152
152
|
end
|
153
153
|
|
154
154
|
it 'should contain <DbtrAcct>' do
|
155
|
-
subject.
|
155
|
+
expect(subject).to have_xml('//Document/CstmrCdtTrfInitn/PmtInf/DbtrAcct/Id/IBAN', 'DE87200500001234567890')
|
156
156
|
end
|
157
157
|
|
158
158
|
it 'should contain <DbtrAgt>' do
|
159
|
-
subject.
|
159
|
+
expect(subject).to have_xml('//Document/CstmrCdtTrfInitn/PmtInf/DbtrAgt/FinInstnId/BIC', 'BANKDEFFXXX')
|
160
160
|
end
|
161
161
|
|
162
162
|
it 'should contain <EndToEndId>' do
|
163
|
-
subject.
|
164
|
-
subject.
|
163
|
+
expect(subject).to have_xml('//Document/CstmrCdtTrfInitn/PmtInf/CdtTrfTxInf[1]/PmtId/EndToEndId', 'XYZ-1234/123')
|
164
|
+
expect(subject).to have_xml('//Document/CstmrCdtTrfInitn/PmtInf/CdtTrfTxInf[2]/PmtId/EndToEndId', 'XYZ-5678/456')
|
165
165
|
end
|
166
166
|
|
167
167
|
it 'should contain <Amt>' do
|
168
|
-
subject.
|
169
|
-
subject.
|
168
|
+
expect(subject).to have_xml('//Document/CstmrCdtTrfInitn/PmtInf/CdtTrfTxInf[1]/Amt/InstdAmt', '102.50')
|
169
|
+
expect(subject).to have_xml('//Document/CstmrCdtTrfInitn/PmtInf/CdtTrfTxInf[2]/Amt/InstdAmt', '59.00')
|
170
170
|
end
|
171
171
|
|
172
172
|
it 'should contain <CdtrAgt> for every BIC given' do
|
173
|
-
subject.
|
174
|
-
subject.
|
173
|
+
expect(subject).to have_xml('//Document/CstmrCdtTrfInitn/PmtInf/CdtTrfTxInf[1]/CdtrAgt/FinInstnId/BIC', 'PBNKDEFF370')
|
174
|
+
expect(subject).not_to have_xml('//Document/CstmrCdtTrfInitn/PmtInf/CdtTrfTxInf[2]/CdtrAgt')
|
175
175
|
end
|
176
176
|
|
177
177
|
it 'should contain <Cdtr>' do
|
178
|
-
subject.
|
179
|
-
subject.
|
178
|
+
expect(subject).to have_xml('//Document/CstmrCdtTrfInitn/PmtInf/CdtTrfTxInf[1]/Cdtr/Nm', 'Telekomiker AG')
|
179
|
+
expect(subject).to have_xml('//Document/CstmrCdtTrfInitn/PmtInf/CdtTrfTxInf[2]/Cdtr/Nm', 'Amazonas GmbH')
|
180
180
|
end
|
181
181
|
|
182
182
|
it 'should contain <CdtrAcct>' do
|
183
|
-
subject.
|
184
|
-
subject.
|
183
|
+
expect(subject).to have_xml('//Document/CstmrCdtTrfInitn/PmtInf/CdtTrfTxInf[1]/CdtrAcct/Id/IBAN', 'DE37112589611964645802')
|
184
|
+
expect(subject).to have_xml('//Document/CstmrCdtTrfInitn/PmtInf/CdtTrfTxInf[2]/CdtrAcct/Id/IBAN', 'DE27793589132923472195')
|
185
185
|
end
|
186
186
|
|
187
187
|
it 'should contain <RmtInf>' do
|
188
|
-
subject.
|
189
|
-
subject.
|
188
|
+
expect(subject).to have_xml('//Document/CstmrCdtTrfInitn/PmtInf/CdtTrfTxInf[1]/RmtInf/Ustrd', 'Rechnung vom 22.08.2013')
|
189
|
+
expect(subject).to have_xml('//Document/CstmrCdtTrfInitn/PmtInf/CdtTrfTxInf[2]/RmtInf/Ustrd', 'Rechnung vom 21.08.2013')
|
190
190
|
end
|
191
191
|
end
|
192
192
|
|
@@ -202,15 +202,15 @@ describe SEPA::CreditTransfer do
|
|
202
202
|
end
|
203
203
|
|
204
204
|
it 'should contain two payment_informations with <ReqdExctnDt>' do
|
205
|
-
subject.
|
206
|
-
subject.
|
205
|
+
expect(subject).to have_xml('//Document/CstmrCdtTrfInitn/PmtInf[1]/ReqdExctnDt', (Date.today + 1).iso8601)
|
206
|
+
expect(subject).to have_xml('//Document/CstmrCdtTrfInitn/PmtInf[2]/ReqdExctnDt', (Date.today + 2).iso8601)
|
207
207
|
|
208
|
-
subject.
|
208
|
+
expect(subject).not_to have_xml('//Document/CstmrCdtTrfInitn/PmtInf[3]')
|
209
209
|
end
|
210
210
|
|
211
211
|
it 'should contain two payment_informations with different <PmtInfId>' do
|
212
|
-
subject.
|
213
|
-
subject.
|
212
|
+
expect(subject).to have_xml('//Document/CstmrCdtTrfInitn/PmtInf[1]/PmtInfId', /SEPA-KING\/[0-9]+\/1/)
|
213
|
+
expect(subject).to have_xml('//Document/CstmrCdtTrfInitn/PmtInf[2]/PmtInfId', /SEPA-KING\/[0-9]+\/2/)
|
214
214
|
end
|
215
215
|
end
|
216
216
|
|
@@ -226,10 +226,10 @@ describe SEPA::CreditTransfer do
|
|
226
226
|
end
|
227
227
|
|
228
228
|
it 'should contain two payment_informations with <BtchBookg>' do
|
229
|
-
subject.
|
230
|
-
subject.
|
229
|
+
expect(subject).to have_xml('//Document/CstmrCdtTrfInitn/PmtInf[1]/BtchBookg', 'false')
|
230
|
+
expect(subject).to have_xml('//Document/CstmrCdtTrfInitn/PmtInf[2]/BtchBookg', 'true')
|
231
231
|
|
232
|
-
subject.
|
232
|
+
expect(subject).not_to have_xml('//Document/CstmrCdtTrfInitn/PmtInf[3]')
|
233
233
|
end
|
234
234
|
end
|
235
235
|
|
@@ -246,24 +246,24 @@ describe SEPA::CreditTransfer do
|
|
246
246
|
end
|
247
247
|
|
248
248
|
it 'should contain multiple payment_informations' do
|
249
|
-
subject.
|
250
|
-
subject.
|
249
|
+
expect(subject).to have_xml('//Document/CstmrCdtTrfInitn/PmtInf[1]/ReqdExctnDt', (Date.today + 1).iso8601)
|
250
|
+
expect(subject).to have_xml('//Document/CstmrCdtTrfInitn/PmtInf[1]/BtchBookg', 'false')
|
251
251
|
|
252
|
-
subject.
|
253
|
-
subject.
|
252
|
+
expect(subject).to have_xml('//Document/CstmrCdtTrfInitn/PmtInf[2]/ReqdExctnDt', (Date.today + 1).iso8601)
|
253
|
+
expect(subject).to have_xml('//Document/CstmrCdtTrfInitn/PmtInf[2]/BtchBookg', 'true')
|
254
254
|
|
255
|
-
subject.
|
256
|
-
subject.
|
255
|
+
expect(subject).to have_xml('//Document/CstmrCdtTrfInitn/PmtInf[3]/ReqdExctnDt', (Date.today + 2).iso8601)
|
256
|
+
expect(subject).to have_xml('//Document/CstmrCdtTrfInitn/PmtInf[3]/BtchBookg', 'false')
|
257
257
|
|
258
|
-
subject.
|
259
|
-
subject.
|
258
|
+
expect(subject).to have_xml('//Document/CstmrCdtTrfInitn/PmtInf[4]/ReqdExctnDt', (Date.today + 2).iso8601)
|
259
|
+
expect(subject).to have_xml('//Document/CstmrCdtTrfInitn/PmtInf[4]/BtchBookg', 'true')
|
260
260
|
end
|
261
261
|
|
262
262
|
it 'should have multiple control sums' do
|
263
|
-
subject.
|
264
|
-
subject.
|
265
|
-
subject.
|
266
|
-
subject.
|
263
|
+
expect(subject).to have_xml('//Document/CstmrCdtTrfInitn/PmtInf[1]/CtrlSum', '1.00')
|
264
|
+
expect(subject).to have_xml('//Document/CstmrCdtTrfInitn/PmtInf[2]/CtrlSum', '2.00')
|
265
|
+
expect(subject).to have_xml('//Document/CstmrCdtTrfInitn/PmtInf[3]/CtrlSum', '4.00')
|
266
|
+
expect(subject).to have_xml('//Document/CstmrCdtTrfInitn/PmtInf[4]/CtrlSum', '8.00')
|
267
267
|
end
|
268
268
|
end
|
269
269
|
end
|
@@ -18,29 +18,29 @@ describe SEPA::CreditTransferTransaction do
|
|
18
18
|
describe :schema_compatible? do
|
19
19
|
context 'for pain.001.003.03' do
|
20
20
|
it 'should success' do
|
21
|
-
SEPA::CreditTransferTransaction.new({}).
|
21
|
+
expect(SEPA::CreditTransferTransaction.new({})).to be_schema_compatible('pain.001.003.03')
|
22
22
|
end
|
23
23
|
end
|
24
24
|
|
25
25
|
context 'pain.001.002.03' do
|
26
26
|
it 'should success for valid attributes' do
|
27
|
-
SEPA::CreditTransferTransaction.new(:bic => 'SPUEDE2UXXX', :service_level => 'SEPA').
|
27
|
+
expect(SEPA::CreditTransferTransaction.new(:bic => 'SPUEDE2UXXX', :service_level => 'SEPA')).to be_schema_compatible('pain.001.002.03')
|
28
28
|
end
|
29
29
|
|
30
30
|
it 'should fail for invalid attributes' do
|
31
|
-
SEPA::CreditTransferTransaction.new(:bic => nil).
|
32
|
-
SEPA::CreditTransferTransaction.new(:bic => 'SPUEDE2UXXX', :service_level => 'URGP').
|
31
|
+
expect(SEPA::CreditTransferTransaction.new(:bic => nil)).not_to be_schema_compatible('pain.001.002.03')
|
32
|
+
expect(SEPA::CreditTransferTransaction.new(:bic => 'SPUEDE2UXXX', :service_level => 'URGP')).not_to be_schema_compatible('pain.001.002.03')
|
33
33
|
end
|
34
34
|
end
|
35
35
|
end
|
36
36
|
|
37
37
|
context 'Requested date' do
|
38
38
|
it 'should allow valid value' do
|
39
|
-
SEPA::CreditTransferTransaction.
|
39
|
+
expect(SEPA::CreditTransferTransaction).to accept(nil, Date.today, Date.today.next, Date.today + 2, for: :requested_date)
|
40
40
|
end
|
41
41
|
|
42
42
|
it 'should not allow invalid value' do
|
43
|
-
SEPA::CreditTransferTransaction.
|
43
|
+
expect(SEPA::CreditTransferTransaction).not_to accept(Date.new(1995,12,21), Date.today - 1, for: :requested_date)
|
44
44
|
end
|
45
45
|
end
|
46
46
|
end
|
@@ -13,11 +13,11 @@ describe SEPA::CreditorAccount do
|
|
13
13
|
|
14
14
|
describe :creditor_identifier do
|
15
15
|
it 'should accept valid value' do
|
16
|
-
SEPA::CreditorAccount.
|
16
|
+
expect(SEPA::CreditorAccount).to accept('DE98ZZZ09999999999', 'AT12ZZZ00000000001', 'IT97ZZZA1B2C3D4E5F6G7H8', 'NL97ZZZ123456780001', 'FR12ZZZ123456', for: :creditor_identifier)
|
17
17
|
end
|
18
18
|
|
19
19
|
it 'should not accept invalid value' do
|
20
|
-
SEPA::CreditorAccount.
|
20
|
+
expect(SEPA::CreditorAccount).not_to accept('', 'invalid', 'DE98ZZZ099999999990', 'DEAAAAAAAAAAAAAAAA', for: :creditor_identifier)
|
21
21
|
end
|
22
22
|
end
|
23
23
|
end
|
data/spec/direct_debit_spec.rb
CHANGED
@@ -23,7 +23,7 @@ describe SEPA::DirectDebit do
|
|
23
23
|
direct_debit.add_transaction(direct_debt_transaction)
|
24
24
|
end
|
25
25
|
|
26
|
-
expect(direct_debit).to
|
26
|
+
expect(direct_debit.transactions.size).to eq(3)
|
27
27
|
end
|
28
28
|
|
29
29
|
it 'should fail for invalid transaction' do
|
@@ -57,7 +57,7 @@ describe SEPA::DirectDebit do
|
|
57
57
|
direct_debit.add_transaction(direct_debt_transaction(reference: "EXAMPLE REFERENCE 2", requested_date: Date.today.next.next))
|
58
58
|
direct_debit.add_transaction(direct_debt_transaction(reference: "EXAMPLE REFERENCE 3"))
|
59
59
|
|
60
|
-
expect(direct_debit.batches).to
|
60
|
+
expect(direct_debit.batches.size).to eq(2)
|
61
61
|
expect(direct_debit.batches[0]).to match(/SEPA-KING\/[0-9]+/)
|
62
62
|
expect(direct_debit.batches[1]).to match(/SEPA-KING\/[0-9]+/)
|
63
63
|
end
|
@@ -164,87 +164,87 @@ describe SEPA::DirectDebit do
|
|
164
164
|
end
|
165
165
|
|
166
166
|
it 'should have message_identification' do
|
167
|
-
subject.
|
167
|
+
expect(subject).to have_xml('//Document/CstmrDrctDbtInitn/GrpHdr/MsgId', /SEPA-KING\/[0-9]+/)
|
168
168
|
end
|
169
169
|
|
170
170
|
it 'should contain <PmtInfId>' do
|
171
|
-
subject.
|
171
|
+
expect(subject).to have_xml('//Document/CstmrDrctDbtInitn/PmtInf/PmtInfId', /SEPA-KING\/[0-9]+\/1/)
|
172
172
|
end
|
173
173
|
|
174
174
|
it 'should contain <ReqdColltnDt>' do
|
175
|
-
subject.
|
175
|
+
expect(subject).to have_xml('//Document/CstmrDrctDbtInitn/PmtInf/ReqdColltnDt', Date.today.next.iso8601)
|
176
176
|
end
|
177
177
|
|
178
178
|
it 'should contain <PmtMtd>' do
|
179
|
-
subject.
|
179
|
+
expect(subject).to have_xml('//Document/CstmrDrctDbtInitn/PmtInf/PmtMtd', 'DD')
|
180
180
|
end
|
181
181
|
|
182
182
|
it 'should contain <BtchBookg>' do
|
183
|
-
subject.
|
183
|
+
expect(subject).to have_xml('//Document/CstmrDrctDbtInitn/PmtInf/BtchBookg', 'true')
|
184
184
|
end
|
185
185
|
|
186
186
|
it 'should contain <NbOfTxs>' do
|
187
|
-
subject.
|
187
|
+
expect(subject).to have_xml('//Document/CstmrDrctDbtInitn/PmtInf/NbOfTxs', '2')
|
188
188
|
end
|
189
189
|
|
190
190
|
it 'should contain <CtrlSum>' do
|
191
|
-
subject.
|
191
|
+
expect(subject).to have_xml('//Document/CstmrDrctDbtInitn/PmtInf/CtrlSum', '789.99')
|
192
192
|
end
|
193
193
|
|
194
194
|
it 'should contain <Cdtr>' do
|
195
|
-
subject.
|
195
|
+
expect(subject).to have_xml('//Document/CstmrDrctDbtInitn/PmtInf/Cdtr/Nm', 'Glaubiger GmbH')
|
196
196
|
end
|
197
197
|
|
198
198
|
it 'should contain <CdtrAcct>' do
|
199
|
-
subject.
|
199
|
+
expect(subject).to have_xml('//Document/CstmrDrctDbtInitn/PmtInf/CdtrAcct/Id/IBAN', 'DE87200500001234567890')
|
200
200
|
end
|
201
201
|
|
202
202
|
it 'should contain <CdtrAgt>' do
|
203
|
-
subject.
|
203
|
+
expect(subject).to have_xml('//Document/CstmrDrctDbtInitn/PmtInf/CdtrAgt/FinInstnId/BIC', 'BANKDEFFXXX')
|
204
204
|
end
|
205
205
|
|
206
206
|
it 'should contain <CdtrAgt>' do
|
207
|
-
subject.
|
207
|
+
expect(subject).to have_xml('//Document/CstmrDrctDbtInitn/PmtInf/CdtrSchmeId/Id/PrvtId/Othr/Id', 'DE98ZZZ09999999999')
|
208
208
|
end
|
209
209
|
|
210
210
|
it 'should contain <EndToEndId>' do
|
211
|
-
subject.
|
212
|
-
subject.
|
211
|
+
expect(subject).to have_xml('//Document/CstmrDrctDbtInitn/PmtInf/DrctDbtTxInf[1]/PmtId/EndToEndId', 'XYZ/2013-08-ABO/12345')
|
212
|
+
expect(subject).to have_xml('//Document/CstmrDrctDbtInitn/PmtInf/DrctDbtTxInf[2]/PmtId/EndToEndId', 'XYZ/2013-08-ABO/6789')
|
213
213
|
end
|
214
214
|
|
215
215
|
it 'should contain <InstdAmt>' do
|
216
|
-
subject.
|
217
|
-
subject.
|
216
|
+
expect(subject).to have_xml('//Document/CstmrDrctDbtInitn/PmtInf/DrctDbtTxInf[1]/InstdAmt', '39.99')
|
217
|
+
expect(subject).to have_xml('//Document/CstmrDrctDbtInitn/PmtInf/DrctDbtTxInf[2]/InstdAmt', '750.00')
|
218
218
|
end
|
219
219
|
|
220
220
|
it 'should contain <MndtId>' do
|
221
|
-
subject.
|
222
|
-
subject.
|
221
|
+
expect(subject).to have_xml('//Document/CstmrDrctDbtInitn/PmtInf/DrctDbtTxInf[1]/DrctDbtTx/MndtRltdInf/MndtId', 'K-02-2011-12345')
|
222
|
+
expect(subject).to have_xml('//Document/CstmrDrctDbtInitn/PmtInf/DrctDbtTxInf[2]/DrctDbtTx/MndtRltdInf/MndtId', 'K-08-2010-42123')
|
223
223
|
end
|
224
224
|
|
225
225
|
it 'should contain <DtOfSgntr>' do
|
226
|
-
subject.
|
227
|
-
subject.
|
226
|
+
expect(subject).to have_xml('//Document/CstmrDrctDbtInitn/PmtInf/DrctDbtTxInf[1]/DrctDbtTx/MndtRltdInf/DtOfSgntr', '2011-01-25')
|
227
|
+
expect(subject).to have_xml('//Document/CstmrDrctDbtInitn/PmtInf/DrctDbtTxInf[2]/DrctDbtTx/MndtRltdInf/DtOfSgntr', '2010-07-25')
|
228
228
|
end
|
229
229
|
|
230
230
|
it 'should contain <DbtrAgt>' do
|
231
|
-
subject.
|
232
|
-
subject.
|
231
|
+
expect(subject).to have_xml('//Document/CstmrDrctDbtInitn/PmtInf/DrctDbtTxInf[1]/DbtrAgt/FinInstnId/BIC', 'SPUEDE2UXXX')
|
232
|
+
expect(subject).to have_xml('//Document/CstmrDrctDbtInitn/PmtInf/DrctDbtTxInf[2]/DbtrAgt/FinInstnId/Othr/Id', 'NOTPROVIDED')
|
233
233
|
end
|
234
234
|
|
235
235
|
it 'should contain <Dbtr>' do
|
236
|
-
subject.
|
237
|
-
subject.
|
236
|
+
expect(subject).to have_xml('//Document/CstmrDrctDbtInitn/PmtInf/DrctDbtTxInf[1]/Dbtr/Nm', 'Zahlemann Sohne GbR')
|
237
|
+
expect(subject).to have_xml('//Document/CstmrDrctDbtInitn/PmtInf/DrctDbtTxInf[2]/Dbtr/Nm', 'Meier Schulze oHG')
|
238
238
|
end
|
239
239
|
|
240
240
|
it 'should contain <DbtrAcct>' do
|
241
|
-
subject.
|
242
|
-
subject.
|
241
|
+
expect(subject).to have_xml('//Document/CstmrDrctDbtInitn/PmtInf/DrctDbtTxInf[1]/DbtrAcct/Id/IBAN', 'DE21500500009876543210')
|
242
|
+
expect(subject).to have_xml('//Document/CstmrDrctDbtInitn/PmtInf/DrctDbtTxInf[2]/DbtrAcct/Id/IBAN', 'DE68210501700012345678')
|
243
243
|
end
|
244
244
|
|
245
245
|
it 'should contain <RmtInf>' do
|
246
|
-
subject.
|
247
|
-
subject.
|
246
|
+
expect(subject).to have_xml('//Document/CstmrDrctDbtInitn/PmtInf/DrctDbtTxInf[1]/RmtInf/Ustrd', 'Unsere Rechnung vom 10.08.2013')
|
247
|
+
expect(subject).to have_xml('//Document/CstmrDrctDbtInitn/PmtInf/DrctDbtTxInf[2]/RmtInf/Ustrd', 'Vielen Dank fur Ihren Einkauf')
|
248
248
|
end
|
249
249
|
end
|
250
250
|
|
@@ -260,15 +260,15 @@ describe SEPA::DirectDebit do
|
|
260
260
|
end
|
261
261
|
|
262
262
|
it 'should contain two payment_informations with <ReqdColltnDt>' do
|
263
|
-
subject.
|
264
|
-
subject.
|
263
|
+
expect(subject).to have_xml('//Document/CstmrDrctDbtInitn/PmtInf[1]/ReqdColltnDt', (Date.today + 1).iso8601)
|
264
|
+
expect(subject).to have_xml('//Document/CstmrDrctDbtInitn/PmtInf[2]/ReqdColltnDt', (Date.today + 2).iso8601)
|
265
265
|
|
266
|
-
subject.
|
266
|
+
expect(subject).not_to have_xml('//Document/CstmrDrctDbtInitn/PmtInf[3]')
|
267
267
|
end
|
268
268
|
|
269
269
|
it 'should contain two payment_informations with different <PmtInfId>' do
|
270
|
-
subject.
|
271
|
-
subject.
|
270
|
+
expect(subject).to have_xml('//Document/CstmrDrctDbtInitn/PmtInf[1]/PmtInfId', /SEPA-KING\/[0-9]+\/1/)
|
271
|
+
expect(subject).to have_xml('//Document/CstmrDrctDbtInitn/PmtInf[2]/PmtInfId', /SEPA-KING\/[0-9]+\/2/)
|
272
272
|
end
|
273
273
|
end
|
274
274
|
|
@@ -283,7 +283,7 @@ describe SEPA::DirectDebit do
|
|
283
283
|
end
|
284
284
|
|
285
285
|
it 'should have errors' do
|
286
|
-
subject.
|
286
|
+
expect(subject.errors_on(:base).size).to eq(1)
|
287
287
|
end
|
288
288
|
|
289
289
|
it 'should raise error on XML generation' do
|
@@ -305,10 +305,10 @@ describe SEPA::DirectDebit do
|
|
305
305
|
end
|
306
306
|
|
307
307
|
it 'should contain two payment_informations with <LclInstrm>' do
|
308
|
-
subject.
|
309
|
-
subject.
|
308
|
+
expect(subject).to have_xml('//Document/CstmrDrctDbtInitn/PmtInf[1]/PmtTpInf/SeqTp', 'OOFF')
|
309
|
+
expect(subject).to have_xml('//Document/CstmrDrctDbtInitn/PmtInf[2]/PmtTpInf/SeqTp', 'FRST')
|
310
310
|
|
311
|
-
subject.
|
311
|
+
expect(subject).not_to have_xml('//Document/CstmrDrctDbtInitn/PmtInf[3]')
|
312
312
|
end
|
313
313
|
end
|
314
314
|
|
@@ -324,10 +324,10 @@ describe SEPA::DirectDebit do
|
|
324
324
|
end
|
325
325
|
|
326
326
|
it 'should contain two payment_informations with <BtchBookg>' do
|
327
|
-
subject.
|
328
|
-
subject.
|
327
|
+
expect(subject).to have_xml('//Document/CstmrDrctDbtInitn/PmtInf[1]/BtchBookg', 'false')
|
328
|
+
expect(subject).to have_xml('//Document/CstmrDrctDbtInitn/PmtInf[2]/BtchBookg', 'true')
|
329
329
|
|
330
|
-
subject.
|
330
|
+
expect(subject).not_to have_xml('//Document/CstmrDrctDbtInitn/PmtInf[3]')
|
331
331
|
end
|
332
332
|
end
|
333
333
|
|
@@ -344,24 +344,24 @@ describe SEPA::DirectDebit do
|
|
344
344
|
end
|
345
345
|
|
346
346
|
it 'should contain multiple payment_informations' do
|
347
|
-
subject.
|
348
|
-
subject.
|
347
|
+
expect(subject).to have_xml('//Document/CstmrDrctDbtInitn/PmtInf[1]/ReqdColltnDt', (Date.today + 1).iso8601)
|
348
|
+
expect(subject).to have_xml('//Document/CstmrDrctDbtInitn/PmtInf[1]/PmtTpInf/SeqTp', 'OOFF')
|
349
349
|
|
350
|
-
subject.
|
351
|
-
subject.
|
350
|
+
expect(subject).to have_xml('//Document/CstmrDrctDbtInitn/PmtInf[2]/ReqdColltnDt', (Date.today + 1).iso8601)
|
351
|
+
expect(subject).to have_xml('//Document/CstmrDrctDbtInitn/PmtInf[2]/PmtTpInf/SeqTp', 'FNAL')
|
352
352
|
|
353
|
-
subject.
|
354
|
-
subject.
|
353
|
+
expect(subject).to have_xml('//Document/CstmrDrctDbtInitn/PmtInf[3]/ReqdColltnDt', (Date.today + 2).iso8601)
|
354
|
+
expect(subject).to have_xml('//Document/CstmrDrctDbtInitn/PmtInf[3]/PmtTpInf/SeqTp', 'OOFF')
|
355
355
|
|
356
|
-
subject.
|
357
|
-
subject.
|
356
|
+
expect(subject).to have_xml('//Document/CstmrDrctDbtInitn/PmtInf[4]/ReqdColltnDt', (Date.today + 2).iso8601)
|
357
|
+
expect(subject).to have_xml('//Document/CstmrDrctDbtInitn/PmtInf[4]/PmtTpInf/SeqTp', 'FNAL')
|
358
358
|
end
|
359
359
|
|
360
360
|
it 'should have multiple control sums' do
|
361
|
-
subject.
|
362
|
-
subject.
|
363
|
-
subject.
|
364
|
-
subject.
|
361
|
+
expect(subject).to have_xml('//Document/CstmrDrctDbtInitn/PmtInf[1]/CtrlSum', '1.00')
|
362
|
+
expect(subject).to have_xml('//Document/CstmrDrctDbtInitn/PmtInf[2]/CtrlSum', '2.00')
|
363
|
+
expect(subject).to have_xml('//Document/CstmrDrctDbtInitn/PmtInf[3]/CtrlSum', '4.00')
|
364
|
+
expect(subject).to have_xml('//Document/CstmrDrctDbtInitn/PmtInf[4]/CtrlSum', '8.00')
|
365
365
|
end
|
366
366
|
end
|
367
367
|
|
@@ -381,8 +381,8 @@ describe SEPA::DirectDebit do
|
|
381
381
|
end
|
382
382
|
|
383
383
|
it 'should contain two payment_informations with <Cdtr>' do
|
384
|
-
subject.
|
385
|
-
subject.
|
384
|
+
expect(subject).to have_xml('//Document/CstmrDrctDbtInitn/PmtInf[1]/Cdtr/Nm', 'Glaubiger GmbH')
|
385
|
+
expect(subject).to have_xml('//Document/CstmrDrctDbtInitn/PmtInf[2]/Cdtr/Nm', 'Creditor Inc.')
|
386
386
|
end
|
387
387
|
end
|
388
388
|
end
|
@@ -20,39 +20,39 @@ describe SEPA::DirectDebitTransaction do
|
|
20
20
|
describe :schema_compatible? do
|
21
21
|
context 'for pain.008.003.02' do
|
22
22
|
it 'should success' do
|
23
|
-
SEPA::DirectDebitTransaction.new({}).
|
23
|
+
expect(SEPA::DirectDebitTransaction.new({})).to be_schema_compatible('pain.008.003.02')
|
24
24
|
end
|
25
25
|
end
|
26
26
|
|
27
27
|
context 'for pain.008.002.02' do
|
28
28
|
it 'should success for valid attributes' do
|
29
|
-
SEPA::DirectDebitTransaction.new(:bic => 'SPUEDE2UXXX', :local_instrument => 'CORE').
|
29
|
+
expect(SEPA::DirectDebitTransaction.new(:bic => 'SPUEDE2UXXX', :local_instrument => 'CORE')).to be_schema_compatible('pain.008.002.02')
|
30
30
|
end
|
31
31
|
|
32
32
|
it 'should fail for invalid attributes' do
|
33
|
-
SEPA::DirectDebitTransaction.new(:bic => nil).
|
34
|
-
SEPA::DirectDebitTransaction.new(:bic => 'SPUEDE2UXXX', :local_instrument => 'COR1').
|
33
|
+
expect(SEPA::DirectDebitTransaction.new(:bic => nil)).not_to be_schema_compatible('pain.008.002.02')
|
34
|
+
expect(SEPA::DirectDebitTransaction.new(:bic => 'SPUEDE2UXXX', :local_instrument => 'COR1')).not_to be_schema_compatible('pain.008.002.02')
|
35
35
|
end
|
36
36
|
end
|
37
37
|
end
|
38
38
|
|
39
39
|
context 'Mandate Date of Signature' do
|
40
40
|
it 'should accept valid value' do
|
41
|
-
SEPA::DirectDebitTransaction.
|
41
|
+
expect(SEPA::DirectDebitTransaction).to accept(Date.today, Date.today - 1, for: :mandate_date_of_signature)
|
42
42
|
end
|
43
43
|
|
44
44
|
it 'should not accept invalid value' do
|
45
|
-
SEPA::DirectDebitTransaction.
|
45
|
+
expect(SEPA::DirectDebitTransaction).not_to accept(nil, '2010-12-01', Date.today + 1, for: :mandate_date_of_signature)
|
46
46
|
end
|
47
47
|
end
|
48
48
|
|
49
49
|
context 'Requested date' do
|
50
50
|
it 'should allow valid value' do
|
51
|
-
SEPA::DirectDebitTransaction.
|
51
|
+
expect(SEPA::DirectDebitTransaction).to accept(nil, Date.today.next, Date.today + 2, for: :requested_date)
|
52
52
|
end
|
53
53
|
|
54
54
|
it 'should not allow invalid value' do
|
55
|
-
SEPA::DirectDebitTransaction.
|
55
|
+
expect(SEPA::DirectDebitTransaction).not_to accept(Date.new(1995,12,21), Date.today - 1, Date.today, for: :requested_date)
|
56
56
|
end
|
57
57
|
end
|
58
58
|
end
|
data/spec/message_spec.rb
CHANGED
@@ -20,11 +20,11 @@ describe SEPA::Message do
|
|
20
20
|
end
|
21
21
|
|
22
22
|
it 'should sum up all transactions' do
|
23
|
-
subject.amount_total.
|
23
|
+
expect(subject.amount_total).to eq(3.3)
|
24
24
|
end
|
25
25
|
|
26
26
|
it 'should sum up selected transactions' do
|
27
|
-
subject.amount_total([subject.transactions[0]]).
|
27
|
+
expect(subject.amount_total([subject.transactions[0]])).to eq(1.1)
|
28
28
|
end
|
29
29
|
end
|
30
30
|
|
@@ -32,13 +32,13 @@ describe SEPA::Message do
|
|
32
32
|
subject { DummyMessage.new }
|
33
33
|
|
34
34
|
it 'should fail with invalid account' do
|
35
|
-
subject.
|
36
|
-
subject.
|
35
|
+
expect(subject).not_to be_valid
|
36
|
+
expect(subject.errors_on(:account).size).to eq(2)
|
37
37
|
end
|
38
38
|
|
39
39
|
it 'should fail without transactions' do
|
40
|
-
subject.
|
41
|
-
subject.
|
40
|
+
expect(subject).not_to be_valid
|
41
|
+
expect(subject.errors_on(:transactions).size).to eq(1)
|
42
42
|
end
|
43
43
|
end
|
44
44
|
|
@@ -46,12 +46,12 @@ describe SEPA::Message do
|
|
46
46
|
subject { DummyMessage.new }
|
47
47
|
|
48
48
|
it 'should have a reader method' do
|
49
|
-
subject.message_identification.
|
49
|
+
expect(subject.message_identification).to match(/SEPA-KING\/[0-9]+/)
|
50
50
|
end
|
51
51
|
|
52
52
|
it 'should have a writer method' do
|
53
53
|
subject.message_identification = "MY_MESSAGE_ID/#{Time.now.to_i}"
|
54
|
-
subject.message_identification.
|
54
|
+
expect(subject.message_identification).to match(/MY_MESSAGE_ID/)
|
55
55
|
end
|
56
56
|
end
|
57
57
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -26,7 +26,6 @@ Dir[File.expand_path(File.join(File.dirname(__FILE__),'support','**','*.rb'))].e
|
|
26
26
|
|
27
27
|
# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
|
28
28
|
RSpec.configure do |config|
|
29
|
-
config.treat_symbols_as_metadata_keys_with_true_values = true
|
30
29
|
config.run_all_when_everything_filtered = true
|
31
30
|
config.filter_run :focus
|
32
31
|
|
@@ -0,0 +1,30 @@
|
|
1
|
+
unless defined?(ActiveModel::Model)
|
2
|
+
# ActiveModel::Model is available since ActiveModel 4.0 only.
|
3
|
+
#
|
4
|
+
# If it's missing, add the code from
|
5
|
+
# https://github.com/rails/rails/blob/master/activemodel/lib/active_model/model.rb
|
6
|
+
module ActiveModel
|
7
|
+
module Model
|
8
|
+
def self.included(base)
|
9
|
+
base.class_eval do
|
10
|
+
extend ActiveModel::Naming
|
11
|
+
extend ActiveModel::Translation
|
12
|
+
include ActiveModel::Validations
|
13
|
+
include ActiveModel::Conversion
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
def initialize(params={})
|
18
|
+
params.each do |attr, value|
|
19
|
+
self.public_send("#{attr}=", value)
|
20
|
+
end if params
|
21
|
+
|
22
|
+
super()
|
23
|
+
end
|
24
|
+
|
25
|
+
def persisted?
|
26
|
+
false
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -6,10 +6,10 @@ RSpec::Matchers.define :validate_against do |xsd|
|
|
6
6
|
@schema = Nokogiri::XML::Schema(File.read("lib/schema/#{xsd}"))
|
7
7
|
@doc = Nokogiri::XML(actual)
|
8
8
|
|
9
|
-
@schema.
|
9
|
+
expect(@schema).to be_valid(@doc)
|
10
10
|
end
|
11
11
|
|
12
|
-
|
12
|
+
failure_message do |actual|
|
13
13
|
# Return the validation errors as string
|
14
14
|
@schema.validate(@doc).join("\n")
|
15
15
|
end
|
@@ -21,13 +21,13 @@ RSpec::Matchers.define :have_xml do |xpath, text|
|
|
21
21
|
doc.remove_namespaces! # so we can use shorter xpath's without any namespace
|
22
22
|
|
23
23
|
nodes = doc.xpath(xpath)
|
24
|
-
nodes.
|
24
|
+
expect(nodes).not_to be_empty
|
25
25
|
if text
|
26
26
|
nodes.each do |node|
|
27
27
|
if text.is_a?(Regexp)
|
28
|
-
node.content.
|
28
|
+
expect(node.content).to match(text)
|
29
29
|
else
|
30
|
-
node.content.
|
30
|
+
expect(node.content).to eq(text)
|
31
31
|
end
|
32
32
|
end
|
33
33
|
end
|
@@ -39,21 +39,21 @@ RSpec::Matchers.define :accept do |*values, options|
|
|
39
39
|
attributes = Array(options[:for])
|
40
40
|
|
41
41
|
attributes.each do |attribute|
|
42
|
-
|
42
|
+
match do |actual|
|
43
43
|
values.all? { |value|
|
44
44
|
expect(
|
45
|
-
actual.new(attribute => value)
|
46
|
-
).to
|
45
|
+
actual.new(attribute => value).errors_on(attribute).size
|
46
|
+
).to eq 0
|
47
47
|
}
|
48
48
|
end
|
49
49
|
end
|
50
50
|
|
51
51
|
attributes.each do |attribute|
|
52
|
-
|
52
|
+
match_when_negated do |actual|
|
53
53
|
values.all? { |value|
|
54
54
|
expect(
|
55
|
-
actual.new(attribute => value)
|
56
|
-
).to
|
55
|
+
actual.new(attribute => value).errors_on(attribute).size
|
56
|
+
).to be >= 1
|
57
57
|
}
|
58
58
|
end
|
59
59
|
end
|
data/spec/transaction_spec.rb
CHANGED
@@ -4,75 +4,75 @@ require 'spec_helper'
|
|
4
4
|
describe SEPA::Transaction do
|
5
5
|
describe :new do
|
6
6
|
it 'should have default for reference' do
|
7
|
-
SEPA::Transaction.new.reference.
|
7
|
+
expect(SEPA::Transaction.new.reference).to eq('NOTPROVIDED')
|
8
8
|
end
|
9
9
|
|
10
10
|
it 'should have default for requested_date' do
|
11
|
-
SEPA::Transaction.new.requested_date.
|
11
|
+
expect(SEPA::Transaction.new.requested_date).to eq(Date.today.next)
|
12
12
|
end
|
13
13
|
|
14
14
|
it 'should have default for batch_booking' do
|
15
|
-
SEPA::Transaction.new.batch_booking.
|
15
|
+
expect(SEPA::Transaction.new.batch_booking).to eq(true)
|
16
16
|
end
|
17
17
|
end
|
18
18
|
|
19
19
|
context 'Name' do
|
20
20
|
it 'should accept valid value' do
|
21
|
-
SEPA::Transaction.
|
21
|
+
expect(SEPA::Transaction).to accept('Manfred Mustermann III.', 'Zahlemann & Söhne GbR', 'X' * 70, for: :name)
|
22
22
|
end
|
23
23
|
|
24
24
|
it 'should not accept invalid value' do
|
25
|
-
SEPA::Transaction.
|
25
|
+
expect(SEPA::Transaction).not_to accept(nil, '', 'X' * 71, for: :name)
|
26
26
|
end
|
27
27
|
end
|
28
28
|
|
29
29
|
context 'IBAN' do
|
30
30
|
it 'should accept valid value' do
|
31
|
-
SEPA::Transaction.
|
31
|
+
expect(SEPA::Transaction).to accept('DE21500500009876543210', 'PL61109010140000071219812874', for: :iban)
|
32
32
|
end
|
33
33
|
|
34
34
|
it 'should not accept invalid value' do
|
35
|
-
SEPA::Transaction.
|
35
|
+
expect(SEPA::Transaction).not_to accept(nil, '', 'invalid', for: :iban)
|
36
36
|
end
|
37
37
|
end
|
38
38
|
|
39
39
|
context 'BIC' do
|
40
40
|
it 'should accept valid value' do
|
41
|
-
SEPA::Transaction.
|
41
|
+
expect(SEPA::Transaction).to accept('DEUTDEFF', 'DEUTDEFF500', 'SPUEDE2UXXX', for: :bic)
|
42
42
|
end
|
43
43
|
|
44
44
|
it 'should not accept invalid value' do
|
45
|
-
SEPA::Transaction.
|
45
|
+
expect(SEPA::Transaction).not_to accept('', 'invalid', for: :bic)
|
46
46
|
end
|
47
47
|
end
|
48
48
|
|
49
49
|
context 'Amount' do
|
50
50
|
it 'should accept valid value' do
|
51
|
-
SEPA::Transaction.
|
51
|
+
expect(SEPA::Transaction).to accept(0.01, 1, 100, 100.00, 99.99, 1234567890.12, BigDecimal('10'), '42', '42.51', '42.512', 1.23456, for: :amount)
|
52
52
|
end
|
53
53
|
|
54
54
|
it 'should not accept invalid value' do
|
55
|
-
SEPA::Transaction.
|
55
|
+
expect(SEPA::Transaction).not_to accept(nil, 0, -3, 'xz', for: :amount)
|
56
56
|
end
|
57
57
|
end
|
58
58
|
|
59
59
|
context 'Reference' do
|
60
60
|
it 'should accept valid value' do
|
61
|
-
SEPA::Transaction.
|
61
|
+
expect(SEPA::Transaction).to accept(nil, 'ABC-1234/78.0', 'X' * 35, for: :reference)
|
62
62
|
end
|
63
63
|
|
64
64
|
it 'should not accept invalid value' do
|
65
|
-
SEPA::Transaction.
|
65
|
+
expect(SEPA::Transaction).not_to accept('', 'X' * 36, for: :reference)
|
66
66
|
end
|
67
67
|
end
|
68
68
|
|
69
69
|
context 'Remittance information' do
|
70
70
|
it 'should allow valid value' do
|
71
|
-
SEPA::Transaction.
|
71
|
+
expect(SEPA::Transaction).to accept(nil, 'Bonus', 'X' * 140, for: :remittance_information)
|
72
72
|
end
|
73
73
|
|
74
74
|
it 'should not allow invalid value' do
|
75
|
-
SEPA::Transaction.
|
75
|
+
expect(SEPA::Transaction).not_to accept('', 'X' * 141, for: :remittance_information)
|
76
76
|
end
|
77
77
|
end
|
78
78
|
end
|
data/spec/validation_spec.rb
CHANGED
@@ -2,24 +2,24 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
describe 'Credit Transfer Initiation' do
|
4
4
|
it "should validate example file" do
|
5
|
-
File.read('spec/examples/pain.001.002.03.xml').
|
6
|
-
File.read('spec/examples/pain.001.003.03.xml').
|
5
|
+
expect(File.read('spec/examples/pain.001.002.03.xml')).to validate_against('pain.001.002.03.xsd')
|
6
|
+
expect(File.read('spec/examples/pain.001.003.03.xml')).to validate_against('pain.001.003.03.xsd')
|
7
7
|
end
|
8
8
|
|
9
9
|
it 'should not validate dummy string' do
|
10
|
-
'foo'.
|
11
|
-
'foo'.
|
10
|
+
expect('foo').not_to validate_against('pain.001.002.03.xsd')
|
11
|
+
expect('foo').not_to validate_against('pain.001.003.03.xsd')
|
12
12
|
end
|
13
13
|
end
|
14
14
|
|
15
15
|
describe 'Direct Debit Initiation' do
|
16
16
|
it 'should validate example file' do
|
17
|
-
File.read('spec/examples/pain.008.002.02.xml').
|
18
|
-
File.read('spec/examples/pain.008.003.02.xml').
|
17
|
+
expect(File.read('spec/examples/pain.008.002.02.xml')).to validate_against('pain.008.002.02.xsd')
|
18
|
+
expect(File.read('spec/examples/pain.008.003.02.xml')).to validate_against('pain.008.003.02.xsd')
|
19
19
|
end
|
20
20
|
|
21
21
|
it 'should not validate dummy string' do
|
22
|
-
'foo'.
|
23
|
-
'foo'.
|
22
|
+
expect('foo').not_to validate_against('pain.008.002.02.xsd')
|
23
|
+
expect('foo').not_to validate_against('pain.008.003.02.xsd')
|
24
24
|
end
|
25
25
|
end
|
data/spec/validator_spec.rb
CHANGED
@@ -10,11 +10,11 @@ describe SEPA::IBANValidator do
|
|
10
10
|
end
|
11
11
|
|
12
12
|
it 'should accept valid IBAN' do
|
13
|
-
Validatable.
|
13
|
+
expect(Validatable).to accept('DE21500500009876543210', 'DE87200500001234567890', for: [:iban, :iban_the_terrible])
|
14
14
|
end
|
15
15
|
|
16
16
|
it 'should not accept an invalid IBAN' do
|
17
|
-
Validatable.
|
17
|
+
expect(Validatable).not_to accept('', 'xxx', 'DE22500500009876543210', 'DE2150050000987654321', for: [:iban, :iban_the_terrible])
|
18
18
|
end
|
19
19
|
end
|
20
20
|
|
@@ -27,11 +27,11 @@ describe SEPA::BICValidator do
|
|
27
27
|
end
|
28
28
|
|
29
29
|
it 'should accept valid BICs' do
|
30
|
-
Validatable.
|
30
|
+
expect(Validatable).to accept('DEUTDEDBDUE', 'DUSSDEDDXXX', for: [:bic, :custom_bic])
|
31
31
|
end
|
32
32
|
|
33
33
|
it 'should not accept an invalid BIC' do
|
34
|
-
Validatable.
|
34
|
+
expect(Validatable).not_to accept('', 'GENODE61HR', 'DEUTDEDBDUEDEUTDEDBDUE', for: [:bic, :custom_bic])
|
35
35
|
end
|
36
36
|
end
|
37
37
|
|
@@ -44,11 +44,11 @@ describe SEPA::CreditorIdentifierValidator do
|
|
44
44
|
end
|
45
45
|
|
46
46
|
it 'should accept valid creditor_identifier' do
|
47
|
-
Validatable.
|
47
|
+
expect(Validatable).to accept('DE98ZZZ09999999999', 'AT12ZZZ00000000001', 'FR12ZZZ123456', 'NL97ZZZ123456780001', for: [:creditor_identifier, :crid])
|
48
48
|
end
|
49
49
|
|
50
50
|
it 'should not accept an invalid creditor_identifier' do
|
51
|
-
Validatable.
|
51
|
+
expect(Validatable).not_to accept('', 'xxx', 'DE98ZZZ099999999990', for: [:creditor_identifier, :crid])
|
52
52
|
end
|
53
53
|
end
|
54
54
|
|
@@ -61,10 +61,10 @@ describe SEPA::MandateIdentifierValidator do
|
|
61
61
|
end
|
62
62
|
|
63
63
|
it 'should accept valid mandate_identifier' do
|
64
|
-
Validatable.
|
64
|
+
expect(Validatable).to accept('XYZ-123', "+?/-:().,'", 'X' * 35, for: [:mandate_id, :mid])
|
65
65
|
end
|
66
66
|
|
67
67
|
it 'should not accept an invalid mandate_identifier' do
|
68
|
-
Validatable.
|
68
|
+
expect(Validatable).not_to accept(nil, '', 'X' * 36, 'ABC 123', '#/*', 'Ümläüt', for: [:mandate_id, :mid])
|
69
69
|
end
|
70
70
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sepa_king
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Georg Leciejewski
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2014-
|
12
|
+
date: 2014-06-09 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activemodel
|
@@ -17,14 +17,14 @@ dependencies:
|
|
17
17
|
requirements:
|
18
18
|
- - ">="
|
19
19
|
- !ruby/object:Gem::Version
|
20
|
-
version:
|
20
|
+
version: 3.0.0
|
21
21
|
type: :runtime
|
22
22
|
prerelease: false
|
23
23
|
version_requirements: !ruby/object:Gem::Requirement
|
24
24
|
requirements:
|
25
25
|
- - ">="
|
26
26
|
- !ruby/object:Gem::Version
|
27
|
-
version:
|
27
|
+
version: 3.0.0
|
28
28
|
- !ruby/object:Gem::Dependency
|
29
29
|
name: i18n
|
30
30
|
requirement: !ruby/object:Gem::Requirement
|
@@ -71,30 +71,30 @@ dependencies:
|
|
71
71
|
name: bundler
|
72
72
|
requirement: !ruby/object:Gem::Requirement
|
73
73
|
requirements:
|
74
|
-
- - "
|
74
|
+
- - ">="
|
75
75
|
- !ruby/object:Gem::Version
|
76
|
-
version: '
|
76
|
+
version: '0'
|
77
77
|
type: :development
|
78
78
|
prerelease: false
|
79
79
|
version_requirements: !ruby/object:Gem::Requirement
|
80
80
|
requirements:
|
81
|
-
- - "
|
81
|
+
- - ">="
|
82
82
|
- !ruby/object:Gem::Version
|
83
|
-
version: '
|
83
|
+
version: '0'
|
84
84
|
- !ruby/object:Gem::Dependency
|
85
85
|
name: rspec
|
86
86
|
requirement: !ruby/object:Gem::Requirement
|
87
87
|
requirements:
|
88
|
-
- - "
|
88
|
+
- - "~>"
|
89
89
|
- !ruby/object:Gem::Version
|
90
|
-
version: '
|
90
|
+
version: '3.0'
|
91
91
|
type: :development
|
92
92
|
prerelease: false
|
93
93
|
version_requirements: !ruby/object:Gem::Requirement
|
94
94
|
requirements:
|
95
|
-
- - "
|
95
|
+
- - "~>"
|
96
96
|
- !ruby/object:Gem::Version
|
97
|
-
version: '
|
97
|
+
version: '3.0'
|
98
98
|
- !ruby/object:Gem::Dependency
|
99
99
|
name: coveralls
|
100
100
|
requirement: !ruby/object:Gem::Requirement
|
@@ -167,6 +167,11 @@ files:
|
|
167
167
|
- LICENSE.txt
|
168
168
|
- README.md
|
169
169
|
- Rakefile
|
170
|
+
- gemfiles/Gemfile-activemodel-3.0.x
|
171
|
+
- gemfiles/Gemfile-activemodel-3.1.x
|
172
|
+
- gemfiles/Gemfile-activemodel-3.2.x
|
173
|
+
- gemfiles/Gemfile-activemodel-4.0.x
|
174
|
+
- gemfiles/Gemfile-activemodel-4.1.x
|
170
175
|
- lib/schema/pain.001.001.03.xsd
|
171
176
|
- lib/schema/pain.001.002.03.xsd
|
172
177
|
- lib/schema/pain.001.003.03.xsd
|
@@ -202,6 +207,7 @@ files:
|
|
202
207
|
- spec/examples/pain.008.003.02.xml
|
203
208
|
- spec/message_spec.rb
|
204
209
|
- spec/spec_helper.rb
|
210
|
+
- spec/support/active_model.rb
|
205
211
|
- spec/support/custom_matcher.rb
|
206
212
|
- spec/support/factories.rb
|
207
213
|
- spec/support/validations.rb
|
@@ -248,6 +254,7 @@ test_files:
|
|
248
254
|
- spec/examples/pain.008.003.02.xml
|
249
255
|
- spec/message_spec.rb
|
250
256
|
- spec/spec_helper.rb
|
257
|
+
- spec/support/active_model.rb
|
251
258
|
- spec/support/custom_matcher.rb
|
252
259
|
- spec/support/factories.rb
|
253
260
|
- spec/support/validations.rb
|