/
subscription_spec.rb
54 lines (44 loc) · 2.22 KB
/
subscription_spec.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
require 'spec_helper'
describe "Braintree::Subscription.create" do
let(:plan_id) { 'plan-id-from-braintree-control-panel' }
let(:expiration_date) { "04/2016" }
it "successfully creates a subscription" do
Braintree::Subscription.create(:payment_method_token => cc_token,
:plan_id => 'my_plan_id').should be_success
end
it "assigns a Braintree-esque ID to the subscription" do
create_subscription.subscription.id.should =~ /^[a-z0-9]{6}$/
end
it "assigns unique IDs to each subscription" do
cc_token_1 = cc_token
cc_token_2 = braintree_credit_card_token(TEST_CC_NUMBER.sub('1', '5'), expiration_date)
first_result = Braintree::Subscription.create(:payment_method_token => cc_token_1,
:plan_id => plan_id)
second_result = Braintree::Subscription.create(:payment_method_token => cc_token_2,
:plan_id => plan_id)
first_result.subscription.id.should_not == second_result.subscription.id
end
it "stores created subscriptions in FakeBraintree.subscriptions" do
FakeBraintree.subscriptions[create_subscription.subscription.id].should_not be_nil
end
it "sets the next billing date to a string of 1.month.from_now in UTC" do
Timecop.freeze do
create_subscription.subscription.next_billing_date.should == 1.month.from_now.utc.strftime('%Y-%m-%d')
end
end
end
describe "Braintree::Subscription.find" do
it "can find a created subscription" do
subscription = Braintree::Subscription.find(subscription_id)
subscription.should_not be_nil
subscription.payment_method_token.should == payment_method_token
subscription.plan_id.should == plan_id
end
it "raises a Braintree:NotFoundError when it cannot find a subscription" do
expect { Braintree::Subscription.find('abc123') }.to raise_error(Braintree::NotFoundError, /abc123/)
end
let(:payment_method_token) { cc_token }
let(:plan_id) { 'my-plan-id' }
let(:subscription_id) { Braintree::Subscription.create(:payment_method_token => payment_method_token,
:plan_id => plan_id).subscription.id }
end