sepa_king_extended 0.10.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (60) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +9 -0
  3. data/.rspec +2 -0
  4. data/.travis.yml +30 -0
  5. data/CONTRIBUTING.md +38 -0
  6. data/Gemfile +2 -0
  7. data/LICENSE.txt +22 -0
  8. data/README.md +267 -0
  9. data/Rakefile +6 -0
  10. data/gemfiles/Gemfile-activemodel-3.0.x +5 -0
  11. data/gemfiles/Gemfile-activemodel-3.1.x +5 -0
  12. data/gemfiles/Gemfile-activemodel-3.2.x +5 -0
  13. data/gemfiles/Gemfile-activemodel-4.0.x +5 -0
  14. data/gemfiles/Gemfile-activemodel-4.1.x +5 -0
  15. data/gemfiles/Gemfile-activemodel-4.2.x +5 -0
  16. data/gemfiles/Gemfile-activemodel-5.0.x +5 -0
  17. data/gemfiles/Gemfile-activemodel-5.1.x +5 -0
  18. data/lib/schema/pain.001.001.03.xsd +921 -0
  19. data/lib/schema/pain.001.002.03.xsd +450 -0
  20. data/lib/schema/pain.001.003.03.xsd +474 -0
  21. data/lib/schema/pain.008.001.02.xsd +879 -0
  22. data/lib/schema/pain.008.002.02.xsd +597 -0
  23. data/lib/schema/pain.008.003.02.xsd +614 -0
  24. data/lib/sepa_king/account/creditor_account.rb +8 -0
  25. data/lib/sepa_king/account/debtor_account.rb +5 -0
  26. data/lib/sepa_king/account.rb +19 -0
  27. data/lib/sepa_king/converter.rb +51 -0
  28. data/lib/sepa_king/message/credit_transfer.rb +99 -0
  29. data/lib/sepa_king/message/direct_debit.rb +151 -0
  30. data/lib/sepa_king/message.rb +135 -0
  31. data/lib/sepa_king/transaction/credit_transfer_transaction.rb +30 -0
  32. data/lib/sepa_king/transaction/direct_debit_transaction.rb +45 -0
  33. data/lib/sepa_king/transaction.rb +44 -0
  34. data/lib/sepa_king/validator.rb +68 -0
  35. data/lib/sepa_king/version.rb +3 -0
  36. data/lib/sepa_king.rb +16 -0
  37. data/sepa_king_extended.gemspec +32 -0
  38. data/spec/account_spec.rb +42 -0
  39. data/spec/converter_spec.rb +74 -0
  40. data/spec/credit_transfer_spec.rb +364 -0
  41. data/spec/credit_transfer_transaction_spec.rb +58 -0
  42. data/spec/creditor_account_spec.rb +23 -0
  43. data/spec/debtor_account_spec.rb +12 -0
  44. data/spec/direct_debit_spec.rb +469 -0
  45. data/spec/direct_debit_transaction_spec.rb +69 -0
  46. data/spec/examples/pain.001.001.03.xml +89 -0
  47. data/spec/examples/pain.001.002.03.xml +89 -0
  48. data/spec/examples/pain.001.003.03.xml +89 -0
  49. data/spec/examples/pain.008.002.02.xml +134 -0
  50. data/spec/examples/pain.008.003.02.xml +134 -0
  51. data/spec/message_spec.rb +88 -0
  52. data/spec/spec_helper.rb +33 -0
  53. data/spec/support/active_model.rb +30 -0
  54. data/spec/support/custom_matcher.rb +60 -0
  55. data/spec/support/factories.rb +24 -0
  56. data/spec/support/validations.rb +27 -0
  57. data/spec/transaction_spec.rb +88 -0
  58. data/spec/validation_spec.rb +25 -0
  59. data/spec/validator_spec.rb +99 -0
  60. metadata +254 -0
