Skip to content

Commit

Permalink
Update existing specs to pass new param
Browse files Browse the repository at this point in the history
  • Loading branch information
Graeme Nathan committed Apr 12, 2018
1 parent 3486072 commit cecc03c
Show file tree
Hide file tree
Showing 10 changed files with 24 additions and 14 deletions.
3 changes: 2 additions & 1 deletion core/spec/models/spree/customer_return_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion core/spec/models/spree/order_cancellations_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
3 changes: 2 additions & 1 deletion core/spec/models/spree/refund_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
9 changes: 5 additions & 4 deletions core/spec/models/spree/reimbursement_performer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 4 additions & 2 deletions core/spec/models/spree/reimbursement_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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|
Expand Down Expand Up @@ -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"
Expand Down
3 changes: 2 additions & 1 deletion core/spec/models/spree/reimbursement_type/credit_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
3 changes: 2 additions & 1 deletion core/spec/models/spree/reimbursement_type/exchange_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) }
Expand Down

0 comments on commit cecc03c

Please sign in to comment.