fake_braintree 0.4.3 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +1 -0
- data/Gemfile +3 -5
- data/LICENSE +1 -1
- data/NEWS.md +9 -0
- data/README.md +19 -25
- data/Rakefile +1 -1
- data/fake_braintree.gemspec +4 -6
- data/lib/fake_braintree/address.rb +8 -8
- data/lib/fake_braintree/credit_card.rb +51 -26
- data/lib/fake_braintree/helpers.rb +2 -2
- data/lib/fake_braintree/sinatra_app.rb +4 -3
- data/lib/fake_braintree/version.rb +1 -1
- data/spec/fake_braintree/address_spec.rb +8 -3
- data/spec/fake_braintree/credit_card_spec.rb +26 -22
- data/spec/fake_braintree/customer_spec.rb +20 -20
- data/spec/fake_braintree/registry_spec.rb +2 -2
- data/spec/fake_braintree/subscription_spec.rb +20 -19
- data/spec/fake_braintree/transaction_spec.rb +30 -13
- data/spec/fake_braintree/transparent_redirect_spec.rb +11 -11
- data/spec/fake_braintree_spec.rb +22 -24
- data/spec/spec_helper.rb +7 -10
- data/spec/support/braintree_logging.rb +7 -0
- data/spec/support/matchers/clear_hash_when_cleared.rb +1 -1
- data/spec/support/matchers/have_accessor_for.rb +1 -1
- metadata +20 -46
@@ -10,7 +10,7 @@ describe 'Braintree::Customer.create' do
|
|
10
10
|
expiration_date: '04/2016'
|
11
11
|
}
|
12
12
|
)
|
13
|
-
result.
|
13
|
+
expect(result).to be_success
|
14
14
|
end
|
15
15
|
|
16
16
|
it 'associates a created credit card with the customer' do
|
@@ -21,8 +21,8 @@ describe 'Braintree::Customer.create' do
|
|
21
21
|
}
|
22
22
|
)
|
23
23
|
credit_cards = Braintree::Customer.find(result.customer.id).credit_cards
|
24
|
-
credit_cards.size.
|
25
|
-
credit_cards.first.expiration_date.
|
24
|
+
expect(credit_cards.size).to eq 1
|
25
|
+
expect(credit_cards.first.expiration_date).to eq '04/2016'
|
26
26
|
end
|
27
27
|
|
28
28
|
it "successfully creates the customer's credit card" do
|
@@ -34,7 +34,7 @@ describe 'Braintree::Customer.create' do
|
|
34
34
|
)
|
35
35
|
|
36
36
|
cc_token = result.customer.credit_cards.first.token
|
37
|
-
expect { Braintree::CreditCard.find(cc_token) }.not_to raise_error
|
37
|
+
expect { Braintree::CreditCard.find(cc_token) }.not_to raise_error
|
38
38
|
end
|
39
39
|
|
40
40
|
it "sets a default credit card for the customer" do
|
@@ -46,18 +46,18 @@ describe 'Braintree::Customer.create' do
|
|
46
46
|
)
|
47
47
|
|
48
48
|
credit_cards = Braintree::Customer.find(result.customer.id).credit_cards
|
49
|
-
credit_cards.first.
|
49
|
+
expect(credit_cards.first).to be_default
|
50
50
|
end
|
51
51
|
|
52
52
|
it 'can handle an empty credit card hash' do
|
53
53
|
result = Braintree::Customer.create(credit_card: {})
|
54
|
-
result.
|
54
|
+
expect(result).to be_success
|
55
55
|
end
|
56
56
|
|
57
57
|
it 'does not overwrite a passed customer id' do
|
58
58
|
result = Braintree::Customer.create({ 'id' => '123' })
|
59
59
|
|
60
|
-
result.customer.id.
|
60
|
+
expect(result.customer.id).to eq('123')
|
61
61
|
end
|
62
62
|
|
63
63
|
it 'creates a customer using an expiration month and year' do
|
@@ -68,7 +68,7 @@ describe 'Braintree::Customer.create' do
|
|
68
68
|
expiration_year: '2016'
|
69
69
|
}
|
70
70
|
)
|
71
|
-
result.
|
71
|
+
expect(result).to be_success
|
72
72
|
end
|
73
73
|
|
74
74
|
it 'records the billing address' do
|
@@ -85,18 +85,18 @@ describe 'Braintree::Customer.create' do
|
|
85
85
|
|
86
86
|
billing_address = result.customer.credit_cards[0].billing_address
|
87
87
|
|
88
|
-
billing_address.street_address.
|
89
|
-
billing_address.postal_code.
|
88
|
+
expect(billing_address.street_address).to eq '1 E Main St'
|
89
|
+
expect(billing_address.postal_code).to eq '60622'
|
90
90
|
end
|
91
91
|
end
|
92
92
|
|
93
93
|
describe 'Braintree::Customer.create', 'when passed verify_card: true' do
|
94
94
|
it 'accepts valid cards' do
|
95
|
-
create_customer(options: { verify_card: true }).
|
95
|
+
expect(create_customer(options: { verify_card: true })).to be_success
|
96
96
|
end
|
97
97
|
|
98
98
|
it 'rejects invalid cards' do
|
99
|
-
create_customer_with_invalid_card(options: { verify_card: true }).
|
99
|
+
expect(create_customer_with_invalid_card(options: { verify_card: true })).to_not be_success
|
100
100
|
end
|
101
101
|
end
|
102
102
|
|
@@ -104,11 +104,11 @@ describe 'Braintree::Customer.create', 'when FakeBraintree.verify_all_cards == t
|
|
104
104
|
before { FakeBraintree.verify_all_cards! }
|
105
105
|
|
106
106
|
it 'accepts valid cards' do
|
107
|
-
create_customer.
|
107
|
+
expect(create_customer).to be_success
|
108
108
|
end
|
109
109
|
|
110
110
|
it 'rejects invalid cards' do
|
111
|
-
create_customer_with_invalid_card.
|
111
|
+
expect(create_customer_with_invalid_card).to_not be_success
|
112
112
|
end
|
113
113
|
end
|
114
114
|
|
@@ -119,11 +119,11 @@ describe 'Braintree::Customer.find' do
|
|
119
119
|
last_name: 'Smith'
|
120
120
|
)
|
121
121
|
|
122
|
-
Braintree::Customer.find(result.customer.id).first_name.
|
122
|
+
expect(Braintree::Customer.find(result.customer.id).first_name).to eq 'Bob'
|
123
123
|
end
|
124
124
|
|
125
125
|
it 'raises an error for a nonexistent customer' do
|
126
|
-
lambda { Braintree::Customer.find('foo') }.
|
126
|
+
expect(lambda { Braintree::Customer.find('foo') }).to raise_error(Braintree::NotFoundError)
|
127
127
|
end
|
128
128
|
end
|
129
129
|
|
@@ -132,8 +132,8 @@ describe 'Braintree::Customer.update' do
|
|
132
132
|
customer_id = create_customer.customer.id
|
133
133
|
result = Braintree::Customer.update(customer_id, first_name: 'Jerry')
|
134
134
|
|
135
|
-
result.
|
136
|
-
Braintree::Customer.find(customer_id).first_name.
|
135
|
+
expect(result).to be_success
|
136
|
+
expect(Braintree::Customer.find(customer_id).first_name).to eq 'Jerry'
|
137
137
|
end
|
138
138
|
|
139
139
|
it 'raises an error for a nonexistent customer' do
|
@@ -148,7 +148,7 @@ describe 'Braintree::Customer.update' do
|
|
148
148
|
result = Braintree::Customer.update(customer.customer.id,
|
149
149
|
credit_card: { number: bad_credit_card }
|
150
150
|
)
|
151
|
-
result.
|
151
|
+
expect(result).to_not be_success
|
152
152
|
end
|
153
153
|
end
|
154
154
|
|
@@ -157,7 +157,7 @@ describe 'Braintree::Customer.delete' do
|
|
157
157
|
customer_id = create_customer.customer.id
|
158
158
|
result = Braintree::Customer.delete(customer_id)
|
159
159
|
|
160
|
-
result.
|
160
|
+
expect(result).to be_success
|
161
161
|
expect { Braintree::Customer.find(customer_id) }.to raise_error(Braintree::NotFoundError)
|
162
162
|
end
|
163
163
|
end
|
@@ -20,12 +20,12 @@ end
|
|
20
20
|
|
21
21
|
describe FakeBraintree::Registry, '#failure?' do
|
22
22
|
it 'returns false if the given CC number is not marked as a failure' do
|
23
|
-
FakeBraintree::Registry.new.failure?('not-a-failure').
|
23
|
+
expect(FakeBraintree::Registry.new.failure?('not-a-failure')).to be_false
|
24
24
|
end
|
25
25
|
|
26
26
|
it 'returns true if the given CC number is marked as a failure' do
|
27
27
|
registry = FakeBraintree::Registry.new
|
28
28
|
registry.failures['abc123'] = 'whatever'
|
29
|
-
registry.failure?('abc123').
|
29
|
+
expect(registry.failure?('abc123')).to be_true
|
30
30
|
end
|
31
31
|
end
|
@@ -5,18 +5,20 @@ describe 'Braintree::Subscription.create' do
|
|
5
5
|
let(:expiration_date) { '04/2016' }
|
6
6
|
|
7
7
|
it 'successfully creates a subscription' do
|
8
|
-
Braintree::Subscription.create(
|
8
|
+
subscription_result = Braintree::Subscription.create(
|
9
9
|
payment_method_token: cc_token,
|
10
10
|
plan_id: 'my_plan_id'
|
11
|
-
)
|
11
|
+
)
|
12
|
+
|
13
|
+
expect(subscription_result).to be_success
|
12
14
|
end
|
13
15
|
|
14
16
|
it 'assigns a Braintree-esque ID to the subscription' do
|
15
|
-
create_subscription.subscription.id.
|
17
|
+
expect(create_subscription.subscription.id).to match /^[a-z0-9]{6}$/
|
16
18
|
end
|
17
19
|
|
18
20
|
it 'supports custom IDs' do
|
19
|
-
create_subscription('id' => 'custom1').subscription.id.
|
21
|
+
expect(create_subscription('id' => 'custom1').subscription.id).to eq 'custom1'
|
20
22
|
end
|
21
23
|
|
22
24
|
it 'assigns unique IDs to each subscription' do
|
@@ -31,16 +33,16 @@ describe 'Braintree::Subscription.create' do
|
|
31
33
|
plan_id: plan_id
|
32
34
|
)
|
33
35
|
|
34
|
-
first_result.subscription.id.
|
36
|
+
expect(first_result.subscription.id).not_to eq second_result.subscription.id
|
35
37
|
end
|
36
38
|
|
37
39
|
it 'stores created subscriptions in FakeBraintree.registry.subscriptions' do
|
38
|
-
FakeBraintree.registry.subscriptions[create_subscription.subscription.id].
|
40
|
+
expect(FakeBraintree.registry.subscriptions[create_subscription.subscription.id]).not_to be_nil
|
39
41
|
end
|
40
42
|
|
41
43
|
it 'sets the next billing date to a string of 1.month.from_now in UTC' do
|
42
44
|
Timecop.freeze do
|
43
|
-
create_subscription.subscription.next_billing_date.
|
45
|
+
expect(create_subscription.subscription.next_billing_date).to eq 1.month.from_now.strftime('%Y-%m-%d')
|
44
46
|
end
|
45
47
|
end
|
46
48
|
end
|
@@ -54,9 +56,9 @@ describe 'Braintree::Subscription.find' do
|
|
54
56
|
plan_id: plan_id
|
55
57
|
).subscription.id
|
56
58
|
subscription = Braintree::Subscription.find(subscription_id)
|
57
|
-
subscription.
|
58
|
-
subscription.payment_method_token.
|
59
|
-
subscription.plan_id.
|
59
|
+
expect(subscription).to_not be_nil
|
60
|
+
expect(subscription.payment_method_token).to eq payment_method_token
|
61
|
+
expect(subscription.plan_id).to eq plan_id
|
60
62
|
end
|
61
63
|
|
62
64
|
it 'raises a Braintree:NotFoundError when it cannot find a subscription' do
|
@@ -69,8 +71,8 @@ describe 'Braintree::Subscription.find' do
|
|
69
71
|
subscription_id = create_subscription(add_ons: { add: [{ inherited_from_id: add_on_id }] }).subscription.id
|
70
72
|
subscription = Braintree::Subscription.find(subscription_id)
|
71
73
|
add_ons = subscription.add_ons
|
72
|
-
add_ons.size.
|
73
|
-
add_ons.first.id.
|
74
|
+
expect(add_ons.size).to eq 1
|
75
|
+
expect(add_ons.first.id).to eq add_on_id
|
74
76
|
end
|
75
77
|
|
76
78
|
it 'returns discounts added with the subscription' do
|
@@ -78,8 +80,8 @@ describe 'Braintree::Subscription.find' do
|
|
78
80
|
subscription_id = create_subscription(discounts: { add: [{ inherited_from_id: discount_id, amount: BigDecimal.new('15.00') }]}).subscription.id
|
79
81
|
subscription = Braintree::Subscription.find(subscription_id)
|
80
82
|
discounts = subscription.discounts
|
81
|
-
discounts.size.
|
82
|
-
discounts.first.id.
|
83
|
+
expect(discounts.size).to eq 1
|
84
|
+
expect(discounts.first.id).to eq discount_id
|
83
85
|
end
|
84
86
|
end
|
85
87
|
|
@@ -88,7 +90,7 @@ describe 'Braintree::Subscription.update' do
|
|
88
90
|
subscription_id = create_subscription.subscription.id
|
89
91
|
|
90
92
|
Braintree::Subscription.update(subscription_id, plan_id: 'a_new_plan')
|
91
|
-
Braintree::Subscription.find(subscription_id).plan_id.
|
93
|
+
expect(Braintree::Subscription.find(subscription_id).plan_id).to eq 'a_new_plan'
|
92
94
|
end
|
93
95
|
end
|
94
96
|
|
@@ -100,17 +102,16 @@ describe 'Braintree::Subscription.retry_charge' do
|
|
100
102
|
result = Braintree::Transaction.submit_for_settlement(
|
101
103
|
authorized_transaction.id
|
102
104
|
)
|
103
|
-
result.
|
105
|
+
expect(result).to be_success
|
104
106
|
end
|
105
107
|
end
|
106
108
|
|
107
|
-
|
108
109
|
describe 'Braintree::Subscription.cancel' do
|
109
110
|
it 'can cancel a subscription' do
|
110
111
|
subscription_id = create_subscription.subscription.id
|
111
112
|
|
112
|
-
Braintree::Subscription.cancel(subscription_id).
|
113
|
-
Braintree::Subscription.find(subscription_id).status.
|
113
|
+
expect(Braintree::Subscription.cancel(subscription_id)).to be_success
|
114
|
+
expect(Braintree::Subscription.find(subscription_id).status).to eq Braintree::Subscription::Status::Canceled
|
114
115
|
end
|
115
116
|
|
116
117
|
it 'cannot cancel an unknown subscription' do
|
@@ -7,8 +7,8 @@ describe FakeBraintree::SinatraApp do
|
|
7
7
|
payment_method_token: cc_token,
|
8
8
|
amount: 10.00
|
9
9
|
)
|
10
|
-
result.
|
11
|
-
result.transaction.type.
|
10
|
+
expect(result).to be_success
|
11
|
+
expect(result.transaction.type).to eq 'sale'
|
12
12
|
end
|
13
13
|
|
14
14
|
context 'when all cards are declined' do
|
@@ -19,14 +19,14 @@ describe FakeBraintree::SinatraApp do
|
|
19
19
|
payment_method_token: cc_token,
|
20
20
|
amount: 10.00
|
21
21
|
)
|
22
|
-
result.
|
22
|
+
expect(result).to_not be_success
|
23
23
|
end
|
24
24
|
end
|
25
25
|
|
26
26
|
context "when the options hash is nil" do
|
27
27
|
it "returns a transaction with a status of authorized" do
|
28
28
|
result = Braintree::Transaction.sale(payment_method_token: cc_token, amount: 10.00)
|
29
|
-
result.transaction.status.
|
29
|
+
expect(result.transaction.status).to eq 'authorized'
|
30
30
|
end
|
31
31
|
end
|
32
32
|
|
@@ -39,7 +39,7 @@ describe FakeBraintree::SinatraApp do
|
|
39
39
|
submit_for_settlement: false
|
40
40
|
}
|
41
41
|
)
|
42
|
-
result.transaction.status.
|
42
|
+
expect(result.transaction.status).to eq 'authorized'
|
43
43
|
end
|
44
44
|
end
|
45
45
|
|
@@ -52,7 +52,7 @@ describe FakeBraintree::SinatraApp do
|
|
52
52
|
add_billing_address_to_payment_method: true
|
53
53
|
}
|
54
54
|
)
|
55
|
-
result.transaction.status.
|
55
|
+
expect(result.transaction.status).to eq 'authorized'
|
56
56
|
end
|
57
57
|
end
|
58
58
|
|
@@ -65,7 +65,7 @@ describe FakeBraintree::SinatraApp do
|
|
65
65
|
submit_for_settlement: true
|
66
66
|
}
|
67
67
|
)
|
68
|
-
result.transaction.status.
|
68
|
+
expect(result.transaction.status).to eq 'submitted_for_settlement'
|
69
69
|
end
|
70
70
|
end
|
71
71
|
end
|
@@ -75,7 +75,7 @@ describe FakeBraintree::SinatraApp do
|
|
75
75
|
context 'Braintree::Transaction.refund' do
|
76
76
|
it 'successfully refunds a transaction' do
|
77
77
|
result = Braintree::Transaction.refund(create_id('foobar'), '1')
|
78
|
-
result.
|
78
|
+
expect(result).to be_success
|
79
79
|
end
|
80
80
|
end
|
81
81
|
end
|
@@ -88,8 +88,8 @@ describe FakeBraintree::SinatraApp do
|
|
88
88
|
amount: 10.00
|
89
89
|
)
|
90
90
|
result = Braintree::Transaction.void(sale.transaction.id)
|
91
|
-
result.
|
92
|
-
result.transaction.status.
|
91
|
+
expect(result).to be_success
|
92
|
+
expect(result.transaction.status).to eq Braintree::Transaction::Status::Voided
|
93
93
|
end
|
94
94
|
end
|
95
95
|
end
|
@@ -99,12 +99,12 @@ describe FakeBraintree::SinatraApp do
|
|
99
99
|
it 'can find a created sale' do
|
100
100
|
id = create_transaction(10.00).id
|
101
101
|
result = Braintree::Transaction.find(id)
|
102
|
-
result.amount.
|
102
|
+
expect(result.amount).to eq 10.00
|
103
103
|
end
|
104
104
|
|
105
105
|
it 'can find >1 transaction' do
|
106
|
-
Braintree::Transaction.find(create_transaction.id).
|
107
|
-
Braintree::Transaction.find(create_transaction.id).
|
106
|
+
expect(Braintree::Transaction.find(create_transaction.id)).to be
|
107
|
+
expect(Braintree::Transaction.find(create_transaction.id)).to be
|
108
108
|
end
|
109
109
|
|
110
110
|
it 'raises an error when the transaction does not exist' do
|
@@ -119,3 +119,20 @@ describe FakeBraintree::SinatraApp do
|
|
119
119
|
end
|
120
120
|
end
|
121
121
|
end
|
122
|
+
|
123
|
+
describe FakeBraintree::SinatraApp do
|
124
|
+
context "Braintree::Transaction.submit_for_settlement" do
|
125
|
+
it "should be able to mark transaction as completed" do
|
126
|
+
id = create_transaction.id
|
127
|
+
|
128
|
+
result = Braintree::Transaction.submit_for_settlement(id)
|
129
|
+
|
130
|
+
expect(result).to be_success
|
131
|
+
expect(Braintree::Transaction.find(id).status).to eq Braintree::Transaction::Status::SubmittedForSettlement
|
132
|
+
end
|
133
|
+
|
134
|
+
def create_transaction
|
135
|
+
Braintree::Transaction.sale(payment_method_token: cc_token, amount: 10.0).transaction
|
136
|
+
end
|
137
|
+
end
|
138
|
+
end
|
@@ -7,12 +7,12 @@ describe FakeBraintree::SinatraApp do
|
|
7
7
|
|
8
8
|
response = post_transparent_redirect(:create_customer_data, redirect_url: redirect_url, customer: build_customer_hash)
|
9
9
|
|
10
|
-
response.code.
|
11
|
-
response['Location'].
|
10
|
+
expect(response.code).to eq '303'
|
11
|
+
expect(response['Location']).to match %r{http://example\.com/redirect_path}
|
12
12
|
params = parse_redirect(response)
|
13
|
-
params[:http_status].
|
14
|
-
params[:id].
|
15
|
-
params[:kind].
|
13
|
+
expect(params[:http_status]).to eq '200'
|
14
|
+
expect(params[:id]).to_not be_nil
|
15
|
+
expect(params[:kind]).to_not be_nil
|
16
16
|
end
|
17
17
|
|
18
18
|
it "preserves redirect_url query parameters" do
|
@@ -25,12 +25,12 @@ describe FakeBraintree::SinatraApp do
|
|
25
25
|
)
|
26
26
|
|
27
27
|
params = parse_redirect(response)
|
28
|
-
params[:preserve].
|
28
|
+
expect(params[:preserve]).to eq 'me'
|
29
29
|
end
|
30
30
|
|
31
31
|
it 'rejects submissions without transparent redirect data' do
|
32
32
|
response = post_transparent_redirect_without_data
|
33
|
-
response.code.
|
33
|
+
expect(response.code).to eq '422'
|
34
34
|
end
|
35
35
|
end
|
36
36
|
|
@@ -44,10 +44,10 @@ describe FakeBraintree::SinatraApp do
|
|
44
44
|
|
45
45
|
result = Braintree::TransparentRedirect.confirm(query)
|
46
46
|
|
47
|
-
result.
|
47
|
+
expect(result).to be_success
|
48
48
|
|
49
49
|
customer = Braintree::Customer.find(result.customer.id)
|
50
|
-
customer.credit_cards.first.last_4.
|
50
|
+
expect(customer.credit_cards.first.last_4).to eq '1111'
|
51
51
|
end
|
52
52
|
end
|
53
53
|
|
@@ -61,10 +61,10 @@ describe FakeBraintree::SinatraApp do
|
|
61
61
|
|
62
62
|
result = Braintree::TransparentRedirect.confirm(query)
|
63
63
|
|
64
|
-
result.
|
64
|
+
expect(result).to be_success
|
65
65
|
|
66
66
|
customer = Braintree::Customer.find(customer.id)
|
67
|
-
customer.credit_cards.first.last_4.
|
67
|
+
expect(customer.credit_cards.first.last_4).to eq '1111'
|
68
68
|
end
|
69
69
|
end
|
70
70
|
end
|
data/spec/fake_braintree_spec.rb
CHANGED
@@ -4,12 +4,12 @@ describe FakeBraintree, '.decline_all_cards!' do
|
|
4
4
|
before { FakeBraintree.decline_all_cards! }
|
5
5
|
|
6
6
|
it 'declines all cards' do
|
7
|
-
create_sale.
|
7
|
+
expect(create_sale).not_to be_success
|
8
8
|
end
|
9
9
|
|
10
10
|
it 'stops declining cards after clear! is called' do
|
11
11
|
FakeBraintree.clear!
|
12
|
-
create_sale.
|
12
|
+
expect(create_sale).to be_success
|
13
13
|
end
|
14
14
|
|
15
15
|
def create_sale
|
@@ -19,7 +19,7 @@ end
|
|
19
19
|
|
20
20
|
describe FakeBraintree, '.log_file_path' do
|
21
21
|
it 'is tmp/log' do
|
22
|
-
FakeBraintree.log_file_path.
|
22
|
+
expect(FakeBraintree.log_file_path).to eq 'tmp/log'
|
23
23
|
end
|
24
24
|
end
|
25
25
|
|
@@ -27,24 +27,19 @@ describe Braintree::Configuration do
|
|
27
27
|
subject { Braintree::Configuration }
|
28
28
|
|
29
29
|
it 'is running in the development environment' do
|
30
|
-
subject.environment.
|
30
|
+
expect(subject.environment).to eq :development
|
31
31
|
end
|
32
32
|
|
33
33
|
it 'has some fake API credentials' do
|
34
|
-
subject.merchant_id.
|
35
|
-
subject.public_key.
|
36
|
-
subject.private_key.
|
34
|
+
expect(subject.merchant_id).to eq 'xxx'
|
35
|
+
expect(subject.public_key).to eq 'xxx'
|
36
|
+
expect(subject.private_key).to eq 'xxx'
|
37
37
|
end
|
38
38
|
end
|
39
39
|
|
40
40
|
describe FakeBraintree do
|
41
41
|
it 'creates a log file' do
|
42
|
-
File.exist?(FakeBraintree.log_file_path).
|
43
|
-
end
|
44
|
-
|
45
|
-
it 'logs to the correct path' do
|
46
|
-
Braintree::Configuration.logger.info('Some test')
|
47
|
-
File.readlines(FakeBraintree.log_file_path).last.should include "Some test"
|
42
|
+
expect(File.exist?(FakeBraintree.log_file_path)).to eq true
|
48
43
|
end
|
49
44
|
end
|
50
45
|
|
@@ -52,12 +47,15 @@ describe FakeBraintree, '.clear_log!' do
|
|
52
47
|
it 'clears the log file' do
|
53
48
|
write_to_log
|
54
49
|
subject.clear_log!
|
55
|
-
File.read(FakeBraintree.log_file_path).
|
50
|
+
expect(File.read(FakeBraintree.log_file_path)).to eq ''
|
56
51
|
end
|
57
52
|
|
58
53
|
it 'is called by clear!' do
|
59
|
-
FakeBraintree.
|
54
|
+
FakeBraintree.stub(:clear_log!)
|
55
|
+
|
60
56
|
FakeBraintree.clear!
|
57
|
+
|
58
|
+
expect(FakeBraintree).to have_received(:clear_log!)
|
61
59
|
end
|
62
60
|
|
63
61
|
def write_to_log
|
@@ -77,7 +75,7 @@ describe FakeBraintree, 'VALID_CREDIT_CARDS' do
|
|
77
75
|
3530111333300000
|
78
76
|
)
|
79
77
|
|
80
|
-
FakeBraintree::VALID_CREDIT_CARDS.sort.
|
78
|
+
expect(FakeBraintree::VALID_CREDIT_CARDS.sort).to eq valid_credit_cards.sort
|
81
79
|
end
|
82
80
|
end
|
83
81
|
|
@@ -90,25 +88,25 @@ end
|
|
90
88
|
describe FakeBraintree, '.generate_transaction' do
|
91
89
|
it 'allows setting the subscription id' do
|
92
90
|
transaction = FakeBraintree.generate_transaction(subscription_id: 'foobar')
|
93
|
-
transaction['subscription_id'].
|
91
|
+
expect(transaction['subscription_id']).to eq 'foobar'
|
94
92
|
end
|
95
93
|
|
96
94
|
it 'allows setting created_at' do
|
97
95
|
time = Time.now
|
98
96
|
transaction = FakeBraintree.generate_transaction(created_at: time)
|
99
|
-
transaction['created_at'].
|
97
|
+
expect(transaction['created_at']).to eq time
|
100
98
|
end
|
101
99
|
|
102
100
|
it 'sets created_at to Time.now by default' do
|
103
101
|
Timecop.freeze do
|
104
102
|
transaction = FakeBraintree.generate_transaction
|
105
|
-
transaction['created_at'].
|
103
|
+
expect(transaction['created_at']).to eq Time.now
|
106
104
|
end
|
107
105
|
end
|
108
106
|
|
109
107
|
it 'has the correct amount' do
|
110
108
|
transaction = FakeBraintree.generate_transaction(amount: '20.00')
|
111
|
-
transaction['amount'].
|
109
|
+
expect(transaction['amount']).to eq '20.00'
|
112
110
|
end
|
113
111
|
|
114
112
|
it 'allows no arguments' do
|
@@ -117,7 +115,7 @@ describe FakeBraintree, '.generate_transaction' do
|
|
117
115
|
|
118
116
|
context 'status_history' do
|
119
117
|
it 'returns a hash with a status_history key' do
|
120
|
-
FakeBraintree.generate_transaction(amount: '20').
|
118
|
+
expect(FakeBraintree.generate_transaction(amount: '20')).to have_key('status_history')
|
121
119
|
end
|
122
120
|
|
123
121
|
it 'has a timestamp of Time.now' do
|
@@ -126,19 +124,19 @@ describe FakeBraintree, '.generate_transaction' do
|
|
126
124
|
status: Braintree::Transaction::Status::Failed,
|
127
125
|
subscription_id: 'my_subscription_id'
|
128
126
|
)
|
129
|
-
transaction['status_history'].first['timestamp'].
|
127
|
+
expect(transaction['status_history'].first['timestamp']).to eq Time.now
|
130
128
|
end
|
131
129
|
end
|
132
130
|
|
133
131
|
it 'has the desired amount' do
|
134
132
|
transaction = FakeBraintree.generate_transaction(amount: '20.00')
|
135
|
-
transaction['status_history'].first['amount'].
|
133
|
+
expect(transaction['status_history'].first['amount']).to eq '20.00'
|
136
134
|
end
|
137
135
|
|
138
136
|
it 'has the desired status' do
|
139
137
|
status = Braintree::Transaction::Status::Failed
|
140
138
|
transaction = FakeBraintree.generate_transaction(status: status)
|
141
|
-
transaction['status_history'].first['status'].
|
139
|
+
expect(transaction['status_history'].first['status']).to eq status
|
142
140
|
end
|
143
141
|
end
|
144
142
|
end
|