From 418d79de1b203f6ab614f4374e615215c26dd095 Mon Sep 17 00:00:00 2001 From: helenye-stripe <111009531+helenye-stripe@users.noreply.github.com> Date: Wed, 28 Feb 2024 12:19:10 -0800 Subject: [PATCH] Add a helper to add a beta version (#1343) * Add a helper to add a beta header * Typo --- lib/stripe.rb | 8 ++++++++ test/stripe_test.rb | 12 ++++++++++++ 2 files changed, 20 insertions(+) diff --git a/lib/stripe.rb b/lib/stripe.rb index 5d1493d4..c20040db 100644 --- a/lib/stripe.rb +++ b/lib/stripe.rb @@ -121,6 +121,14 @@ module Stripe } end + def self.add_beta_version(beta_name, version) + if api_version.include?("; #{beta_name}=") + raise "Stripe version header #{api_version} already contains entry for beta #{beta_name}" + end + + self.api_version = "#{api_version}; #{beta_name}=#{version}" + end + class Preview def self._get_default_opts(opts) { api_mode: :preview }.merge(opts) diff --git a/test/stripe_test.rb b/test/stripe_test.rb index fbc60370..fe5d3328 100644 --- a/test/stripe_test.rb +++ b/test/stripe_test.rb @@ -119,6 +119,18 @@ class StripeTest < Test::Unit::TestCase assert_equal "2018-02-28", Stripe.api_version end + should "allow beta versions to be added once only" do + Stripe.api_version = "2018-02-28" + + Stripe.add_beta_version("my_beta", "v2") + assert_equal "2018-02-28; my_beta=v2", Stripe.api_version + + err = assert_raises do + Stripe.add_beta_version("my_beta", "v1") + assert_equal(err, "Stripe version header 2018-02-28; my_beta=v2 already contains entry for beta my_beta") + end + end + should "allow connect_base to be configured" do Stripe.connect_base = "https://other.stripe.com" assert_equal "https://other.stripe.com", Stripe.connect_base