Files
ubicloud/spec/model/payment_method_spec.rb
Jeremy Evans 4b819d3cb2 Change all create_with_id to create
It hasn't been necessary to use create_with_id since
ebc79622df, in December 2024.

I have plans to introduce:

```ruby
def create_with_id(id, values)
  obj = new(values)
  obj.id = id
  obj.save_changes
end
```

This will make it easier to use the same id when creating
multiple objects.  The first step is removing the existing
uses of create_with_id.
2025-08-06 01:55:51 +09:00

32 lines
1.4 KiB
Ruby

# frozen_string_literal: true
require_relative "spec_helper"
RSpec.describe PaymentMethod do
subject(:payment_method) { described_class.create(stripe_id: "pm_1234567890") }
it "return Stripe Data if Stripe enabled" do
allow(Config).to receive(:stripe_secret_key).and_return("secret_key")
expect(Stripe::PaymentMethod).to receive(:retrieve).with("pm_1234567890").and_return(Stripe::StripeObject.construct_from("id" => "pm_1234567890", "card" => Stripe::StripeObject.construct_from("brand" => "Visa", "last4" => "1234", "exp_month" => 12, "exp_year" => 2023)))
expect(payment_method.stripe_data).to eq({"brand" => "Visa", "last4" => "1234", "exp_month" => 12, "exp_year" => 2023})
end
it "not return Stripe Data if Stripe not enabled" do
allow(Config).to receive(:stripe_secret_key).and_return(nil)
expect(Stripe::PaymentMethod).not_to receive(:retrieve)
expect(payment_method.stripe_data).to be_nil
end
it "delete Stripe payment method if Stripe enabled" do
allow(Config).to receive(:stripe_secret_key).and_return("secret_key")
expect(Stripe::PaymentMethod).to receive(:detach).with("pm_1234567890")
payment_method.destroy
end
it "not delete Stripe payment method if Stripe not enabled" do
allow(Config).to receive(:stripe_secret_key).and_return(nil)
expect(Stripe::PaymentMethod).not_to receive(:detach)
payment_method.destroy
end
end