diff --git a/core/spec/models/spree/customer_return_spec.rb b/core/spec/models/spree/customer_return_spec.rb index f98a0cdccac..a0572c33e58 100644 --- a/core/spec/models/spree/customer_return_spec.rb +++ b/core/spec/models/spree/customer_return_spec.rb @@ -282,7 +282,8 @@ end context 'when all reimbursements are reimbursed' do - before { reimbursement.perform! } + let(:created_by_user) { create(:user, email: 'user@email.com') } + before { reimbursement.perform!(created_by_user) } it { is_expected.to be true } end diff --git a/core/spec/models/spree/order/outstanding_balance_integration_spec.rb b/core/spec/models/spree/order/outstanding_balance_integration_spec.rb index 08206556c5e..8242dca6e96 100644 --- a/core/spec/models/spree/order/outstanding_balance_integration_spec.rb +++ b/core/spec/models/spree/order/outstanding_balance_integration_spec.rb @@ -83,13 +83,14 @@ context 'with a cancelled item' do let(:cancelations) { Spree::OrderCancellations.new(order) } let(:cancelled_item) { item_1 } + let(:created_by_user) { create(:user, email: 'user@email.com') } before do # Required to refund Spree::RefundReason.create!(name: Spree::RefundReason::RETURN_PROCESSING_REASON, mutable: false) cancelations.cancel_unit(cancelled_item.inventory_units.first) - cancelations.reimburse_units(cancelled_item.inventory_units) + cancelations.reimburse_units(cancelled_item.inventory_units, created_by_user) order.reload end diff --git a/core/spec/models/spree/order_cancellations_spec.rb b/core/spec/models/spree/order_cancellations_spec.rb index ad801ea6140..394b1b8df8d 100644 --- a/core/spec/models/spree/order_cancellations_spec.rb +++ b/core/spec/models/spree/order_cancellations_spec.rb @@ -47,10 +47,11 @@ end describe "#reimburse_units" do - subject { Spree::OrderCancellations.new(order).reimburse_units(inventory_units) } + subject { Spree::OrderCancellations.new(order).reimburse_units(inventory_units, created_by_user) } let(:order) { create(:shipped_order, line_items_count: 2) } let(:inventory_units) { order.inventory_units } let!(:default_refund_reason) { Spree::RefundReason.find_or_create_by!(name: Spree::RefundReason::RETURN_PROCESSING_REASON, mutable: false) } + let(:created_by_user) { create(:user, email: 'user@email.com') } it "creates and performs a reimbursement" do expect { subject }.to change { Spree::Reimbursement.count }.by(1) diff --git a/core/spec/models/spree/refund_spec.rb b/core/spec/models/spree/refund_spec.rb index 249e89e4c49..bbbd36b3019 100644 --- a/core/spec/models/spree/refund_spec.rb +++ b/core/spec/models/spree/refund_spec.rb @@ -176,11 +176,12 @@ let(:customer_return) { reimbursement.customer_return } let(:reimbursement) { create(:reimbursement) } let!(:default_refund_reason) { Spree::RefundReason.find_or_create_by!(name: Spree::RefundReason::RETURN_PROCESSING_REASON, mutable: false) } + let(:created_by_user) { create(:user, email: 'user@email.com') } subject { Spree::Refund.total_amount_reimbursed_for(reimbursement) } context 'with reimbursements performed' do - before { reimbursement.perform! } + before { reimbursement.perform!(created_by_user) } it 'returns the total amount' do amount = Spree::Refund.total_amount_reimbursed_for(reimbursement) diff --git a/core/spec/models/spree/reimbursement_performer_spec.rb b/core/spec/models/spree/reimbursement_performer_spec.rb index 5f870e52450..57fb27567b9 100644 --- a/core/spec/models/spree/reimbursement_performer_spec.rb +++ b/core/spec/models/spree/reimbursement_performer_spec.rb @@ -7,25 +7,26 @@ let(:return_item) { reimbursement.return_items.first } let(:reimbursement_type) { double("ReimbursementType") } let(:reimbursement_type_hash) { { reimbursement_type => [return_item] } } + let(:created_by_user) { create(:user, email: 'user@email.com') } before do expect(Spree::ReimbursementPerformer).to receive(:calculate_reimbursement_types).and_return(reimbursement_type_hash) end describe ".simulate" do - subject { Spree::ReimbursementPerformer.simulate(reimbursement) } + subject { Spree::ReimbursementPerformer.simulate(reimbursement, created_by_user) } it "reimburses each calculated reimbursement types with the correct return items as a simulation" do - expect(reimbursement_type).to receive(:reimburse).with(reimbursement, [return_item], true) + expect(reimbursement_type).to receive(:reimburse).with(reimbursement, [return_item], true, created_by_user) subject end end describe '.perform' do - subject { Spree::ReimbursementPerformer.perform(reimbursement) } + subject { Spree::ReimbursementPerformer.perform(reimbursement, created_by_user) } it "reimburses each calculated reimbursement types with the correct return items as a simulation" do - expect(reimbursement_type).to receive(:reimburse).with(reimbursement, [return_item], false) + expect(reimbursement_type).to receive(:reimburse).with(reimbursement, [return_item], false, created_by_user) subject end end diff --git a/core/spec/models/spree/reimbursement_spec.rb b/core/spec/models/spree/reimbursement_spec.rb index 9815bb96dd8..53c9bd3489d 100644 --- a/core/spec/models/spree/reimbursement_spec.rb +++ b/core/spec/models/spree/reimbursement_spec.rb @@ -66,8 +66,9 @@ let!(:default_refund_reason) { Spree::RefundReason.find_or_create_by!(name: Spree::RefundReason::RETURN_PROCESSING_REASON, mutable: false) } let(:reimbursement) { create(:reimbursement, customer_return: customer_return, order: order, return_items: [return_item]) } + let(:created_by_user) { create(:user, email: 'user@email.com') } - subject { reimbursement.perform! } + subject { reimbursement.perform!(created_by_user) } before do order.shipments.each do |shipment| @@ -230,13 +231,14 @@ end describe "#return_all" do - subject { reimbursement.return_all } + subject { reimbursement.return_all(created_by_user) } let!(:default_refund_reason) { Spree::RefundReason.find_or_create_by!(name: Spree::RefundReason::RETURN_PROCESSING_REASON, mutable: false) } let(:order) { create(:shipped_order, line_items_count: 1) } let(:inventory_unit) { order.inventory_units.first } let(:return_item) { build(:return_item, inventory_unit: inventory_unit) } let(:reimbursement) { build(:reimbursement, order: order, return_items: [return_item]) } + let(:created_by_user) { create(:user, email: 'user@email.com') } it "accepts all the return items" do expect { subject }.to change { return_item.acceptance_status }.to "accepted" diff --git a/core/spec/models/spree/reimbursement_type/credit_spec.rb b/core/spec/models/spree/reimbursement_type/credit_spec.rb index 18100d74110..4702a0e307f 100644 --- a/core/spec/models/spree/reimbursement_type/credit_spec.rb +++ b/core/spec/models/spree/reimbursement_type/credit_spec.rb @@ -10,13 +10,14 @@ module Spree let(:simulate) { false } let!(:default_refund_reason) { Spree::RefundReason.find_or_create_by!(name: Spree::RefundReason::RETURN_PROCESSING_REASON, mutable: false) } let(:creditable) { DummyCreditable.new(amount: 99.99) } + let(:created_by_user) { create(:user, email: 'user@email.com') } class DummyCreditable < Spree::Base attr_accessor :amount self.table_name = 'spree_payments' # Your creditable class should not use this table end - subject { Spree::ReimbursementType::Credit.reimburse(reimbursement, [return_item], simulate) } + subject { Spree::ReimbursementType::Credit.reimburse(reimbursement, [return_item], simulate, created_by_user) } before do reimbursement.update!(total: reimbursement.calculated_total) diff --git a/core/spec/models/spree/reimbursement_type/exchange_spec.rb b/core/spec/models/spree/reimbursement_type/exchange_spec.rb index 3a699391869..38757f35991 100644 --- a/core/spec/models/spree/reimbursement_type/exchange_spec.rb +++ b/core/spec/models/spree/reimbursement_type/exchange_spec.rb @@ -9,8 +9,9 @@ module Spree let(:return_items) { reimbursement.return_items } let(:new_exchange) { double("Exchange") } let(:simulate) { true } + let(:created_by_user) { create(:user, email: 'user@email.com') } - subject { Spree::ReimbursementType::Exchange.reimburse(reimbursement, return_items, simulate) } + subject { Spree::ReimbursementType::Exchange.reimburse(reimbursement, return_items, simulate, created_by_user) } context 'return items are supplied' do before do diff --git a/core/spec/models/spree/reimbursement_type/original_payment_spec.rb b/core/spec/models/spree/reimbursement_type/original_payment_spec.rb index 85cddeaeca9..ea97ade5af7 100644 --- a/core/spec/models/spree/reimbursement_type/original_payment_spec.rb +++ b/core/spec/models/spree/reimbursement_type/original_payment_spec.rb @@ -9,8 +9,9 @@ module Spree let(:payment) { reimbursement.order.payments.first } let(:simulate) { false } let!(:default_refund_reason) { Spree::RefundReason.find_or_create_by!(name: Spree::RefundReason::RETURN_PROCESSING_REASON, mutable: false) } + let(:created_by_user) { create(:user, email: 'user@email.com') } - subject { Spree::ReimbursementType::OriginalPayment.reimburse(reimbursement, [return_item], simulate) } + subject { Spree::ReimbursementType::OriginalPayment.reimburse(reimbursement, [return_item], simulate, created_by_user) } before { reimbursement.update!(total: reimbursement.calculated_total) } diff --git a/core/spec/models/spree/reimbursement_type/store_credit_spec.rb b/core/spec/models/spree/reimbursement_type/store_credit_spec.rb index 17aea92481b..cf0f49f2219 100644 --- a/core/spec/models/spree/reimbursement_type/store_credit_spec.rb +++ b/core/spec/models/spree/reimbursement_type/store_credit_spec.rb @@ -12,7 +12,7 @@ module Spree let!(:default_refund_reason) { Spree::RefundReason.find_or_create_by!(name: Spree::RefundReason::RETURN_PROCESSING_REASON, mutable: false) } let!(:primary_credit_type) { create(:primary_credit_type) } - let!(:created_by_user) { create(:user, email: 'user@email.com') } + let(:created_by_user) { create(:user, email: 'user@email.com') } let!(:default_reimbursement_category) { create(:store_credit_category) } subject { Spree::ReimbursementType::StoreCredit.reimburse(reimbursement, [return_item, return_item2], simulate, created_by_user) }