Fix payment identifier generation

Upstream fix from Spree 2.2.

See: 4e747187d7
This commit is contained in:
Matt-Yorkley
2021-01-13 16:45:19 +00:00
parent 3877721209
commit 18c9e16303
2 changed files with 14 additions and 6 deletions

View File

@@ -23,7 +23,7 @@ module Spree
has_one :adjustment, as: :source, dependent: :destroy
validate :validate_source
before_save :set_unique_identifier
before_create :set_unique_identifier
after_save :create_payment_profile, if: :profiles_supported?

View File

@@ -636,14 +636,22 @@ describe Spree::Payment do
end
context "#set_unique_identifier" do
# Regression test for #1998
# Regression test for Spree #1998
it "sets a unique identifier on create" do
payment.run_callbacks(:save)
payment.run_callbacks(:create)
expect(payment.identifier).not_to be_blank
expect(payment.identifier.size).to eq(8)
expect(payment.identifier).to be_a(String)
end
# Regression test for Spree #3733
it "does not regenerate the identifier on re-save" do
payment.save
old_identifier = payment.identifier
payment.save
expect(payment.identifier).to eq old_identifier
end
context "other payment exists" do
let(:other_payment) {
gateway.name = 'Gateway'
@@ -660,10 +668,10 @@ describe Spree::Payment do
before { other_payment.save! }
it "doesn't set duplicate identifier" do
payment.should_receive(:generate_identifier).and_return(other_payment.identifier)
payment.should_receive(:generate_identifier).and_call_original
allow(payment).to receive(:generate_identifier).and_return(other_payment.identifier)
allow(payment).to receive(:generate_identifier).and_call_original
payment.run_callbacks(:save)
payment.run_callbacks(:create)
expect(payment.identifier).not_to be_blank
expect(payment.identifier).not_to eq(other_payment.identifier)