stripe-ruby/test/stripe/payment_method_test.rb
Olivier Bellone ec91de6849
Upgrade Rubocop and fix a bunch of issues (#786)
* Bump Rubocop to 0.57.2

* Style/StderrPuts: Use warn instead of .puts

* Style/ExpandPathArguments: Use expand_path('../test_helper', __dir__) instead of expand_path('../../test_helper', __FILE__)

* Style/Encoding: Unnecessary utf-8 encoding comment

* Style/StringLiterals: Prefer double-quoted strings

* Style/AccessModifierDeclarations

* Style/FormatStringToken: Prefer annotated tokens

* Naming/UncommunicativeMethodParamName

* Metrics/LineLength: set maximum line length to 100 characters

* Style/IfUnlessModifier: Favor modifier if usage when having a single-line body

* Style/ClassVars

* Metrics/LineLength: set maximum line length to 80 characters (default)

* Style/AccessModifierDeclarations: EnforcedStyle: inline
2019-05-24 10:43:42 -07:00

85 lines
2.9 KiB
Ruby

# frozen_string_literal: true
require ::File.expand_path("../test_helper", __dir__)
module Stripe
class PaymentMethodTest < Test::Unit::TestCase
should "be listable" do
payment_methods = Stripe::PaymentMethod.list(
customer: "cus_123",
type: "card"
)
assert_requested :get, "#{Stripe.api_base}/v1/payment_methods?customer=cus_123&type=card"
assert payment_methods.data.is_a?(Array)
assert payment_methods.first.is_a?(Stripe::PaymentMethod)
end
should "be retrievable" do
payment_method = Stripe::PaymentMethod.retrieve("pm_123")
assert_requested :get, "#{Stripe.api_base}/v1/payment_methods/pm_123"
assert payment_method.is_a?(Stripe::PaymentMethod)
end
should "be creatable" do
payment_method = Stripe::PaymentMethod.create(
type: "card"
)
assert_requested :post, "#{Stripe.api_base}/v1/payment_methods"
assert payment_method.is_a?(Stripe::PaymentMethod)
end
should "be saveable" do
payment_method = Stripe::PaymentMethod.retrieve("pm_123")
payment_method.metadata["key"] = "value"
payment_method.save
assert_requested :post, "#{Stripe.api_base}/v1/payment_methods/#{payment_method.id}"
end
should "be updateable" do
payment_method = Stripe::PaymentMethod.update("pm_123", metadata: { key: "value" })
assert_requested :post, "#{Stripe.api_base}/v1/payment_methods/pm_123"
assert payment_method.is_a?(Stripe::PaymentMethod)
end
context "#attach" do
should "attach payment_method" do
payment_method = Stripe::PaymentMethod.construct_from(id: "pm_123", object: "payment_method")
payment_method = payment_method.attach(
customer: "cus_123"
)
assert_requested :post, "#{Stripe.api_base}/v1/payment_methods/pm_123/attach"
assert payment_method.is_a?(Stripe::PaymentMethod)
end
end
context ".attach" do
should "attach payment_method" do
payment_method = Stripe::PaymentMethod.attach("pm_123", customer: "cus_123")
assert_requested :post, "#{Stripe.api_base}/v1/payment_methods/pm_123/attach"
assert payment_method.is_a?(Stripe::PaymentMethod)
end
end
context "#detach" do
should "detach payment_method" do
payment_method = Stripe::PaymentMethod.construct_from(id: "pm_123", object: "payment_method")
payment_method = payment_method.detach
assert_requested :post, "#{Stripe.api_base}/v1/payment_methods/pm_123/detach"
assert payment_method.is_a?(Stripe::PaymentMethod)
end
end
context ".detach" do
should "detach payment_method" do
payment_method = Stripe::PaymentMethod.detach("pm_123")
assert_requested :post, "#{Stripe.api_base}/v1/payment_methods/pm_123/detach"
assert payment_method.is_a?(Stripe::PaymentMethod)
end
end
end
end