Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Gabe Berke-Williams
committed
Nov 18, 2011
1 parent
45b5e62
commit 0a647db
Showing
5 changed files
with
84 additions
and
89 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,62 +1,58 @@ | ||
require 'spec_helper' | ||
|
||
describe FakeBraintree::SinatraApp do | ||
context "Braintree::Subscription.create" do | ||
let(:plan_id) { 'plan-id-from-braintree-control-panel' } | ||
let(:cc_number) { %w(4111 1111 1111 9876).join } | ||
let(:expiration_date) { "04/2016" } | ||
let(:payment_method_token) { braintree_credit_card_token(cc_number, expiration_date) } | ||
let(:payment_method_token_2) { braintree_credit_card_token(cc_number.sub('1', '5'), expiration_date) } | ||
|
||
it "successfully creates a subscription" do | ||
result = Braintree::Subscription.create(:payment_method_token => payment_method_token, | ||
:plan_id => plan_id) | ||
result.should be_success | ||
end | ||
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 | ||
result = Braintree::Subscription.create(:payment_method_token => cc_token, | ||
:plan_id => plan_id) | ||
result.should be_success | ||
end | ||
|
||
it "assigns a Braintree-esque ID to the subscription" do | ||
result = Braintree::Subscription.create(:payment_method_token => payment_method_token, | ||
:plan_id => plan_id) | ||
it "assigns a Braintree-esque ID to the subscription" do | ||
result = Braintree::Subscription.create(:payment_method_token => cc_token, | ||
:plan_id => plan_id) | ||
|
||
result.subscription.id.should =~ /^[a-z0-9]{6}$/ | ||
end | ||
result.subscription.id.should =~ /^[a-z0-9]{6}$/ | ||
end | ||
|
||
it "assigns unique IDs to each subscription" do | ||
first_result = Braintree::Subscription.create(:payment_method_token => payment_method_token, | ||
:plan_id => plan_id) | ||
second_result = Braintree::Subscription.create(:payment_method_token => payment_method_token_2, | ||
:plan_id => plan_id) | ||
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 | ||
first_result.subscription.id.should_not == second_result.subscription.id | ||
end | ||
|
||
it "sets the next billing date to 1 month from now in UTC" do | ||
Timecop.freeze do | ||
result = Braintree::Subscription.create(:payment_method_token => payment_method_token, | ||
:plan_id => plan_id) | ||
it "sets the next billing date to 1 month from now in UTC" do | ||
Timecop.freeze do | ||
result = Braintree::Subscription.create(:payment_method_token => cc_token, | ||
:plan_id => plan_id) | ||
|
||
result.subscription.next_billing_date.to_i.should == 1.month.from_now.utc.to_i | ||
end | ||
result.subscription.next_billing_date.to_i.should == 1.month.from_now.utc.to_i | ||
end | ||
end | ||
end | ||
|
||
context "Braintree::Subscription.find" do | ||
let(:cc_number) { %w(4111 1111 1111 9876).join } | ||
let(:expiration_date) { "04/2016" } | ||
let(:payment_method_token) { braintree_credit_card_token(cc_number, expiration_date) } | ||
let(:plan_id) { 'my-plan-id' } | ||
let(:subscription_result) { Braintree::Subscription.create(:payment_method_token => payment_method_token, | ||
:plan_id => plan_id) } | ||
|
||
it "can find a created subscription" do | ||
subscription = Braintree::Subscription.find(subscription_result.subscription.id) | ||
subscription.should_not be_nil | ||
subscription.payment_method_token.should == payment_method_token | ||
subscription.plan_id.should == plan_id | ||
end | ||
describe "Braintree::Subscription.find" do | ||
|
||
it "raises a Braintree:NotFoundError when it cannot find a subscription" do | ||
expect { Braintree::Subscription.find('abc123') }.to raise_error(Braintree::NotFoundError, /abc123/) | ||
end | ||
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
module CustomerHelpers | ||
def create_customer(credit_card_options = {}) | ||
credit_card_options[:number] ||= TEST_CC_NUMBER | ||
credit_card_options[:expiration_date] ||= '04/2016' | ||
Braintree::Customer.create(:credit_card => credit_card_options) | ||
end | ||
|
||
def create_customer_with_invalid_card(credit_card_options = {}) | ||
credit_card_options[:number] = '123456' | ||
create_customer(credit_card_options) | ||
end | ||
end |