Skip to content

Commit

Permalink
Use stripe-ruby-mock.
Browse files Browse the repository at this point in the history
  • Loading branch information
dblock committed Jun 22, 2016
1 parent 2196048 commit ed1d332
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 14 deletions.
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ group :development, :test do
gem 'rake', '~> 10.4'
gem 'rubocop', '0.34.2'
gem 'foreman'
gem 'stripe-ruby-mock', require: 'stripe_mock'
end

group :development do
Expand Down
12 changes: 12 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ GEM
descendants_tracker (~> 0.0.4)
ice_nine (~> 0.11.0)
thread_safe (~> 0.3, >= 0.3.1)
blankslate (3.1.3)
bson (4.1.1)
builder (3.2.2)
capybara (2.7.1)
Expand Down Expand Up @@ -67,6 +68,7 @@ GEM
descendants_tracker (~> 0.0.1)
crack (0.4.3)
safe_yaml (~> 1.0.0)
dante (0.2.0)
database_cleaner (1.5.3)
descendants_tracker (0.0.4)
thread_safe (~> 0.3, >= 0.3.1)
Expand Down Expand Up @@ -141,6 +143,11 @@ GEM
uri_template
i18n (0.7.0)
ice_nine (0.11.2)
jimson-temp (0.9.5)
blankslate (>= 3.1.2)
multi_json (~> 1.0)
rack (~> 1.4)
rest-client (~> 1.0)
json (1.8.3)
kaminari (0.17.0)
actionpack (>= 3.0.0)
Expand Down Expand Up @@ -282,6 +289,10 @@ GEM
websocket-driver
stripe (1.43.1)
rest-client (~> 1.4)
stripe-ruby-mock (2.2.3)
dante (>= 0.2.0)
jimson-temp
stripe (>= 1.31.0)
thor (0.19.1)
thread_safe (0.3.5)
time_ago_in_words (0.1.1)
Expand Down Expand Up @@ -337,6 +348,7 @@ DEPENDENCIES
selenium-webdriver
slack-ruby-bot-server
stripe
stripe-ruby-mock
time_ago_in_words
vcr
wannabe_bool
Expand Down
25 changes: 11 additions & 14 deletions spec/api/endpoints/subscriptions_endpoint_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,28 +42,25 @@
end
end
context 'existing team' do
include_context :stripe_mock
let!(:team) { Fabricate(:team) }
it 'creates a subscription' do
expect(Stripe::Customer).to receive(:create).with(
source: 'token',
plan: 'slack-playplay-yearly',
email: 'foo@bar.com',
metadata: {
id: team._id,
team_id: team.team_id,
name: team.name,
domain: team.domain
}
).and_return('id' => 'customer_id')
before do
stripe_helper.create_plan(id: 'slack-playplay-yearly', amount: 2999)
client.subscriptions._post(
team_id: team._id,
stripe_token: 'token',
stripe_token: stripe_helper.generate_card_token,
stripe_token_type: 'card',
stripe_email: 'foo@bar.com'
)
team.reload
end
it 'creates a subscription' do
expect(team.premium).to be true
expect(team.stripe_customer_id).to eq 'customer_id'
expect(team.stripe_customer_id).to_not be_blank
customer = Stripe::Customer.retrieve(team.stripe_customer_id)
expect(customer).to_not be nil
subscriptions = customer.subscriptions
expect(subscriptions.count).to eq 1
end
end
end
Expand Down
10 changes: 10 additions & 0 deletions spec/support/stripe.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
RSpec.shared_context :stripe_mock do
let(:stripe_helper) { StripeMock.create_test_helper }
before do
StripeMock.start
end
after do
StripeMock.stop
end
end

RSpec.configure do |config|
config.before do
allow(Stripe).to receive(:api_key).and_return('key')
Expand Down

0 comments on commit ed1d332

Please sign in to comment.