pagseguro-oficial 2.5.0 → 2.6.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (140) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +13 -1
  3. data/CONTRIBUTING.md +39 -0
  4. data/Dockerfile +20 -0
  5. data/README.md +22 -0
  6. data/docker-compose.yml +5 -0
  7. data/examples/checkout/create_payment_request.rb +1 -1
  8. data/examples/direct/create_transaction_using_boleto.rb +1 -1
  9. data/examples/direct/create_transaction_using_credit_card.rb +1 -1
  10. data/examples/direct/create_transaction_using_online_debit.rb +1 -1
  11. data/examples/preapproval/cancel_preapproval.rb +26 -0
  12. data/examples/preapproval/change_preapproval_payment.rb +50 -0
  13. data/examples/preapproval/change_preapproval_status.rb +29 -0
  14. data/examples/preapproval/charge_preapproval.rb +36 -0
  15. data/examples/preapproval/create_preapproval.rb +68 -0
  16. data/examples/preapproval/create_preapproval_auto.rb +53 -0
  17. data/examples/preapproval/create_preapproval_discount.rb +30 -0
  18. data/examples/preapproval/create_preapproval_manual.rb +58 -0
  19. data/examples/preapproval/create_preapproval_transparent.rb +41 -0
  20. data/examples/preapproval/preapproval_retry.rb +29 -0
  21. data/examples/preapproval/search/search_by_date_interval.rb +45 -0
  22. data/examples/preapproval/search/search_by_days_interval.rb +46 -0
  23. data/examples/preapproval/search/search_by_notification_code.rb +50 -0
  24. data/examples/preapproval/search/search_by_subscription_code.rb +50 -0
  25. data/examples/preapproval/search/search_subscription_payment_orders.rb +53 -0
  26. data/examples/split_payment/create_payment_request.rb +1 -1
  27. data/examples/split_payment/create_transaction_using_boleto.rb +118 -0
  28. data/examples/split_payment/create_transaction_using_credit_card.rb +152 -0
  29. data/lib/pagseguro.rb +33 -1
  30. data/lib/pagseguro/credit_card_transaction_request.rb +1 -1
  31. data/lib/pagseguro/document.rb +8 -0
  32. data/lib/pagseguro/holder.rb +8 -0
  33. data/lib/pagseguro/manual_subscription_charger.rb +59 -0
  34. data/lib/pagseguro/manual_subscription_charger/request_serializer.rb +50 -0
  35. data/lib/pagseguro/manual_subscription_charger/response.rb +36 -0
  36. data/lib/pagseguro/manual_subscription_charger/response_serializer.rb +17 -0
  37. data/lib/pagseguro/payment_request/request_serializer.rb +25 -1
  38. data/lib/pagseguro/receiver.rb +3 -0
  39. data/lib/pagseguro/request.rb +32 -2
  40. data/lib/pagseguro/sender.rb +21 -3
  41. data/lib/pagseguro/subscription.rb +132 -0
  42. data/lib/pagseguro/subscription/request_serializer.rb +129 -0
  43. data/lib/pagseguro/subscription/response.rb +49 -0
  44. data/lib/pagseguro/subscription/response_serializer.rb +62 -0
  45. data/lib/pagseguro/subscription/subscription_search.rb +135 -0
  46. data/lib/pagseguro/subscription_canceller.rb +30 -0
  47. data/lib/pagseguro/subscription_canceller/response.rb +34 -0
  48. data/lib/pagseguro/subscription_change_payment.rb +46 -0
  49. data/lib/pagseguro/subscription_change_payment/request_serializer.rb +80 -0
  50. data/lib/pagseguro/subscription_change_payment/response.rb +26 -0
  51. data/lib/pagseguro/subscription_change_status.rb +50 -0
  52. data/lib/pagseguro/subscription_change_status/request_serializer.rb +28 -0
  53. data/lib/pagseguro/subscription_change_status/response.rb +26 -0
  54. data/lib/pagseguro/subscription_discount.rb +41 -0
  55. data/lib/pagseguro/subscription_discount/request_serializer.rb +34 -0
  56. data/lib/pagseguro/subscription_discount/response.rb +34 -0
  57. data/lib/pagseguro/subscription_payment_method.rb +21 -0
  58. data/lib/pagseguro/subscription_payment_order.rb +57 -0
  59. data/lib/pagseguro/subscription_payment_order/response.rb +37 -0
  60. data/lib/pagseguro/subscription_payment_order/response_serializer.rb +51 -0
  61. data/lib/pagseguro/subscription_plan.rb +69 -0
  62. data/lib/pagseguro/subscription_plan/request_serializer.rb +81 -0
  63. data/lib/pagseguro/subscription_plan/response.rb +36 -0
  64. data/lib/pagseguro/subscription_plan/response_serializer.rb +17 -0
  65. data/lib/pagseguro/subscription_retry.rb +35 -0
  66. data/lib/pagseguro/subscription_retry/response.rb +34 -0
  67. data/lib/pagseguro/subscription_search_payment_orders.rb +131 -0
  68. data/lib/pagseguro/subscription_transaction.rb +29 -0
  69. data/lib/pagseguro/subscription_transactions.rb +5 -0
  70. data/lib/pagseguro/transaction.rb +0 -10
  71. data/lib/pagseguro/transaction/serializer.rb +19 -2
  72. data/lib/pagseguro/transaction_request.rb +26 -1
  73. data/lib/pagseguro/transaction_request/request_serializer.rb +164 -1
  74. data/lib/pagseguro/version.rb +1 -1
  75. data/spec/fixtures/manual_subscription_charger/fail.xml +6 -0
  76. data/spec/fixtures/manual_subscription_charger/success.xml +4 -0
  77. data/spec/fixtures/subscription/fail.xml +6 -0
  78. data/spec/fixtures/subscription/find_success.xml +28 -0
  79. data/spec/fixtures/subscription/search_success.xml +18 -0
  80. data/spec/fixtures/subscription/success.xml +4 -0
  81. data/spec/fixtures/subscription_canceller/fail.xml +6 -0
  82. data/spec/fixtures/subscription_change_payment/fail.xml +7 -0
  83. data/spec/fixtures/subscription_change_status/fail.xml +7 -0
  84. data/spec/fixtures/subscription_discount/fail.xml +6 -0
  85. data/spec/fixtures/subscription_payment_order/success.xml +18 -0
  86. data/spec/fixtures/subscription_plan/fail.xml +6 -0
  87. data/spec/fixtures/subscription_plan/success.xml +4 -0
  88. data/spec/fixtures/subscription_retry/fail.xml +7 -0
  89. data/spec/fixtures/subscription_search_payment_orders/success.xml +43 -0
  90. data/spec/fixtures/transactions/without_status_and_type.xml +71 -0
  91. data/spec/pagseguro/credit_card_transaction_request_spec.rb +1 -1
  92. data/spec/pagseguro/document_spec.rb +15 -0
  93. data/spec/pagseguro/holder_spec.rb +1 -0
  94. data/spec/pagseguro/manual_subscription_charger/request_serializer_spec.rb +79 -0
  95. data/spec/pagseguro/manual_subscription_charger/response_serializer_spec.rb +10 -0
  96. data/spec/pagseguro/manual_subscription_charger/response_spec.rb +65 -0
  97. data/spec/pagseguro/manual_subscription_charger_spec.rb +68 -0
  98. data/spec/pagseguro/payment_request/request_serializer_spec.rb +54 -22
  99. data/spec/pagseguro/receiver_spec.rb +1 -0
  100. data/spec/pagseguro/sender_spec.rb +16 -2
  101. data/spec/pagseguro/subscription/request_serializer_spec.rb +233 -0
  102. data/spec/pagseguro/subscription/response_serializer_spec.rb +46 -0
  103. data/spec/pagseguro/subscription/response_spec.rb +79 -0
  104. data/spec/pagseguro/subscription/subscription_search_spec.rb +154 -0
  105. data/spec/pagseguro/subscription_canceller/response_spec.rb +58 -0
  106. data/spec/pagseguro/subscription_canceller_spec.rb +57 -0
  107. data/spec/pagseguro/subscription_change_payment/request_serializer_spec.rb +150 -0
  108. data/spec/pagseguro/subscription_change_payment/response_spec.rb +41 -0
  109. data/spec/pagseguro/subscription_change_payment_spec.rb +60 -0
  110. data/spec/pagseguro/subscription_change_status/request_serializer_spec.rb +19 -0
  111. data/spec/pagseguro/subscription_change_status/response_spec.rb +41 -0
  112. data/spec/pagseguro/subscription_change_status_spec.rb +53 -0
  113. data/spec/pagseguro/subscription_discount/request_serializer_spec.rb +27 -0
  114. data/spec/pagseguro/subscription_discount/response_spec.rb +58 -0
  115. data/spec/pagseguro/subscription_discount_spec.rb +60 -0
  116. data/spec/pagseguro/subscription_payment_method_spec.rb +10 -0
  117. data/spec/pagseguro/subscription_payment_order/response_serializer_spec.rb +24 -0
  118. data/spec/pagseguro/subscription_payment_order/response_spec.rb +55 -0
  119. data/spec/pagseguro/subscription_payment_order_spec.rb +27 -0
  120. data/spec/pagseguro/subscription_plan/request_serializer_spec.rb +253 -0
  121. data/spec/pagseguro/subscription_plan/response_serializer_spec.rb +10 -0
  122. data/spec/pagseguro/subscription_plan/response_spec.rb +65 -0
  123. data/spec/pagseguro/subscription_plan_spec.rb +118 -0
  124. data/spec/pagseguro/subscription_retry/response_spec.rb +58 -0
  125. data/spec/pagseguro/subscription_retry_spec.rb +62 -0
  126. data/spec/pagseguro/subscription_search_payment_order_spec.rb +129 -0
  127. data/spec/pagseguro/subscription_spec.rb +137 -0
  128. data/spec/pagseguro/subscription_transaction_spec.rb +24 -0
  129. data/spec/pagseguro/subscription_transactions_spec.rb +37 -0
  130. data/spec/pagseguro/transaction/response_spec.rb +0 -42
  131. data/spec/pagseguro/transaction/serializer_spec.rb +5 -6
  132. data/spec/pagseguro/transaction_request/request_serializer_spec.rb +623 -159
  133. data/spec/pagseguro/transaction_request_spec.rb +26 -0
  134. data/spec/pagseguro/transaction_spec.rb +0 -48
  135. data/spec/spec_helper.rb +1 -0
  136. metadata +154 -8
  137. data/examples/checkout/search/search_transaction_status_history.rb +0 -22
  138. data/lib/pagseguro/transaction/status_collection.rb +0 -20
  139. data/spec/fixtures/transactions/status_history.xml +0 -12
  140. data/spec/pagseguro/transaction/status_collection_spec.rb +0 -43
