-
-
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.
We want to start breaking out some of the complex logic of the in memory updater into smaller more focused classes. Co-Authored-By: Adam Mueller <[email protected]> Co-Authored-By: Benjamin Willems <[email protected]> Co-Authored-By: Andrew Stewart <[email protected]> Co-Authored-By: Harmony Bouvier <[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: Chris Todorov <[email protected]> Co-Authored-By: Tom Van Manen <[email protected]> Co-Authored-By: Noah Silvera <[email protected]>
- Loading branch information
1 parent
0b8e26d
commit fbf96ff
Showing
3 changed files
with
28 additions
and
5 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
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,9 @@ | ||
class Spree::ItemTotalUpdater | ||
class << self | ||
def recalculate(item) | ||
item.adjustment_total = item.adjustments | ||
.reject(&:included?) | ||
.sum(&:amount) | ||
end | ||
end | ||
end |
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,18 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'rails_helper' | ||
|
||
RSpec.describe Spree::ItemTotalUpdater do | ||
describe ".recalculate" do | ||
subject { described_class.recalculate(item) } | ||
|
||
let(:item) { create :line_item, adjustments: [adjustment] } | ||
let(:adjustment) { create :adjustment, amount: 1} | ||
|
||
it "sets the adjustment total on the item" do | ||
expect { subject } | ||
.to change { item.adjustment_total } | ||
.from(0).to(1) | ||
end | ||
end | ||
end |