forked from pay-rails/pay
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Continues organizing API and tests all existing methods
- Loading branch information
1 parent
130052a
commit 2cfd1fb
Showing
11 changed files
with
334 additions
and
53 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
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 |
---|---|---|
|
@@ -10,8 +10,8 @@ Gem::Specification.new do |s| | |
s.authors = ['Jason Charnes'] | ||
s.email = ['[email protected]'] | ||
s.homepage = 'https://github.com/jasoncharnes/pay' | ||
s.summary = 'A wrapper for handing subscriptions in Rails.' | ||
s.description = 'A wrapper for handing subscriptions in Rails.' | ||
s.summary = 'A Ruby on Rails subscription engine.' | ||
s.description = 'A Ruby on Rails subscription engine.' | ||
s.license = 'MIT' | ||
|
||
s.files = Dir[ | ||
|
@@ -26,6 +26,7 @@ Gem::Specification.new do |s| | |
s.add_dependency 'braintree', '~> 2.75' | ||
|
||
s.add_development_dependency 'byebug' | ||
s.add_development_dependency 'mocha' | ||
s.add_development_dependency 'pry' | ||
s.add_development_dependency 'rubocop' | ||
s.add_development_dependency 'sqlite3' | ||
|
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,99 @@ | ||
require 'test_helper' | ||
require 'stripe_mock' | ||
require 'minitest/mock' | ||
|
||
class Pay::Billable::Stripe::Test < ActiveSupport::TestCase | ||
setup do | ||
StripeMock.start | ||
|
||
@billable = User.new | ||
|
||
@stripe_helper = StripeMock.create_test_helper | ||
@stripe_helper.create_plan(id: 'test-monthly', amount: 1500) | ||
end | ||
|
||
teardown do | ||
StripeMock.stop | ||
end | ||
|
||
test 'getting a stripe customer with a processor id' do | ||
customer = Stripe::Customer.create( | ||
email: '[email protected]', | ||
card: @stripe_helper.generate_card_token | ||
) | ||
|
||
@billable.processor_id = customer.id | ||
|
||
assert_equal @billable.stripe_customer, customer | ||
end | ||
|
||
test 'getting a stripe customer without a processor id' do | ||
assert_nil @billable.processor | ||
assert_nil @billable.processor_id | ||
|
||
@billable.email = '[email protected]' | ||
@billable.card_token = @stripe_helper.generate_card_token( | ||
brand: 'Visa', | ||
last4: '9191', | ||
exp_year: 1984 | ||
) | ||
|
||
@billable.stripe_customer | ||
|
||
assert_equal @billable.processor, 'stripe' | ||
assert_not_nil @billable.processor_id | ||
end | ||
|
||
test 'can create a subscription' do | ||
@billable.card_token = @stripe_helper.generate_card_token( | ||
brand: 'Visa', | ||
last4: '9191', | ||
exp_year: 1984 | ||
) | ||
@billable.subscribe('default', 'test-monthly') | ||
|
||
assert @billable.subscribed? | ||
assert_equal 'default', @billable.subscription.name | ||
assert_equal 'test-monthly', @billable.subscription.processor_plan | ||
end | ||
|
||
test 'can update their card' do | ||
customer = Stripe::Customer.create( | ||
email: '[email protected]', | ||
card: @stripe_helper.generate_card_token | ||
) | ||
|
||
@billable.stubs(:customer).returns(customer) | ||
card = @stripe_helper.generate_card_token(brand: 'Visa', last4: '4242') | ||
@billable.processor = 'stripe' | ||
@billable.update_card(card) | ||
|
||
assert @billable.card_brand == 'Visa' | ||
assert @billable.card_last4 == '4242' | ||
|
||
card = @stripe_helper.generate_card_token( | ||
brand: 'Discover', | ||
last4: '1117' | ||
) | ||
@billable.update_card(card) | ||
|
||
assert @billable.card_brand == 'Discover' | ||
assert @billable.card_last4 == '1117' | ||
end | ||
|
||
test 'retriving a stripe subscription' do | ||
@stripe_helper.create_plan(id: 'default', amount: 1500) | ||
|
||
customer = Stripe::Customer.create( | ||
email: '[email protected]', | ||
source: @stripe_helper.generate_card_token(brand: 'Visa', last4: '4242') | ||
) | ||
|
||
subscription = Stripe::Subscription.create( | ||
plan: 'default', | ||
customer: customer.id | ||
) | ||
|
||
assert_equal @billable.stripe_subscription(subscription.id), subscription | ||
end | ||
end |
Oops, something went wrong.