@@ -0,0 +1,58 @@
1
+ require 'spec_helper'
2
+
3
+ RSpec.describe PagSeguro::SubscriptionRetry::Response do
4
+ subject { described_class.new(response, object) }
5
+
6
+ let(:object) { PagSeguro::SubscriptionRetry.new }
7
+
8
+ context '#success?' do
9
+ let(:response) do
10
+ double(:HttpResponse, xml?: true)
11
+ end
12
+
13
+ it 'delegate to response' do
14
+ allow(response).to receive(:success?).and_return(true)
15
+ expect(subject).to be_success
16
+
17
+ allow(response).to receive(:success?).and_return(false)
18
+ expect(subject).not_to be_success
19
+ end
20
+ end
21
+
22
+ describe '#serialize' do
23
+ let(:response) do
24
+ double(:HttpResponse, xml?: true, success?: true)
25
+ end
26
+
27
+ context 'when request succeeds' do
28
+ it 'not change errors' do
29
+ expect { subject.serialize }.not_to change { object.errors.empty? }
30
+ end
31
+ end
32
+
33
+ context 'when request fails' do
34
+ let(:response) do
35
+ double(
36
+ :HttpResponse,
37
+ data: parsed_xml,
38
+ error: Aitch::BadRequestError,
39
+ error?: true,
40
+ success?: false,
41
+ xml?: true
42
+ )
43
+ end
44
+
45
+ let(:raw_xml) do
46
+ File.read('./spec/fixtures/subscription_retry/fail.xml')
47
+ end
48
+
49
+ let(:parsed_xml) do
50
+ Nokogiri::XML(raw_xml)
51
+ end
52
+
53
+ it 'change errors' do
54
+ expect { subject.serialize }.to change { object.errors.empty? }
55
+ end
56
+ end
57
+ end
58
+ end
@@ -0,0 +1,62 @@
1
+ require 'spec_helper'
2
+
3
+ describe PagSeguro::SubscriptionRetry do
4
+ it_assigns_attribute :subscription_code
5
+ it_assigns_attribute :payment_order_code
6
+
7
+ context 'errors attribute' do
8
+ it 'should start with errors' do
9
+ expect(subject.errors).to be_a PagSeguro::Errors
10
+ end
11
+
12
+ it 'should start with empty errors' do
13
+ expect(subject.errors).to be_empty
14
+ end
15
+ end
16
+
17
+ describe '#create' do
18
+ before do
19
+ subject.subscription_code = '1234'
20
+ subject.payment_order_code = '5678'
21
+ subject.credentials = credentials
22
+
23
+ FakeWeb.register_uri(
24
+ :post,
25
+ 'https://ws.pagseguro.uol.com.br/pre-approvals/1234/payment-orders/5678/payment?email=user@example.com&token=TOKEN',
26
+ body: ''
27
+ )
28
+ end
29
+
30
+ let(:credentials) do
31
+ PagSeguro::AccountCredentials.new('user@example.com', 'TOKEN')
32
+ end
33
+
34
+ let(:request) do
35
+ double(
36
+ :Request,
37
+ success?: true,
38
+ xml?: true,
39
+ body: '<paymentResult><transactionCode>1234</transactionCode></paymentResult>'
40
+ )
41
+ end
42
+
43
+ it 'sends it to correct url' do
44
+ expect(PagSeguro).to receive(:api_url).with(
45
+ 'pre-approvals/1234/payment-orders/5678/payment?email=user@example.com&token=TOKEN'
46
+ ).and_return('https://ws.pagseguro.uol.com.br/pre-approvals/1234/payment-orders/5678/payment?email=user@example.com&token=TOKEN')
47
+
48
+ subject.save
49
+ end
50
+
51
+ context 'when parsing' do
52
+ it 'create' do
53
+ expect(PagSeguro::Request).to receive(:post_xml).with(
54
+ 'pre-approvals/1234/payment-orders/5678/payment', nil, credentials, nil,
55
+ { headers: { "Accept" => "application/vnd.pagseguro.com.br.v1+xml;charset=ISO-8859-1" }}
56
+ ).and_return(request)
57
+
58
+ subject.save
59
+ end
60
+ end
61
+ end
62
+ end
@@ -0,0 +1,129 @@
1
+ require 'spec_helper'
2
+
3
+ describe PagSeguro::SubscriptionSearchPaymentOrders do
4
+ let(:credentials) { PagSeguro::AccountCredentials.new('user@example.com', 'TOKEN') }
5
+ let(:status) { :not_processed }
6
+ let(:code) { '12345' }
7
+
8
+ let(:options) { {credentials: credentials} }
9
+
10
+ subject { described_class.new(code, status, options) }
11
+
12
+ context 'when search succeeds' do
13
+ before do
14
+ FakeWeb.register_uri(
15
+ :get,
16
+ 'https://ws.pagseguro.uol.com.br/pre-approvals/12345/payment-orders?status=3&page=1&email=user%40example.com&token=TOKEN&charset=UTF-8',
17
+ content_type: 'text/xml',
18
+ status: 200,
19
+ body: data
20
+ )
21
+
22
+ subject.next_page!
23
+ end
24
+
25
+ let(:data) { File.read('./spec/fixtures/subscription_search_payment_orders/success.xml') }
26
+
27
+ it 'must have results in page' do
28
+ expect(subject.results).to eq 2
29
+ end
30
+
31
+ it 'must have total pages' do
32
+ expect(subject.total_pages).to eq 1
33
+ end
34
+
35
+ it 'must have date of create' do
36
+ expect(subject.created_at).to eq Time.new(2016, 3, 30, 18, 59, 53, '-03:00')
37
+ end
38
+
39
+ context '#payment_orders' do
40
+ it 'must return a array of SubscriptionPaymentOrder' do
41
+ expect(subject.payment_orders).to be_an Array
42
+
43
+ subject.payment_orders.each do |payment_order|
44
+ expect(payment_order).to be_a PagSeguro::SubscriptionPaymentOrder
45
+ end
46
+ end
47
+
48
+ context 'payment order object' do
49
+ let(:order) { subject.payment_orders.first }
50
+
51
+ it { expect(order.code).to eq 'D2579C9461BA45F880419FE535763EFE' }
52
+ it { expect(order.status).to eq :paid }
53
+ it { expect(order.amount).to eq '80.00' }
54
+ it { expect(order.gross_amount).to eq '230' }
55
+ it { expect(order.last_event_date).to eq Time.new(2016,3,30,0,50,11, '-03:00') }
56
+ it { expect(order.discount.type).to eq 'DISCOUNT_PERCENT' }
57
+ it { expect(order.discount.value).to eq '0' }
58
+ it { expect(order.scheduling_date).to eq Time.new(2016,4,14,15,14,29, '-03:00') }
59
+ it { expect(order.transactions.first.code).to eq 'DBFABA621D734DCDA471F592E964A39E' }
60
+ it { expect(order.transactions.first.date).to eq Time.new(2016,3,30,0,48,49, '-03:00') }
61
+ it { expect(order.transactions.first.status).to eq :paid }
62
+ end
63
+ end
64
+ end
65
+
66
+ context 'when search fails' do
67
+ before do
68
+ FakeWeb.register_uri(
69
+ :get,
70
+ 'https://ws.pagseguro.uol.com.br/pre-approvals/12345/payment-orders?status=3&page=1&email=user%40example.com&token=TOKEN&charset=UTF-8',
71
+ content_type: 'text/xml',
72
+ status: 400
73
+ )
74
+
75
+ subject.next_page!
76
+ end
77
+
78
+ it 'must do not be valid' do
79
+ expect(subject).to_not be_valid
80
+ end
81
+
82
+ it 'errors cannot be empty' do
83
+ expect{ subject.valid? }.to change{ subject.errors.empty? }.to false
84
+ end
85
+ end
86
+
87
+ context 'page control' do
88
+ it 'page default should be 1' do
89
+ expect(subject.page).to eq 0
90
+ end
91
+
92
+ it 'search can begin with other page' do
93
+ options[:page] = 2
94
+ expect(subject.page).to eq 2
95
+ end
96
+
97
+ context 'next page' do
98
+ it 'should increment the page by 1' do
99
+ allow(subject).to receive(:total_pages).and_return(10)
100
+ expect{ subject.next_page! }.to change{ subject.page }.from(0).to(1)
101
+ end
102
+
103
+ it 'not increment if no have more pages' do
104
+ subject.next_page!
105
+ allow(subject).to receive(:total_pages).and_return(1)
106
+ expect{ subject.next_page! }.to_not change{ subject.page }
107
+ end
108
+ end
109
+
110
+ context 'previous page' do
111
+ it 'should decrement the page by 1' do
112
+ options[:page] = 3
113
+ expect{ subject.previous_page! }.to change{ subject.page }.from(3).to(2)
114
+ end
115
+
116
+ it 'not decrement unless current page be more than 1' do
117
+ expect{ subject.previous_page! }.not_to change{ subject.page }
118
+ end
119
+ end
120
+
121
+ context 'when page changes' do
122
+ it 'fetched clear! should be called' do
123
+ allow(subject).to receive(:total_pages).and_return(10)
124
+ expect(subject).to receive(:clear!).with(no_args)
125
+ subject.next_page!
126
+ end
127
+ end
128
+ end
129
+ end
@@ -0,0 +1,137 @@
1
+ require 'spec_helper'
2
+
3
+ shared_examples 'Subscription find' do |path|
4
+ let(:base_url) { PagSeguro.root_uri(:api) }
5
+ let(:extended_url) { [base_url, path].join }
6
+
7
+ before do
8
+ FakeWeb.register_uri(
9
+ :get,
10
+ extended_url,
11
+ body: 'OK'
12
+ )
13
+ end
14
+
15
+ it 'must send to correct URL' do
16
+ expect(PagSeguro).
17
+ to receive(:api_url).
18
+ with(path).
19
+ and_return(extended_url)
20
+
21
+ search
22
+ end
23
+
24
+ it 'must to call response and serialize' do
25
+ response = double(:Response)
26
+
27
+ expect(PagSeguro::Subscription::Response).
28
+ to receive(:new).
29
+ with(any_args).
30
+ and_return(response)
31
+
32
+ allow(response).to receive(:serialize)
33
+
34
+ search
35
+ end
36
+
37
+ it 'must return a PagSeguro::Subscription object' do
38
+ expect(search).to be_a PagSeguro::Subscription
39
+ end
40
+ end
41
+
42
+ describe PagSeguro::Subscription do
43
+ it_assigns_attribute :code
44
+ it_assigns_attribute :name
45
+ it_assigns_attribute :date
46
+ it_assigns_attribute :tracker
47
+ it_assigns_attribute :status
48
+ it_assigns_attribute :charge
49
+ it_assigns_attribute :plan
50
+ it_assigns_attribute :reference
51
+ it_assigns_attribute :last_event_date
52
+
53
+ it_ensures_type PagSeguro::Sender, :sender
54
+ it_ensures_type PagSeguro::SubscriptionPaymentMethod, :payment_method
55
+
56
+ context 'errors attribute' do
57
+ it 'should start with errors' do
58
+ expect(subject.errors).to be_a PagSeguro::Errors
59
+ end
60
+
61
+ it 'should start with empty errors' do
62
+ expect(subject.errors).to be_empty
63
+ end
64
+ end
65
+
66
+ context '#create' do
67
+ before do
68
+ subject.credentials = credentials
69
+
70
+ FakeWeb.register_uri(
71
+ :post,
72
+ 'https://ws.pagseguro.uol.com.br/pre-approvals?email=user@example.com&token=TOKEN',
73
+ body: ''
74
+ )
75
+ end
76
+
77
+ let(:credentials) { PagSeguro::AccountCredentials.new('user@example.com', 'TOKEN') }
78
+
79
+ let(:request) do
80
+ double(
81
+ :Request,
82
+ xml?: true,
83
+ success?: true,
84
+ body: '<directPreApproval><code>12345</code></directPreApproval>'
85
+ )
86
+ end
87
+
88
+ it 'sends it to correct url' do
89
+ expect(PagSeguro).
90
+ to receive(:api_url).
91
+ with('pre-approvals?email=user@example.com&token=TOKEN').
92
+ and_return('https://ws.pagseguro.uol.com.br/pre-approvals?email=user@example.com&token=TOKEN')
93
+
94
+ subject.create
95
+ end
96
+
97
+ context 'when parsing' do
98
+ it 'create a subscription' do
99
+ expect(PagSeguro::Request).
100
+ to receive(:post_xml).
101
+ with(
102
+ 'pre-approvals',
103
+ nil,
104
+ credentials,
105
+ a_string_matching(/<directPreApproval>/),
106
+ {:headers=>{"Accept"=>"application/vnd.pagseguro.com.br.v1+xml;charset=ISO-8859-1"}}).
107
+ and_return(request)
108
+
109
+ subject.create
110
+ end
111
+
112
+ it 'update subscription with the new code' do
113
+ allow(PagSeguro::Request).to receive(:post_xml).and_return(request)
114
+ expect { subject.create }.to change { subject.code }.to('12345')
115
+ end
116
+ end
117
+
118
+ context 'find subscriptions' do
119
+ let(:code) { 12345 }
120
+ let(:request) { double(:Request, success?: true, xml?: true, body: '') }
121
+
122
+ context 'by notification code' do
123
+ let(:search) { PagSeguro::Subscription.find_by_notification_code(code, credentials: credentials) }
124
+
125
+ it_behaves_like 'Subscription find',
126
+ 'v2/pre-approvals/notifications/12345?email=user@example.com&token=TOKEN'
127
+ end
128
+
129
+ context 'subscription code' do
130
+ let(:search) { PagSeguro::Subscription.find_by_code(code, credentials: credentials) }
131
+
132
+ it_behaves_like 'Subscription find',
133
+ 'v2/pre-approvals/12345?email=user@example.com&token=TOKEN'
134
+ end
135
+ end
136
+ end
137
+ end
@@ -0,0 +1,24 @@
1
+ require 'spec_helper'
2
+
3
+ describe PagSeguro::SubscriptionTransaction do
4
+ it_assigns_attribute :code
5
+ it_assigns_attribute :status
6
+ it_assigns_attribute :date
7
+
8
+ context '#status_code' do
9
+ before do
10
+ subject.status = :waiting_payment
11
+ end
12
+
13
+ it 'must return the code related' do
14
+ expect(subject.status_code).to eq 1
15
+ end
16
+ end
17
+
18
+ context 'comparison' do
19
+ let(:params) { {code: '1234', status: :paid, date: Time.new(2016,1,1)} }
20
+ subject { described_class.new(params) }
21
+
22
+ it { expect(subject).to eq(PagSeguro::SubscriptionTransaction.new(params)) }
23
+ end
24
+ end
@@ -0,0 +1,37 @@
1
+ require 'spec_helper'
2
+
3
+ describe PagSeguro::SubscriptionTransactions do
4
+ [
5
+ :size,
6
+ :clear,
7
+ :empty?,
8
+ :any?,
9
+ :each,
10
+ :map
11
+ ].each do |method|
12
+ it { is_expected.to respond_to(method) }
13
+ end
14
+
15
+ it 'should initialize empty' do
16
+ expect(subject).to be_empty
17
+ end
18
+
19
+ context 'adding a new transaction' do
20
+ let(:transaction) { { code: '1234' } }
21
+
22
+ it "shouldn't add the same transaction" do
23
+ subject << transaction
24
+ expect{ subject << transaction }.to_not change{ subject.size }
25
+ end
26
+
27
+ context 'ensures type the new transaction' do
28
+ it 'can be a hash' do
29
+ expect{ subject << transaction }.to change{ subject.size }.to(1)
30
+ end
31
+
32
+ it 'can be a PagSeguro::Document' do
33
+ expect{ subject << PagSeguro::SubscriptionTransaction.new(code: '1234') }.to change{ subject.size }.to(1)
34
+ end
35
+ end
36
+ end
37
+ end