catarse_pagarme 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +10 -0
- data/Gemfile +3 -0
- data/Gemfile.lock +120 -0
- data/MIT-LICENSE +20 -0
- data/README.md +35 -0
- data/Rakefile +34 -0
- data/app/assets/images/catarse_pagarme/.keep +0 -0
- data/app/assets/javascripts/catarse_pagarme.js +5 -0
- data/app/assets/javascripts/catarse_pagarme/application.js +12 -0
- data/app/assets/javascripts/catarse_pagarme/credit_card.js +142 -0
- data/app/assets/javascripts/catarse_pagarme/payment_choice.js +22 -0
- data/app/assets/javascripts/catarse_pagarme/payment_slip.js +63 -0
- data/app/assets/stylesheets/catarse_pagarme/application.css +15 -0
- data/app/controllers/catarse_pagarme/application_controller.rb +51 -0
- data/app/controllers/catarse_pagarme/credit_card_base_controller.rb +48 -0
- data/app/controllers/catarse_pagarme/credit_cards_controller.rb +8 -0
- data/app/controllers/catarse_pagarme/notifications_controller.rb +20 -0
- data/app/controllers/catarse_pagarme/pagarme_controller.rb +10 -0
- data/app/controllers/catarse_pagarme/slip_controller.rb +43 -0
- data/app/controllers/catarse_pagarme/subscriptions_controller.rb +27 -0
- data/app/helpers/catarse_pagarme/application_helper.rb +23 -0
- data/app/models/catarse_pagarme/contribution_concern.rb +9 -0
- data/app/models/catarse_pagarme/contribution_delegator.rb +94 -0
- data/app/models/catarse_pagarme/credit_card_concern.rb +9 -0
- data/app/models/catarse_pagarme/credit_card_delegator.rb +26 -0
- data/app/models/catarse_pagarme/credit_card_transaction.rb +11 -0
- data/app/models/catarse_pagarme/payment_type.rb +6 -0
- data/app/models/catarse_pagarme/save_credit_card_transaction.rb +33 -0
- data/app/models/catarse_pagarme/slip_transaction.rb +37 -0
- data/app/models/catarse_pagarme/subscription_transaction.rb +21 -0
- data/app/models/catarse_pagarme/transaction_base.rb +36 -0
- data/app/views/catarse_pagarme/pagarme/review.html.slim +112 -0
- data/app/views/layouts/catarse_pagarme/application.html.erb +14 -0
- data/bin/rails +12 -0
- data/catarse_pagarme.gemspec +26 -0
- data/config/initializers/register.rb +5 -0
- data/config/routes.rb +15 -0
- data/lib/catarse_pagarme.rb +19 -0
- data/lib/catarse_pagarme/configuration.rb +16 -0
- data/lib/catarse_pagarme/engine.rb +10 -0
- data/lib/catarse_pagarme/payment_engine.rb +37 -0
- data/lib/catarse_pagarme/version.rb +3 -0
- data/lib/tasks/catarse_pagarme_tasks.rake +4 -0
- data/spec/controllers/catarse_pagarme/credit_cards_controller_spec.rb +62 -0
- data/spec/controllers/catarse_pagarme/notifications_controller_spec.rb +41 -0
- data/spec/controllers/catarse_pagarme/pagarme_controller_spec.rb +5 -0
- data/spec/controllers/catarse_pagarme/slip_controller_spec.rb +68 -0
- data/spec/controllers/catarse_pagarme/subscriptions_controller_spec.rb +95 -0
- data/spec/dummy/README.rdoc +28 -0
- data/spec/dummy/Rakefile +6 -0
- data/spec/dummy/app/assets/images/.keep +0 -0
- data/spec/dummy/app/assets/javascripts/application.js +13 -0
- data/spec/dummy/app/assets/stylesheets/application.css +15 -0
- data/spec/dummy/app/controllers/application_controller.rb +5 -0
- data/spec/dummy/app/controllers/concerns/.keep +0 -0
- data/spec/dummy/app/helpers/application_helper.rb +2 -0
- data/spec/dummy/app/mailers/.keep +0 -0
- data/spec/dummy/app/models/.keep +0 -0
- data/spec/dummy/app/models/bank_account.rb +5 -0
- data/spec/dummy/app/models/category.rb +2 -0
- data/spec/dummy/app/models/concerns/.keep +0 -0
- data/spec/dummy/app/models/contribution.rb +29 -0
- data/spec/dummy/app/models/credit_card.rb +3 -0
- data/spec/dummy/app/models/payment_engines.rb +2 -0
- data/spec/dummy/app/models/payment_notification.rb +3 -0
- data/spec/dummy/app/models/project.rb +5 -0
- data/spec/dummy/app/models/user.rb +13 -0
- data/spec/dummy/app/models/user_total.rb +3 -0
- data/spec/dummy/app/views/layouts/application.html.erb +14 -0
- data/spec/dummy/bin/bundle +3 -0
- data/spec/dummy/bin/rails +4 -0
- data/spec/dummy/bin/rake +4 -0
- data/spec/dummy/config.ru +4 -0
- data/spec/dummy/config/application.rb +23 -0
- data/spec/dummy/config/boot.rb +5 -0
- data/spec/dummy/config/database.yml +55 -0
- data/spec/dummy/config/environment.rb +5 -0
- data/spec/dummy/config/environments/development.rb +37 -0
- data/spec/dummy/config/environments/production.rb +82 -0
- data/spec/dummy/config/environments/test.rb +39 -0
- data/spec/dummy/config/initializers/assets.rb +8 -0
- data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/spec/dummy/config/initializers/cookies_serializer.rb +3 -0
- data/spec/dummy/config/initializers/filter_parameter_logging.rb +4 -0
- data/spec/dummy/config/initializers/inflections.rb +16 -0
- data/spec/dummy/config/initializers/mime_types.rb +4 -0
- data/spec/dummy/config/initializers/pagarme.rb +6 -0
- data/spec/dummy/config/initializers/session_store.rb +3 -0
- data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
- data/spec/dummy/config/locales/en.yml +23 -0
- data/spec/dummy/config/routes.rb +3 -0
- data/spec/dummy/config/secrets.yml +22 -0
- data/spec/dummy/lib/assets/.keep +0 -0
- data/spec/dummy/public/404.html +67 -0
- data/spec/dummy/public/422.html +67 -0
- data/spec/dummy/public/500.html +66 -0
- data/spec/dummy/public/favicon.ico +0 -0
- data/spec/helpers/catarse_pagarme/application_helper_spec.rb +23 -0
- data/spec/models/catarse_pagarme/contribution_delegator_spec.rb +146 -0
- data/spec/models/catarse_pagarme/credit_card_transaction_spec.rb +70 -0
- data/spec/models/catarse_pagarme/slip_transaction_spec.rb +102 -0
- data/spec/spec_helper.rb +36 -0
- data/spec/support/factories.rb +70 -0
- metadata +280 -0
@@ -0,0 +1,66 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<title>We're sorry, but something went wrong (500)</title>
|
5
|
+
<meta name="viewport" content="width=device-width,initial-scale=1">
|
6
|
+
<style>
|
7
|
+
body {
|
8
|
+
background-color: #EFEFEF;
|
9
|
+
color: #2E2F30;
|
10
|
+
text-align: center;
|
11
|
+
font-family: arial, sans-serif;
|
12
|
+
margin: 0;
|
13
|
+
}
|
14
|
+
|
15
|
+
div.dialog {
|
16
|
+
width: 95%;
|
17
|
+
max-width: 33em;
|
18
|
+
margin: 4em auto 0;
|
19
|
+
}
|
20
|
+
|
21
|
+
div.dialog > div {
|
22
|
+
border: 1px solid #CCC;
|
23
|
+
border-right-color: #999;
|
24
|
+
border-left-color: #999;
|
25
|
+
border-bottom-color: #BBB;
|
26
|
+
border-top: #B00100 solid 4px;
|
27
|
+
border-top-left-radius: 9px;
|
28
|
+
border-top-right-radius: 9px;
|
29
|
+
background-color: white;
|
30
|
+
padding: 7px 12% 0;
|
31
|
+
box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
|
32
|
+
}
|
33
|
+
|
34
|
+
h1 {
|
35
|
+
font-size: 100%;
|
36
|
+
color: #730E15;
|
37
|
+
line-height: 1.5em;
|
38
|
+
}
|
39
|
+
|
40
|
+
div.dialog > p {
|
41
|
+
margin: 0 0 1em;
|
42
|
+
padding: 1em;
|
43
|
+
background-color: #F7F7F7;
|
44
|
+
border: 1px solid #CCC;
|
45
|
+
border-right-color: #999;
|
46
|
+
border-left-color: #999;
|
47
|
+
border-bottom-color: #999;
|
48
|
+
border-bottom-left-radius: 4px;
|
49
|
+
border-bottom-right-radius: 4px;
|
50
|
+
border-top-color: #DADADA;
|
51
|
+
color: #666;
|
52
|
+
box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
|
53
|
+
}
|
54
|
+
</style>
|
55
|
+
</head>
|
56
|
+
|
57
|
+
<body>
|
58
|
+
<!-- This file lives in public/500.html -->
|
59
|
+
<div class="dialog">
|
60
|
+
<div>
|
61
|
+
<h1>We're sorry, but something went wrong.</h1>
|
62
|
+
</div>
|
63
|
+
<p>If you are the application owner check the logs for more information.</p>
|
64
|
+
</div>
|
65
|
+
</body>
|
66
|
+
</html>
|
File without changes
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe CatarsePagarme::ApplicationHelper do
|
4
|
+
before do
|
5
|
+
installments_hash = {"installments"=>{"1"=>{"installment"=>1, "amount"=>10000, "installment_amount"=>10000}, "2"=>{"installment"=>2, "amount"=>10000, "installment_amount"=>5000}, "3"=>{"installment"=>3, "amount"=>10000, "installment_amount"=>3333}, "4"=>{"installment"=>4, "amount"=>10000, "installment_amount"=>2500}, "5"=>{"installment"=>5, "amount"=>10000, "installment_amount"=>2000}, "6"=>{"installment"=>6, "amount"=>10000, "installment_amount"=>1667}, "7"=>{"installment"=>7, "amount"=>10000, "installment_amount"=>1429}, "8"=>{"installment"=>8, "amount"=>10000, "installment_amount"=>1250}, "9"=>{"installment"=>9, "amount"=>10000, "installment_amount"=>1111}, "10"=>{"installment"=>10, "amount"=>10000, "installment_amount"=>1000}, "11"=>{"installment"=>11, "amount"=>10000, "installment_amount"=>909}, "12"=>{"installment"=>12, "amount"=>10000, "installment_amount"=>833}}}
|
6
|
+
PagarMe::Transaction.stub(:calculate_installments).and_return(installments_hash)
|
7
|
+
CatarsePagarme.configuration.stub(:max_installments).and_return(6)
|
8
|
+
end
|
9
|
+
|
10
|
+
let(:contribution) { create(:contribution, value: 100) }
|
11
|
+
|
12
|
+
context "#installments_for_select" do
|
13
|
+
subject { installments_for_select(contribution) }
|
14
|
+
it { expect(subject.size).to eq(6) }
|
15
|
+
it { expect(subject[0][0]).to eq('1x $100.00') }
|
16
|
+
it { expect(subject[0][1]).to eq(1) }
|
17
|
+
end
|
18
|
+
|
19
|
+
context '#format_instalment_text' do
|
20
|
+
subject { format_instalment_text(4, 100.0) }
|
21
|
+
it { expect(subject).to eq('4x $100.00') }
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,146 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe CatarsePagarme::ContributionDelegator do
|
4
|
+
let(:contribution) { create(:contribution, value: 10) }
|
5
|
+
let(:delegator) { contribution.pagarme_delegator }
|
6
|
+
|
7
|
+
context "instance of CatarsePagarme::ContributionDelegator" do
|
8
|
+
it { expect(delegator).to be_a CatarsePagarme::ContributionDelegator }
|
9
|
+
end
|
10
|
+
|
11
|
+
context "#value_for_transaction" do
|
12
|
+
subject { delegator.value_for_transaction }
|
13
|
+
|
14
|
+
it "should convert contribution value to pagarme value format" do
|
15
|
+
expect(subject).to eq(1000)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
context "#value_with_installment_tax" do
|
20
|
+
let(:installment) { 5 }
|
21
|
+
subject { delegator.value_with_installment_tax(installment)}
|
22
|
+
|
23
|
+
before do
|
24
|
+
CatarsePagarme.configuration.stub(:interest_rate).and_return(1.8)
|
25
|
+
end
|
26
|
+
|
27
|
+
it "should return the contribution value with installments tax" do
|
28
|
+
expect(subject).to eq(1057)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
context "#get_fee" do
|
33
|
+
before do
|
34
|
+
CatarsePagarme.configuration.stub(:slip_tax).and_return(2.00)
|
35
|
+
CatarsePagarme.configuration.stub(:credit_card_tax).and_return(0.01)
|
36
|
+
end
|
37
|
+
|
38
|
+
context 'when choice is slip' do
|
39
|
+
subject { delegator.get_fee(CatarsePagarme::PaymentType::SLIP).to_f }
|
40
|
+
it { expect(subject).to eq(2.00) }
|
41
|
+
end
|
42
|
+
|
43
|
+
context 'when choice is credit card' do
|
44
|
+
subject { delegator.get_fee(CatarsePagarme::PaymentType::CREDIT_CARD).to_f }
|
45
|
+
it { expect(subject).to eq(0.49) }
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
context "#get_installments" do
|
50
|
+
before do
|
51
|
+
delegator.stub(:value_for_transaction).and_return(10000)
|
52
|
+
end
|
53
|
+
subject { delegator.get_installments }
|
54
|
+
|
55
|
+
it { expect(subject['installments'].size).to eq(12) }
|
56
|
+
it { expect(subject['installments']['2']['installment_amount']).to eq(5000) }
|
57
|
+
end
|
58
|
+
|
59
|
+
context "#change_status_by_transaction" do
|
60
|
+
|
61
|
+
%w(paid authorized).each do |status|
|
62
|
+
context "when status is #{status}" do
|
63
|
+
context "and contribution is already confirmed" do
|
64
|
+
before do
|
65
|
+
contribution.stub(:confirmed?).and_return(true)
|
66
|
+
contribution.should_not_receive(:confirm)
|
67
|
+
end
|
68
|
+
|
69
|
+
it { delegator.change_status_by_transaction(status) }
|
70
|
+
end
|
71
|
+
|
72
|
+
context "and contribution is not confirmed" do
|
73
|
+
before do
|
74
|
+
contribution.stub(:confirmed?).and_return(false)
|
75
|
+
contribution.should_receive(:confirm)
|
76
|
+
end
|
77
|
+
|
78
|
+
it { delegator.change_status_by_transaction(status) }
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
%w(waiting_payment processing).each do |status|
|
84
|
+
context "when status is #{status}" do
|
85
|
+
context "and contribution is already waiting confirmation" do
|
86
|
+
before do
|
87
|
+
contribution.stub(:waiting_confirmation?).and_return(true)
|
88
|
+
contribution.should_not_receive(:waiting)
|
89
|
+
end
|
90
|
+
|
91
|
+
it { delegator.change_status_by_transaction(status) }
|
92
|
+
end
|
93
|
+
|
94
|
+
context "and contribution is pending" do
|
95
|
+
before do
|
96
|
+
contribution.stub(:waiting_confirmation?).and_return(false)
|
97
|
+
contribution.should_receive(:waiting)
|
98
|
+
end
|
99
|
+
|
100
|
+
it { delegator.change_status_by_transaction(status) }
|
101
|
+
end
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
105
|
+
context "when status is refunded" do
|
106
|
+
context "and contribution is already refunded" do
|
107
|
+
before do
|
108
|
+
contribution.stub(:refunded?).and_return(true)
|
109
|
+
contribution.should_not_receive(:refund)
|
110
|
+
end
|
111
|
+
|
112
|
+
it { delegator.change_status_by_transaction('refunded') }
|
113
|
+
end
|
114
|
+
|
115
|
+
context "and contribution is not refunded" do
|
116
|
+
before do
|
117
|
+
contribution.stub(:refunded?).and_return(false)
|
118
|
+
contribution.should_receive(:refund)
|
119
|
+
end
|
120
|
+
|
121
|
+
it { delegator.change_status_by_transaction('refunded') }
|
122
|
+
end
|
123
|
+
end
|
124
|
+
|
125
|
+
context "when status is refused" do
|
126
|
+
context "and contribution is already canceled" do
|
127
|
+
before do
|
128
|
+
contribution.stub(:canceled?).and_return(true)
|
129
|
+
contribution.should_not_receive(:cancel)
|
130
|
+
end
|
131
|
+
|
132
|
+
it { delegator.change_status_by_transaction('refused') }
|
133
|
+
end
|
134
|
+
|
135
|
+
context "and contribution is not canceled" do
|
136
|
+
before do
|
137
|
+
contribution.stub(:canceled?).and_return(false)
|
138
|
+
contribution.should_receive(:cancel)
|
139
|
+
end
|
140
|
+
|
141
|
+
it { delegator.change_status_by_transaction('refused') }
|
142
|
+
end
|
143
|
+
end
|
144
|
+
|
145
|
+
end
|
146
|
+
end
|
@@ -0,0 +1,70 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe CatarsePagarme::CreditCardTransaction do
|
4
|
+
let(:contribution) { create(:contribution, value: 100) }
|
5
|
+
|
6
|
+
let(:pagarme_transaction) {
|
7
|
+
transaction = double
|
8
|
+
transaction.stub(:id).and_return('abcd')
|
9
|
+
transaction.stub(:charge).and_return(true)
|
10
|
+
transaction.stub(:status).and_return('paid')
|
11
|
+
transaction.stub(:boleto_url).and_return(nil)
|
12
|
+
transaction.stub(:installments).and_return(3)
|
13
|
+
transaction
|
14
|
+
}
|
15
|
+
|
16
|
+
let(:valid_attributes) do
|
17
|
+
{
|
18
|
+
payment_method: 'credit_card',
|
19
|
+
card_number: '4901720080344448',
|
20
|
+
card_holder_name: 'Foo bar',
|
21
|
+
card_expiration_month: '10',
|
22
|
+
card_expiration_year: '19',
|
23
|
+
card_cvv: '434',
|
24
|
+
amount: contribution.pagarme_delegator.value_for_transaction,
|
25
|
+
postback_url: 'http://test.foo',
|
26
|
+
installments: 1
|
27
|
+
}
|
28
|
+
end
|
29
|
+
|
30
|
+
let(:card_transaction) { CatarsePagarme::CreditCardTransaction.new(valid_attributes, contribution) }
|
31
|
+
|
32
|
+
before do
|
33
|
+
PagarMe::Transaction.stub(:new).and_return(pagarme_transaction)
|
34
|
+
CatarsePagarme::ContributionDelegator.any_instance.stub(:change_status_by_transaction).and_return(true)
|
35
|
+
CatarsePagarme.configuration.stub(:credit_card_tax).and_return(0.01)
|
36
|
+
end
|
37
|
+
|
38
|
+
describe '#charge!' do
|
39
|
+
describe 'with valid attributes' do
|
40
|
+
before do
|
41
|
+
contribution.should_receive(:update_attributes).and_call_original
|
42
|
+
CatarsePagarme::ContributionDelegator.any_instance.should_receive(:change_status_by_transaction).with('paid')
|
43
|
+
|
44
|
+
card_transaction.charge!
|
45
|
+
contribution.reload
|
46
|
+
end
|
47
|
+
|
48
|
+
it "should update contribution payment_id" do
|
49
|
+
expect(contribution.payment_id).to eq('abcd')
|
50
|
+
end
|
51
|
+
|
52
|
+
it "should update contribution payment_service_fee" do
|
53
|
+
expect(contribution.payment_service_fee.to_f).to eq(1.39)
|
54
|
+
end
|
55
|
+
|
56
|
+
it "should update contribution payment_method" do
|
57
|
+
expect(contribution.payment_method).to eq('Pagarme')
|
58
|
+
end
|
59
|
+
|
60
|
+
it "should update contribution installments" do
|
61
|
+
expect(contribution.installments).to eq(3)
|
62
|
+
end
|
63
|
+
|
64
|
+
it "should update contribution payment_choice" do
|
65
|
+
expect(contribution.payment_choice).to eq(CatarsePagarme::PaymentType::CREDIT_CARD)
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
end
|
@@ -0,0 +1,102 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe CatarsePagarme::SlipTransaction do
|
4
|
+
let(:contribution) { create(:contribution, value: 100) }
|
5
|
+
let(:pagarme_transaction) {
|
6
|
+
transaction = double
|
7
|
+
transaction.stub(:id).and_return('abcd')
|
8
|
+
transaction.stub(:charge).and_return(true)
|
9
|
+
transaction.stub(:status).and_return('paid')
|
10
|
+
transaction.stub(:boleto_url).and_return('boleto url')
|
11
|
+
transaction.stub(:installments).and_return(nil)
|
12
|
+
transaction
|
13
|
+
}
|
14
|
+
let(:valid_attributes) do
|
15
|
+
{
|
16
|
+
slip_payment: {
|
17
|
+
payment_method: 'boleto',
|
18
|
+
amount: contribution.pagarme_delegator.value_for_transaction,
|
19
|
+
postback_url: 'http://test.foo'
|
20
|
+
}, user: {
|
21
|
+
bank_account_attributes: {
|
22
|
+
name: 'foo', agency: '1', agency_digit: '1',
|
23
|
+
account: '1', account_digit: '1', owner_name: 'foo',
|
24
|
+
owner_document: 'bar'
|
25
|
+
}
|
26
|
+
}
|
27
|
+
}
|
28
|
+
end
|
29
|
+
|
30
|
+
let(:invalid_attributes) do
|
31
|
+
{
|
32
|
+
slip_payment: {
|
33
|
+
payment_method: 'boleto',
|
34
|
+
amount: contribution.pagarme_delegator.value_for_transaction,
|
35
|
+
postback_url: 'http://test.foo'
|
36
|
+
}, user: {
|
37
|
+
bank_account_attributes: {
|
38
|
+
name: ''
|
39
|
+
}
|
40
|
+
}
|
41
|
+
}
|
42
|
+
end
|
43
|
+
|
44
|
+
let(:slip_transaction) { CatarsePagarme::SlipTransaction.new(valid_attributes, contribution) }
|
45
|
+
|
46
|
+
before do
|
47
|
+
PagarMe::Transaction.stub(:new).and_return(pagarme_transaction)
|
48
|
+
CatarsePagarme::ContributionDelegator.any_instance.stub(:change_status_by_transaction).and_return(true)
|
49
|
+
end
|
50
|
+
|
51
|
+
context "#user" do
|
52
|
+
subject { slip_transaction.user }
|
53
|
+
it { expect(subject).to eq(contribution.user) }
|
54
|
+
end
|
55
|
+
|
56
|
+
context "#charge!" do
|
57
|
+
context "with invalid attributes" do
|
58
|
+
let(:slip_transaction) {
|
59
|
+
CatarsePagarme::SlipTransaction.new(invalid_attributes, contribution)
|
60
|
+
}
|
61
|
+
|
62
|
+
it "should raises an error" do
|
63
|
+
expect {
|
64
|
+
slip_transaction.charge!
|
65
|
+
}.to raise_error(PagarMe::PagarMeError)
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
context "with valid attributes" do
|
70
|
+
before do
|
71
|
+
slip_transaction.should_receive(:update_user_bank_account).and_call_original
|
72
|
+
slip_transaction.user.should_receive(:update_attributes).and_return(true)
|
73
|
+
contribution.should_receive(:update_attributes).and_call_original
|
74
|
+
CatarsePagarme::ContributionDelegator.any_instance.should_receive(:change_status_by_transaction).with('paid')
|
75
|
+
|
76
|
+
slip_transaction.charge!
|
77
|
+
contribution.reload
|
78
|
+
end
|
79
|
+
|
80
|
+
it "should update contribution payment_id" do
|
81
|
+
expect(contribution.payment_id).to eq('abcd')
|
82
|
+
end
|
83
|
+
|
84
|
+
it "should update contribution payment_service_fee" do
|
85
|
+
expect(contribution.payment_service_fee).to eq(0.0)
|
86
|
+
end
|
87
|
+
|
88
|
+
it "should update contribution payment_method" do
|
89
|
+
expect(contribution.payment_method).to eq('Pagarme')
|
90
|
+
end
|
91
|
+
|
92
|
+
it "should update contribution slip_url" do
|
93
|
+
expect(contribution.slip_url).to eq('boleto url')
|
94
|
+
end
|
95
|
+
|
96
|
+
it "should update contribution payment_choice" do
|
97
|
+
expect(contribution.payment_choice).to eq(CatarsePagarme::PaymentType::SLIP)
|
98
|
+
end
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
# This file is copied to spec/ when you run 'rails generate rspec:install'
|
2
|
+
ENV["RAILS_ENV"] ||= 'test'
|
3
|
+
|
4
|
+
require File.expand_path("../dummy/config/environment", __FILE__)
|
5
|
+
|
6
|
+
require 'pagarme'
|
7
|
+
require 'rspec/rails'
|
8
|
+
require 'factory_girl'
|
9
|
+
# Requires supporting ruby files with custom matchers and macros, etc,
|
10
|
+
# in spec/support/ and its subdirectories.
|
11
|
+
Dir[ File.expand_path("../support/**/*.rb", __FILE__)].each {|f| require f}
|
12
|
+
|
13
|
+
RSpec.configure do |config|
|
14
|
+
config.include FactoryGirl::Syntax::Methods
|
15
|
+
config.use_transactional_examples = true
|
16
|
+
|
17
|
+
# If true, the base class of anonymous controllers will be inferred
|
18
|
+
# automatically. This will be the default behavior in future versions of
|
19
|
+
# rspec-rails.
|
20
|
+
config.infer_base_class_for_anonymous_controllers = false
|
21
|
+
|
22
|
+
# Run specs in random order to surface order dependencies. If you find an
|
23
|
+
# order dependency and want to debug it, you can fix the order by providing
|
24
|
+
# the seed, which is printed after each run.
|
25
|
+
# --seed 1234
|
26
|
+
config.order = "random"
|
27
|
+
|
28
|
+
config.expect_with :rspec do |c|
|
29
|
+
c.syntax = :expect
|
30
|
+
end
|
31
|
+
|
32
|
+
config.before(:each) do
|
33
|
+
PagarMe.stub(:api_key).and_return('ak_test_Rw4JR98FmYST2ngEHtMvVf5QJW7Eoo')
|
34
|
+
PaymentEngines.stub(:configuration).and_return({})
|
35
|
+
end
|
36
|
+
end
|