@@ -0,0 +1,89 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <!-- Mit XMLSpy v2008 rel. 2 sp2 (http://www.altova.com) von benutzerservice benutzerservice (SIZ GmbH) bearbeitet -->
3
+ <Document xmlns="urn:iso:std:iso:20022:tech:xsd:pain.001.002.03" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="urn:iso:std:iso:20022:tech:xsd:pain.001.002.03 pain.001.002.03.xsd">
4
+ <CstmrCdtTrfInitn>
5
+ <GrpHdr>
6
+ <MsgId>Message-ID-4711</MsgId>
7
+ <CreDtTm>2010-11-11T09:30:47.000Z</CreDtTm>
8
+ <NbOfTxs>2</NbOfTxs>
9
+ <InitgPty>
10
+ <Nm>Initiator Name</Nm>
11
+ </InitgPty>
12
+ </GrpHdr>
13
+ <PmtInf>
14
+ <PmtInfId>Payment-Information-ID-4711</PmtInfId>
15
+ <PmtMtd>TRF</PmtMtd>
16
+ <BtchBookg>true</BtchBookg>
17
+ <NbOfTxs>2</NbOfTxs>
18
+ <CtrlSum>6655.86</CtrlSum>
19
+ <PmtTpInf>
20
+ <SvcLvl>
21
+ <Cd>SEPA</Cd>
22
+ </SvcLvl>
23
+ </PmtTpInf>
24
+ <ReqdExctnDt>2010-11-25</ReqdExctnDt>
25
+ <Dbtr>
26
+ <Nm>Debtor Name</Nm>
27
+ </Dbtr>
28
+ <DbtrAcct>
29
+ <Id>
30
+ <IBAN>DE87200500001234567890</IBAN>
31
+ </Id>
32
+ </DbtrAcct>
33
+ <DbtrAgt>
34
+ <FinInstnId>
35
+ <BIC>BANKDEFFXXX</BIC>
36
+ </FinInstnId>
37
+ </DbtrAgt>
38
+ <ChrgBr>SLEV</ChrgBr>
39
+ <CdtTrfTxInf>
40
+ <PmtId>
41
+ <EndToEndId>OriginatorID1234</EndToEndId>
42
+ </PmtId>
43
+ <Amt>
44
+ <InstdAmt Ccy="EUR">6543.14</InstdAmt>
45
+ </Amt>
46
+ <CdtrAgt>
47
+ <FinInstnId>
48
+ <BIC>SPUEDE2UXXX</BIC>
49
+ </FinInstnId>
50
+ </CdtrAgt>
51
+ <Cdtr>
52
+ <Nm>Creditor Name</Nm>
53
+ </Cdtr>
54
+ <CdtrAcct>
55
+ <Id>
56
+ <IBAN>DE21500500009876543210</IBAN>
57
+ </Id>
58
+ </CdtrAcct>
59
+ <RmtInf>
60
+ <Ustrd>Unstructured Remittance Information</Ustrd>
61
+ </RmtInf>
62
+ </CdtTrfTxInf>
63
+ <CdtTrfTxInf>
64
+ <PmtId>
65
+ <EndToEndId>OriginatorID1235</EndToEndId>
66
+ </PmtId>
67
+ <Amt>
68
+ <InstdAmt Ccy="EUR">112.72</InstdAmt>
69
+ </Amt>
70
+ <CdtrAgt>
71
+ <FinInstnId>
72
+ <BIC>SPUEDE2UXXX</BIC>
73
+ </FinInstnId>
74
+ </CdtrAgt>
75
+ <Cdtr>
76
+ <Nm>Other Creditor Name</Nm>
77
+ </Cdtr>
78
+ <CdtrAcct>
79
+ <Id>
80
+ <IBAN>DE21500500001234567897</IBAN>
81
+ </Id>
82
+ </CdtrAcct>
83
+ <RmtInf>
84
+ <Ustrd>Unstructured Remittance Information</Ustrd>
85
+ </RmtInf>
86
+ </CdtTrfTxInf>
87
+ </PmtInf>
88
+ </CstmrCdtTrfInitn>
89
+ </Document>
@@ -0,0 +1,89 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <!-- Mit XMLSpy v2008 rel. 2 sp2 (http://www.altova.com) von benutzerservice benutzerservice (SIZ GmbH) bearbeitet -->
3
+ <Document xmlns="urn:iso:std:iso:20022:tech:xsd:pain.001.003.03" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="urn:iso:std:iso:20022:tech:xsd:pain.001.003.03 pain.001.003.03.xsd">
4
+ <CstmrCdtTrfInitn>
5
+ <GrpHdr>
6
+ <MsgId>Message-ID-4711</MsgId>
7
+ <CreDtTm>2010-11-11T09:30:47.000Z</CreDtTm>
8
+ <NbOfTxs>2</NbOfTxs>
9
+ <InitgPty>
10
+ <Nm>Initiator Name</Nm>
11
+ </InitgPty>
12
+ </GrpHdr>
13
+ <PmtInf>
14
+ <PmtInfId>Payment-Information-ID-4711</PmtInfId>
15
+ <PmtMtd>TRF</PmtMtd>
16
+ <BtchBookg>true</BtchBookg>
17
+ <NbOfTxs>2</NbOfTxs>
18
+ <CtrlSum>6655.86</CtrlSum>
19
+ <PmtTpInf>
20
+ <SvcLvl>
21
+ <Cd>SEPA</Cd>
22
+ </SvcLvl>
23
+ </PmtTpInf>
24
+ <ReqdExctnDt>2010-11-25</ReqdExctnDt>
25
+ <Dbtr>
26
+ <Nm>Debtor Name</Nm>
27
+ </Dbtr>
28
+ <DbtrAcct>
29
+ <Id>
30
+ <IBAN>DE87200500001234567890</IBAN>
31
+ </Id>
32
+ </DbtrAcct>
33
+ <DbtrAgt>
34
+ <FinInstnId>
35
+ <BIC>BANKDEFFXXX</BIC>
36
+ </FinInstnId>
37
+ </DbtrAgt>
38
+ <ChrgBr>SLEV</ChrgBr>
39
+ <CdtTrfTxInf>
40
+ <PmtId>
41
+ <EndToEndId>OriginatorID1234</EndToEndId>
42
+ </PmtId>
43
+ <Amt>
44
+ <InstdAmt Ccy="EUR">6543.14</InstdAmt>
45
+ </Amt>
46
+ <CdtrAgt>
47
+ <FinInstnId>
48
+ <BIC>SPUEDE2UXXX</BIC>
49
+ </FinInstnId>
50
+ </CdtrAgt>
51
+ <Cdtr>
52
+ <Nm>Creditor Name</Nm>
53
+ </Cdtr>
54
+ <CdtrAcct>
55
+ <Id>
56
+ <IBAN>DE21500500009876543210</IBAN>
57
+ </Id>
58
+ </CdtrAcct>
59
+ <RmtInf>
60
+ <Ustrd>Unstructured Remittance Information</Ustrd>
61
+ </RmtInf>
62
+ </CdtTrfTxInf>
63
+ <CdtTrfTxInf>
64
+ <PmtId>
65
+ <EndToEndId>OriginatorID1235</EndToEndId>
66
+ </PmtId>
67
+ <Amt>
68
+ <InstdAmt Ccy="EUR">112.72</InstdAmt>
69
+ </Amt>
70
+ <CdtrAgt>
71
+ <FinInstnId>
72
+ <BIC>SPUEDE2UXXX</BIC>
73
+ </FinInstnId>
74
+ </CdtrAgt>
75
+ <Cdtr>
76
+ <Nm>Other Creditor Name</Nm>
77
+ </Cdtr>
78
+ <CdtrAcct>
79
+ <Id>
80
+ <IBAN>DE21500500001234567897</IBAN>
81
+ </Id>
82
+ </CdtrAcct>
83
+ <RmtInf>
84
+ <Ustrd>Unstructured Remittance Information</Ustrd>
85
+ </RmtInf>
86
+ </CdtTrfTxInf>
87
+ </PmtInf>
88
+ </CstmrCdtTrfInitn>
89
+ </Document>
@@ -0,0 +1,134 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <Document xmlns="urn:iso:std:iso:20022:tech:xsd:pain.008.002.02" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="urn:iso:std:iso:20022:tech:xsd:pain.008.002.02 pain.008.002.02.xsd">
3
+ <CstmrDrctDbtInitn>
4
+ <GrpHdr>
5
+ <MsgId>Message-ID</MsgId>
6
+ <CreDtTm>2010-11-21T09:30:47.000Z</CreDtTm>
7
+ <NbOfTxs>2</NbOfTxs>
8
+ <InitgPty>
9
+ <Nm>Initiator Name</Nm>
10
+ </InitgPty>
11
+ </GrpHdr>
12
+ <PmtInf>
13
+ <PmtInfId>Payment-ID</PmtInfId>
14
+ <PmtMtd>DD</PmtMtd>
15
+ <NbOfTxs>2</NbOfTxs>
16
+ <CtrlSum>6655.86</CtrlSum>
17
+ <PmtTpInf>
18
+ <SvcLvl>
19
+ <Cd>SEPA</Cd>
20
+ </SvcLvl>
21
+ <LclInstrm>
22
+ <Cd>CORE</Cd>
23
+ </LclInstrm>
24
+ <SeqTp>FRST</SeqTp>
25
+ </PmtTpInf>
26
+ <ReqdColltnDt>2010-12-03</ReqdColltnDt>
27
+ <Cdtr>
28
+ <Nm>Creditor Name</Nm>
29
+ </Cdtr>
30
+ <CdtrAcct>
31
+ <Id>
32
+ <IBAN>DE87200500001234567890</IBAN>
33
+ </Id>
34
+ </CdtrAcct>
35
+ <CdtrAgt>
36
+ <FinInstnId>
37
+ <BIC>BANKDEFFXXX</BIC>
38
+ </FinInstnId>
39
+ </CdtrAgt>
40
+ <ChrgBr>SLEV</ChrgBr>
41
+ <CdtrSchmeId>
42
+ <Id>
43
+ <PrvtId>
44
+ <Othr>
45
+ <Id>DE00ZZZ00099999999</Id>
46
+ <SchmeNm>
47
+ <Prtry>SEPA</Prtry>
48
+ </SchmeNm>
49
+ </Othr>
50
+ </PrvtId>
51
+ </Id>
52
+ </CdtrSchmeId>
53
+ <DrctDbtTxInf>
54
+ <PmtId>
55
+ <EndToEndId>OriginatorID1234</EndToEndId>
56
+ </PmtId>
57
+ <InstdAmt Ccy="EUR">6543.14</InstdAmt>
58
+ <DrctDbtTx>
59
+ <MndtRltdInf>
60
+ <MndtId>Mandate-Id</MndtId>
61
+ <DtOfSgntr>2010-11-20</DtOfSgntr>
62
+ <AmdmntInd>true</AmdmntInd>
63
+ <AmdmntInfDtls>
64
+ <OrgnlCdtrSchmeId>
65
+ <Nm>Original Creditor Name</Nm>
66
+ <Id>
67
+ <PrvtId>
68
+ <Othr>
69
+ <Id>AA00ZZZOriginalCreditorID</Id>
70
+ <SchmeNm>
71
+ <Prtry>SEPA</Prtry>
72
+ </SchmeNm>
73
+ </Othr>
74
+ </PrvtId>
75
+ </Id>
76
+ </OrgnlCdtrSchmeId>
77
+ </AmdmntInfDtls>
78
+ </MndtRltdInf>
79
+ </DrctDbtTx>
80
+ <DbtrAgt>
81
+ <FinInstnId>
82
+ <BIC>SPUEDE2UXXX</BIC>
83
+ </FinInstnId>
84
+ </DbtrAgt>
85
+ <Dbtr>
86
+ <Nm>Debtor Name</Nm>
87
+ </Dbtr>
88
+ <DbtrAcct>
89
+ <Id>
90
+ <IBAN>DE21500500009876543210</IBAN>
91
+ </Id>
92
+ </DbtrAcct>
93
+ <UltmtDbtr>
94
+ <Nm>Ultimate Debtor Name</Nm>
95
+ </UltmtDbtr>
96
+ <RmtInf>
97
+ <Ustrd>Unstructured Remittance Information</Ustrd>
98
+ </RmtInf>
99
+ </DrctDbtTxInf>
100
+ <DrctDbtTxInf>
101
+ <PmtId>
102
+ <EndToEndId>OriginatorID1235</EndToEndId>
103
+ </PmtId>
104
+ <InstdAmt Ccy="EUR">112.72</InstdAmt>
105
+ <DrctDbtTx>
106
+ <MndtRltdInf>
107
+ <MndtId>Other-Mandate-Id</MndtId>
108
+ <DtOfSgntr>2010-11-20</DtOfSgntr>
109
+ <AmdmntInd>false</AmdmntInd>
110
+ </MndtRltdInf>
111
+ </DrctDbtTx>
112
+ <DbtrAgt>
113
+ <FinInstnId>
114
+ <BIC>SPUEDE2UXXX</BIC>
115
+ </FinInstnId>
116
+ </DbtrAgt>
117
+ <Dbtr>
118
+ <Nm>Other Debtor Name</Nm>
119
+ </Dbtr>
120
+ <DbtrAcct>
121
+ <Id>
122
+ <IBAN>DE21500500001234567897</IBAN>
123
+ </Id>
124
+ </DbtrAcct>
125
+ <UltmtDbtr>
126
+ <Nm>Ultimate Debtor Name</Nm>
127
+ </UltmtDbtr>
128
+ <RmtInf>
129
+ <Ustrd>Unstructured Remittance Information</Ustrd>
130
+ </RmtInf>
131
+ </DrctDbtTxInf>
132
+ </PmtInf>
133
+ </CstmrDrctDbtInitn>
134
+ </Document>
@@ -0,0 +1,134 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <Document xmlns="urn:iso:std:iso:20022:tech:xsd:pain.008.003.02" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="urn:iso:std:iso:20022:tech:xsd:pain.008.003.02 pain.008.003.02.xsd">
3
+ <CstmrDrctDbtInitn>
4
+ <GrpHdr>
5
+ <MsgId>Message-ID</MsgId>
6
+ <CreDtTm>2010-11-21T09:30:47.000Z</CreDtTm>
7
+ <NbOfTxs>2</NbOfTxs>
8
+ <InitgPty>
9
+ <Nm>Initiator Name</Nm>
10
+ </InitgPty>
11
+ </GrpHdr>
12
+ <PmtInf>
13
+ <PmtInfId>Payment-ID</PmtInfId>
14
+ <PmtMtd>DD</PmtMtd>
15
+ <NbOfTxs>2</NbOfTxs>
16
+ <CtrlSum>6655.86</CtrlSum>
17
+ <PmtTpInf>
18
+ <SvcLvl>
19
+ <Cd>SEPA</Cd>
20
+ </SvcLvl>
21
+ <LclInstrm>
22
+ <Cd>CORE</Cd>
23
+ </LclInstrm>
24
+ <SeqTp>FRST</SeqTp>
25
+ </PmtTpInf>
26
+ <ReqdColltnDt>2010-12-03</ReqdColltnDt>
27
+ <Cdtr>
28
+ <Nm>Creditor Name</Nm>
29
+ </Cdtr>
30
+ <CdtrAcct>
31
+ <Id>
32
+ <IBAN>DE87200500001234567890</IBAN>
33
+ </Id>
34
+ </CdtrAcct>
35
+ <CdtrAgt>
36
+ <FinInstnId>
37
+ <BIC>BANKDEFFXXX</BIC>
38
+ </FinInstnId>
39
+ </CdtrAgt>
40
+ <ChrgBr>SLEV</ChrgBr>
41
+ <CdtrSchmeId>
42
+ <Id>
43
+ <PrvtId>
44
+ <Othr>
45
+ <Id>DE00ZZZ00099999999</Id>
46
+ <SchmeNm>
47
+ <Prtry>SEPA</Prtry>
48
+ </SchmeNm>
49
+ </Othr>
50
+ </PrvtId>
51
+ </Id>
52
+ </CdtrSchmeId>
53
+ <DrctDbtTxInf>
54
+ <PmtId>
55
+ <EndToEndId>OriginatorID1234</EndToEndId>
56
+ </PmtId>
57
+ <InstdAmt Ccy="EUR">6543.14</InstdAmt>
58
+ <DrctDbtTx>
59
+ <MndtRltdInf>
60
+ <MndtId>Mandate-Id</MndtId>
61
+ <DtOfSgntr>2010-11-20</DtOfSgntr>
62
+ <AmdmntInd>true</AmdmntInd>
63
+ <AmdmntInfDtls>
64
+ <OrgnlCdtrSchmeId>
65
+ <Nm>Original Creditor Name</Nm>
66
+ <Id>
67
+ <PrvtId>
68
+ <Othr>
69
+ <Id>AA00ZZZOriginalCreditorID</Id>
70
+ <SchmeNm>
71
+ <Prtry>SEPA</Prtry>
72
+ </SchmeNm>
73
+ </Othr>
74
+ </PrvtId>
75
+ </Id>
76
+ </OrgnlCdtrSchmeId>
77
+ </AmdmntInfDtls>
78
+ </MndtRltdInf>
79
+ </DrctDbtTx>
80
+ <DbtrAgt>
81
+ <FinInstnId>
82
+ <BIC>SPUEDE2UXXX</BIC>
83
+ </FinInstnId>
84
+ </DbtrAgt>
85
+ <Dbtr>
86
+ <Nm>Debtor Name</Nm>
87
+ </Dbtr>
88
+ <DbtrAcct>
89
+ <Id>
90
+ <IBAN>DE21500500009876543210</IBAN>
91
+ </Id>
92
+ </DbtrAcct>
93
+ <UltmtDbtr>
94
+ <Nm>Ultimate Debtor Name</Nm>
95
+ </UltmtDbtr>
96
+ <RmtInf>
97
+ <Ustrd>Unstructured Remittance Information</Ustrd>
98
+ </RmtInf>
99
+ </DrctDbtTxInf>
100
+ <DrctDbtTxInf>
101
+ <PmtId>
102
+ <EndToEndId>OriginatorID1235</EndToEndId>
103
+ </PmtId>
104
+ <InstdAmt Ccy="EUR">112.72</InstdAmt>
105
+ <DrctDbtTx>
106
+ <MndtRltdInf>
107
+ <MndtId>Other-Mandate-Id</MndtId>
108
+ <DtOfSgntr>2010-11-20</DtOfSgntr>
109
+ <AmdmntInd>false</AmdmntInd>
110
+ </MndtRltdInf>
111
+ </DrctDbtTx>
112
+ <DbtrAgt>
113
+ <FinInstnId>
114
+ <BIC>SPUEDE2UXXX</BIC>
115
+ </FinInstnId>
116
+ </DbtrAgt>
117
+ <Dbtr>
118
+ <Nm>Other Debtor Name</Nm>
119
+ </Dbtr>
120
+ <DbtrAcct>
121
+ <Id>
122
+ <IBAN>DE21500500001234567897</IBAN>
123
+ </Id>
124
+ </DbtrAcct>
125
+ <UltmtDbtr>
126
+ <Nm>Ultimate Debtor Name</Nm>
127
+ </UltmtDbtr>
128
+ <RmtInf>
129
+ <Ustrd>Unstructured Remittance Information</Ustrd>
130
+ </RmtInf>
131
+ </DrctDbtTxInf>
132
+ </PmtInf>
133
+ </CstmrDrctDbtInitn>
134
+ </Document>
@@ -0,0 +1,88 @@
1
+ # encoding: utf-8
2
+ require 'spec_helper'
3
+
4
+ class DummyTransaction < SEPA::Transaction
5
+ def valid?; true end
6
+ end
7
+
8
+ class DummyMessage < SEPA::Message
9
+ self.account_class = SEPA::Account
10
+ self.transaction_class = DummyTransaction
11
+ end
12
+
13
+ describe SEPA::Message do
14
+ describe :amount_total do
15
+ subject do
16
+ message = DummyMessage.new
17
+ message.add_transaction amount: 1.1
18
+ message.add_transaction amount: 2.2
19
+ message
20
+ end
21
+
22
+ it 'should sum up all transactions' do
23
+ expect(subject.amount_total).to eq(3.3)
24
+ end
25
+
26
+ it 'should sum up selected transactions' do
27
+ expect(subject.amount_total([subject.transactions[0]])).to eq(1.1)
28
+ end
29
+ end
30
+
31
+ describe 'validation' do
32
+ subject { DummyMessage.new }
33
+
34
+ it 'should fail with invalid account' do
35
+ expect(subject).not_to be_valid
36
+ expect(subject.errors_on(:account).size).to eq(2)
37
+ end
38
+
39
+ it 'should fail without transactions' do
40
+ expect(subject).not_to be_valid
41
+ expect(subject.errors_on(:transactions).size).to eq(1)
42
+ end
43
+ end
44
+
45
+ describe :message_identification do
46
+ subject { DummyMessage.new }
47
+
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
52
+ end
53
+
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
86
+ end
87
+ end
88
+ end
@@ -0,0 +1,33 @@
1
+ # This file was generated by the `rspec --init` command. Conventionally, all
2
+ # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
3
+ # Require this file using `require "spec_helper"` to ensure that it is only
4
+ # loaded once.
5
+
6
+ require 'simplecov'
7
+ require 'coveralls'
8
+
9
+ SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter.new([
10
+ SimpleCov::Formatter::HTMLFormatter,
11
+ Coveralls::SimpleCov::Formatter
12
+ ])
13
+ SimpleCov.start do
14
+ add_filter '/spec/'
15
+ end
16
+
17
+ require 'sepa_king'
18
+
19
+ # Requires supporting ruby files with custom matchers and macros, etc,
20
+ # in spec/support/ and its subdirectories.
21
+ Dir[File.expand_path(File.join(File.dirname(__FILE__),'support','**','*.rb'))].each {|f| require f}
22
+
23
+ # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
24
+ RSpec.configure do |config|
25
+ config.run_all_when_everything_filtered = true
26
+ config.filter_run :focus
27
+
28
+ # Run specs in random order to surface order dependencies. If you find an
29
+ # order dependency and want to debug it, you can fix the order by providing
30
+ # the seed, which is printed after each run.
31
+ # --seed 1234
32
+ config.order = 'random'
33
+ end
@@ -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
@@ -0,0 +1,60 @@
1
+ require 'rspec/expectations'
2
+ require 'nokogiri'
3
+
4
+ RSpec::Matchers.define :validate_against do |xsd|
5
+ match do |actual|
6
+ @schema = Nokogiri::XML::Schema(File.read("lib/schema/#{xsd}"))
7
+ @doc = Nokogiri::XML(actual)
8
+
9
+ expect(@schema).to be_valid(@doc)
10
+ end
11
+
12
+ failure_message 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
+ expect(nodes).not_to be_empty
25
+ if text
26
+ nodes.each do |node|
27
+ if text.is_a?(Regexp)
28
+ expect(node.content).to match(text)
29
+ else
30
+ expect(node.content).to eq(text)
31
+ end
32
+ end
33
+ end
34
+ true
35
+ end
36
+ end
37
+
38
+ RSpec::Matchers.define :accept do |*values, options|
39
+ attributes = Array(options[:for])
40
+
41
+ attributes.each do |attribute|
42
+ match do |actual|
43
+ values.all? { |value|
44
+ expect(
45
+ actual.new(attribute => value).errors_on(attribute).size
46
+ ).to eq 0
47
+ }
48
+ end
49
+ end
50
+
51
+ attributes.each do |attribute|
52
+ match_when_negated do |actual|
53
+ values.all? { |value|
54
+ expect(
55
+ actual.new(attribute => value).errors_on(attribute).size
56
+ ).to be >= 1
57
+ }
58
+ end
59
+ end
60
+ end
@@ -0,0 +1,24 @@
1
+ # encoding: utf-8
2
+
3
+ def credit_transfer_transaction(attributes={})
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
+ }.merge(attributes)
11
+ end
12
+
13
+ def direct_debt_transaction(attributes={})
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
+ requested_date: Date.today + 1
23
+ }.merge(attributes)
24
+ end