sps_king 0.5.0 → 0.6.0
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/.github/workflows/test.yml +3 -3
- data/CHANGELOG.md +9 -0
- data/README.md +17 -14
- data/gemfiles/{Gemfile-activemodel-6.1.x → Gemfile-activemodel-7.2.x} +1 -1
- data/gemfiles/{Gemfile-activemodel-7.0.x → Gemfile-activemodel-8.0.x} +1 -1
- data/lib/sps_king/account/address.rb +55 -0
- data/lib/sps_king/account/creditor_account.rb +3 -0
- data/lib/sps_king/account/creditor_address.rb +2 -34
- data/lib/sps_king/account/debtor_account.rb +1 -0
- data/lib/sps_king/account/debtor_address.rb +2 -31
- data/lib/sps_king/account.rb +3 -0
- data/lib/sps_king/converter.rb +14 -10
- data/lib/sps_king/message/credit_transfer.rb +114 -111
- data/lib/sps_king/message/direct_debit.rb +121 -118
- data/lib/sps_king/message.rb +54 -48
- data/lib/sps_king/structured_remittance_information.rb +2 -0
- data/lib/sps_king/transaction/credit_transfer_transaction.rb +3 -0
- data/lib/sps_king/transaction/direct_debit_transaction.rb +9 -6
- data/lib/sps_king/transaction.rb +10 -7
- data/lib/sps_king/validator.rb +9 -0
- data/lib/sps_king/version.rb +3 -1
- data/lib/sps_king.rb +1 -0
- data/spec/lib/sps_king/account/address_spec.rb +85 -0
- data/spec/lib/sps_king/account/creditor_account_spec.rb +14 -13
- data/spec/lib/sps_king/account/debtor_account_spec.rb +1 -0
- data/spec/lib/sps_king/account_spec.rb +12 -2
- data/spec/lib/sps_king/converter_spec.rb +25 -5
- data/spec/lib/sps_king/message/credit_transfer_spec.rb +184 -45
- data/spec/lib/sps_king/message/direct_debit_spec.rb +218 -102
- data/spec/lib/sps_king/message_spec.rb +23 -8
- data/spec/lib/sps_king/structured_remittance_information_spec.rb +7 -2
- data/spec/lib/sps_king/transaction/credit_transfer_transaction_spec.rb +14 -2
- data/spec/lib/sps_king/transaction/direct_debit_transaction_spec.rb +8 -7
- data/spec/lib/sps_king/transaction_spec.rb +62 -27
- data/spec/lib/sps_king/validator_spec.rb +38 -9
- data/spec/spec_helper.rb +8 -4
- data/spec/support/active_model.rb +3 -1
- data/spec/support/factories.rb +11 -10
- data/spec/support/validations.rb +2 -0
- data/sps_king.gemspec +1 -0
- metadata +8 -12
- data/spec/lib/sps_king/account/creditor_address_spec.rb +0 -14
- data/spec/lib/sps_king/account/debtor_address_spec.rb +0 -14
@@ -1,4 +1,5 @@
|
|
1
1
|
# encoding: utf-8
|
2
|
+
|
2
3
|
require 'spec_helper'
|
3
4
|
|
4
5
|
describe SPS::DirectDebitTransaction do
|
@@ -13,12 +14,12 @@ describe SPS::DirectDebitTransaction do
|
|
13
14
|
it 'should create a valid transaction' do
|
14
15
|
expect(
|
15
16
|
SPS::DirectDebitTransaction.new(
|
16
|
-
name:
|
17
|
-
iban:
|
18
|
-
amount:
|
19
|
-
reference:
|
20
|
-
instruction:
|
21
|
-
remittance_information:
|
17
|
+
name: 'Zahlemann & Söhne Gbr',
|
18
|
+
iban: 'CH7081232000001998736',
|
19
|
+
amount: 39.99,
|
20
|
+
reference: 'XYZ-1234/123',
|
21
|
+
instruction: '123',
|
22
|
+
remittance_information: 'Vielen Dank für Ihren Einkauf!',
|
22
23
|
structured_remittance_information: structured_remittance_information
|
23
24
|
)
|
24
25
|
).to be_valid
|
@@ -50,7 +51,7 @@ describe SPS::DirectDebitTransaction do
|
|
50
51
|
|
51
52
|
it 'should not allow invalid value' do
|
52
53
|
expect(SPS::DirectDebitTransaction)
|
53
|
-
.not_to accept(Date.new(1995,12,21), Date.today - 1, Date.today, for: :requested_date)
|
54
|
+
.not_to accept(Date.new(1995, 12, 21), Date.today - 1, Date.today, for: :requested_date)
|
54
55
|
end
|
55
56
|
end
|
56
57
|
end
|
@@ -1,4 +1,5 @@
|
|
1
1
|
# encoding: utf-8
|
2
|
+
|
2
3
|
require 'spec_helper'
|
3
4
|
|
4
5
|
describe SPS::Transaction do
|
@@ -18,7 +19,12 @@ describe SPS::Transaction do
|
|
18
19
|
|
19
20
|
context 'Name' do
|
20
21
|
it 'should accept valid value' do
|
21
|
-
expect(SPS::Transaction).to accept(
|
22
|
+
expect(SPS::Transaction).to accept(
|
23
|
+
'Manfred Mustermann III.',
|
24
|
+
'Zahlemann & Söhne GbR',
|
25
|
+
'X' * 70,
|
26
|
+
for: :name
|
27
|
+
)
|
22
28
|
end
|
23
29
|
|
24
30
|
it 'should not accept invalid value' do
|
@@ -29,51 +35,67 @@ describe SPS::Transaction do
|
|
29
35
|
context 'Adress' do
|
30
36
|
context 'with address_line' do
|
31
37
|
it 'should accept valid value' do
|
32
|
-
expect(SPS::Transaction).to accept(
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
38
|
+
expect(SPS::Transaction).to accept(
|
39
|
+
SPS::DebtorAddress.new(
|
40
|
+
country_code: "CH",
|
41
|
+
address_line1: "Musterstrasse 123",
|
42
|
+
address_line2: "1234 Musterstadt"
|
43
|
+
),
|
44
|
+
for: :debtor_address
|
45
|
+
)
|
37
46
|
end
|
38
47
|
|
39
48
|
it 'should accept valid value' do
|
40
|
-
expect(SPS::Transaction).to accept(
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
49
|
+
expect(SPS::Transaction).to accept(
|
50
|
+
SPS::CreditorAddress.new(
|
51
|
+
country_code: "CH",
|
52
|
+
address_line1: "Musterstrasse 123",
|
53
|
+
address_line2: "1234 Musterstadt"
|
54
|
+
),
|
55
|
+
for: :creditor_address
|
56
|
+
)
|
45
57
|
end
|
46
58
|
end
|
47
59
|
|
48
60
|
context 'with individual address fields' do
|
49
61
|
it 'should accept valid value' do
|
50
|
-
expect(SPS::Transaction).to accept(
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
62
|
+
expect(SPS::Transaction).to accept(
|
63
|
+
SPS::DebtorAddress.new(
|
64
|
+
country_code: "CH",
|
65
|
+
street_name: 'Mustergasse',
|
66
|
+
post_code: '1234',
|
67
|
+
town_name: 'Musterstadt'
|
68
|
+
),
|
69
|
+
for: :debtor_address
|
70
|
+
)
|
56
71
|
end
|
57
72
|
|
58
73
|
it 'should accept valid value' do
|
59
|
-
expect(SPS::Transaction).to accept(
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
74
|
+
expect(SPS::Transaction).to accept(
|
75
|
+
SPS::CreditorAddress.new(
|
76
|
+
country_code: "CH",
|
77
|
+
street_name: 'Mustergasse',
|
78
|
+
building_number: '123',
|
79
|
+
post_code: '1234',
|
80
|
+
town_name: 'Musterstadt'
|
81
|
+
),
|
82
|
+
for: :creditor_address
|
83
|
+
)
|
66
84
|
end
|
67
85
|
end
|
68
86
|
|
69
87
|
it 'should not accept invalid value' do
|
70
|
-
expect(SPS::Transaction).not_to accept('', {}
|
88
|
+
expect(SPS::Transaction).not_to accept('', {}, for: :name)
|
71
89
|
end
|
72
90
|
end
|
73
91
|
|
74
92
|
context 'IBAN' do
|
75
93
|
it 'should accept valid value' do
|
76
|
-
expect(SPS::Transaction).to accept(
|
94
|
+
expect(SPS::Transaction).to accept(
|
95
|
+
'DE21500500009876543210',
|
96
|
+
'PL61109010140000071219812874',
|
97
|
+
for: :iban
|
98
|
+
)
|
77
99
|
end
|
78
100
|
|
79
101
|
it 'should not accept invalid value' do
|
@@ -93,7 +115,20 @@ describe SPS::Transaction do
|
|
93
115
|
|
94
116
|
context 'Amount' do
|
95
117
|
it 'should accept valid value' do
|
96
|
-
expect(SPS::Transaction).to accept(
|
118
|
+
expect(SPS::Transaction).to accept(
|
119
|
+
0.01,
|
120
|
+
1,
|
121
|
+
100,
|
122
|
+
100.00,
|
123
|
+
99.99,
|
124
|
+
1234567890.12,
|
125
|
+
BigDecimal('10'),
|
126
|
+
'42',
|
127
|
+
'42.51',
|
128
|
+
'42.512',
|
129
|
+
1.23456,
|
130
|
+
for: :amount
|
131
|
+
)
|
97
132
|
end
|
98
133
|
|
99
134
|
it 'should not accept invalid value' do
|
@@ -1,26 +1,37 @@
|
|
1
1
|
# encoding: utf-8
|
2
|
+
|
2
3
|
require 'spec_helper'
|
3
4
|
|
4
5
|
describe SPS::IBANValidator do
|
5
6
|
class Validatable
|
7
|
+
|
6
8
|
include ActiveModel::Model
|
7
9
|
attr_accessor :iban, :iban_the_terrible
|
10
|
+
|
8
11
|
validates_with SPS::IBANValidator, message: "%{value} seems wrong"
|
9
12
|
validates_with SPS::IBANValidator, field_name: :iban_the_terrible
|
13
|
+
|
10
14
|
end
|
11
15
|
|
12
16
|
it 'should accept valid IBAN' do
|
13
17
|
expect(Validatable)
|
14
|
-
.to accept(
|
18
|
+
.to accept(
|
19
|
+
'DE21500500009876543210',
|
20
|
+
'DE87200500001234567890',
|
21
|
+
for: [:iban, :iban_the_terrible]
|
22
|
+
)
|
15
23
|
end
|
16
24
|
|
17
25
|
it 'should not accept an invalid IBAN' do
|
18
|
-
expect(Validatable).not_to accept(
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
26
|
+
expect(Validatable).not_to accept(
|
27
|
+
'',
|
28
|
+
'xxx', # Oviously no IBAN
|
29
|
+
'DE22500500009876543210', # wrong checksum
|
30
|
+
'DE2150050000987654321', # too short
|
31
|
+
'de87200500001234567890', # downcase characters
|
32
|
+
'DE87 2005 0000 1234 5678 90', # spaces included
|
33
|
+
for: [:iban, :iban_the_terrible]
|
34
|
+
)
|
24
35
|
end
|
25
36
|
|
26
37
|
it "should customize error message" do
|
@@ -32,10 +43,13 @@ end
|
|
32
43
|
|
33
44
|
describe SPS::BICValidator do
|
34
45
|
class Validatable
|
46
|
+
|
35
47
|
include ActiveModel::Model
|
36
48
|
attr_accessor :bic, :custom_bic
|
49
|
+
|
37
50
|
validates_with SPS::BICValidator, message: "%{value} seems wrong"
|
38
51
|
validates_with SPS::BICValidator, field_name: :custom_bic
|
52
|
+
|
39
53
|
end
|
40
54
|
|
41
55
|
it 'should accept valid BICs' do
|
@@ -56,18 +70,33 @@ end
|
|
56
70
|
|
57
71
|
describe SPS::CreditorIdentifierValidator do
|
58
72
|
class Validatable
|
73
|
+
|
59
74
|
include ActiveModel::Model
|
60
75
|
attr_accessor :creditor_identifier, :crid
|
76
|
+
|
61
77
|
validates_with SPS::CreditorIdentifierValidator, message: "%{value} seems wrong"
|
62
78
|
validates_with SPS::CreditorIdentifierValidator, field_name: :crid
|
79
|
+
|
63
80
|
end
|
64
81
|
|
65
82
|
it 'should accept valid creditor_identifier' do
|
66
|
-
expect(Validatable).to accept(
|
83
|
+
expect(Validatable).to accept(
|
84
|
+
'DE98ZZZ09999999999',
|
85
|
+
'AT12ZZZ00000000001',
|
86
|
+
'FR12ZZZ123456',
|
87
|
+
'NL97ZZZ123456780001',
|
88
|
+
'ABC1W',
|
89
|
+
for: [:creditor_identifier, :crid]
|
90
|
+
)
|
67
91
|
end
|
68
92
|
|
69
93
|
it 'should not accept an invalid creditor_identifier' do
|
70
|
-
expect(Validatable).not_to accept(
|
94
|
+
expect(Validatable).not_to accept(
|
95
|
+
'',
|
96
|
+
'xxx',
|
97
|
+
'DE98ZZZ099999999990',
|
98
|
+
for: [:creditor_identifier, :crid]
|
99
|
+
)
|
71
100
|
end
|
72
101
|
|
73
102
|
it "should customize error message" do
|
data/spec/spec_helper.rb
CHANGED
@@ -5,9 +5,11 @@
|
|
5
5
|
|
6
6
|
require 'simplecov'
|
7
7
|
|
8
|
-
SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter.new(
|
9
|
-
|
10
|
-
|
8
|
+
SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter.new(
|
9
|
+
[
|
10
|
+
SimpleCov::Formatter::HTMLFormatter
|
11
|
+
]
|
12
|
+
)
|
11
13
|
SimpleCov.start do
|
12
14
|
add_filter '/spec/'
|
13
15
|
end
|
@@ -16,7 +18,9 @@ require 'sps_king'
|
|
16
18
|
|
17
19
|
# Requires supporting ruby files with custom matchers and macros, etc,
|
18
20
|
# in spec/support/ and its subdirectories.
|
19
|
-
Dir[File.expand_path(File.join(File.dirname(__FILE__),'support','**','*.rb'))].each {|f|
|
21
|
+
Dir[File.expand_path(File.join(File.dirname(__FILE__), 'support', '**', '*.rb'))].each { |f|
|
22
|
+
require f
|
23
|
+
}
|
20
24
|
|
21
25
|
# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
|
22
26
|
RSpec.configure do |config|
|
@@ -5,6 +5,7 @@ unless defined?(ActiveModel::Model)
|
|
5
5
|
# https://github.com/rails/rails/blob/master/activemodel/lib/active_model/model.rb
|
6
6
|
module ActiveModel
|
7
7
|
module Model
|
8
|
+
|
8
9
|
def self.included(base)
|
9
10
|
base.class_eval do
|
10
11
|
extend ActiveModel::Naming
|
@@ -14,7 +15,7 @@ unless defined?(ActiveModel::Model)
|
|
14
15
|
end
|
15
16
|
end
|
16
17
|
|
17
|
-
def initialize(params={})
|
18
|
+
def initialize(params = {})
|
18
19
|
params.each do |attr, value|
|
19
20
|
self.public_send("#{attr}=", value)
|
20
21
|
end if params
|
@@ -25,6 +26,7 @@ unless defined?(ActiveModel::Model)
|
|
25
26
|
def persisted?
|
26
27
|
false
|
27
28
|
end
|
29
|
+
|
28
30
|
end
|
29
31
|
end
|
30
32
|
end
|
data/spec/support/factories.rb
CHANGED
@@ -1,7 +1,8 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
|
3
|
-
def credit_transfer_transaction(attributes={})
|
4
|
-
{
|
3
|
+
def credit_transfer_transaction(attributes = {})
|
4
|
+
{
|
5
|
+
name: 'Contoso AG',
|
5
6
|
bic: 'RAIFCH22',
|
6
7
|
iban: 'CH5481230000001998736',
|
7
8
|
amount: 102.50,
|
@@ -10,15 +11,15 @@ def credit_transfer_transaction(attributes={})
|
|
10
11
|
}.merge(attributes)
|
11
12
|
end
|
12
13
|
|
13
|
-
def direct_debt_transaction(attributes={})
|
14
|
+
def direct_debt_transaction(attributes = {})
|
14
15
|
{
|
15
|
-
name:
|
16
|
-
iban:
|
17
|
-
amount:
|
18
|
-
instruction:
|
19
|
-
reference:
|
20
|
-
remittance_information:
|
21
|
-
requested_date:
|
16
|
+
name: 'Müller & Schmidt oHG',
|
17
|
+
iban: 'CH5481230000001998736',
|
18
|
+
amount: 750.00,
|
19
|
+
instruction: '123',
|
20
|
+
reference: 'XYZ/2013-08-ABO/6789',
|
21
|
+
remittance_information: 'Vielen Dank für Ihren Einkauf!',
|
22
|
+
requested_date: Date.today + 1,
|
22
23
|
structured_remittance_information: structured_remittance_information
|
23
24
|
}.merge(attributes)
|
24
25
|
end
|
data/spec/support/validations.rb
CHANGED
@@ -2,6 +2,7 @@
|
|
2
2
|
# https://github.com/rspec/rspec-rails/blob/master/lib/rspec/rails/extensions/active_record/base.rb
|
3
3
|
|
4
4
|
module ::ActiveModel::Validations
|
5
|
+
|
5
6
|
# Extension to enhance `to have` on AR Model instances. Calls
|
6
7
|
# model.valid? in order to prepare the object's errors object. Accepts
|
7
8
|
# a :context option to specify the validation context.
|
@@ -24,4 +25,5 @@ module ::ActiveModel::Validations
|
|
24
25
|
end
|
25
26
|
|
26
27
|
alias :error_on :errors_on
|
28
|
+
|
27
29
|
end
|
data/sps_king.gemspec
CHANGED
metadata
CHANGED
@@ -1,14 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sps_king
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.6.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tobias Schoknecht
|
8
|
-
autorequire:
|
9
8
|
bindir: bin
|
10
9
|
cert_chain: []
|
11
|
-
date:
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
12
11
|
dependencies:
|
13
12
|
- !ruby/object:Gem::Dependency
|
14
13
|
name: activemodel
|
@@ -126,13 +125,14 @@ files:
|
|
126
125
|
- README.md
|
127
126
|
- Rakefile
|
128
127
|
- cliff.toml
|
129
|
-
- gemfiles/Gemfile-activemodel-6.1.x
|
130
|
-
- gemfiles/Gemfile-activemodel-7.0.x
|
131
128
|
- gemfiles/Gemfile-activemodel-7.1.x
|
129
|
+
- gemfiles/Gemfile-activemodel-7.2.x
|
130
|
+
- gemfiles/Gemfile-activemodel-8.0.x
|
132
131
|
- lib/schema/pain.001.001.03.ch.02.xsd
|
133
132
|
- lib/schema/pain.008.001.02.ch.03.xsd
|
134
133
|
- lib/sps_king.rb
|
135
134
|
- lib/sps_king/account.rb
|
135
|
+
- lib/sps_king/account/address.rb
|
136
136
|
- lib/sps_king/account/creditor_account.rb
|
137
137
|
- lib/sps_king/account/creditor_address.rb
|
138
138
|
- lib/sps_king/account/debtor_account.rb
|
@@ -150,10 +150,9 @@ files:
|
|
150
150
|
- lib/sps_king/version.rb
|
151
151
|
- spec/examples/pain.001.001.03.ch.02.xml
|
152
152
|
- spec/examples/pain.008.001.02.ch.03.xml
|
153
|
+
- spec/lib/sps_king/account/address_spec.rb
|
153
154
|
- spec/lib/sps_king/account/creditor_account_spec.rb
|
154
|
-
- spec/lib/sps_king/account/creditor_address_spec.rb
|
155
155
|
- spec/lib/sps_king/account/debtor_account_spec.rb
|
156
|
-
- spec/lib/sps_king/account/debtor_address_spec.rb
|
157
156
|
- spec/lib/sps_king/account_spec.rb
|
158
157
|
- spec/lib/sps_king/converter_spec.rb
|
159
158
|
- spec/lib/sps_king/message/credit_transfer_spec.rb
|
@@ -175,7 +174,6 @@ homepage: http://github.com/Barzahlen/sps_king
|
|
175
174
|
licenses:
|
176
175
|
- MIT
|
177
176
|
metadata: {}
|
178
|
-
post_install_message:
|
179
177
|
rdoc_options: []
|
180
178
|
require_paths:
|
181
179
|
- lib
|
@@ -190,17 +188,15 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
190
188
|
- !ruby/object:Gem::Version
|
191
189
|
version: '0'
|
192
190
|
requirements: []
|
193
|
-
rubygems_version: 3.
|
194
|
-
signing_key:
|
191
|
+
rubygems_version: 3.6.8
|
195
192
|
specification_version: 4
|
196
193
|
summary: Ruby gem for creating SPS XML files
|
197
194
|
test_files:
|
198
195
|
- spec/examples/pain.001.001.03.ch.02.xml
|
199
196
|
- spec/examples/pain.008.001.02.ch.03.xml
|
197
|
+
- spec/lib/sps_king/account/address_spec.rb
|
200
198
|
- spec/lib/sps_king/account/creditor_account_spec.rb
|
201
|
-
- spec/lib/sps_king/account/creditor_address_spec.rb
|
202
199
|
- spec/lib/sps_king/account/debtor_account_spec.rb
|
203
|
-
- spec/lib/sps_king/account/debtor_address_spec.rb
|
204
200
|
- spec/lib/sps_king/account_spec.rb
|
205
201
|
- spec/lib/sps_king/converter_spec.rb
|
206
202
|
- spec/lib/sps_king/message/credit_transfer_spec.rb
|
@@ -1,14 +0,0 @@
|
|
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
|
@@ -1,14 +0,0 @@
|
|
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
|