Skip to content

Commit

Permalink
Add a helper to add a beta version (#1343)
Browse files Browse the repository at this point in the history
* Add a helper to add a beta header

* Typo
  • Loading branch information
helenye-stripe authored Feb 28, 2024
1 parent d249b5f commit 418d79d
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
8 changes: 8 additions & 0 deletions lib/stripe.rb
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,14 @@ def self.set_app_info(name, partner_id: nil, url: nil, version: nil)
}
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)
Expand Down
12 changes: 12 additions & 0 deletions test/stripe_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 418d79d

Please # to comment.