Update add_beta_version

This commit is contained in:
Michael Broshi 2025-03-27 11:47:01 -04:00
parent 80c1033710
commit fd98c84804
2 changed files with 33 additions and 8 deletions

View File

@ -160,11 +160,19 @@ 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}"
unless version.match?(/\Av\d+\z/)
raise ArgumentError, "Version must be in the format 'v' followed by a number (e.g., 'v3')"
end
self.api_version = "#{api_version}; #{beta_name}=#{version}"
if api_version.include?("; #{beta_name}=")
current_version = api_version.match(/; #{beta_name}=v(\d+)/)[1].to_i
new_version = version[1..-1].to_i
return if new_version <= current_version # Keep the higher version, no update needed
self.api_version = api_version.sub(/; #{beta_name}=v\d+/, "; #{beta_name}=#{version}")
else
self.api_version = "#{api_version}; #{beta_name}=#{version}"
end
end
class RawRequest

View File

@ -129,16 +129,33 @@ class StripeTest < Test::Unit::TestCase
assert_equal "https://other.stripe.com", Stripe.meter_events_base
end
should "allow beta versions to be added once only" do
should "allow beta versions to be added multiple times" 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
# same version should be a no-op
Stripe.add_beta_version("my_beta", "v2")
assert_equal "2018-02-28; my_beta=v2", Stripe.api_version
# higher version should use higher version
Stripe.add_beta_version("my_beta", "v5")
assert_equal "2018-02-28; my_beta=v5", Stripe.api_version
# lower version should be a no-op
Stripe.add_beta_version("my_beta", "v4")
assert_equal "2018-02-28; my_beta=v5", Stripe.api_version
end
should "allow append multiple beta names" 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
Stripe.add_beta_version("my_beta_two", "v4")
assert_equal "2018-02-28; my_beta=v2; my_beta_two=v4", Stripe.api_version
end
should "allow verify_ssl_certs to be configured" do