ashmont 0.0.14 → 0.0.15
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +6 -0
- data/ashmont.gemspec +3 -3
- data/lib/ashmont/subscription.rb +2 -1
- data/lib/ashmont/version.rb +1 -1
- data/spec/ashmont/customer_spec.rb +36 -36
- data/spec/ashmont/errors_spec.rb +12 -12
- data/spec/ashmont/subscribed_customer_spec.rb +15 -15
- data/spec/ashmont/subscription_spec.rb +32 -32
- data/spec/ashmont_spec.rb +3 -3
- metadata +21 -9
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4cbc767616cdfb36fa0361192652eb7260cf7819
|
4
|
+
data.tar.gz: dfcfe21d97c3bc0141650d489b2f9e15353fb042
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2bacaf4575b5a27b377a7fbf64b8b2bbfc14f3681f57c0ebece26f82f81c0036d7186e22ace36328fd4b7ad118f45a0ca87774540a938d86bdcc9bf618d90ce2
|
7
|
+
data.tar.gz: fc714edba413131497708bdb572d60ce885993b00fb5fdc9fcee26b776801395e22b4920ca39c14eb2399eb98448a89c7260b6f379d42cc548580291970aa748
|
data/CHANGELOG.md
CHANGED
data/ashmont.gemspec
CHANGED
@@ -19,9 +19,9 @@ Gem::Specification.new do |s|
|
|
19
19
|
s.require_paths = ["lib"]
|
20
20
|
|
21
21
|
s.add_dependency('braintree', '>= 2.74.0')
|
22
|
-
s.add_dependency('activesupport', '>=
|
23
|
-
s.add_dependency('i18n', '
|
24
|
-
s.add_dependency('tzinfo', '>=
|
22
|
+
s.add_dependency('activesupport', '~> 5.0', '>= 5.0.2')
|
23
|
+
s.add_dependency('i18n', '~> 0.8.1')
|
24
|
+
s.add_dependency('tzinfo', '~> 1.2', '>= 1.2.3')
|
25
25
|
s.add_development_dependency('bourne')
|
26
26
|
s.add_development_dependency('rake')
|
27
27
|
s.add_development_dependency('rspec')
|
data/lib/ashmont/subscription.rb
CHANGED
data/lib/ashmont/version.rb
CHANGED
@@ -9,12 +9,12 @@ describe Ashmont::Customer do
|
|
9
9
|
|
10
10
|
result = Ashmont::Customer.new(token).credit_card
|
11
11
|
|
12
|
-
Braintree::Customer.
|
13
|
-
result.
|
12
|
+
expect(Braintree::Customer).to have_received(:find).with(token)
|
13
|
+
expect(result).to eq("first")
|
14
14
|
end
|
15
15
|
|
16
16
|
it "returns nothing without a remote customer" do
|
17
|
-
Ashmont::Customer.new.credit_card.
|
17
|
+
expect(Ashmont::Customer.new.credit_card).to be_nil
|
18
18
|
end
|
19
19
|
|
20
20
|
it "returns all credit cards" do
|
@@ -24,12 +24,12 @@ describe Ashmont::Customer do
|
|
24
24
|
|
25
25
|
result = Ashmont::Customer.new(token).credit_cards
|
26
26
|
|
27
|
-
Braintree::Customer.
|
28
|
-
result.
|
27
|
+
expect(Braintree::Customer).to have_received(:find).with(token)
|
28
|
+
expect(result).to eq(["first", "second"])
|
29
29
|
end
|
30
30
|
|
31
31
|
it "returns an empty array without a remote customer" do
|
32
|
-
Ashmont::Customer.new.credit_cards.
|
32
|
+
expect(Ashmont::Customer.new.credit_cards).to eq([])
|
33
33
|
end
|
34
34
|
|
35
35
|
|
@@ -37,11 +37,11 @@ describe Ashmont::Customer do
|
|
37
37
|
remote_customer = stub("customer", :email => "admin@example.com")
|
38
38
|
Braintree::Customer.stubs(:find => remote_customer)
|
39
39
|
|
40
|
-
Ashmont::Customer.new("abc").billing_email.
|
40
|
+
expect(Ashmont::Customer.new("abc").billing_email).to eq("admin@example.com")
|
41
41
|
end
|
42
42
|
|
43
43
|
it "doesn't have an email without a remote customer" do
|
44
|
-
Ashmont::Customer.new.billing_email.
|
44
|
+
expect(Ashmont::Customer.new.billing_email).to be_nil
|
45
45
|
end
|
46
46
|
|
47
47
|
it "creates a valid remote customer" do
|
@@ -52,11 +52,11 @@ describe Ashmont::Customer do
|
|
52
52
|
Braintree::Customer.stubs(:create => create_result)
|
53
53
|
|
54
54
|
customer = Ashmont::Customer.new
|
55
|
-
customer.save(attributes).
|
55
|
+
expect(customer.save(attributes)).to be true
|
56
56
|
|
57
|
-
Braintree::Customer.
|
58
|
-
customer.token.
|
59
|
-
customer.errors.
|
57
|
+
expect(Braintree::Customer).to have_received(:create).with(:email => "ben@example.com", :credit_card => {})
|
58
|
+
expect(customer.token).to eq(token)
|
59
|
+
expect(customer.errors).to be_empty
|
60
60
|
end
|
61
61
|
|
62
62
|
it "creates a remote customer with a credit card" do
|
@@ -82,7 +82,7 @@ describe Ashmont::Customer do
|
|
82
82
|
:country_name => "United States of America"
|
83
83
|
)
|
84
84
|
|
85
|
-
Braintree::Customer.
|
85
|
+
expect(Braintree::Customer).to have_received(:create).with(
|
86
86
|
:email => "jrobot@example.com",
|
87
87
|
:credit_card => {
|
88
88
|
:cardholder_name => "Jim Robot",
|
@@ -114,10 +114,10 @@ describe Ashmont::Customer do
|
|
114
114
|
Ashmont::Errors.stubs(:new => errors)
|
115
115
|
|
116
116
|
customer = Ashmont::Customer.new
|
117
|
-
customer.save("email" => "ben.franklin@example.com").
|
117
|
+
expect(customer.save("email" => "ben.franklin@example.com")).to be false
|
118
118
|
|
119
|
-
Ashmont::Errors.
|
120
|
-
customer.errors.
|
119
|
+
expect(Ashmont::Errors).to have_received(:new).with(verification, error_messages)
|
120
|
+
expect(customer.errors).to eq(errors)
|
121
121
|
end
|
122
122
|
|
123
123
|
it "updates a remote customer with valid changes" do
|
@@ -128,10 +128,10 @@ describe Ashmont::Customer do
|
|
128
128
|
Braintree::Customer.stubs(:update => update_result)
|
129
129
|
|
130
130
|
customer = Ashmont::Customer.new(token)
|
131
|
-
customer.save(updates).
|
131
|
+
expect(customer.save(updates)).to be true
|
132
132
|
|
133
|
-
Braintree::Customer.
|
134
|
-
customer.billing_email.
|
133
|
+
expect(Braintree::Customer).to have_received(:update).with(token, :email => "somebody@example.com", :credit_card => {})
|
134
|
+
expect(customer.billing_email).to eq("somebody@example.com")
|
135
135
|
end
|
136
136
|
|
137
137
|
it "updates a remote customer with a credit card" do
|
@@ -159,7 +159,7 @@ describe Ashmont::Customer do
|
|
159
159
|
:country_name => "United States of America"
|
160
160
|
)
|
161
161
|
|
162
|
-
Braintree::Customer.
|
162
|
+
expect(Braintree::Customer).to have_received(:update).with(
|
163
163
|
token,
|
164
164
|
:email => "jrobot@example.com",
|
165
165
|
:credit_card => {
|
@@ -195,10 +195,10 @@ describe Ashmont::Customer do
|
|
195
195
|
Ashmont::Errors.stubs(:new => errors)
|
196
196
|
|
197
197
|
customer = Ashmont::Customer.new("xyz")
|
198
|
-
customer.save("email" => "ben.franklin@example.com").
|
198
|
+
expect(customer.save("email" => "ben.franklin@example.com")).to be false
|
199
199
|
|
200
|
-
Ashmont::Errors.
|
201
|
-
customer.errors.
|
200
|
+
expect(Ashmont::Errors).to have_received(:new).with(verification, error_messages)
|
201
|
+
expect(customer.errors).to eq(errors)
|
202
202
|
end
|
203
203
|
|
204
204
|
it "delete a remote customer" do
|
@@ -208,7 +208,7 @@ describe Ashmont::Customer do
|
|
208
208
|
customer = Ashmont::Customer.new(token)
|
209
209
|
customer.delete
|
210
210
|
|
211
|
-
Braintree::Customer.
|
211
|
+
expect(Braintree::Customer).to have_received(:delete).with(token)
|
212
212
|
end
|
213
213
|
|
214
214
|
it "has billing info with a credit card" do
|
@@ -218,8 +218,8 @@ describe Ashmont::Customer do
|
|
218
218
|
Braintree::Customer.stubs(:find => remote_customer)
|
219
219
|
|
220
220
|
customer = Ashmont::Customer.new("xyz")
|
221
|
-
customer.
|
222
|
-
customer.payment_method_token.
|
221
|
+
expect(customer).to have_billing_info
|
222
|
+
expect(customer.payment_method_token).to eq(token)
|
223
223
|
end
|
224
224
|
|
225
225
|
it "doesn't have billing info without a credit card" do
|
@@ -227,8 +227,8 @@ describe Ashmont::Customer do
|
|
227
227
|
Braintree::Customer.stubs(:find => remote_customer)
|
228
228
|
|
229
229
|
customer = Ashmont::Customer.new("xyz")
|
230
|
-
customer.
|
231
|
-
customer.payment_method_token.
|
230
|
+
expect(customer).to_not have_billing_info
|
231
|
+
expect(customer.payment_method_token).to be_nil
|
232
232
|
end
|
233
233
|
|
234
234
|
%w(last_4 cardholder_name expiration_month expiration_year).each do |credit_card_attribute|
|
@@ -237,7 +237,7 @@ describe Ashmont::Customer do
|
|
237
237
|
remote_customer = stub("customer", :credit_cards => [credit_card])
|
238
238
|
Braintree::Customer.stubs(:find => remote_customer)
|
239
239
|
|
240
|
-
Ashmont::Customer.new("xyz").send(credit_card_attribute).
|
240
|
+
expect(Ashmont::Customer.new("xyz").send(credit_card_attribute)).to eq("expected")
|
241
241
|
end
|
242
242
|
end
|
243
243
|
|
@@ -248,7 +248,7 @@ describe Ashmont::Customer do
|
|
248
248
|
remote_customer = stub("customer", :credit_cards => [credit_card])
|
249
249
|
Braintree::Customer.stubs(:find => remote_customer)
|
250
250
|
|
251
|
-
Ashmont::Customer.new("xyz").send(billing_address_attribute).
|
251
|
+
expect(Ashmont::Customer.new("xyz").send(billing_address_attribute)).to eq("expected")
|
252
252
|
end
|
253
253
|
end
|
254
254
|
|
@@ -260,10 +260,10 @@ describe Ashmont::Customer do
|
|
260
260
|
Braintree::TransparentRedirect.stubs(:confirm => confirm_result)
|
261
261
|
|
262
262
|
customer = Ashmont::Customer.new
|
263
|
-
customer.confirm(query_string).
|
263
|
+
expect(customer.confirm(query_string)).to be true
|
264
264
|
|
265
|
-
Braintree::TransparentRedirect.
|
266
|
-
customer.token.
|
265
|
+
expect(Braintree::TransparentRedirect).to have_received(:confirm).with(query_string)
|
266
|
+
expect(customer.token).to eq(token)
|
267
267
|
end
|
268
268
|
|
269
269
|
it "adds errors for an invalid transparent redirect query string" do
|
@@ -278,9 +278,9 @@ describe Ashmont::Customer do
|
|
278
278
|
Ashmont::Errors.stubs(:new => errors)
|
279
279
|
|
280
280
|
customer = Ashmont::Customer.new
|
281
|
-
customer.confirm("abc").
|
281
|
+
expect(customer.confirm("abc")).to be false
|
282
282
|
|
283
|
-
Ashmont::Errors.
|
284
|
-
customer.errors.
|
283
|
+
expect(Ashmont::Errors).to have_received(:new).with(verification, error_messages)
|
284
|
+
expect(customer.errors).to eq(errors)
|
285
285
|
end
|
286
286
|
end
|
data/spec/ashmont/errors_spec.rb
CHANGED
@@ -2,38 +2,38 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
describe Ashmont::Errors do
|
4
4
|
it "adds an error for a declined number" do
|
5
|
-
errors_for(:status => "processor_declined", :processor_response_text => "failure").
|
6
|
-
|
5
|
+
expect(errors_for(:status => "processor_declined", :processor_response_text => "failure")).
|
6
|
+
to include("number was denied by the payment processor with the message: failure")
|
7
7
|
end
|
8
8
|
|
9
9
|
it "adds an error for a mismatched cvv" do
|
10
|
-
errors_for(:status => "gateway_rejected").
|
10
|
+
expect(errors_for(:status => "gateway_rejected")).to include("cvv did not match")
|
11
11
|
end
|
12
12
|
|
13
13
|
it "adds a generic card number error" do
|
14
|
-
errors_for(:messages => { :number => "Credit card number is unsupported" }).
|
15
|
-
|
14
|
+
expect(errors_for(:messages => { :number => "Credit card number is unsupported" })).
|
15
|
+
to include("number is unsupported")
|
16
16
|
end
|
17
17
|
|
18
18
|
it "adds a generic cvv error" do
|
19
|
-
errors_for(:messages => { :CVV => "CVV is unsupported" }).
|
20
|
-
|
19
|
+
expect(errors_for(:messages => { :CVV => "CVV is unsupported" })).
|
20
|
+
to include("cvv is unsupported")
|
21
21
|
end
|
22
22
|
|
23
23
|
it "adds a generic expiration_month error" do
|
24
|
-
errors_for(:messages => { :expiration_month => "Expiration month is unsupported" }).
|
25
|
-
|
24
|
+
expect(errors_for(:messages => { :expiration_month => "Expiration month is unsupported" })).
|
25
|
+
to include("expiration_month is unsupported")
|
26
26
|
end
|
27
27
|
|
28
28
|
it "adds a generic expiration_year error" do
|
29
|
-
errors_for(:messages => { :expiration_year => "Expiration year is unsupported" }).
|
30
|
-
|
29
|
+
expect(errors_for(:messages => { :expiration_year => "Expiration year is unsupported" })).
|
30
|
+
to include("expiration_year is unsupported")
|
31
31
|
end
|
32
32
|
|
33
33
|
it "handles error results without a status" do
|
34
34
|
result = {}
|
35
35
|
errors = [ stub("error", :attribute => "foo", :message => "bar") ]
|
36
|
-
expect { Ashmont::Errors.new(result, errors).to_hash }.to_not raise_error
|
36
|
+
expect { Ashmont::Errors.new(result, errors).to_hash }.to_not raise_error
|
37
37
|
end
|
38
38
|
|
39
39
|
def errors_for(options = {})
|
@@ -10,8 +10,8 @@ describe Ashmont::SubscribedCustomer do
|
|
10
10
|
delegated_methods.each do |method|
|
11
11
|
customer.stubs(method => "expected")
|
12
12
|
result = subscribed_customer.send(method, "argument")
|
13
|
-
customer.
|
14
|
-
result.
|
13
|
+
expect(customer).to have_received(method).with("argument")
|
14
|
+
expect(result).to eq("expected")
|
15
15
|
end
|
16
16
|
end
|
17
17
|
|
@@ -21,15 +21,15 @@ describe Ashmont::SubscribedCustomer do
|
|
21
21
|
%w(reload status next_billing_date transactions most_recent_transaction retry_charge past_due?).each do |method|
|
22
22
|
subscription.stubs(method => "expected")
|
23
23
|
result = subscribed_customer.send(method, "argument")
|
24
|
-
subscription.
|
25
|
-
result.
|
24
|
+
expect(subscription).to have_received(method).with("argument")
|
25
|
+
expect(result).to eq("expected")
|
26
26
|
end
|
27
27
|
end
|
28
28
|
|
29
29
|
it "delegates #subscription_token to its subscription's token" do
|
30
30
|
subscription = stub("subscription", :token => "expected")
|
31
31
|
subscribed_customer = build_subscribed_customer(:subscription => subscription)
|
32
|
-
subscribed_customer.subscription_token.
|
32
|
+
expect(subscribed_customer.subscription_token).to eq("expected")
|
33
33
|
end
|
34
34
|
|
35
35
|
it "#reloads the subscription" do
|
@@ -38,8 +38,8 @@ describe Ashmont::SubscribedCustomer do
|
|
38
38
|
|
39
39
|
result = subscribed_customer.reload
|
40
40
|
|
41
|
-
subscription.
|
42
|
-
result.
|
41
|
+
expect(subscription).to have_received(:reload)
|
42
|
+
expect(result).to eq("expected")
|
43
43
|
end
|
44
44
|
|
45
45
|
it "can #save the customer" do
|
@@ -49,8 +49,8 @@ describe Ashmont::SubscribedCustomer do
|
|
49
49
|
|
50
50
|
result = subscribed_customer.save(attributes)
|
51
51
|
|
52
|
-
customer.
|
53
|
-
result.
|
52
|
+
expect(customer).to have_received(:save).with(attributes)
|
53
|
+
expect(result).to be true
|
54
54
|
end
|
55
55
|
|
56
56
|
it "saves a new customer without attributes" do
|
@@ -59,7 +59,7 @@ describe Ashmont::SubscribedCustomer do
|
|
59
59
|
|
60
60
|
subscribed_customer.save({})
|
61
61
|
|
62
|
-
customer.
|
62
|
+
expect(customer).to have_received(:save).with({})
|
63
63
|
end
|
64
64
|
|
65
65
|
it "doesn't #save the customer without any customer attributes" do
|
@@ -69,7 +69,7 @@ describe Ashmont::SubscribedCustomer do
|
|
69
69
|
|
70
70
|
subscribed_customer.save(attributes)
|
71
71
|
|
72
|
-
customer.
|
72
|
+
expect(customer).to have_received(:save).never
|
73
73
|
end
|
74
74
|
|
75
75
|
it "can #save the subscription" do
|
@@ -81,8 +81,8 @@ describe Ashmont::SubscribedCustomer do
|
|
81
81
|
|
82
82
|
result = subscribed_customer.save(attributes)
|
83
83
|
|
84
|
-
subscription.
|
85
|
-
result.
|
84
|
+
expect(subscription).to have_received(:save).with(:plan_id => 41, :price => "15", :payment_method_token => payment_method_token)
|
85
|
+
expect(result).to eq("expected")
|
86
86
|
end
|
87
87
|
|
88
88
|
it "retries the subscription when past due" do
|
@@ -91,7 +91,7 @@ describe Ashmont::SubscribedCustomer do
|
|
91
91
|
subscribed_customer = build_subscribed_customer(:subscription => subscription)
|
92
92
|
subscribed_customer.save({})
|
93
93
|
|
94
|
-
subscription.
|
94
|
+
expect(subscription).to have_received(:retry_charge)
|
95
95
|
end
|
96
96
|
|
97
97
|
it "merges #errors from the customer and subscription" do
|
@@ -99,7 +99,7 @@ describe Ashmont::SubscribedCustomer do
|
|
99
99
|
customer = stub("customer", :errors => stub_errors("two" => "second"))
|
100
100
|
subscribed_customer = build_subscribed_customer(:subscription => subscription, :customer => customer)
|
101
101
|
|
102
|
-
subscribed_customer.errors.to_hash.
|
102
|
+
expect(subscribed_customer.errors.to_hash).to eq({ "one" => "first", "two" => "second" })
|
103
103
|
end
|
104
104
|
|
105
105
|
def build_subscribed_customer(options = {})
|
@@ -6,8 +6,8 @@ describe Ashmont::Subscription do
|
|
6
6
|
remote_subscription = stub_remote_subscription(delegated_method => "expected")
|
7
7
|
subscription = Ashmont::Subscription.new(remote_subscription.id)
|
8
8
|
result = subscription.send(delegated_method)
|
9
|
-
Braintree::Subscription.
|
10
|
-
result.
|
9
|
+
expect(Braintree::Subscription).to have_received(:find).with(remote_subscription.id)
|
10
|
+
expect(result).to eq("expected")
|
11
11
|
end
|
12
12
|
end
|
13
13
|
|
@@ -16,17 +16,17 @@ describe Ashmont::Subscription do
|
|
16
16
|
remote_subscription = stub_remote_subscription(:next_billing_date => unconverted_date)
|
17
17
|
subscription = Ashmont::Subscription.new("xyz")
|
18
18
|
result = subscription.next_billing_date
|
19
|
-
result.utc_offset.
|
20
|
-
result.strftime("%Y-%m-%d").
|
19
|
+
expect(result.utc_offset).to eq(ActiveSupport::TimeZone[Ashmont.merchant_account_time_zone].utc_offset)
|
20
|
+
expect(result.strftime("%Y-%m-%d")).to eq(unconverted_date)
|
21
21
|
end
|
22
22
|
|
23
23
|
it "doesn't have a next billing date without a remote subscription" do
|
24
|
-
Ashmont::Subscription.new.next_billing_date.
|
24
|
+
expect(Ashmont::Subscription.new.next_billing_date).to be_nil
|
25
25
|
end
|
26
26
|
|
27
27
|
it "returns the token" do
|
28
28
|
subscription = Ashmont::Subscription.new('abc')
|
29
|
-
subscription.token.
|
29
|
+
expect(subscription.token).to eq('abc')
|
30
30
|
end
|
31
31
|
|
32
32
|
it "retries a subscription" do
|
@@ -39,11 +39,11 @@ describe Ashmont::Subscription do
|
|
39
39
|
Braintree::Transaction.stubs(:submit_for_settlement => settlement_result)
|
40
40
|
|
41
41
|
subscription = Ashmont::Subscription.new(subscription_token)
|
42
|
-
subscription.retry_charge.
|
43
|
-
subscription.errors.
|
42
|
+
expect(subscription.retry_charge).to be true
|
43
|
+
expect(subscription.errors).to be_empty
|
44
44
|
|
45
|
-
Braintree::Subscription.
|
46
|
-
Braintree::Transaction.
|
45
|
+
expect(Braintree::Subscription).to have_received(:retry_charge).with(subscription_token)
|
46
|
+
expect(Braintree::Transaction).to have_received(:submit_for_settlement).with(transaction_token)
|
47
47
|
end
|
48
48
|
|
49
49
|
it "has errors after a failed subscription retry" do
|
@@ -59,12 +59,12 @@ describe Ashmont::Subscription do
|
|
59
59
|
Ashmont::Errors.stubs(:new => errors)
|
60
60
|
|
61
61
|
subscription = Ashmont::Subscription.new(subscription_token)
|
62
|
-
subscription.retry_charge.
|
63
|
-
subscription.errors.
|
62
|
+
expect(subscription.retry_charge).to be false
|
63
|
+
expect(subscription.errors).to eq(errors)
|
64
64
|
|
65
|
-
Braintree::Subscription.
|
66
|
-
Braintree::Transaction.
|
67
|
-
Ashmont::Errors.
|
65
|
+
expect(Braintree::Subscription).to have_received(:retry_charge).with(subscription_token)
|
66
|
+
expect(Braintree::Transaction).to have_received(:submit_for_settlement).with(transaction_token)
|
67
|
+
expect(Ashmont::Errors).to have_received(:new).with(transaction, error_messages)
|
68
68
|
end
|
69
69
|
|
70
70
|
it "reloads the subscription after retrying a charge" do
|
@@ -88,8 +88,8 @@ describe Ashmont::Subscription do
|
|
88
88
|
subscription = Ashmont::Subscription.new(token)
|
89
89
|
result = subscription.save(:name => "Billy")
|
90
90
|
|
91
|
-
Braintree::Subscription.
|
92
|
-
result.
|
91
|
+
expect(Braintree::Subscription).to have_received(:update).with(token, has_entries(:name => "Billy"))
|
92
|
+
expect(result).to eq("expected")
|
93
93
|
end
|
94
94
|
|
95
95
|
it "creates a successful subscription" do
|
@@ -99,11 +99,11 @@ describe Ashmont::Subscription do
|
|
99
99
|
Braintree::Subscription.stubs(:create => result)
|
100
100
|
|
101
101
|
subscription = Ashmont::Subscription.new
|
102
|
-
subscription.save(attributes).
|
102
|
+
expect(subscription.save(attributes)).to be true
|
103
103
|
|
104
|
-
Braintree::Subscription.
|
105
|
-
subscription.token.
|
106
|
-
subscription.status.
|
104
|
+
expect(Braintree::Subscription).to have_received(:create).with(has_entries(attributes))
|
105
|
+
expect(subscription.token).to eq(remote_subscription.id)
|
106
|
+
expect(subscription.status).to eq("fine")
|
107
107
|
end
|
108
108
|
|
109
109
|
it "passes a configured merchant account id" do
|
@@ -115,7 +115,7 @@ describe Ashmont::Subscription do
|
|
115
115
|
subscription = Ashmont::Subscription.new
|
116
116
|
subscription.save({})
|
117
117
|
|
118
|
-
Braintree::Subscription.
|
118
|
+
expect(Braintree::Subscription).to have_received(:create).with(has_entries(:merchant_account_id => merchant_account_id))
|
119
119
|
end
|
120
120
|
end
|
121
121
|
|
@@ -127,7 +127,7 @@ describe Ashmont::Subscription do
|
|
127
127
|
subscription = Ashmont::Subscription.new
|
128
128
|
subscription.save({})
|
129
129
|
|
130
|
-
Braintree::Subscription.
|
130
|
+
expect(Braintree::Subscription).to have_received(:create).with(has_entries(:merchant_account_id => nil)).never
|
131
131
|
end
|
132
132
|
|
133
133
|
it "returns the most recent transaction" do
|
@@ -138,7 +138,7 @@ describe Ashmont::Subscription do
|
|
138
138
|
|
139
139
|
subscription = Ashmont::Subscription.new("xyz")
|
140
140
|
|
141
|
-
subscription.most_recent_transaction.created_at.
|
141
|
+
expect(subscription.most_recent_transaction.created_at).to eq(1.day.ago)
|
142
142
|
end
|
143
143
|
end
|
144
144
|
|
@@ -147,40 +147,40 @@ describe Ashmont::Subscription do
|
|
147
147
|
new_remote_subscription = stub_remote_subscription(:status => "new")
|
148
148
|
Braintree::Subscription.stubs(:find).returns(old_remote_subscription).then.returns(new_remote_subscription)
|
149
149
|
subscription = Ashmont::Subscription.new(old_remote_subscription.id)
|
150
|
-
subscription.status.
|
151
|
-
subscription.reload.status.
|
150
|
+
expect(subscription.status).to eq("old")
|
151
|
+
expect(subscription.reload.status).to eq("new")
|
152
152
|
end
|
153
153
|
|
154
154
|
it "finds status from the remote subscription" do
|
155
155
|
remote_subscription = stub_remote_subscription(:status => "a-ok")
|
156
156
|
subscription = Ashmont::Subscription.new("xyz")
|
157
|
-
subscription.status.
|
157
|
+
expect(subscription.status).to eq("a-ok")
|
158
158
|
end
|
159
159
|
|
160
160
|
it "doesn't have status without a remote subscription" do
|
161
161
|
subscription = Ashmont::Subscription.new(nil)
|
162
|
-
subscription.status.
|
162
|
+
expect(subscription.status).to be_nil
|
163
163
|
end
|
164
164
|
|
165
165
|
it "uses a cached status when provided" do
|
166
166
|
remote_subscription = stub_remote_subscription(:status => "past-due")
|
167
167
|
subscription = Ashmont::Subscription.new("xyz", :status => "a-ok")
|
168
|
-
subscription.status.
|
168
|
+
expect(subscription.status).to eq("a-ok")
|
169
169
|
end
|
170
170
|
|
171
171
|
it "updates the cached status when reloading" do
|
172
172
|
remote_subscription = stub_remote_subscription(:status => "active")
|
173
173
|
subscription = Ashmont::Subscription.new("xyz", :status => "past-due")
|
174
174
|
subscription.reload
|
175
|
-
subscription.status.
|
175
|
+
expect(subscription.status).to eq("active")
|
176
176
|
end
|
177
177
|
|
178
178
|
it "is past due with a past due status" do
|
179
|
-
Ashmont::Subscription.new("xyz", :status => Braintree::Subscription::Status::PastDue).
|
179
|
+
expect(Ashmont::Subscription.new("xyz", :status => Braintree::Subscription::Status::PastDue)).to be_past_due
|
180
180
|
end
|
181
181
|
|
182
182
|
it "isn't past due with an active status" do
|
183
|
-
Ashmont::Subscription.new("xyz", :status => Braintree::Subscription::Status::Active).
|
183
|
+
expect(Ashmont::Subscription.new("xyz", :status => Braintree::Subscription::Status::Active)).to_not be_past_due
|
184
184
|
end
|
185
185
|
|
186
186
|
def with_configured_merchant_acount_id
|
data/spec/ashmont_spec.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ashmont
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.15
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- thoughtbot
|
@@ -29,44 +29,56 @@ dependencies:
|
|
29
29
|
name: activesupport
|
30
30
|
requirement: !ruby/object:Gem::Requirement
|
31
31
|
requirements:
|
32
|
+
- - "~>"
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: '5.0'
|
32
35
|
- - ">="
|
33
36
|
- !ruby/object:Gem::Version
|
34
|
-
version:
|
37
|
+
version: 5.0.2
|
35
38
|
type: :runtime
|
36
39
|
prerelease: false
|
37
40
|
version_requirements: !ruby/object:Gem::Requirement
|
38
41
|
requirements:
|
42
|
+
- - "~>"
|
43
|
+
- !ruby/object:Gem::Version
|
44
|
+
version: '5.0'
|
39
45
|
- - ">="
|
40
46
|
- !ruby/object:Gem::Version
|
41
|
-
version:
|
47
|
+
version: 5.0.2
|
42
48
|
- !ruby/object:Gem::Dependency
|
43
49
|
name: i18n
|
44
50
|
requirement: !ruby/object:Gem::Requirement
|
45
51
|
requirements:
|
46
|
-
- - "
|
52
|
+
- - "~>"
|
47
53
|
- !ruby/object:Gem::Version
|
48
|
-
version:
|
54
|
+
version: 0.8.1
|
49
55
|
type: :runtime
|
50
56
|
prerelease: false
|
51
57
|
version_requirements: !ruby/object:Gem::Requirement
|
52
58
|
requirements:
|
53
|
-
- - "
|
59
|
+
- - "~>"
|
54
60
|
- !ruby/object:Gem::Version
|
55
|
-
version:
|
61
|
+
version: 0.8.1
|
56
62
|
- !ruby/object:Gem::Dependency
|
57
63
|
name: tzinfo
|
58
64
|
requirement: !ruby/object:Gem::Requirement
|
59
65
|
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '1.2'
|
60
69
|
- - ">="
|
61
70
|
- !ruby/object:Gem::Version
|
62
|
-
version:
|
71
|
+
version: 1.2.3
|
63
72
|
type: :runtime
|
64
73
|
prerelease: false
|
65
74
|
version_requirements: !ruby/object:Gem::Requirement
|
66
75
|
requirements:
|
76
|
+
- - "~>"
|
77
|
+
- !ruby/object:Gem::Version
|
78
|
+
version: '1.2'
|
67
79
|
- - ">="
|
68
80
|
- !ruby/object:Gem::Version
|
69
|
-
version:
|
81
|
+
version: 1.2.3
|
70
82
|
- !ruby/object:Gem::Dependency
|
71
83
|
name: bourne
|
72
84
|
requirement: !ruby/object:Gem::Requirement
|