sepa_king 0.0.4 → 0.0.5

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.
data/spec/message_spec.rb CHANGED
@@ -12,11 +12,18 @@ end
12
12
 
13
13
  describe SEPA::Message do
14
14
  describe :amount_total do
15
- it 'should sum up transactions' do
15
+ it 'should sum up all transactions' do
16
16
  message = DummyMessage.new
17
- message.add_transaction :amount => 1.1
18
- message.add_transaction :amount => 2.2
17
+ message.add_transaction amount: 1.1
18
+ message.add_transaction amount: 2.2
19
19
  message.amount_total.should == 3.3
20
20
  end
21
+
22
+ it 'should sum up selected transactions' do
23
+ message = DummyMessage.new
24
+ message.add_transaction amount: 1.1
25
+ message.add_transaction amount: 2.2
26
+ message.amount_total([message.transactions[0]]).should == 1.1
27
+ end
21
28
  end
22
29
  end
data/spec/spec_helper.rb CHANGED
@@ -5,10 +5,15 @@
5
5
 
6
6
  require 'simplecov'
7
7
  require 'coveralls'
8
- SimpleCov.formatter = Coveralls::SimpleCov::Formatter
9
- SimpleCov.start
10
8
 
11
- require 'xml'
9
+ SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[
10
+ SimpleCov::Formatter::HTMLFormatter,
11
+ Coveralls::SimpleCov::Formatter
12
+ ]
13
+ SimpleCov.start do
14
+ add_filter '/spec/'
15
+ end
16
+
12
17
  require 'sepa_king'
13
18
 
14
19
  # Requires supporting ruby files with custom matchers and macros, etc,
@@ -1,9 +1,52 @@
1
1
  require 'rspec/expectations'
2
+ require 'nokogiri'
2
3
 
3
4
  RSpec::Matchers.define :validate_against do |xsd|
4
5
  match do |actual|
5
- schema_doc = XML::Document.file("lib/schema/#{xsd}")
6
- schema = XML::Schema.document(schema_doc)
7
- actual.validate_schema(schema)
6
+ @schema = Nokogiri::XML::Schema(File.read("lib/schema/#{xsd}"))
7
+ @doc = Nokogiri::XML(actual)
8
+
9
+ @schema.should be_valid(@doc)
10
+ end
11
+
12
+ failure_message_for_should do |actual|
13
+ # Return the validation errors as string
14
+ @schema.validate(@doc).join("\n")
15
+ end
16
+ end
17
+
18
+ RSpec::Matchers.define :have_xml do |xpath, text|
19
+ match do |actual|
20
+ doc = Nokogiri::XML(actual)
21
+ doc.remove_namespaces! # so we can use shorter xpath's without any namespace
22
+
23
+ nodes = doc.xpath(xpath)
24
+ nodes.should_not be_empty
25
+ if text
26
+ nodes.each do |node|
27
+ node.content.should == text
28
+ end
29
+ end
30
+ true
31
+ end
32
+ end
33
+
34
+ RSpec::Matchers.define :accept do |*values, options|
35
+ attribute = options[:for]
36
+
37
+ match_for_should do |actual|
38
+ values.all? { |value|
39
+ expect(
40
+ actual.new(attribute => value)
41
+ ).to have(:no).errors_on(attribute)
42
+ }
43
+ end
44
+
45
+ match_for_should_not do |actual|
46
+ values.all? { |value|
47
+ expect(
48
+ actual.new(attribute => value)
49
+ ).to have_at_least(1).errors_on(attribute)
50
+ }
8
51
  end
9
52
  end
