diff --git a/.github/workflows/rspec_tests.yml b/.github/workflows/rspec_tests.yml index 816fda8a8..4ccb9771f 100644 --- a/.github/workflows/rspec_tests.yml +++ b/.github/workflows/rspec_tests.yml @@ -23,7 +23,7 @@ jobs: fail-fast: false matrix: ruby: ["3.1", "3.2", "3.3"] - gemfile: ["stripe_12", "stripe_13"] + gemfile: ["stripe_6", "stripe_7", "stripe_8", "stripe_9", "stripe_10", "stripe_11", "stripe_12", "stripe_13"] env: BUNDLE_GEMFILE: ${{ github.workspace }}/gemfiles/${{ matrix.gemfile }}.gemfile steps: diff --git a/README.md b/README.md index c6d53c695..f0fabcbe8 100644 --- a/README.md +++ b/README.md @@ -12,7 +12,7 @@ This gem has unexpectedly grown in popularity and I've gotten pretty busy, so I' In your gemfile: - gem 'stripe-ruby-mock', :require => 'stripe_mock' + gem 'stripe-ruby-mock' ## !!! Important diff --git a/gemfiles/stripe_10.gemfile b/gemfiles/stripe_10.gemfile new file mode 100644 index 000000000..6c8f85abd --- /dev/null +++ b/gemfiles/stripe_10.gemfile @@ -0,0 +1,13 @@ +# This file was generated by Appraisal + +source "https://rubygems.org" + +gem "appraisal" +gem "stripe", "10.15.0" + +group :test do + gem "rake" + gem "dotenv" +end + +gemspec path: "../" diff --git a/gemfiles/stripe_10.gemfile.lock b/gemfiles/stripe_10.gemfile.lock new file mode 100644 index 000000000..1d7243d65 --- /dev/null +++ b/gemfiles/stripe_10.gemfile.lock @@ -0,0 +1,59 @@ +PATH + remote: .. + specs: + stripe-ruby-mock (5.0.0) + dante (>= 0.2.0) + drb (>= 2.0.4, < 3) + multi_json (~> 1.0) + stripe (> 5, < 14) + +GEM + remote: https://rubygems.org/ + specs: + appraisal (2.5.0) + bundler + rake + thor (>= 0.14.0) + daemons (1.4.1) + dante (0.2.0) + diff-lcs (1.6.2) + dotenv (3.2.0) + drb (2.2.3) + eventmachine (1.2.7) + multi_json (1.19.1) + rack (2.2.22) + rake (13.3.1) + rspec (3.13.2) + rspec-core (~> 3.13.0) + rspec-expectations (~> 3.13.0) + rspec-mocks (~> 3.13.0) + rspec-core (3.13.6) + rspec-support (~> 3.13.0) + rspec-expectations (3.13.5) + diff-lcs (>= 1.2.0, < 2.0) + rspec-support (~> 3.13.0) + rspec-mocks (3.13.8) + diff-lcs (>= 1.2.0, < 2.0) + rspec-support (~> 3.13.0) + rspec-support (3.13.7) + stripe (10.15.0) + thin (1.8.2) + daemons (~> 1.0, >= 1.0.9) + eventmachine (~> 1.0, >= 1.0.4) + rack (>= 1, < 3) + thor (1.5.0) + +PLATFORMS + ruby + +DEPENDENCIES + appraisal + dotenv + rake + rspec (~> 3.13.0) + stripe (= 10.15.0) + stripe-ruby-mock! + thin (~> 1.8.1) + +BUNDLED WITH + 2.6.8 diff --git a/gemfiles/stripe_11.gemfile b/gemfiles/stripe_11.gemfile new file mode 100644 index 000000000..70126711d --- /dev/null +++ b/gemfiles/stripe_11.gemfile @@ -0,0 +1,13 @@ +# This file was generated by Appraisal + +source "https://rubygems.org" + +gem "appraisal" +gem "stripe", "11.7.0" + +group :test do + gem "rake" + gem "dotenv" +end + +gemspec path: "../" diff --git a/gemfiles/stripe_11.gemfile.lock b/gemfiles/stripe_11.gemfile.lock new file mode 100644 index 000000000..8b9cf63f3 --- /dev/null +++ b/gemfiles/stripe_11.gemfile.lock @@ -0,0 +1,59 @@ +PATH + remote: .. + specs: + stripe-ruby-mock (5.0.0) + dante (>= 0.2.0) + drb (>= 2.0.4, < 3) + multi_json (~> 1.0) + stripe (> 5, < 14) + +GEM + remote: https://rubygems.org/ + specs: + appraisal (2.5.0) + bundler + rake + thor (>= 0.14.0) + daemons (1.4.1) + dante (0.2.0) + diff-lcs (1.6.2) + dotenv (3.2.0) + drb (2.2.3) + eventmachine (1.2.7) + multi_json (1.19.1) + rack (2.2.22) + rake (13.3.1) + rspec (3.13.2) + rspec-core (~> 3.13.0) + rspec-expectations (~> 3.13.0) + rspec-mocks (~> 3.13.0) + rspec-core (3.13.6) + rspec-support (~> 3.13.0) + rspec-expectations (3.13.5) + diff-lcs (>= 1.2.0, < 2.0) + rspec-support (~> 3.13.0) + rspec-mocks (3.13.8) + diff-lcs (>= 1.2.0, < 2.0) + rspec-support (~> 3.13.0) + rspec-support (3.13.7) + stripe (11.7.0) + thin (1.8.2) + daemons (~> 1.0, >= 1.0.9) + eventmachine (~> 1.0, >= 1.0.4) + rack (>= 1, < 3) + thor (1.5.0) + +PLATFORMS + ruby + +DEPENDENCIES + appraisal + dotenv + rake + rspec (~> 3.13.0) + stripe (= 11.7.0) + stripe-ruby-mock! + thin (~> 1.8.1) + +BUNDLED WITH + 2.6.8 diff --git a/gemfiles/stripe_12.gemfile.lock b/gemfiles/stripe_12.gemfile.lock index 88b5215e0..88eeed1b6 100644 --- a/gemfiles/stripe_12.gemfile.lock +++ b/gemfiles/stripe_12.gemfile.lock @@ -1,7 +1,7 @@ PATH remote: .. specs: - stripe-ruby-mock (4.0.0) + stripe-ruby-mock (5.0.0) dante (>= 0.2.0) drb (>= 2.0.4, < 3) multi_json (~> 1.0) diff --git a/gemfiles/stripe_13.gemfile.lock b/gemfiles/stripe_13.gemfile.lock index 8c3e4d4f1..45ed3970c 100644 --- a/gemfiles/stripe_13.gemfile.lock +++ b/gemfiles/stripe_13.gemfile.lock @@ -1,7 +1,7 @@ PATH remote: .. specs: - stripe-ruby-mock (4.0.0) + stripe-ruby-mock (5.0.0) dante (>= 0.2.0) drb (>= 2.0.4, < 3) multi_json (~> 1.0) diff --git a/gemfiles/stripe_6.gemfile b/gemfiles/stripe_6.gemfile new file mode 100644 index 000000000..f4cc536b1 --- /dev/null +++ b/gemfiles/stripe_6.gemfile @@ -0,0 +1,13 @@ +# This file was generated by Appraisal + +source "https://rubygems.org" + +gem "appraisal" +gem "stripe", "6.5.0" + +group :test do + gem "rake" + gem "dotenv" +end + +gemspec path: "../" diff --git a/gemfiles/stripe_6.gemfile.lock b/gemfiles/stripe_6.gemfile.lock new file mode 100644 index 000000000..764417045 --- /dev/null +++ b/gemfiles/stripe_6.gemfile.lock @@ -0,0 +1,59 @@ +PATH + remote: .. + specs: + stripe-ruby-mock (5.0.0) + dante (>= 0.2.0) + drb (>= 2.0.4, < 3) + multi_json (~> 1.0) + stripe (> 5, < 14) + +GEM + remote: https://rubygems.org/ + specs: + appraisal (2.5.0) + bundler + rake + thor (>= 0.14.0) + daemons (1.4.1) + dante (0.2.0) + diff-lcs (1.6.2) + dotenv (3.2.0) + drb (2.2.3) + eventmachine (1.2.7) + multi_json (1.19.1) + rack (2.2.22) + rake (13.3.1) + rspec (3.13.2) + rspec-core (~> 3.13.0) + rspec-expectations (~> 3.13.0) + rspec-mocks (~> 3.13.0) + rspec-core (3.13.6) + rspec-support (~> 3.13.0) + rspec-expectations (3.13.5) + diff-lcs (>= 1.2.0, < 2.0) + rspec-support (~> 3.13.0) + rspec-mocks (3.13.8) + diff-lcs (>= 1.2.0, < 2.0) + rspec-support (~> 3.13.0) + rspec-support (3.13.7) + stripe (6.5.0) + thin (1.8.2) + daemons (~> 1.0, >= 1.0.9) + eventmachine (~> 1.0, >= 1.0.4) + rack (>= 1, < 3) + thor (1.5.0) + +PLATFORMS + ruby + +DEPENDENCIES + appraisal + dotenv + rake + rspec (~> 3.13.0) + stripe (= 6.5.0) + stripe-ruby-mock! + thin (~> 1.8.1) + +BUNDLED WITH + 2.6.8 diff --git a/gemfiles/stripe_7.gemfile b/gemfiles/stripe_7.gemfile new file mode 100644 index 000000000..18c2fc622 --- /dev/null +++ b/gemfiles/stripe_7.gemfile @@ -0,0 +1,13 @@ +# This file was generated by Appraisal + +source "https://rubygems.org" + +gem "appraisal" +gem "stripe", "7.1.0" + +group :test do + gem "rake" + gem "dotenv" +end + +gemspec path: "../" diff --git a/gemfiles/stripe_7.gemfile.lock b/gemfiles/stripe_7.gemfile.lock new file mode 100644 index 000000000..d3ae828b5 --- /dev/null +++ b/gemfiles/stripe_7.gemfile.lock @@ -0,0 +1,59 @@ +PATH + remote: .. + specs: + stripe-ruby-mock (5.0.0) + dante (>= 0.2.0) + drb (>= 2.0.4, < 3) + multi_json (~> 1.0) + stripe (> 5, < 14) + +GEM + remote: https://rubygems.org/ + specs: + appraisal (2.5.0) + bundler + rake + thor (>= 0.14.0) + daemons (1.4.1) + dante (0.2.0) + diff-lcs (1.6.2) + dotenv (3.2.0) + drb (2.2.3) + eventmachine (1.2.7) + multi_json (1.19.1) + rack (2.2.22) + rake (13.3.1) + rspec (3.13.2) + rspec-core (~> 3.13.0) + rspec-expectations (~> 3.13.0) + rspec-mocks (~> 3.13.0) + rspec-core (3.13.6) + rspec-support (~> 3.13.0) + rspec-expectations (3.13.5) + diff-lcs (>= 1.2.0, < 2.0) + rspec-support (~> 3.13.0) + rspec-mocks (3.13.8) + diff-lcs (>= 1.2.0, < 2.0) + rspec-support (~> 3.13.0) + rspec-support (3.13.7) + stripe (7.1.0) + thin (1.8.2) + daemons (~> 1.0, >= 1.0.9) + eventmachine (~> 1.0, >= 1.0.4) + rack (>= 1, < 3) + thor (1.5.0) + +PLATFORMS + ruby + +DEPENDENCIES + appraisal + dotenv + rake + rspec (~> 3.13.0) + stripe (= 7.1.0) + stripe-ruby-mock! + thin (~> 1.8.1) + +BUNDLED WITH + 2.6.8 diff --git a/gemfiles/stripe_8.gemfile b/gemfiles/stripe_8.gemfile new file mode 100644 index 000000000..2278a61b1 --- /dev/null +++ b/gemfiles/stripe_8.gemfile @@ -0,0 +1,13 @@ +# This file was generated by Appraisal + +source "https://rubygems.org" + +gem "appraisal" +gem "stripe", "8.7.0" + +group :test do + gem "rake" + gem "dotenv" +end + +gemspec path: "../" diff --git a/gemfiles/stripe_8.gemfile.lock b/gemfiles/stripe_8.gemfile.lock new file mode 100644 index 000000000..70e91752d --- /dev/null +++ b/gemfiles/stripe_8.gemfile.lock @@ -0,0 +1,59 @@ +PATH + remote: .. + specs: + stripe-ruby-mock (5.0.0) + dante (>= 0.2.0) + drb (>= 2.0.4, < 3) + multi_json (~> 1.0) + stripe (> 5, < 14) + +GEM + remote: https://rubygems.org/ + specs: + appraisal (2.5.0) + bundler + rake + thor (>= 0.14.0) + daemons (1.4.1) + dante (0.2.0) + diff-lcs (1.6.2) + dotenv (3.2.0) + drb (2.2.3) + eventmachine (1.2.7) + multi_json (1.19.1) + rack (2.2.22) + rake (13.3.1) + rspec (3.13.2) + rspec-core (~> 3.13.0) + rspec-expectations (~> 3.13.0) + rspec-mocks (~> 3.13.0) + rspec-core (3.13.6) + rspec-support (~> 3.13.0) + rspec-expectations (3.13.5) + diff-lcs (>= 1.2.0, < 2.0) + rspec-support (~> 3.13.0) + rspec-mocks (3.13.8) + diff-lcs (>= 1.2.0, < 2.0) + rspec-support (~> 3.13.0) + rspec-support (3.13.7) + stripe (8.7.0) + thin (1.8.2) + daemons (~> 1.0, >= 1.0.9) + eventmachine (~> 1.0, >= 1.0.4) + rack (>= 1, < 3) + thor (1.5.0) + +PLATFORMS + ruby + +DEPENDENCIES + appraisal + dotenv + rake + rspec (~> 3.13.0) + stripe (= 8.7.0) + stripe-ruby-mock! + thin (~> 1.8.1) + +BUNDLED WITH + 2.6.8 diff --git a/gemfiles/stripe_9.gemfile b/gemfiles/stripe_9.gemfile new file mode 100644 index 000000000..a478f7235 --- /dev/null +++ b/gemfiles/stripe_9.gemfile @@ -0,0 +1,13 @@ +# This file was generated by Appraisal + +source "https://rubygems.org" + +gem "appraisal" +gem "stripe", "9.4.0" + +group :test do + gem "rake" + gem "dotenv" +end + +gemspec path: "../" diff --git a/gemfiles/stripe_9.gemfile.lock b/gemfiles/stripe_9.gemfile.lock new file mode 100644 index 000000000..1e2c2bcde --- /dev/null +++ b/gemfiles/stripe_9.gemfile.lock @@ -0,0 +1,59 @@ +PATH + remote: .. + specs: + stripe-ruby-mock (5.0.0) + dante (>= 0.2.0) + drb (>= 2.0.4, < 3) + multi_json (~> 1.0) + stripe (> 5, < 14) + +GEM + remote: https://rubygems.org/ + specs: + appraisal (2.5.0) + bundler + rake + thor (>= 0.14.0) + daemons (1.4.1) + dante (0.2.0) + diff-lcs (1.6.2) + dotenv (3.2.0) + drb (2.2.3) + eventmachine (1.2.7) + multi_json (1.19.1) + rack (2.2.22) + rake (13.3.1) + rspec (3.13.2) + rspec-core (~> 3.13.0) + rspec-expectations (~> 3.13.0) + rspec-mocks (~> 3.13.0) + rspec-core (3.13.6) + rspec-support (~> 3.13.0) + rspec-expectations (3.13.5) + diff-lcs (>= 1.2.0, < 2.0) + rspec-support (~> 3.13.0) + rspec-mocks (3.13.8) + diff-lcs (>= 1.2.0, < 2.0) + rspec-support (~> 3.13.0) + rspec-support (3.13.7) + stripe (9.4.0) + thin (1.8.2) + daemons (~> 1.0, >= 1.0.9) + eventmachine (~> 1.0, >= 1.0.4) + rack (>= 1, < 3) + thor (1.5.0) + +PLATFORMS + ruby + +DEPENDENCIES + appraisal + dotenv + rake + rspec (~> 3.13.0) + stripe (= 9.4.0) + stripe-ruby-mock! + thin (~> 1.8.1) + +BUNDLED WITH + 2.6.8 diff --git a/lib/stripe-ruby-mock.rb b/lib/stripe-ruby-mock.rb new file mode 100644 index 000000000..fd600b8ce --- /dev/null +++ b/lib/stripe-ruby-mock.rb @@ -0,0 +1 @@ +require 'stripe_mock' diff --git a/lib/stripe_mock/request_handlers/promotion_codes.rb b/lib/stripe_mock/request_handlers/promotion_codes.rb index a8ecf11bc..77b4b625e 100644 --- a/lib/stripe_mock/request_handlers/promotion_codes.rb +++ b/lib/stripe_mock/request_handlers/promotion_codes.rb @@ -36,7 +36,13 @@ def get_promotion_code(route, method_url, params, headers) end def list_promotion_code(route, method_url, params, headers) - Data.mock_list_object(promotion_codes.values, params) + promotion_code_data = promotion_codes.values + + if params.key?(:code) + promotion_code_data.select! { |promotion_code| params[:code].downcase == promotion_code[:code].downcase } + end + + Data.mock_list_object(promotion_code_data, params) end end end diff --git a/spec/shared_stripe_examples/invoice_examples.rb b/spec/shared_stripe_examples/invoice_examples.rb index afab6c43f..6fa0908f6 100644 --- a/spec/shared_stripe_examples/invoice_examples.rb +++ b/spec/shared_stripe_examples/invoice_examples.rb @@ -235,10 +235,10 @@ describe 'parameter validation' do it 'fails without parameters' do - expect { Stripe::Invoice.upcoming() }.to raise_error {|e| + expect { Stripe::Invoice.upcoming({}) }.to raise_error {|e| expect(e).to be_a(Stripe::InvalidRequestError) expect(e.http_status).to eq(400) - expect(e.message).to eq('Missing required param: customer if subscription is not provided') + expect(e.message).to eq('Missing required param: customer if subscription is not provided') } end @@ -630,7 +630,7 @@ end - context "creating a preview invoice" do + context "creating a preview invoice", skip: !Stripe::Invoice.respond_to?(:create_preview) && "Stripe::Invoice.create_preview not available in stripe #{Stripe::VERSION}" do let(:customer) { Stripe::Customer.create(source: stripe_helper.generate_card_token) } let(:product) { stripe_helper.create_product(id: "prod_preview") } let(:plan) { stripe_helper.create_plan(id: 'preview_plan', product: product.id, amount: 50_00, interval: 'month', currency: 'usd') } diff --git a/spec/shared_stripe_examples/promotion_code_examples.rb b/spec/shared_stripe_examples/promotion_code_examples.rb index a3ae3aa70..6216c384f 100644 --- a/spec/shared_stripe_examples/promotion_code_examples.rb +++ b/spec/shared_stripe_examples/promotion_code_examples.rb @@ -65,4 +65,20 @@ expect(all.count).to eq(2) expect(all.map(&:code)).to include("10PERCENT", "20PERCENT") end + + it 'lists promotion codes filtering by case-insensitive code' do + Stripe::PromotionCode.create({ coupon: coupon.id, code: '10PERCENT' }) + Stripe::PromotionCode.create({ coupon: coupon.id, code: '20PERCENT' }) + + all = Stripe::PromotionCode.list + expect(all.count).to eq 2 + + one = Stripe::PromotionCode.list({ code: '10PERCENT' }) + expect(one.count).to eq 1 + expect(one.map(&:code)).to include('10PERCENT') + + two = Stripe::PromotionCode.list({ code: '20percent' }) + expect(two.count).to eq 1 + expect(two.map(&:code)).to include('20PERCENT') + end end diff --git a/spec/shared_stripe_examples/subscription_examples.rb b/spec/shared_stripe_examples/subscription_examples.rb index 213aa26f0..b4fa3b44b 100644 --- a/spec/shared_stripe_examples/subscription_examples.rb +++ b/spec/shared_stripe_examples/subscription_examples.rb @@ -4,6 +4,23 @@ shared_examples 'Customer Subscriptions with plans' do let(:gen_card_tk) { stripe_helper.generate_card_token } + # Stripe v6 uses #delete, v7+ uses #cancel + def cancel_subscription(sub, **opts) + if sub.respond_to?(:cancel) + sub.cancel(**opts) + else + sub.delete(**opts) + end + end + + def cancel_subscription_by_id(id) + if Stripe::Subscription.respond_to?(:cancel) + Stripe::Subscription.cancel(id) + else + Stripe::Subscription.delete(id) + end + end + let(:product) { stripe_helper.create_product } let(:plan_attrs) { {id: 'silver', product: product.id, amount: 4999, currency: 'usd'} } let(:plan) { stripe_helper.create_plan(plan_attrs) } @@ -687,7 +704,7 @@ customer = Stripe::Customer.create(id: 'test_customer_sub', source: gen_card_tk) sub = Stripe::Subscription.create({ items: { '0' => { plan: 'silver' } }, customer: customer.id }) - sub.cancel(at_period_end: true) + cancel_subscription(sub, at_period_end: true) expect(sub.cancel_at_period_end).to be_truthy expect(sub.save).to be_truthy @@ -752,7 +769,7 @@ customer = Stripe::Customer.create(source: gen_card_tk, plan: plan.id) subscription = Stripe::Subscription.retrieve(customer.subscriptions.data.first.id) - subscription.cancel + cancel_subscription(subscription) expect { subscription.save }.to raise_error { |e| expect(e).to be_a(Stripe::InvalidRequestError) @@ -765,7 +782,7 @@ customer = Stripe::Customer.create(id: 'test_customer_sub', source: gen_card_tk) sub = Stripe::Subscription.create({ items: [ { plan: plan.id } ], customer: customer.id }) - sub.cancel(at_period_end: true) + cancel_subscription(sub, at_period_end: true) expect(sub.cancel_at_period_end).to be_truthy expect(sub.save).to be_truthy @@ -1208,7 +1225,7 @@ customer = Stripe::Customer.create(source: gen_card_tk, plan: plan.id) sub = Stripe::Subscription.retrieve(customer.subscriptions.data.first.id) - result = sub.cancel + result = cancel_subscription(sub) expect(result.status).to eq('canceled') expect(result.cancel_at_period_end).to eq false @@ -1310,7 +1327,7 @@ customer = Stripe::Customer.create(id: 'test_customer_sub', source: gen_card_tk, plan: "trial") sub = Stripe::Subscription.retrieve(customer.subscriptions.data.first.id) - result = sub.cancel(at_period_end: true) + result = cancel_subscription(sub, at_period_end: true) expect(result.status).to eq('trialing') @@ -1398,7 +1415,7 @@ it "does not include canceled subscriptions by default" do customer = Stripe::Customer.create(source: gen_card_tk) subscription = Stripe::Subscription.create({ plan: plan.id, customer: customer.id }) - subscription.cancel + cancel_subscription(subscription) list = Stripe::Subscription.list({customer: customer.id}) @@ -1507,7 +1524,7 @@ customer = Stripe::Customer.create(email: 'johnny@appleseed.com', source: gen_card_tk) one = Stripe::Subscription.create(customer: customer.id, items: [{plan: "Sample5"}], metadata: {key: 'uno'}) two = Stripe::Subscription.create(customer: customer.id, items: [{plan: "Sample5"}], metadata: {key: 'dos'}) - Stripe::Subscription.cancel(two.id) + cancel_subscription_by_id(two.id) response = Stripe::Subscription.search({query: 'status:"active"'}, stripe_version: '2020-08-27') expect(response.data.map(&:id)).to match_array([one.id]) diff --git a/spec/support/shared_contexts/stripe_validator_spec.rb b/spec/support/shared_contexts/stripe_validator.rb similarity index 100% rename from spec/support/shared_contexts/stripe_validator_spec.rb rename to spec/support/shared_contexts/stripe_validator.rb