Skip to content

Commit

Permalink
Rename Spree::ItemTotalUpdater to Spree::ItemTotal
Browse files Browse the repository at this point in the history
Co-Authored-By: Harmony Evangelina <[email protected]>
Co-Authored-By: Jared Norman <[email protected]>
Co-Authored-By: Kendra Riga <[email protected]>
Co-Authored-By: Sofia Besenski <[email protected]>
Co-Authored-By: benjamin wil <[email protected]>
  • Loading branch information
6 people committed Dec 20, 2024
1 parent 27e4988 commit 1593c06
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 29 deletions.
15 changes: 15 additions & 0 deletions core/app/models/spree/item_total.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# frozen_string_literal: true

class Spree::ItemTotal
def initialize(item)
@item = item
end

def recalculate!
item.adjustment_total = item.adjustments.reject(&:included?).sum(&:amount)
end

private

attr_reader :item
end
11 changes: 0 additions & 11 deletions core/app/models/spree/item_total_updater.rb

This file was deleted.

23 changes: 23 additions & 0 deletions core/spec/models/spree/item_total_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# frozen_string_literal: true

require 'rails_helper'

RSpec.describe Spree::ItemTotal do
describe "#recalculate!" do
subject { described_class.new(item).recalculate! }

let(:item) { create :line_item, adjustments: [adjustment] }
let(:adjustment) { create :adjustment, amount: 19.99 }

it "sets the adjustment total on the item" do
expect { subject }
.to change { item.adjustment_total }
.from(0).to(19.99)
end

it "does not factor in included adjustments" do
adjustment.update!(included: true)
expect { subject }.not_to change { item.adjustment_total }.from(0)
end
end
end
18 changes: 0 additions & 18 deletions core/spec/models/spree/item_total_updater_spec.rb

This file was deleted.

0 comments on commit 1593c06

Please sign in to comment.