sepa_king 0.6.0 → 0.7.0

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: f0171ca52d3b9667fa2aab79ce037fc9d82b94f1
4
- data.tar.gz: 108d5e3dfab121f5bb8f154ca8a786fdd0fcc02f
3
+ metadata.gz: c07809500fdf4e08660e27eef792b69530285d64
4
+ data.tar.gz: c54f6fa344d87892a6642e3ef2dd3e140b643eb5
5
5
  SHA512:
6
- metadata.gz: 8d270da4b9707bf2e58daa7d58313f90be7578e3cb7b87e4b4da451479b75710c159513ef86f49aab30e4feff4162290eddf9422ac21690e3bd93905042bb6c2
7
- data.tar.gz: ced4136ed50cb16d4256b081d7ef651b6969a7c11593f6490d9fbfe6d492105455d339a63efc8c39965c365bca85b6b4cde99c3f6a70fe48b4b866000c8e12f4
6
+ metadata.gz: 4fbe19893a4147654d7f65a04f57caf74c85876cc547173157e427c36d92e919c7b10bd48e12fb3fcce03ff78e4fbf16f234b2d78983753edad209885f71f784
7
+ data.tar.gz: 90ad61a32ef0c8f1e0b6e3a190a448b54c4fb5f90ea30d81e6c0775d0df18ad03123d5964faf319b787f6a70c2f7e77736e813f990186d42d0c89f4f50f48010
data/.travis.yml CHANGED
@@ -1,8 +1,9 @@
1
1
  rvm:
2
2
  - 1.9.3
3
- - 2.0
4
- - 2.1
5
- - 2.2
3
+ - 2.0.0
4
+ - 2.1.10
5
+ - 2.2.5
6
+ - 2.3.1
6
7
  gemfile:
7
8
  - gemfiles/Gemfile-activemodel-3.0.x
8
9
  - gemfiles/Gemfile-activemodel-3.1.x
@@ -10,4 +11,13 @@ gemfile:
10
11
  - gemfiles/Gemfile-activemodel-4.0.x
11
12
  - gemfiles/Gemfile-activemodel-4.1.x
12
13
  - gemfiles/Gemfile-activemodel-4.2.x
14
+ - gemfiles/Gemfile-activemodel-5.0.x
15
+ matrix:
16
+ exclude:
17
+ - rvm: 1.9.3
18
+ gemfile: gemfiles/Gemfile-activemodel-5.0.x
19
+ - rvm: 2.0.0
20
+ gemfile: gemfiles/Gemfile-activemodel-5.0.x
21
+ - rvm: 2.1.10
22
+ gemfile: gemfiles/Gemfile-activemodel-5.0.x
13
23
  sudo: false
data/LICENSE.txt CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2013-2015 Georg Leciejewski (Sales King GmbH) & Georg Ledermann
1
+ Copyright (c) 2013-2016 Georg Leciejewski (Sales King GmbH) & Georg Ledermann
2
2
 
3
3
  MIT License
4
4
 
