Skip to content

Commit

Permalink
Refactor create_item_adjustments_spec
Browse files Browse the repository at this point in the history
To use in-memory items more.
  • Loading branch information
jordan-brough committed Sep 17, 2016
1 parent c98ab97 commit f74c9a0
Showing 1 changed file with 21 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ module Spree
class Promotion
module Actions
describe CreateItemAdjustments, type: :model do
let(:order) { create(:order) }
let(:order) { create(:order_with_line_items, line_items_count: 1) }
let(:promotion) { create(:promotion, :with_line_item_adjustment, adjustment_rate: adjustment_amount) }
let(:adjustment_amount) { 10 }
let(:action) { promotion.actions.first! }
let!(:line_item) { create(:line_item, order: order) }
let(:line_item) { order.line_items.to_a.first }
let(:payload) { { order: order, promotion: promotion } }

before do
Expand Down Expand Up @@ -128,26 +128,32 @@ module Actions
let(:promotion) { create(:promotion, :with_line_item_adjustment) }
let(:other_promotion) { create(:promotion, :with_line_item_adjustment) }

it "destroys adjustments for incompleted orders" do
order = Order.create
action.adjustments.create!(label: "Check", amount: 0, order: order, adjustable: order)
context 'with incomplete orders' do
let(:order) { create(:order) }

expect {
action.destroy
}.to change { Adjustment.count }.by(-1)
it 'destroys adjustments' do
order.adjustments.create!(label: 'Check', amount: 0, order: order, source: action)

expect {
action.destroy
}.to change { Adjustment.count }.by(-1)
end
end

it "nullifies adjustments for completed orders" do
order = Order.create(completed_at: Time.current)
adjustment = action.adjustments.create!(label: "Check", amount: 0, order: order, adjustable: order)
context 'with complete orders' do
let(:order) { create(:completed_order_with_totals) }

expect {
action.destroy
}.to change { adjustment.reload.source_id }.from(action.id).to nil
it 'nullifies adjustments for completed orders' do
adjustment = order.adjustments.create!(label: 'Check', amount: 0, order: order, source: action)

expect {
action.destroy
}.to change { adjustment.reload.source_id }.from(action.id).to nil
end
end

it "doesnt mess with unrelated adjustments" do
other_action.adjustments.create!(label: "Check", amount: 0, order: order, adjustable: order)
order.adjustments.create!(label: "Check", amount: 0, order: order, source: action)

expect {
action.destroy
Expand Down

0 comments on commit f74c9a0

Please sign in to comment.