-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rename Spree::ItemTotalUpdater to Spree::ItemTotal
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
1 parent
27e4988
commit 1593c06
Showing
4 changed files
with
38 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file was deleted.
Oops, something went wrong.