@@ -0,0 +1,23 @@
1
+ # encoding: utf-8
2
+
3
+ def credit_transfer_transaction
4
+ { name: 'Telekomiker AG',
5
+ bic: 'PBNKDEFF370',
6
+ iban: 'DE37112589611964645802',
7
+ amount: 102.50,
8
+ reference: 'XYZ-1234/123',
9
+ remittance_information: 'Rechnung vom 22.08.2013'
10
+ }
11
+ end
12
+
13
+ def direct_debt_transaction
14
+ { name: 'Müller & Schmidt oHG',
15
+ bic: 'GENODEF1JEV',
16
+ iban: 'DE68210501700012345678',
17
+ amount: 750.00,
18
+ reference: 'XYZ/2013-08-ABO/6789',
19
+ remittance_information: 'Vielen Dank für Ihren Einkauf!',
20
+ mandate_id: 'K-08-2010-42123',
21
+ mandate_date_of_signature: Date.new(2010,7,25)
22
+ }
23
+ end
@@ -13,7 +13,7 @@ module ::ActiveModel::Validations
13
13
  # expect(model).to have(:no).errors_on(:attribute)
14
14
  # expect(model).to have(1).error_on(:attribute)
15
15
  # expect(model).to have(n).errors_on(:attribute)
16
- # expect(model).to have(n).errors_on(:attribute, :context => :create)
16
+ # expect(model).to have(n).errors_on(:attribute, context: :create)
17
17
  #
18
18
  # expect(model.errors_on(:attribute)).to include("can't be blank")
19
19
  def errors_on(attribute, options = {})
@@ -2,111 +2,87 @@
2
2
  require 'spec_helper'
3
3
 
4
4
  describe SEPA::Transaction do
5
+ describe :new do
6
+ it 'should have default for reference' do
7
+ SEPA::Transaction.new.reference.should == 'NOTPROVIDED'
8
+ end
9
+
10
+ it 'should have default for requested_date' do
11
+ SEPA::Transaction.new.requested_date.should == Date.today.next
12
+ end
13
+
14
+ it 'should have default for batch_booking' do
15
+ SEPA::Transaction.new.batch_booking.should == true
16
+ end
17
+ end
18
+
5
19
  context 'Name' do
6
20
  it 'should accept valid value' do
7
- [ 'Manfred Mustermann III.', 'Zahlemann & Söhne GbR', 'X' * 70 ].each do |value_value|
8
- expect(
9
- SEPA::Transaction.new :name => value_value
10
- ).to have(:no).errors_on(:name)
11
- end
21
+ SEPA::Transaction.should accept('Manfred Mustermann III.', 'Zahlemann & Söhne GbR', 'X' * 70, for: :name)
12
22
  end
13
23
 
14
24
  it 'should not accept invalid value' do
15
- [ nil, '', 'X' * 71 ].each do |invalue_value|
16
- expect(
17
- SEPA::Transaction.new :name => invalue_value
18
- ).to have_at_least(1).errors_on(:name)
19
- end
25
+ SEPA::Transaction.should_not accept(nil, '', 'X' * 71, for: :name)
20
26
  end
21
27
  end
22
28
 
23
29
  context 'IBAN' do
24
30
  it 'should accept valid value' do
25
- [ 'DE21500500009876543210', 'PL61109010140000071219812874' ].each do |value_value|
26
- expect(
27
- SEPA::Transaction.new :iban => value_value
28
- ).to have(:no).errors_on(:iban)
29
- end
31
+ SEPA::Transaction.should accept('DE21500500009876543210', 'PL61109010140000071219812874', for: :iban)
30
32
  end
31
33
 
32
34
  it 'should not accept invalid value' do
33
- [ nil, '', 'invalid' ].each do |invalue_value|
34
- expect(
35
- SEPA::Transaction.new :iban => invalue_value
36
- ).to have_at_least(1).errors_on(:iban)
37
- end
35
+ SEPA::Transaction.should_not accept(nil, '', 'invalid', for: :iban)
38
36
  end
39
37
  end
40
38
 
41
39
  context 'BIC' do
42
40
  it 'should accept valid value' do
43
- [ 'DEUTDEFF', 'DEUTDEFF500', 'SPUEDE2UXXX' ].each do |value_value|
44
- expect(
45
- SEPA::Transaction.new :bic => value_value
46
- ).to have(:no).errors_on(:bic)
47
- end
41
+ SEPA::Transaction.should accept('DEUTDEFF', 'DEUTDEFF500', 'SPUEDE2UXXX', for: :bic)
48
42
  end
49
43
 
