Skip to content

armgit / spree

Public Imported from GitHub
0

Open Source Platform for DTC, B2B Commerce, Marketplaces & Omnichannel. REST APIs, TypeScript SDKs, and production-ready Next.js storefront. Self-host it. Own your data. No vendor lock-in. Zero platform fees.

Add more refund reasons (#12506)

Łukasz Adamczyke42a3583da46
diff --git a/core/app/models/spree/refund_reason.rb b/core/app/models/spree/refund_reason.rb
index 198b6b0744..2ec087a7b7 100644
--- a/core/app/models/spree/refund_reason.rb
+++ b/core/app/models/spree/refund_reason.rb
@@ -3,11 +3,21 @@ module Spree
include Spree::NamedType
RETURN_PROCESSING_REASON = 'Return processing'
+ ORDER_CANCELED_REASON = 'Order Canceled'
+ SHIPMENT_CANCELED_REASON = 'Shipment Canceled'
has_many :refunds, dependent: :restrict_with_error
def self.return_processing_reason
- find_by(name: RETURN_PROCESSING_REASON, mutable: false)
+ find_or_create_by(name: RETURN_PROCESSING_REASON, mutable: false)
+ end
+
+ def self.order_canceled_reason
+ find_or_create_by(name: ORDER_CANCELED_REASON, mutable: false)
+ end
+
+ def self.shipment_canceled_reason
+ find_or_create_by(name: SHIPMENT_CANCELED_REASON, mutable: false)
end
end
end
diff --git a/core/spec/models/spree/refund_reason_spec.rb b/core/spec/models/spree/refund_reason_spec.rb
index 4f2f2555ad..b89c193c56 100644
--- a/core/spec/models/spree/refund_reason_spec.rb
+++ b/core/spec/models/spree/refund_reason_spec.rb
@@ -10,7 +10,40 @@ describe Spree::RefundReason do
end
context 'default refund reason not present' do
- it { expect(described_class.return_processing_reason).to eq(nil) }
+ it 'creates a new refund reason on the fly' do
+ expect(described_class.return_processing_reason).to be_present
+ expect(described_class.return_processing_reason.name).to eq('Return processing')
+ end
+ end
+ end
+
+ describe '.order_canceled_reason' do
+ context 'order canceled reason present' do
+ let!(:refund_reason) { create(:refund_reason, name: 'Order Canceled') }
+
+ it { expect(described_class.order_canceled_reason).to eq(refund_reason) }
+ end
+
+ context 'order canceled reason not present' do
+ it 'creates a new refund reason on the fly' do
+ expect(described_class.order_canceled_reason).to be_present
+ expect(described_class.order_canceled_reason.name).to eq('Order Canceled')
+ end
+ end
+ end
+
+ describe '.shipment_canceled_reason' do
+ context 'shipment canceled reason present' do
+ let!(:refund_reason) { create(:refund_reason, name: 'Shipment Canceled') }
+
+ it { expect(described_class.shipment_canceled_reason).to eq(refund_reason) }
+ end
+
+ context 'shipment canceled reason not present' do
+ it 'creates a new refund reason on the fly' do
+ expect(described_class.shipment_canceled_reason).to be_present
+ expect(described_class.shipment_canceled_reason.name).to eq('Shipment Canceled')
+ end
end
end
end