stripe-ruby-mock 3.1.0 → 4.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (39) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/rspec_tests.yml +7 -10
  3. data/CHANGELOG.md +24 -0
  4. data/Gemfile +0 -5
  5. data/README.md +3 -3
  6. data/bin/stripe-mock-server +1 -0
  7. data/lib/stripe_mock/api/client.rb +1 -1
  8. data/lib/stripe_mock/data.rb +53 -9
  9. data/lib/stripe_mock/instance.rb +4 -2
  10. data/lib/stripe_mock/request_handlers/charges.rb +20 -1
  11. data/lib/stripe_mock/request_handlers/checkout_session.rb +12 -11
  12. data/lib/stripe_mock/request_handlers/customers.rb +12 -1
  13. data/lib/stripe_mock/request_handlers/helpers/search_helpers.rb +67 -0
  14. data/lib/stripe_mock/request_handlers/invoices.rb +18 -3
  15. data/lib/stripe_mock/request_handlers/payment_intents.rb +11 -2
  16. data/lib/stripe_mock/request_handlers/payment_methods.rb +5 -1
  17. data/lib/stripe_mock/request_handlers/payouts.rb +10 -3
  18. data/lib/stripe_mock/request_handlers/prices.rb +13 -4
  19. data/lib/stripe_mock/request_handlers/products.rb +14 -5
  20. data/lib/stripe_mock/request_handlers/subscriptions.rb +11 -2
  21. data/lib/stripe_mock/request_handlers/tax_ids.rb +66 -0
  22. data/lib/stripe_mock/server.rb +9 -4
  23. data/lib/stripe_mock/test_strategies/base.rb +0 -1
  24. data/lib/stripe_mock/version.rb +1 -1
  25. data/lib/stripe_mock.rb +2 -0
  26. data/spec/shared_stripe_examples/bank_token_examples.rb +5 -7
  27. data/spec/shared_stripe_examples/charge_examples.rb +97 -0
  28. data/spec/shared_stripe_examples/checkout_session_examples.rb +0 -5
  29. data/spec/shared_stripe_examples/customer_examples.rb +56 -0
  30. data/spec/shared_stripe_examples/invoice_examples.rb +86 -1
  31. data/spec/shared_stripe_examples/payment_intent_examples.rb +75 -13
  32. data/spec/shared_stripe_examples/payment_method_examples.rb +10 -0
  33. data/spec/shared_stripe_examples/payout_examples.rb +26 -6
  34. data/spec/shared_stripe_examples/price_examples.rb +70 -1
  35. data/spec/shared_stripe_examples/product_examples.rb +71 -0
  36. data/spec/shared_stripe_examples/subscription_examples.rb +65 -6
  37. data/spec/spec_helper.rb +1 -1
  38. data/stripe-ruby-mock.gemspec +3 -3
  39. metadata +22 -17
@@ -90,9 +90,9 @@ shared_examples 'PaymentIntent API' do
90
90
  amount: 100, currency: 'usd', confirm: true
91
91
  )
92
92
  expect(payment_intent.status).to eq('succeeded')
93
- expect(payment_intent.charges.data.size).to eq(1)
94
- expect(payment_intent.charges.data.first.object).to eq('charge')
95
- balance_txn = payment_intent.charges.data.first.balance_transaction
93
+ charge = Stripe::Charge.retrieve(payment_intent.latest_charge)
94
+ expect(charge.object).to eq('charge')
95
+ balance_txn = charge.balance_transaction
96
96
  expect(balance_txn).to match(/^test_txn/)
97
97
  expect(Stripe::BalanceTransaction.retrieve(balance_txn).id).to eq(balance_txn)
98
98
  end
@@ -104,7 +104,7 @@ shared_examples 'PaymentIntent API' do
104
104
  customer: customer,
105
105
  payment_method: customer.sources.first
106
106
 
107
- charge = payment_intent.charges.data.first
107
+ charge = Stripe::Charge.retrieve(payment_intent.latest_charge)
108
108
  expect(charge.amount).to eq(payment_intent.amount)
109
109
  expect(charge.payment_intent).to eq(payment_intent.id)
110
110
  expect(charge.description).to be_nil
@@ -121,17 +121,17 @@ shared_examples 'PaymentIntent API' do
121
121
  amount: 100, currency: "usd", confirm: true, payment_method: "test_pm_1"
122
122
  )
123
123
  expect(payment_intent.status).to eq("succeeded")