50
44
  it 'should not accept invalid value' do
51
- [ nil, '', 'invalid' ].each do |invalue_value|
52
- expect(
53
- SEPA::Transaction.new :bic => invalue_value
54
- ).to have_at_least(1).errors_on(:bic)
55
- end
45
+ SEPA::Transaction.should_not accept(nil, '', 'invalid', for: :bic)
56
46
  end
57
47
  end
58
48
 
59
49
  context 'Amount' do
60
50
  it 'should accept valid value' do
61
- [ 0.01, 1, 100, 100.00, 99.99, 1234567890.12, BigDecimal('10'), '42', '42.51', '42.512', 1.23456 ].each do |value_value|
62
- expect(
63
- SEPA::Transaction.new :amount => value_value
64
- ).to have(:no).errors_on(:amount)
65
- end
51
+ SEPA::Transaction.should accept(0.01, 1, 100, 100.00, 99.99, 1234567890.12, BigDecimal('10'), '42', '42.51', '42.512', 1.23456, for: :amount)
66
52
  end
67
53
 
68
54
  it 'should not accept invalid value' do
69
- [ nil, 0, -3, 'xz' ].each do |invalue_value|
70
- expect(
71
- SEPA::Transaction.new :amount => invalue_value
72
- ).to have_at_least(1).errors_on(:amount)
73
- end
55
+ SEPA::Transaction.should_not accept(nil, 0, -3, 'xz', for: :amount)
74
56
  end
75
57
  end
76
58
 
77
59
  context 'Reference' do
78
60
  it 'should accept valid value' do
79
- [ nil, 'ABC-1234/78.0', 'X' * 35 ].each do |value_value|
80
- expect(
81
- SEPA::Transaction.new :reference => value_value
82
- ).to have(:no).errors_on(:reference)
83
- end
61
+ SEPA::Transaction.should accept(nil, 'ABC-1234/78.0', 'X' * 35, for: :reference)
84
62
  end
85
63
 
86
64
  it 'should not accept invalid value' do
87
- [ '', 'X' * 36 ].each do |invalid_value|
88
- expect(
89
- SEPA::Transaction.new :reference => invalid_value
90
- ).to have_at_least(1).errors_on(:reference)
91
- end
65
+ SEPA::Transaction.should_not accept('', 'X' * 36, for: :amount)
92
66
  end
93
67
  end
94
68
 
95
69
  context 'Remittance information' do
96
70
  it 'should allow valid value' do
97
- [ nil, 'Bonus', 'X' * 140 ].each do |valid_value|
98
- expect(
99
- SEPA::Transaction.new :remittance_information => valid_value
100
- ).to have(:no).errors_on(:remittance_information)
101
- end
71
+ SEPA::Transaction.should accept(nil, 'Bonus', 'X' * 140, for: :remittance_information)
72
+ end
73
+
74
+ it 'should not allow invalid value' do
75
+ SEPA::Transaction.should_not accept('', 'X' * 141, for: :remittance_information)
76
+ end
77
+ end
78
+
79
+ context 'Requested date' do
80
+ it 'should allow valid value' do
81
+ SEPA::Transaction.should accept(nil, Date.today.next, Date.today + 2, for: :requested_date)
102
82
  end
103
83
 
104
84
  it 'should not allow invalid value' do
105
- [ '', 'X' * 141 ].each do |invalid_value|
106
- expect(
107
- SEPA::Transaction.new :remittance_information => invalid_value
108
- ).to have_at_least(1).errors_on(:remittance_information)
109
- end
85
+ SEPA::Transaction.should_not accept(Date.new(1995,12,21), Date.today - 1, Date.today, for: :requested_date)
110
86
  end
111
87
  end
112
88
  end
@@ -2,12 +2,20 @@ require 'spec_helper'
2
2
 
3
3
  describe 'Credit Transfer Initiation' do
4
4
  it "should validate example file" do
5
- XML::Document.file('spec/examples/pain.001.002.03.xml').should validate_against('pain.001.002.03.xsd')
5
+ File.read('spec/examples/pain.001.002.03.xml').should validate_against('pain.001.002.03.xsd')
6
+ end
7
+
8
+ it 'should not validate dummy string' do
9
+ 'foo'.should_not validate_against('pain.001.002.03.xsd')
6
10
  end