data/README.md CHANGED
@@ -13,8 +13,8 @@ We love building payment applications! So after developing the [DTAUS library fo
13
13
 
14
14
  This gem implements the following two messages out of the ISO 20022 standard:
15
15
 
16
- * Credit Transfer Initiation (pain.001.003.03 and pain.001.002.03)
17
- * Direct Debit Initiation (pain.008.003.02 and pain.008.002.02 and pain.008.001.02)
16
+ * Credit Transfer Initiation (`pain.001.003.03`, `pain.001.002.03` and `pain.001.001.03`)
17
+ * Direct Debit Initiation (`pain.008.003.02`, `pain.008.002.02` and `pain.008.001.02`)
18
18
 
19
19
  This means it handles the "Specification of Data Formats" in version 2.6 (2012-11-17) and version 2.7 (2013-11-04)
20
20
 
@@ -24,6 +24,7 @@ BTW: **pain** is a shortcut for **Pa**yment **In**itiation.
24
24
  ## Requirements
25
25
 
26
26
  * Ruby 1.9.3 or newer
27
+ * ActiveModel 3.0 or newer
27
28
 
28
29
 
29
30
  ## Installation
@@ -185,10 +186,10 @@ sct.add_transaction(
185
186
  # True or False
186
187
  batch_booking: true,
187
188
 
188
- # OPTIONAL: Urgent Payment
189
+ # OPTIONAL: Urgent Payment
189
190
  # One of these strings:
190
191
  # 'SEPA' ("SEPA-Zahlung")
191
- # 'URGP' ("Taggleiche Eilüberweisung")
192
+ # 'URGP' ("Taggleiche Eilüberweisung")
192
193
  service_level: 'URGP'
193
194
  )
194
195
  sct.add_transaction ...
@@ -251,4 +252,4 @@ https://github.com/salesking/sepa_king/graphs/contributors
251
252
 
252
253
  Released under the MIT license
253
254
 
254
- Copyright (c) 2013-2015 Georg Leciejewski (SalesKing), Georg Ledermann (https://github.com/ledermann)
255
+ Copyright (c) 2013-2016 Georg Leciejewski (SalesKing), Georg Ledermann (https://github.com/ledermann)
@@ -2,4 +2,4 @@ source 'https://rubygems.org'
2
2
 
3
3
  gemspec path: '..'
4
4
 
5
- gem 'activemodel', '~>3.0.0'
5
+ gem 'activemodel', '~>3.0.20'
@@ -2,4 +2,4 @@ source 'https://rubygems.org'
2
2
 
3
3
  gemspec path: '..'
4
4
 
5
- gem 'activemodel', '~>3.1.0'
5
+ gem 'activemodel', '~>3.1.12'
@@ -2,4 +2,4 @@ source 'https://rubygems.org'
2
2
 
3
3
  gemspec path: '..'
4
4
 
5
- gem 'activemodel', '~>3.2.0'
5
+ gem 'activemodel', '~>3.2.22.2'
@@ -2,4 +2,4 @@ source 'https://rubygems.org'
2
2
 
3
3
  gemspec path: '..'
4
4
 
5
- gem 'activemodel', '~>4.0.0'
5
+ gem 'activemodel', '~>4.0.13'
@@ -2,4 +2,4 @@ source 'https://rubygems.org'
2
2
 
3
3
  gemspec path: '..'
4
4
 
5
- gem 'activemodel', '~>4.1.0'
5
+ gem 'activemodel', '~>4.1.15'
@@ -2,4 +2,4 @@ source 'https://rubygems.org'
2
2
 
3
3
  gemspec path: '..'
4
4
 
5
- gem 'activemodel', '~>4.2.0'
5
+ gem 'activemodel', '~>4.2.6'
@@ -0,0 +1,5 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec path: '..'
4
+
5
+ gem 'activemodel', '5.0.0.rc1'
File without changes
@@ -83,6 +83,28 @@ module SEPA
83
83
  end
84
84
  end
85
85
 
86
+ def build_amendment_informations(builder, transaction)
87
+ return unless transaction.original_debtor_account || transaction.same_mandate_new_debtor_agent
88
+ builder.AmdmntInd(true)
89
+ builder.AmdmntInfDtls do
90
+ if transaction.original_debtor_account
91
+ builder.OrgnlDbtrAcct do
92
+ builder.Id do
93
+ builder.IBAN(transaction.original_debtor_account)
94
+ end
95
+ end
96
+ else
97
+ builder.OrgnlDbtrAgt do
98
+ builder.FinInstnId do
99
+ builder.Othr do
100
+ builder.Id('SMNDA')
101
+ end
102
+ end
103
+ end
104
+ end
105
+ end
106
+ end
107
+
86
108
  def build_transaction(builder, transaction)
87
109
  builder.DrctDbtTxInf do
88
110
  builder.PmtId do
@@ -93,6 +115,7 @@ module SEPA
93
115
  builder.MndtRltdInf do
94
116
  builder.MndtId(transaction.mandate_id)
95
117
  builder.DtOfSgntr(transaction.mandate_date_of_signature.iso8601)
118
+ build_amendment_informations(builder, transaction)
96
119
  end
97
120
  end
98
121
  builder.DbtrAgt do
@@ -66,11 +66,19 @@ module SEPA
66
66
  end
67
67
  end
68
68
 
69
- attr_writer :message_identification # Set unique identifer for the message
69
+ # Set unique identifer for the message
70
+ def message_identification=(value)
71
+ raise ArgumentError.new('mesage_identification must be a string!') unless value.is_a?(String)
70
72
 
71
- # Unique identifer for the whole message
73
+ regex = /\A([A-Za-z0-9]|[\+|\?|\/|\-|\:|\(|\)|\.|\,|\'|\ ]){1,35}\z/
74
+ raise ArgumentError.new("mesage_identification does not match #{regex}!") unless value.match(regex)
75
+
76
+ @message_identification = value
77
+ end
78
+
79
+ # Get unique identifer for the message (with fallback to a random string)
72
80
  def message_identification
73
- @message_identification ||= "SEPA-KING/#{Time.now.to_i}"
81
+ @message_identification ||= "SEPA-KING/#{SecureRandom.hex(11)}"
74
82
  end
75
83
 
76
84
  # Returns the id of the batch to which the given transaction belongs
@@ -5,11 +5,7 @@ module SEPA
5
5
 
6
6
  validates_inclusion_of :service_level, :in => %w(SEPA URGP)
7
7
 
8
- validate do |t|
9
- if t.requested_date.is_a?(Date)
10
- errors.add(:requested_date, 'is in the past') if t.requested_date < Date.today
11
- end
12
- end
8
+ validate { |t| t.validate_requested_date_after(Date.today) }
13
9
 
14
10
  def initialize(attributes = {})
15
11
  super
@@ -4,13 +4,15 @@ module SEPA
4
4
  SEQUENCE_TYPES = %w(FRST OOFF RCUR FNAL)
5
5
  LOCAL_INSTRUMENTS = %w(CORE COR1 B2B)
6
6
 
7
- attr_accessor :mandate_id, :mandate_date_of_signature, :local_instrument, :sequence_type, :creditor_account
7
+ attr_accessor :mandate_id, :mandate_date_of_signature, :local_instrument, :sequence_type, :creditor_account, :original_debtor_account, :same_mandate_new_debtor_agent
8
8
 
9
9
  validates_with MandateIdentifierValidator, field_name: :mandate_id
10
10
  validates_presence_of :mandate_date_of_signature
11
11
  validates_inclusion_of :local_instrument, in: LOCAL_INSTRUMENTS
12
12
  validates_inclusion_of :sequence_type, in: SEQUENCE_TYPES
13
13
 
14
+ validate { |t| t.validate_requested_date_after(Date.today.next) }
15
+
14
16
  validate do |t|
15
17
  if creditor_account
16
18
  errors.add(:creditor_account, 'is not correct') unless creditor_account.valid?
@@ -21,10 +23,6 @@ module SEPA
21
23
  else
22
24
  errors.add(:mandate_date_of_signature, 'is not a Date')
23
25
  end
24
-
25
- if t.requested_date.is_a?(Date)
26
- errors.add(:requested_date, 'is not in the future') if t.requested_date <= Date.today
27
- end
28
26
  end
29
27
 
30
28
  def initialize(attributes = {})
@@ -4,6 +4,8 @@ module SEPA
4
4
  include ActiveModel::Validations
5
5
  extend Converter
6
6
 
7
+ DEFAULT_REQUESTED_DATE = Date.new(1999, 1, 1).freeze
8
+
7
9
  attr_accessor :name, :iban, :bic, :amount, :instruction, :reference, :remittance_information, :requested_date, :batch_booking
8
10
  convert :name, :instruction, :reference, :remittance_information, to: :text
9
11
  convert :amount, to: :decimal
@@ -22,9 +24,19 @@ module SEPA
22
24
  send("#{name}=", value)
23
25
  end
24
26
 
25
- self.requested_date ||= Date.today.next
27
+ self.requested_date ||= DEFAULT_REQUESTED_DATE
26
28
  self.reference ||= 'NOTPROVIDED'
27
29
  self.batch_booking = true if self.batch_booking.nil?
28
30
  end
31
+
32
+ protected
33
+
34
+ def validate_requested_date_after(min_requested_date)
35
+ return unless requested_date.is_a?(Date)
36
+
37
+ if requested_date != DEFAULT_REQUESTED_DATE && requested_date < min_requested_date
38
+ errors.add(:requested_date, "must be greater or equal to #{min_requested_date}, or nil")
39
+ end
40
+ end
29
41
  end
30
42
  end
@@ -1,3 +1,3 @@
1
1
  module SEPA
2
- VERSION = '0.6.0'
2
+ VERSION = '0.7.0'
3
3
  end
data/lib/sepa_king.rb CHANGED
@@ -4,7 +4,7 @@ require 'bigdecimal'
4
4
  require 'builder'
5
5
  require 'iban-tools'
6
6
 
7
- require 'core_ext/string'
7
+ require 'sepa_king/core_ext/string'
8
8
 
9
9
  require 'sepa_king/converter'
10
10
  require 'sepa_king/validator'
data/sepa_king.gemspec CHANGED
@@ -28,7 +28,7 @@ Gem::Specification.new do |s|
28
28
  s.add_development_dependency 'bundler'
29
29
  s.add_development_dependency 'rspec', '~> 3.0'
30
30
  s.add_development_dependency 'coveralls'
31
- s.add_development_dependency 'simplecov'
31
+ s.add_development_dependency 'simplecov', '~> 0.11.0'
32
32
  s.add_development_dependency 'rake'
33
33
  s.add_development_dependency 'nokogiri'
34
34
  end
@@ -2,6 +2,7 @@
2
2
  require 'spec_helper'
3
3
 
4
4
  describe SEPA::CreditTransfer do
5
+ let(:message_id_regex) { /SEPA-KING\/[0-9a-z_]{22}/ }
5
6
  let(:credit_transfer) {
6
7
  SEPA::CreditTransfer.new name: 'Schuldner GmbH',
7
8
  bic: 'BANKDEFFXXX',
@@ -120,15 +121,15 @@ describe SEPA::CreditTransfer do
120
121
  end
121
122
 
122
123
  it 'should have message_identification' do
123
- expect(subject).to have_xml('//Document/CstmrCdtTrfInitn/GrpHdr/MsgId', /SEPA-KING\/[0-9]+/)
124
+ expect(subject).to have_xml('//Document/CstmrCdtTrfInitn/GrpHdr/MsgId', message_id_regex)
124
125
  end
125
126
 
126
127
  it 'should contain <PmtInfId>' do
127
- expect(subject).to have_xml('//Document/CstmrCdtTrfInitn/PmtInf/PmtInfId', /SEPA-KING\/[0-9]+\/1/)
128
+ expect(subject).to have_xml('//Document/CstmrCdtTrfInitn/PmtInf/PmtInfId', /#{message_id_regex}\/1/)
128
129
  end
129
130
 
130
131
  it 'should contain <ReqdExctnDt>' do
131
- expect(subject).to have_xml('//Document/CstmrCdtTrfInitn/PmtInf/ReqdExctnDt', Date.today.next.iso8601)
132
+ expect(subject).to have_xml('//Document/CstmrCdtTrfInitn/PmtInf/ReqdExctnDt', Date.new(1999, 1, 1).iso8601)
132
133
  end
133
134
 
134
135
  it 'should contain <PmtMtd>' do
@@ -209,8 +210,8 @@ describe SEPA::CreditTransfer do
209
210
  end
210
211
 
211
212
  it 'should contain two payment_informations with different <PmtInfId>' do
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/)
213
+ expect(subject).to have_xml('//Document/CstmrCdtTrfInitn/PmtInf[1]/PmtInfId', /#{message_id_regex}\/1/)
214
+ expect(subject).to have_xml('//Document/CstmrCdtTrfInitn/PmtInf[2]/PmtInfId', /#{message_id_regex}\/2/)
214
215
  end
215
216
  end
216
217
 
@@ -36,7 +36,7 @@ describe SEPA::CreditTransferTransaction do
36
36
 
37
37
  context 'Requested date' do
38
38
  it 'should allow valid value' do
39
- expect(SEPA::CreditTransferTransaction).to accept(nil, Date.today, Date.today.next, Date.today + 2, for: :requested_date)
39
+ expect(SEPA::CreditTransferTransaction).to accept(nil, Date.new(1999, 1, 1), 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
@@ -2,6 +2,8 @@
2
2
  require 'spec_helper'
3
3
 
4
4
  describe SEPA::DirectDebit do
5
+ let(:message_id_regex) { /SEPA-KING\/[0-9a-z_]{22}/ }
6
+
5
7
  let(:direct_debit) {
6
8
  SEPA::DirectDebit.new name: 'Gläubiger GmbH',
7
9
  bic: 'BANKDEFFXXX',
@@ -37,7 +39,7 @@ describe SEPA::DirectDebit do
37
39
  it 'returns the id of the batch where the given transactions belongs to (1 batch)' do
38
40
  direct_debit.add_transaction(direct_debt_transaction(reference: "EXAMPLE REFERENCE"))
39
41
 
40
- expect(direct_debit.batch_id("EXAMPLE REFERENCE")).to match(/SEPA-KING\/[0-9]+\/1/)
42
+ expect(direct_debit.batch_id("EXAMPLE REFERENCE")).to match(/#{message_id_regex}\/1/)
41
43
  end
42
44
 
43
45
  it 'returns the id of the batch where the given transactions belongs to (2 batches)' do
@@ -45,9 +47,9 @@ describe SEPA::DirectDebit do
45
47
  direct_debit.add_transaction(direct_debt_transaction(reference: "EXAMPLE REFERENCE 2", requested_date: Date.today.next.next))
46
48
  direct_debit.add_transaction(direct_debt_transaction(reference: "EXAMPLE REFERENCE 3"))
47
49
 
48
- expect(direct_debit.batch_id("EXAMPLE REFERENCE 1")).to match(/SEPA-KING\/[0-9]+\/1/)
49
- expect(direct_debit.batch_id("EXAMPLE REFERENCE 2")).to match(/SEPA-KING\/[0-9]+\/2/)
50
- expect(direct_debit.batch_id("EXAMPLE REFERENCE 3")).to match(/SEPA-KING\/[0-9]+\/1/)
50
+ expect(direct_debit.batch_id("EXAMPLE REFERENCE 1")).to match(/#{message_id_regex}\/1/)
51
+ expect(direct_debit.batch_id("EXAMPLE REFERENCE 2")).to match(/#{message_id_regex}\/2/)
52
+ expect(direct_debit.batch_id("EXAMPLE REFERENCE 3")).to match(/#{message_id_regex}\/1/)
51
53
  end
52
54
  end
53
55
 
@@ -58,8 +60,8 @@ describe SEPA::DirectDebit do
58
60
  direct_debit.add_transaction(direct_debt_transaction(reference: "EXAMPLE REFERENCE 3"))
59
61
 
60
62
  expect(direct_debit.batches.size).to eq(2)
61
- expect(direct_debit.batches[0]).to match(/SEPA-KING\/[0-9]+/)
62
- expect(direct_debit.batches[1]).to match(/SEPA-KING\/[0-9]+/)
63
+ expect(direct_debit.batches[0]).to match(/#{message_id_regex}\/[0-9]+/)
64
+ expect(direct_debit.batches[1]).to match(/#{message_id_regex}\/[0-9]+/)
63
65
  end
64
66
  end
65
67
 
@@ -164,7 +166,7 @@ describe SEPA::DirectDebit do
164
166
  end
165
167
 
166
168
  it 'should have message_identification' do
167
- expect(subject).to have_xml('//Document/CstmrDrctDbtInitn/GrpHdr/MsgId', /SEPA-KING\/[0-9]+/)
169
+ expect(subject).to have_xml('//Document/CstmrDrctDbtInitn/GrpHdr/MsgId', message_id_regex)
168
170
  end
169
171
 
170
172
  it 'should have creditor identifier' do
@@ -172,11 +174,11 @@ describe SEPA::DirectDebit do
172
174
  end
173
175
 
174
176
  it 'should contain <PmtInfId>' do
175
- expect(subject).to have_xml('//Document/CstmrDrctDbtInitn/PmtInf/PmtInfId', /SEPA-KING\/[0-9]+\/1/)
177
+ expect(subject).to have_xml('//Document/CstmrDrctDbtInitn/PmtInf/PmtInfId', /#{message_id_regex}\/1/)
176
178
  end
177
179
 
178
180
  it 'should contain <ReqdColltnDt>' do
179
- expect(subject).to have_xml('//Document/CstmrDrctDbtInitn/PmtInf/ReqdColltnDt', Date.today.next.iso8601)
181
+ expect(subject).to have_xml('//Document/CstmrDrctDbtInitn/PmtInf/ReqdColltnDt', Date.new(1999, 1, 1).iso8601)
180
182
  end
181
183
 
182
184
  it 'should contain <PmtMtd>' do
@@ -271,8 +273,8 @@ describe SEPA::DirectDebit do
271
273
  end
272
274
 
273
275
  it 'should contain two payment_informations with different <PmtInfId>' do
274
- expect(subject).to have_xml('//Document/CstmrDrctDbtInitn/PmtInf[1]/PmtInfId', /SEPA-KING\/[0-9]+\/1/)
275
- expect(subject).to have_xml('//Document/CstmrDrctDbtInitn/PmtInf[2]/PmtInfId', /SEPA-KING\/[0-9]+\/2/)
276
+ expect(subject).to have_xml('//Document/CstmrDrctDbtInitn/PmtInf[1]/PmtInfId', /#{message_id_regex}\/1/)
277
+ expect(subject).to have_xml('//Document/CstmrDrctDbtInitn/PmtInf[2]/PmtInfId', /#{message_id_regex}\/2/)
276
278
  end
277
279
  end
278
280
 
@@ -389,6 +391,26 @@ describe SEPA::DirectDebit do
389
391
  expect(subject).to have_xml('//Document/CstmrDrctDbtInitn/PmtInf[2]/Cdtr/Nm', 'Creditor Inc.')
390
392
  end
391
393
  end
394
+
395
+ context 'with mandate amendments' do
396
+ subject do
397
+ sdd = direct_debit
398
+
399
+ sdd.add_transaction(direct_debt_transaction.merge(original_debtor_account: 'NL08RABO0135742099'))
400
+ sdd.add_transaction(direct_debt_transaction.merge(same_mandate_new_debtor_agent: true))
401
+ sdd.to_xml
402
+ end
403
+
404
+ it 'should include amendment indicator' do
405
+ expect(subject).to have_xml('//Document/CstmrDrctDbtInitn/PmtInf/DrctDbtTxInf[1]/DrctDbtTx/MndtRltdInf/AmdmntInd', 'true')
406
+ expect(subject).to have_xml('//Document/CstmrDrctDbtInitn/PmtInf/DrctDbtTxInf[2]/DrctDbtTx/MndtRltdInf/AmdmntInd', 'true')
407
+ end
408
+
409
+ it 'should include amendment information details' do
410
+ expect(subject).to have_xml('//Document/CstmrDrctDbtInitn/PmtInf/DrctDbtTxInf[1]/DrctDbtTx/MndtRltdInf/AmdmntInfDtls/OrgnlDbtrAcct/Id/IBAN', 'NL08RABO0135742099')
411
+ expect(subject).to have_xml('//Document/CstmrDrctDbtInitn/PmtInf/DrctDbtTxInf[2]/DrctDbtTx/MndtRltdInf/AmdmntInfDtls/OrgnlDbtrAgt/FinInstnId/Othr/Id', 'SMNDA')
412
+ end
413
+ end
392
414
  end
393
415
  end
394
416
  end
@@ -48,7 +48,7 @@ describe SEPA::DirectDebitTransaction do
48
48
 
49
49
  context 'Requested date' do
50
50
  it 'should allow valid value' do
51
- expect(SEPA::DirectDebitTransaction).to accept(nil, Date.today.next, Date.today + 2, for: :requested_date)
51
+ expect(SEPA::DirectDebitTransaction).to accept(nil, Date.new(1999, 1, 1), Date.today.next, Date.today + 2, for: :requested_date)
52
52
  end
53
53
 
54
54
  it 'should not allow invalid value' do
data/spec/message_spec.rb CHANGED
@@ -45,13 +45,44 @@ describe SEPA::Message do
45
45
  describe :message_identification do
46
46
  subject { DummyMessage.new }
47
47
 
48
- it 'should have a reader method' do
49
- expect(subject.message_identification).to match(/SEPA-KING\/[0-9]+/)
48
+ describe 'getter' do
49
+ it 'should return prefixed random hex string' do
50
+ expect(subject.message_identification).to match(/SEPA-KING\/([a-f0-9]{2}){11}/)
51
+ end
50
52
  end
51
53
 
52
- it 'should have a writer method' do
53
- subject.message_identification = "MY_MESSAGE_ID/#{Time.now.to_i}"
54
- expect(subject.message_identification).to match(/MY_MESSAGE_ID/)
54
+ describe 'setter' do
55
+ it 'should accept valid ID' do
56
+ [ 'gid://myMoneyApp/Payment/15108', # for example, Rails Global ID could be a candidate
57
+ Time.now.to_f.to_s # or a time based string
58
+ ].each do |valid_msgid|
59
+ subject.message_identification = valid_msgid
60
+ expect(subject.message_identification).to eq(valid_msgid)
61
+ end
62
+ end
63
+
64
+ it 'should deny invalid string' do
65
+ [ 'my_MESSAGE_ID/123', # contains underscore
66
+ '', # blank string
67
+ 'üöäß', # non-ASCII chars
68
+ '1' * 36 # too long
69
+ ].each do |arg|
70
+ expect {
71
+ subject.message_identification = arg
72
+ }.to raise_error(ArgumentError)
73
+ end
74
+ end
75
+
76
+ it 'should deny argument other than String' do
77
+ [ 123,
78
+ nil,
79
+ :foo
80
+ ].each do |arg|
81
+ expect {
82
+ subject.message_identification = arg
83
+ }.to raise_error(ArgumentError)
84
+ end
85
+ end
55
86
  end
56
87
  end
57
88
  end
data/spec/spec_helper.rb CHANGED
@@ -6,10 +6,10 @@
6
6
  require 'simplecov'
7
7
  require 'coveralls'
8
8
 
9
- SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[
9
+ SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter.new([
10
10
  SimpleCov::Formatter::HTMLFormatter,
11
11
  Coveralls::SimpleCov::Formatter
12
- ]
12
+ ])
13
13
  SimpleCov.start do
14
14
  add_filter '/spec/'
15
15
  end
@@ -8,7 +8,7 @@ describe SEPA::Transaction do
8
8
  end
9
9
 
10
10
  it 'should have default for requested_date' do
11
- expect(SEPA::Transaction.new.requested_date).to eq(Date.today.next)
11
+ expect(SEPA::Transaction.new.requested_date).to eq(Date.new(1999, 1, 1))
12
12
  end
13
13
 
14
14
  it 'should have default for batch_booking' do
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.6.0
4
+ version: 0.7.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: 2015-10-29 00:00:00.000000000 Z
12
+ date: 2016-05-28 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activemodel
@@ -113,16 +113,16 @@ dependencies:
113
113
  name: simplecov
114
114
  requirement: !ruby/object:Gem::Requirement
115
115
  requirements:
116
- - - ">="
116
+ - - "~>"
117
117
  - !ruby/object:Gem::Version
118
- version: '0'
118
+ version: 0.11.0
119
119
  type: :development
120
120
  prerelease: false
121
121
  version_requirements: !ruby/object:Gem::Requirement
122
122
  requirements:
123
- - - ">="
123
+ - - "~>"
124
124
  - !ruby/object:Gem::Version
125
- version: '0'
125
+ version: 0.11.0
126
126
  - !ruby/object:Gem::Dependency
127
127
  name: rake
128
128
  requirement: !ruby/object:Gem::Requirement
@@ -173,7 +173,7 @@ files:
173
173
  - gemfiles/Gemfile-activemodel-4.0.x
174
174
  - gemfiles/Gemfile-activemodel-4.1.x
175
175
  - gemfiles/Gemfile-activemodel-4.2.x
176
- - lib/core_ext/string.rb
176
+ - gemfiles/Gemfile-activemodel-5.0.x
177
177
  - lib/schema/pain.001.001.03.xsd
178
178
  - lib/schema/pain.001.002.03.xsd
179
179
  - lib/schema/pain.001.003.03.xsd
@@ -185,6 +185,7 @@ files:
185
185
  - lib/sepa_king/account/creditor_account.rb
186
186
  - lib/sepa_king/account/debtor_account.rb
187
187
  - lib/sepa_king/converter.rb
188
+ - lib/sepa_king/core_ext/string.rb
188
189
  - lib/sepa_king/message.rb
189
190
  - lib/sepa_king/message/credit_transfer.rb
190
191
  - lib/sepa_king/message/direct_debit.rb
@@ -237,7 +238,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
237
238
  version: '0'
238
239
  requirements: []
239
240
  rubyforge_project:
240
- rubygems_version: 2.4.8
241
+ rubygems_version: 2.6.4
241
242
  signing_key:
242
243
  specification_version: 4
243
244
  summary: Ruby gem for creating SEPA XML files