124
- expect(payment_intent.charges.data.size).to eq(1)
125
- expect(payment_intent.charges.data.first.object).to eq("charge")
126
- expect(payment_intent.charges.data.first.payment_method).to eq("test_pm_1")
124
+ charge = Stripe::Charge.retrieve(payment_intent.latest_charge)
125
+ expect(charge.object).to eq("charge")
126
+ expect(charge.payment_method).to eq("test_pm_1")
127
127
  end
128
128
 
129
129
  it "confirms a stripe payment_intent" do
130
130
  payment_intent = Stripe::PaymentIntent.create(amount: 100, currency: "usd")
131
131
  confirmed_payment_intent = payment_intent.confirm()
132
132
  expect(confirmed_payment_intent.status).to eq("succeeded")
133
- expect(confirmed_payment_intent.charges.data.size).to eq(1)
134
- expect(confirmed_payment_intent.charges.data.first.object).to eq('charge')
133
+ charge = Stripe::Charge.retrieve(confirmed_payment_intent.latest_charge)
134
+ expect(charge.object).to eq('charge')
135
135
  end
136
136
 
137
137
  it 'creates a charge for a confirmed stripe payment_intent' do
@@ -141,7 +141,7 @@ shared_examples 'PaymentIntent API' do
141
141
  payment_method: customer.sources.first
142
142
 
143
143
  confirmed_payment_intent = payment_intent.confirm
144
- charge = confirmed_payment_intent.charges.data.first
144
+ charge = Stripe::Charge.retrieve(payment_intent.latest_charge)
145
145
  expect(charge.amount).to eq(confirmed_payment_intent.amount)
146
146
  expect(charge.payment_intent).to eq(confirmed_payment_intent.id)
147
147
  expect(charge.description).to be_nil
@@ -157,8 +157,8 @@ shared_examples 'PaymentIntent API' do
157
157
  payment_intent = Stripe::PaymentIntent.create(amount: 100, currency: "usd")
158
158
  confirmed_payment_intent = payment_intent.capture()
159
159
  expect(confirmed_payment_intent.status).to eq("succeeded")
160
- expect(confirmed_payment_intent.charges.data.size).to eq(1)
161
- expect(confirmed_payment_intent.charges.data.first.object).to eq('charge')
160
+ charge = Stripe::Charge.retrieve(confirmed_payment_intent.latest_charge)
161
+ expect(charge.object).to eq('charge')
162
162
  end
163
163
 
164
164
  it 'creates a charge for a captured stripe payment_intent' do
@@ -170,7 +170,7 @@ shared_examples 'PaymentIntent API' do
170
170
  capture_method: 'manual'
171
171
 
172
172
  captured_payment_intent = payment_intent.capture
173
- charge = captured_payment_intent.charges.data.first
173
+ charge = Stripe::Charge.retrieve(captured_payment_intent.latest_charge)
174
174
  expect(charge.amount).to eq(captured_payment_intent.amount)
175
175
  expect(charge.payment_intent).to eq(captured_payment_intent.id)
176
176
  expect(charge.description).to be_nil
@@ -218,4 +218,66 @@ shared_examples 'PaymentIntent API' do
218
218
  expect(e.http_status).to eq(400)
219
219
  }
220
220
  end