7
11
  end
8
12
 
9
13
  describe 'Direct Debit Initiation' do
10
14
  it 'should validate example file' do
11
- XML::Document.file('spec/examples/pain.008.002.02.xml').should validate_against('pain.008.002.02.xsd')
15
+ File.read('spec/examples/pain.008.002.02.xml').should validate_against('pain.008.002.02.xsd')
16
+ end
17
+
18
+ it 'should not validate dummy string' do
19
+ 'foo'.should_not validate_against('pain.008.002.02.xsd')
12
20
  end
13
21
  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.0.4
4
+ version: 0.0.5
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: 2013-08-26 00:00:00.000000000 Z
12
+ date: 2013-08-29 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activemodel
@@ -87,16 +87,16 @@ dependencies:
87
87
  requirements:
88
88
  - - '>='
89
89
  - !ruby/object:Gem::Version
90
- version: '0'
90
+ version: '2.14'
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: '0'
97
+ version: '2.14'
98
98
  - !ruby/object:Gem::Dependency
99
- name: simplecov
99
+ name: coveralls
100
100
  requirement: !ruby/object:Gem::Requirement
101
101
  requirements:
102
102
  - - '>='
@@ -110,7 +110,7 @@ dependencies:
110
110
  - !ruby/object:Gem::Version
111
111
  version: '0'
112
112
  - !ruby/object:Gem::Dependency
113
- name: coveralls
113
+ name: simplecov
114
114
  requirement: !ruby/object:Gem::Requirement
115
115
  requirements:
116
116
  - - '>='
@@ -138,7 +138,7 @@ dependencies:
138
138
  - !ruby/object:Gem::Version
139
139
  version: '0'
140
140
  - !ruby/object:Gem::Dependency
141
- name: libxml-ruby
141
+ name: nokogiri
142
142
  requirement: !ruby/object:Gem::Requirement
143
143
  requirements:
144
144
  - - '>='
@@ -162,9 +162,10 @@ files:
162
162
  - .gitignore
163
163
  - .rspec
164
164
  - .travis.yml
165
+ - CONTRIBUTING.md
165
166
  - Gemfile
166
- - MIT-LICENSE
167
- - README.markdown
167
+ - LICENSE.txt
168
+ - README.md
168
169
  - Rakefile
169
170
  - lib/schema/pain.001.002.03.xsd
170
171
  - lib/schema/pain.008.002.02.xsd
@@ -179,6 +180,7 @@ files:
179
180
  - lib/sepa_king/transaction.rb
180
181
  - lib/sepa_king/transaction/credit_transfer_transaction.rb
181
182
  - lib/sepa_king/transaction/direct_debit_transaction.rb
183
+ - lib/sepa_king/validator.rb
182
184
  - lib/sepa_king/version.rb
183
185
  - sepa_king.gemspec
184
186
  - spec/account_spec.rb
@@ -194,6 +196,7 @@ files:
194
196
  - spec/message_spec.rb
195
197
  - spec/spec_helper.rb
196
198
  - spec/support/custom_matcher.rb
199
+ - spec/support/factories.rb
197
200
  - spec/support/validations.rb
198
201
  - spec/transaction_spec.rb
199
202
  - spec/validation_spec.rb
@@ -209,7 +212,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
209
212
  requirements:
210
213
  - - '>='
211
214
  - !ruby/object:Gem::Version
212
- version: '0'
215
+ version: 1.9.3
213
216
  required_rubygems_version: !ruby/object:Gem::Requirement
214
217
  requirements:
215
218
  - - '>='
@@ -220,7 +223,7 @@ rubyforge_project:
220
223
  rubygems_version: 2.0.7
221
224
  signing_key:
222
225
  specification_version: 4
223
- summary: Generate SEPA XML files with Ruby ... the easy way
226
+ summary: Ruby gem for creating SEPA XML files
224
227
  test_files:
225
228
  - spec/account_spec.rb
226
229
  - spec/converter_spec.rb
@@ -235,6 +238,7 @@ test_files:
235
238
  - spec/message_spec.rb
236
239
  - spec/spec_helper.rb
237
240
  - spec/support/custom_matcher.rb
241
+ - spec/support/factories.rb
238
242
  - spec/support/validations.rb
239
243
  - spec/transaction_spec.rb
240
244
  - spec/validation_spec.rb
data/README.markdown DELETED
@@ -1,91 +0,0 @@
1
- # Handle SEPA like a king
2
-
3
- [![Build Status](https://secure.travis-ci.org/salesking/sepa_king.png)](http://travis-ci.org/salesking/sepa_king)
4
- [![Code Climate](https://codeclimate.com/github/salesking/sepa_king.png)](https://codeclimate.com/github/salesking/sepa_king)
5
- [![Coverage Status](https://coveralls.io/repos/salesking/sepa_king/badge.png)](https://coveralls.io/r/salesking/sepa_king)
6
-
7
- We love building payment applications! So after developing the [DTAUS library for Ruby](https://github.com/salesking/king_dtaus) we move on with SEPA!
8
-
9
- This is just the beginning. There is still a lot to do. Please stay tuned...
10
-
11
-
12
- ## Features
13
-
14
- * Credit transfer (pain.001.002.03)
15
- * Debit transfer (pain.008.002.02)
16
- * 100% test coverage to ensure software quality
17
- * Tested with Ruby 1.9.3 and 2.0.0
18
-
19
-
20
- ## Installation
21
-
22
- gem install sepa_king
23
-
24
-
25
- ## Examples
26
-
27
- How to create a SEPA file for direct debit ("Lastschrift")
28
-
29
- ```ruby
30
- # First: Create the main object
31
- dd = SEPA::DirectDebit.new :name => 'Gläubiger GmbH',
32
- :bic => 'BANKDEFFXXX',
33
- :iban => 'DE87200500001234567890',
34
- :identifier => 'DE98ZZZ09999999999'
35
-
36
- # Second: Add transactions
37
- dd.add_transaction :name => 'Zahlemann & Söhne GbR',
38
- :bic => 'SPUEDE2UXXX',
39
- :iban => 'DE21500500009876543210',
40
- :amount => 39.99,
41
- :reference => 'XYZ/2013-08-ABO/6789',
42
- :remittance_information => 'Vielen Dank für Ihren Einkauf!',
43
- :mandate_id => 'K-02-2011-12345',
44
- :mandate_date_of_signature => Date.new(2011,1,25)
45
- dd.add_transaction ...
46
-
47
- # Last: create XML string
48
- xml_string = dd.to_xml
49
- ```
50
-
51
-
52
- How to create a SEPA file for credit transfer ("Überweisung")
53
-
54
- ```ruby
55
- # First: Create the main object
56
- ct = SEPA::CreditTransfer.new :name => 'Schuldner GmbH',
57
- :bic => 'BANKDEFFXXX',
58
- :iban => 'DE87200500001234567890'
59
-
60
- # Second: Add transactions
61
- ct.add_transaction :name => 'Telekomiker AG',
62
- :bic => 'PBNKDEFF370',
63
- :iban => 'DE37112589611964645802',
64
- :amount => 102.50,
65
- :reference => 'XYZ-1234/123',
66
- :remittance_information => 'Rechnung vom 22.08.2013'
67
- ct.add_transaction ...
68
-
69
- # Last: create XML string
70
- xml_string = ct.to_xml
71
- ```
72
-
73
- Make sure to read the code and the specs!
74
-
75
-
76
- ## Changelog
77
-
78
- https://github.com/salesking/sepa_king/releases
79
-
80
-
81
- ## Resources
82
-
83
- * http://www.ebics.de/index.php?id=77
84
- * SalesKing: http://salesking.eu
85
-
86
-
87
- ## License
88
-
89
- Released under the MIT license
90
-
91
- Copyright (c) 2013 Georg Leciejewski (SalesKing), Georg Ledermann (https://github.com/ledermann)