Skip to content

Commit 0e9e271

Browse files
committed
Code improvements
1 parent f32c2ea commit 0e9e271

File tree

2 files changed

+13
-14
lines changed

2 files changed

+13
-14
lines changed

lib/stripe_mock/request_handlers/customers.rb

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ def new_customer(route, method_url, params, headers)
2929
params[:default_source] = sources.first[:id]
3030
end
3131

32-
customers[ params[:id] ] = Data.mock_customer(sources, params)
32+
customers[params[:id]] = Data.mock_customer(sources, params)
3333

3434
if params[:plan]
3535
plan_id = params[:plan].to_s
@@ -48,13 +48,12 @@ def new_customer(route, method_url, params, headers)
4848
end
4949

5050
if params[:coupon]
51-
coupon = coupons[ params[:coupon] ]
51+
coupon = coupons[params[:coupon]]
5252
assert_existence :coupon, params[:coupon], coupon
53-
5453
add_coupon_to_object(customers[params[:id]], coupon)
5554
end
5655

57-
customers[ params[:id] ]
56+
customers[params[:id]]
5857
end
5958

6059
def update_customer(route, method_url, params, headers)

spec/shared_stripe_examples/customer_examples.rb

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ def gen_card_tk
114114
expect(customer.subscriptions.first.customer).to eq(customer.id)
115115
end
116116

117-
it "creates a customer with a plan (string/symbol agnostic)" do
117+
it 'creates a customer with a plan (string/symbol agnostic)' do
118118
stripe_helper.create_plan(id: 'silver', product: product.id)
119119

120120
Stripe::Customer.create(id: 'cust_SLV1', source: gen_card_tk, :plan => 'silver')
@@ -135,7 +135,6 @@ def gen_card_tk
135135
end
136136

137137
context "create customer" do
138-
139138
it "with a trial when trial_end is set" do
140139
plan = stripe_helper.create_plan(id: 'no_trial', product: product.id, amount: 999)
141140
trial_end = Time.now.utc.to_i + 3600
@@ -195,7 +194,7 @@ def gen_card_tk
195194
expect(customer.subscriptions.first.trial_end).to be_nil
196195
end
197196

198-
it "returns an error if trial_end is set to a past time" do
197+
it 'returns an error if trial_end is set to a past time' do
199198
plan = stripe_helper.create_plan(id: 'silver', product: product.id, amount: 999)
200199
expect {
201200
Stripe::Customer.create(id: 'test_cus_trial_end', source: gen_card_tk, plan: 'silver', trial_end: Time.now.utc.to_i - 3600)
@@ -205,7 +204,7 @@ def gen_card_tk
205204
}
206205
end
207206

208-
it "returns an error if trial_end is set without a plan" do
207+
it 'returns an error if trial_end is set without a plan' do
209208
expect {
210209
Stripe::Customer.create(id: 'test_cus_trial_end', source: gen_card_tk, trial_end: "now")
211210
}.to raise_error {|e|
@@ -218,7 +217,7 @@ def gen_card_tk
218217

219218
it 'cannot create a customer with a plan that does not exist' do
220219
expect {
221-
customer = Stripe::Customer.create(id: 'test_cus_no_plan', source: gen_card_tk, :plan => 'non-existant')
220+
Stripe::Customer.create(id: 'test_cus_no_plan', source: gen_card_tk, :plan => 'non-existant')
222221
}.to raise_error {|e|
223222
expect(e).to be_a(Stripe::InvalidRequestError)
224223
expect(e.message).to eq('No such plan: non-existant')
@@ -228,18 +227,17 @@ def gen_card_tk
228227
it 'cannot create a customer with an existing plan, but no card token' do
229228
plan = stripe_helper.create_plan(id: 'p', product: product.id)
230229
expect {
231-
customer = Stripe::Customer.create(id: 'test_cus_no_plan', :plan => 'p')
230+
Stripe::Customer.create(id: 'test_cus_no_plan', :plan => 'p')
232231
}.to raise_error {|e|
233232
expect(e).to be_a(Stripe::InvalidRequestError)
234233
expect(e.message).to eq('You must supply a valid card')
235234
}
236235
end
237236

238237
it 'creates a customer with a coupon discount' do
239-
coupon = Stripe::Coupon.create(id: "10PERCENT", duration: 'once')
238+
coupon = Stripe::Coupon.create(id: '10PERCENT', duration: 'once')
240239

241-
customer =
242-
Stripe::Customer.create(id: 'test_cus_coupon', coupon: '10PERCENT')
240+
Stripe::Customer.create(id: 'test_cus_coupon', coupon: '10PERCENT')
243241

244242
customer = Stripe::Customer.retrieve('test_cus_coupon')
245243
expect(customer.discount).to_not be_nil
@@ -251,19 +249,21 @@ def gen_card_tk
251249
describe 'repeating coupon with duration limit', live: true do
252250
let!(:coupon) { stripe_helper.create_coupon(id: '10OFF', amount_off: 1000, currency: 'usd', duration: 'repeating', duration_in_months: 12) }
253251
let!(:customer) { Stripe::Customer.create(coupon: coupon.id) }
252+
254253
it 'creates the discount with the end date', live: true do
255254
discount = Stripe::Customer.retrieve(customer.id).discount
256255
expect(discount).to_not be_nil
257256
expect(discount.coupon).to_not be_nil
258257
expect(discount.end).to be_within(10).of (DateTime.now >> 12).to_time.to_i
259258
end
259+
260260
after { Stripe::Coupon.retrieve(coupon.id).delete }
261261
after { Stripe::Customer.retrieve(customer.id).delete }
262262
end
263263

264264
it 'cannot create a customer with a coupon that does not exist' do
265265
expect{
266-
customer = Stripe::Customer.create(id: 'test_cus_no_coupon', coupon: '5OFF')
266+
Stripe::Customer.create(id: 'test_cus_no_coupon', coupon: '5OFF')
267267
}.to raise_error {|e|
268268
expect(e).to be_a(Stripe::InvalidRequestError)
269269
expect(e.message).to eq('No such coupon: 5OFF')

0 commit comments

Comments
 (0)