221
+
222
+ context "search" do
223
+ # the Search API requires about a minute between writes and reads, so add sleeps accordingly when running live
224
+ it "searches payment intents for exact matches", :aggregate_failures do
225
+ response = Stripe::PaymentIntent.search({query: 'currency:"usd"'}, stripe_version: '2020-08-27')
226
+ expect(response.data.size).to eq(0)
227
+
228
+ customer = Stripe::Customer.create(email: 'johnny@appleseed.com', source: stripe_helper.generate_card_token)
229
+ one = Stripe::PaymentIntent.create(
230
+ amount: 100,
231
+ customer: customer.id,
232
+ currency: 'usd',
233
+ metadata: {key: 'uno'},
234
+ )
235
+ two = Stripe::PaymentIntent.create(
236
+ amount: 3184, # status: requires_action
237
+ customer: customer.id,
238
+ currency: 'gbp',
239
+ metadata: {key: 'dos'},
240
+ )
241
+
242
+ response = Stripe::PaymentIntent.search({query: 'amount:100'}, stripe_version: '2020-08-27')
243
+ expect(response.data.map(&:id)).to match_array([one.id])
244
+
245
+ response = Stripe::PaymentIntent.search({query: 'currency:"gbp"'}, stripe_version: '2020-08-27')
246
+ expect(response.data.map(&:id)).to match_array([two.id])
247
+
248
+ response = Stripe::PaymentIntent.search({query: %(customer:"#{customer.id}")}, stripe_version: '2020-08-27')
249
+ expect(response.data.map(&:id)).to match_array([one.id, two.id])
250
+
251
+ response = Stripe::PaymentIntent.search({query: 'status:"requires_action"'}, stripe_version: '2020-08-27')
252
+ expect(response.data.map(&:id)).to match_array([two.id])
253
+
254
+ response = Stripe::PaymentIntent.search({query: 'metadata["key"]:"uno"'}, stripe_version: '2020-08-27')
255
+ expect(response.data.map(&:id)).to match_array([one.id])
256
+ end
257
+
258
+ it "respects limit", :aggregate_failures do
259
+ 11.times do
260
+ Stripe::PaymentIntent.create(amount: 100, currency: 'usd')
261
+ end
262
+
263
+ response = Stripe::PaymentIntent.search({query: 'amount:100'}, stripe_version: '2020-08-27')
264
+ expect(response.data.size).to eq(10)
265
+ response = Stripe::PaymentIntent.search({query: 'amount:100', limit: 1}, stripe_version: '2020-08-27')
266
+ expect(response.data.size).to eq(1)
267
+ end
268
+
269
+ it "reports search errors", :aggregate_failures do
270
+ expect {
271
+ Stripe::PaymentIntent.search({limit: 1}, stripe_version: '2020-08-27')
272
+ }.to raise_error(Stripe::InvalidRequestError, /Missing required param: query./)
273
+
274
+ expect {
275
+ Stripe::PaymentIntent.search({query: 'asdf'}, stripe_version: '2020-08-27')
276
+ }.to raise_error(Stripe::InvalidRequestError, /We were unable to parse your search query./)
277
+
278
+ expect {
279
+ Stripe::PaymentIntent.search({query: 'foo:"bar"'}, stripe_version: '2020-08-27')
280
+ }.to raise_error(Stripe::InvalidRequestError, /Field `foo` is an unsupported search field for resource `payment_intents`./)
281
+ end
282
+ end
221
283
  end
@@ -450,5 +450,15 @@ shared_examples 'PaymentMethod API' do
450
450
  end.to raise_error(Stripe::InvalidRequestError)
451
451
  end
452
452
  end
453
+
454
+ context 'with us_bank_account' do
455
+ let(:payment_method) do
456
+ Stripe::PaymentMethod.create(type: 'us_bank_account')
457
+ end
458
+
459
+ it 'works' do
460
+ expect(payment_method.type).to eq('us_bank_account')
461
+ end
462
+ end
453
463
  end
454
464
  end
@@ -3,10 +3,10 @@ require 'spec_helper'
3
3
  shared_examples 'Payout API' do
4
4
 
5
5
  it "creates a stripe payout" do
6
- payout = Stripe::Payout.create(amount: "100", currency: "usd")
6
+ payout = Stripe::Payout.create(amount: 100, currency: "usd")
7
7
 
8
8
  expect(payout.id).to match(/^test_po/)
9
- expect(payout.amount).to eq('100')
9
+ expect(payout.amount).to eq(100)
10
10
  expect(payout.currency).to eq('usd')
11
11
  expect(payout.metadata.to_hash).to eq({})
12
12
  end
@@ -14,7 +14,7 @@ shared_examples 'Payout API' do
14
14
  describe "listing payouts" do
15
15
  before do
16
16
  3.times do
17
- Stripe::Payout.create(amount: "100", currency: "usd")
17
+ Stripe::Payout.create(amount: 100, currency: "usd")
18
18
  end
19
19
  end
20
20
 
@@ -28,7 +28,7 @@ shared_examples 'Payout API' do
28
28
  end
29
29
 
30
30
  it "retrieves a stripe payout" do
31
- original = Stripe::Payout.create(amount: "100", currency: "usd")
31
+ original = Stripe::Payout.create(amount: 100, currency: "usd")
32
32
  payout = Stripe::Payout.retrieve(original.id)
33
33
 
34
34
  expect(payout.id).to eq(original.id)
@@ -37,6 +37,25 @@ shared_examples 'Payout API' do
37
37
  expect(payout.metadata.to_hash).to eq(original.metadata.to_hash)
38
38
  end
39
39
 
40
+ it "updates a stripe payout using method" do
41
+ original = Stripe::Payout.create(amount: 100, currency: "usd")
42
+ updated = Stripe::Payout.update(original.id, amount: 1337)
43
+ payout = Stripe::Payout.retrieve(original.id)
44
+ expect(payout.amount).to eq(1337)
45
+ end
46
+
47
+ it "updates a stripe payout object" do
48
+ original = Stripe::Payout.create(amount: 100, currency: "usd")
49
+ payout = Stripe::Payout.retrieve(original.id)
50
+
51
+ expect(payout.id).to eq(original.id)
52
+
53
+ payout.amount = 1337
54
+ payout.save
55
+ payout = Stripe::Payout.retrieve(original.id)
56
+ expect(payout.amount).to eq(1337)
57
+ end
58
+
40
59
  it "cannot retrieve a payout that doesn't exist" do
41
60
  expect { Stripe::Payout.retrieve('nope') }.to raise_error {|e|
42
61
  expect(e).to be_a Stripe::InvalidRequestError
@@ -46,17 +65,18 @@ shared_examples 'Payout API' do
46
65
  end
47
66
 
48
67
  it 'when amount is not integer', live: true do
49
- expect { Stripe::Payout.create(amount: '400.2',
68
+ expect { Stripe::Payout.create(amount: 400.2,
50
69
  currency: 'usd',
51
70
  description: 'Payout for test@example.com') }.to raise_error { |e|
52
71
  expect(e).to be_a Stripe::InvalidRequestError
53
72
  expect(e.param).to eq('amount')
73
+ expect(e.message).to match(/^Invalid.*integer/)
54
74
  expect(e.http_status).to eq(400)
55
75
  }
56
76
  end
57
77
 
58
78
  it 'when amount is negative', live: true do
59
- expect { Stripe::Payout.create(amount: '-400',
79
+ expect { Stripe::Payout.create(amount: -400,
60
80
  currency: 'usd',
61
81
  description: 'Payout for test@example.com') }.to raise_error { |e|
62
82
  expect(e).to be_a Stripe::InvalidRequestError
@@ -128,7 +128,7 @@ shared_examples 'Price API' do
128
128
  expect(two.map &:id).to include('price Two')
129
129
  expect(two.map &:amount).to include(98765)
130
130
  end
131
-
131
+
132
132
  it "retrieves prices filtering by currency" do
133
133
  5.times do | i|
134
134
  stripe_helper.create_price(id: "usd price #{i}", product: product_id, amount: 11, currency: 'usd')
@@ -165,6 +165,75 @@ shared_examples 'Price API' do
165
165
  expect(other_product_prices.all? {|p| p.product == other_product.id }).to be_truthy
166
166
  end
167
167
 
168
+ context "searching prices" do
169
+ # the Search API requires about a minute between writes and reads, so add sleeps accordingly when running live
170
+ it "searches prices for exact matches", :aggregate_failures do
171
+ response = Stripe::Price.search({query: 'currency:"usd"'}, stripe_version: '2020-08-27')
172
+ expect(response.data.size).to eq(0)
173
+
174
+ one = stripe_helper.create_price(
175
+ amount: 100,
176
+ currency: 'usd',
177
+ lookup_key: 'one',
178
+ product: product_id,
179
+ metadata: {key: 'uno'},
180
+ type: "one_time",
181
+ )
182
+ two = stripe_helper.create_price(
183
+ active: false,
184
+ amount: 200,
185
+ currency: 'gbp',
186
+ lookup_key: 'two',
187
+ product: product_id,
188
+ recurring: {interval: 'month'},
189
+ metadata: {key: 'dos'},
190
+ )
191
+
192
+ response = Stripe::Price.search({query: 'active:"true"'}, stripe_version: '2020-08-27')
193
+ expect(response.data.map(&:id)).to match_array([one.id])
194
+
195
+ response = Stripe::Price.search({query: 'currency:"gbp"'}, stripe_version: '2020-08-27')
196
+ expect(response.data.map(&:id)).to match_array([two.id])
197
+
198
+ response = Stripe::Price.search({query: 'lookup_key:"one"'}, stripe_version: '2020-08-27')
199
+ expect(response.data.map(&:id)).to match_array([one.id])
200
+
201
+ response = Stripe::Price.search({query: %(product:"#{product.id}")}, stripe_version: '2020-08-27')
202
+ expect(response.data.map(&:id)).to match_array([one.id, two.id])
203
+
204
+ response = Stripe::Price.search({query: 'type:"recurring"'}, stripe_version: '2020-08-27')
205
+ expect(response.data.map(&:id)).to match_array([two.id])
206
+
207
+ response = Stripe::Price.search({query: 'metadata["key"]:"uno"'}, stripe_version: '2020-08-27')
208
+ expect(response.data.map(&:id)).to match_array([one.id])
209
+ end
210
+
211
+ it "respects limit", :aggregate_failures do
212
+ 11.times do
213
+ stripe_helper.create_price(product: product_id)
214
+ end
215
+
216
+ response = Stripe::Price.search({query: %(product:"#{product.id}")}, stripe_version: '2020-08-27')
217
+ expect(response.data.size).to eq(10)
218
+ response = Stripe::Price.search({query: %(product:"#{product.id}"), limit: 1}, stripe_version: '2020-08-27')
219
+ expect(response.data.size).to eq(1)
220
+ end
221
+
222
+ it "reports search errors", :aggregate_failures do
223
+ expect {
224
+ Stripe::Price.search({limit: 1}, stripe_version: '2020-08-27')
225
+ }.to raise_error(Stripe::InvalidRequestError, /Missing required param: query./)
226
+
227
+ expect {
228
+ Stripe::Price.search({query: 'asdf'}, stripe_version: '2020-08-27')
229
+ }.to raise_error(Stripe::InvalidRequestError, /We were unable to parse your search query./)
230
+
231
+ expect {
232
+ Stripe::Price.search({query: 'foo:"bar"'}, stripe_version: '2020-08-27')
233
+ }.to raise_error(Stripe::InvalidRequestError, /Field `foo` is an unsupported search field for resource `prices`./)
234
+ end
235
+ end
236
+
168
237
  describe "Validations", :live => true do
169
238
  include_context "stripe validator"
170
239
  let(:params) { stripe_helper.create_price_params(product: product_id) }
@@ -85,6 +85,74 @@ shared_examples "Product API" do
85
85
  expect(all.count).to eq(100)
86
86
  end
87
87
 
88
+ context "searching products" do
89
+ # the Search API requires about a minute between writes and reads, so add sleeps accordingly when running live
90
+ it "searches products for exact matches", :aggregate_failures do
91
+ response = Stripe::Product.search({query: 'name:"one"'}, stripe_version: '2020-08-27')
92
+ expect(response.data.size).to eq(0)
93
+
94
+ one = stripe_helper.create_product(
95
+ id: "product_1",
96
+ name: "one",
97
+ description: "un",
98
+ shippable: true,
99
+ url: "http://example.com/one",
100
+ metadata: {key: "uno"},
101
+ )
102
+ two = stripe_helper.create_product(
103
+ id: "product_2",
104
+ name: "two",
105
+ active: false,
106
+ description: "deux",
107
+ url: "http://example.com/two",
108
+ metadata: {key: "dos"},
109
+ )
110
+
111
+ response = Stripe::Product.search({query: 'active:"true"'}, stripe_version: '2020-08-27')
112
+ expect(response.data.map(&:id)).to match_array([one.id])
113
+
114
+ response = Stripe::Product.search({query: 'description:"deux"'}, stripe_version: '2020-08-27')
115
+ expect(response.data.map(&:id)).to match_array([two.id])
116
+
117
+ response = Stripe::Product.search({query: 'name:"one"'}, stripe_version: '2020-08-27')
118
+ expect(response.data.map(&:id)).to match_array([one.id])
119
+
120
+ response = Stripe::Product.search({query: 'shippable:"true"'}, stripe_version: '2020-08-27')
121
+ expect(response.data.map(&:id)).to match_array([one.id])
122
+
123
+ response = Stripe::Product.search({query: 'url:"http://example.com/two"'}, stripe_version: '2020-08-27')
124
+ expect(response.data.map(&:id)).to match_array([two.id])
125
+
126
+ response = Stripe::Product.search({query: 'metadata["key"]:"uno"'}, stripe_version: '2020-08-27')
127
+ expect(response.data.map(&:id)).to match_array([one.id])
128
+ end
129
+
130
+ it "respects limit", :aggregate_failures do
131
+ 11.times do |i|
132
+ stripe_helper.create_product(id: "product_#{i}", name: "Product #{i}")
133
+ end
134
+
135
+ response = Stripe::Product.search({query: 'active:"true"'}, stripe_version: '2020-08-27')
136
+ expect(response.data.size).to eq(10)
137
+ response = Stripe::Product.search({query: 'active:"true"', limit: 1}, stripe_version: '2020-08-27')
138
+ expect(response.data.size).to eq(1)
139
+ end
140
+
141
+ it "reports search errors", :aggregate_failures do
142
+ expect {
143
+ Stripe::Product.search({limit: 1}, stripe_version: '2020-08-27')
144
+ }.to raise_error(Stripe::InvalidRequestError, /Missing required param: query./)
145
+
146
+ expect {
147
+ Stripe::Product.search({query: 'asdf'}, stripe_version: '2020-08-27')
148
+ }.to raise_error(Stripe::InvalidRequestError, /We were unable to parse your search query./)
149
+
150
+ expect {
151
+ Stripe::Product.search({query: 'foo:"bar"'}, stripe_version: '2020-08-27')
152
+ }.to raise_error(Stripe::InvalidRequestError, /Field `foo` is an unsupported search field for resource `products`./)
153
+ end
154
+ end
155
+
88
156
  describe "Validation", :live => true do
89
157
  include_context "stripe validator"
90
158
  let(:params) { stripe_helper.create_product_params }
@@ -124,15 +192,18 @@ shared_examples "Product API" do
124
192
  :attributes,
125
193
  :caption,
126
194
  :created,
195
+ :default_price,
127
196
  :deactivate_on,
128
197
  :description,
129
198
  :images,
199
+ :marketing_features,
130
200
  :livemode,
131
201
  :metadata,
132
202
  :name,
133
203
  :package_dimensions,
134
204
  :shippable,
135
205
  :statement_descriptor,
206
+ :tax_code,
136
207
  :type,
137
208
  :unit_label,
138
209
  :updated,
@@ -687,7 +687,7 @@ shared_examples 'Customer Subscriptions with plans' do
687
687
  customer = Stripe::Customer.create(id: 'test_customer_sub', source: gen_card_tk)
688
688
 
689
689
  sub = Stripe::Subscription.create({ items: { '0' => { plan: 'silver' } }, customer: customer.id })
690
- sub.delete(at_period_end: true)
690
+ sub.cancel(at_period_end: true)
691
691
 
692
692
  expect(sub.cancel_at_period_end).to be_truthy
693
693
  expect(sub.save).to be_truthy
@@ -752,7 +752,7 @@ shared_examples 'Customer Subscriptions with plans' do
752
752
  customer = Stripe::Customer.create(source: gen_card_tk, plan: plan.id)
753
753
 
754
754
  subscription = Stripe::Subscription.retrieve(customer.subscriptions.data.first.id)
755
- subscription.delete
755
+ subscription.cancel
756
756
 
757
757
  expect { subscription.save }.to raise_error { |e|
758
758
  expect(e).to be_a(Stripe::InvalidRequestError)
@@ -765,7 +765,7 @@ shared_examples 'Customer Subscriptions with plans' do
765
765
  customer = Stripe::Customer.create(id: 'test_customer_sub', source: gen_card_tk)
766
766
 
767
767
  sub = Stripe::Subscription.create({ items: [ { plan: plan.id } ], customer: customer.id })
768
- sub.delete(at_period_end: true)
768
+ sub.cancel(at_period_end: true)
769
769
 
770
770
  expect(sub.cancel_at_period_end).to be_truthy
771
771
  expect(sub.save).to be_truthy
@@ -1180,7 +1180,7 @@ shared_examples 'Customer Subscriptions with plans' do
1180
1180
  customer = Stripe::Customer.create(source: gen_card_tk, plan: plan.id)
1181
1181
 
1182
1182
  sub = Stripe::Subscription.retrieve(customer.subscriptions.data.first.id)
1183
- result = sub.delete
1183
+ result = sub.cancel
1184
1184
 
1185
1185
  expect(result.status).to eq('canceled')
1186
1186
  expect(result.cancel_at_period_end).to eq false
@@ -1247,7 +1247,7 @@ shared_examples 'Customer Subscriptions with plans' do
1247
1247
  customer = Stripe::Customer.create(id: 'test_customer_sub', source: gen_card_tk, plan: "trial")
1248
1248
 
1249
1249
  sub = Stripe::Subscription.retrieve(customer.subscriptions.data.first.id)
1250
- result = sub.delete(at_period_end: true)
1250
+ result = sub.cancel(at_period_end: true)
1251
1251
 
1252
1252
  expect(result.status).to eq('trialing')
1253
1253
 
@@ -1331,7 +1331,7 @@ shared_examples 'Customer Subscriptions with plans' do
1331
1331
  it "does not include canceled subscriptions by default" do
1332
1332
  customer = Stripe::Customer.create(source: gen_card_tk)
1333
1333
  subscription = Stripe::Subscription.create({ plan: plan.id, customer: customer.id })
1334
- subscription.delete
1334
+ subscription.cancel
1335
1335
 
1336
1336
  list = Stripe::Subscription.list({customer: customer.id})
1337
1337
 
@@ -1423,6 +1423,65 @@ shared_examples 'Customer Subscriptions with plans' do
1423
1423
  expect(subscription.items.data[0].metadata.to_h).to eq(foo: 'bar')
1424
1424
  end
1425
1425
  end
1426
+
1427
+ context "search" do
1428
+ # the Search API requires about a minute between writes and reads, so add sleeps accordingly when running live
1429
+ it "searches subscriptions for exact matches", :aggregate_failures do
1430
+ response = Stripe::Subscription.search({query: 'status:"active"'}, stripe_version: '2020-08-27')
1431
+ expect(response.data.size).to eq(0)
1432
+
1433
+ stripe_helper.create_plan(
1434
+ amount: 500,
1435
+ interval: 'month',
1436
+ product: product.id,
1437
+ currency: 'usd',
1438
+ id: 'Sample5'
1439
+ )
1440
+ customer = Stripe::Customer.create(email: 'johnny@appleseed.com', source: gen_card_tk)
1441
+ one = Stripe::Subscription.create(customer: customer.id, items: [{plan: "Sample5"}], metadata: {key: 'uno'})
1442
+ two = Stripe::Subscription.create(customer: customer.id, items: [{plan: "Sample5"}], metadata: {key: 'dos'})
1443
+ Stripe::Subscription.cancel(two.id)
1444
+
1445
+ response = Stripe::Subscription.search({query: 'status:"active"'}, stripe_version: '2020-08-27')
1446
+ expect(response.data.map(&:id)).to match_array([one.id])
1447
+
1448
+ response = Stripe::Subscription.search({query: 'metadata["key"]:"dos"'}, stripe_version: '2020-08-27')
1449
+ expect(response.data.map(&:id)).to match_array([two.id])
1450
+ end
1451
+
1452
+ it "respects limit", :aggregate_failures do
1453
+ stripe_helper.create_plan(
1454
+ amount: 500,
1455
+ interval: 'month',
1456
+ product: product.id,
1457
+ currency: 'usd',
1458
+ id: 'Sample5'
1459
+ )
1460
+ customer = Stripe::Customer.create(email: 'johnny@appleseed.com', source: gen_card_tk)
1461
+ 11.times do
1462
+ Stripe::Subscription.create(customer: customer.id, items: [{plan: "Sample5"}])
1463
+ end
1464
+
1465
+ response = Stripe::Subscription.search({query: 'status:"active"'}, stripe_version: '2020-08-27')
1466
+ expect(response.data.size).to eq(10)
1467
+ response = Stripe::Subscription.search({query: 'status:"active"', limit: 1}, stripe_version: '2020-08-27')
1468
+ expect(response.data.size).to eq(1)
1469
+ end
1470
+
1471
+ it "reports search errors", :aggregate_failures do
1472
+ expect {
1473
+ Stripe::Subscription.search({limit: 1}, stripe_version: '2020-08-27')
1474
+ }.to raise_error(Stripe::InvalidRequestError, /Missing required param: query./)
1475
+
1476
+ expect {
1477
+ Stripe::Subscription.search({query: 'asdf'}, stripe_version: '2020-08-27')
1478
+ }.to raise_error(Stripe::InvalidRequestError, /We were unable to parse your search query./)
1479
+
1480
+ expect {
1481
+ Stripe::Subscription.search({query: 'foo:"bar"'}, stripe_version: '2020-08-27')
1482
+ }.to raise_error(Stripe::InvalidRequestError, /Field `foo` is an unsupported search field for resource `subscriptions`./)
1483
+ end
1484
+ end
1426
1485
  end
1427
1486
 
1428
1487
  shared_examples 'Customer Subscriptions with prices' do
data/spec/spec_helper.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  require 'set'
2
2
 
3
- gem 'rspec', '~> 3.1'
3
+ gem 'rspec', '~> 3.13'
4
4
  require 'rspec'
5
5
  require 'stripe'
6
6
  require 'stripe_mock'
@@ -22,11 +22,11 @@ Gem::Specification.new do |gem|
22
22
  gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
23
23
  gem.require_paths = ['lib']
24
24
 
25
- gem.add_dependency 'stripe', '> 5', '< 6'
25
+ gem.add_dependency 'stripe', '> 5', '< 13'
26
26
  gem.add_dependency 'multi_json', '~> 1.0'
27
27
  gem.add_dependency 'dante', '>= 0.2.0'
28
+ gem.add_dependency 'drb', '>= 2.0.4', '< 3'
28
29
 
29
- gem.add_development_dependency 'rspec', '~> 3.7.0'
30
- gem.add_development_dependency 'rubygems-tasks', '~> 0.2'
30
+ gem.add_development_dependency 'rspec', '~> 3.13.0'
31
31
  gem.add_development_dependency 'thin', '~> 1.8.1'
32
32
  end
metadata CHANGED
@@ -1,14 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: stripe-ruby-mock
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.1.0
4
+ version: 4.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gilbert
8
- autorequire:
9
8
  bindir: bin
10
9
  cert_chain: []
11
- date: 2024-01-02 00:00:00.000000000 Z
10
+ date: 1980-01-02 00:00:00.000000000 Z
12
11
  dependencies:
13
12
  - !ruby/object:Gem::Dependency
14
13
  name: stripe
@@ -19,7 +18,7 @@ dependencies:
19
18
  version: '5'
20
19
  - - "<"
21
20
  - !ruby/object:Gem::Version
22
- version: '6'
21
+ version: '13'
23
22
  type: :runtime
24
23
  prerelease: false
25
24
  version_requirements: !ruby/object:Gem::Requirement
@@ -29,7 +28,7 @@ dependencies:
29
28
  version: '5'
30
29
  - - "<"
31
30
  - !ruby/object:Gem::Version
32
- version: '6'
31
+ version: '13'
33
32
  - !ruby/object:Gem::Dependency
34
33
  name: multi_json
35
34
  requirement: !ruby/object:Gem::Requirement
@@ -59,33 +58,39 @@ dependencies:
59
58
  - !ruby/object:Gem::Version
60
59
  version: 0.2.0
61
60
  - !ruby/object:Gem::Dependency
62
- name: rspec
61
+ name: drb
63
62
  requirement: !ruby/object:Gem::Requirement
64
63
  requirements:
65
- - - "~>"
64
+ - - ">="
66
65
  - !ruby/object:Gem::Version
67
- version: 3.7.0
68
- type: :development
66
+ version: 2.0.4
67
+ - - "<"
68
+ - !ruby/object:Gem::Version
69
+ version: '3'
70
+ type: :runtime
69
71
  prerelease: false
70
72
  version_requirements: !ruby/object:Gem::Requirement
71
73
  requirements:
72
- - - "~>"
74
+ - - ">="
73
75
  - !ruby/object:Gem::Version
74
- version: 3.7.0
76
+ version: 2.0.4
77
+ - - "<"
78
+ - !ruby/object:Gem::Version
79
+ version: '3'
75
80
  - !ruby/object:Gem::Dependency
76
- name: rubygems-tasks
81
+ name: rspec
77
82
  requirement: !ruby/object:Gem::Requirement
78
83
  requirements:
79
84
  - - "~>"
80
85
  - !ruby/object:Gem::Version
81
- version: '0.2'
86
+ version: 3.13.0
82
87
  type: :development
83
88
  prerelease: false
84
89
  version_requirements: !ruby/object:Gem::Requirement
85
90
  requirements:
86
91
  - - "~>"
87
92
  - !ruby/object:Gem::Version
88
- version: '0.2'
93
+ version: 3.13.0
89
94
  - !ruby/object:Gem::Dependency
90
95
  name: thin
91
96
  requirement: !ruby/object:Gem::Requirement
@@ -162,6 +167,7 @@ files:
162
167
  - lib/stripe_mock/request_handlers/helpers/charge_helpers.rb
163
168
  - lib/stripe_mock/request_handlers/helpers/coupon_helpers.rb
164
169
  - lib/stripe_mock/request_handlers/helpers/external_account_helpers.rb
170
+ - lib/stripe_mock/request_handlers/helpers/search_helpers.rb
165
171
  - lib/stripe_mock/request_handlers/helpers/subscription_helpers.rb
166
172
  - lib/stripe_mock/request_handlers/helpers/token_helpers.rb
167
173
  - lib/stripe_mock/request_handlers/invoice_items.rb
@@ -180,6 +186,7 @@ files:
180
186
  - lib/stripe_mock/request_handlers/sources.rb
181
187
  - lib/stripe_mock/request_handlers/subscription_items.rb
182
188
  - lib/stripe_mock/request_handlers/subscriptions.rb
189
+ - lib/stripe_mock/request_handlers/tax_ids.rb
183
190
  - lib/stripe_mock/request_handlers/tax_rates.rb
184
191
  - lib/stripe_mock/request_handlers/tokens.rb
185
192
  - lib/stripe_mock/request_handlers/transfers.rb
@@ -342,7 +349,6 @@ metadata:
342
349
  bug_tracker_uri: https://github.com/stripe-ruby-mock/stripe-ruby-mock/issues
343
350
  changelog_uri: https://github.com/stripe-ruby-mock/stripe-ruby-mock/blob/master/CHANGELOG.md
344
351
  source_code_uri: https://github.com/stripe-ruby-mock/stripe-ruby-mock
345
- post_install_message:
346
352
  rdoc_options: []
347
353
  require_paths:
348
354
  - lib
@@ -357,8 +363,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
357
363
  - !ruby/object:Gem::Version
358
364
  version: '0'
359
365
  requirements: []
360
- rubygems_version: 3.0.3.1
361
- signing_key:
366
+ rubygems_version: 3.6.7
362
367
  specification_version: 4
363
368
  summary: TDD with stripe
364
369
  test_files: