Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

In-memory order updater #5872

Draft
wants to merge 26 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
d9914f2
Set tax adjustment amount without persistance
harmonymjb Jan 3, 2025
1d501dd
Mark adjustments for removal in OrderTaxation
Noah-Silvera Jan 10, 2025
001c16c
Ignore order adjustments marked for destruction
adammathys Jan 31, 2025
e590083
Add `db-query-matchers` gem
benjaminwil Oct 11, 2024
d1a3687
Copy existing `OrderUpdater` implementation
benjaminwil Oct 11, 2024
fe6839b
Add `persist` flag to `#recalculate`
benjaminwil Oct 11, 2024
e0ed371
Add describe block to Shipment#update_amounts test
Noah-Silvera Oct 25, 2024
a32dc65
Conditionally persist Shipment#update_amounts changes
Noah-Silvera Oct 25, 2024
bc61d6f
Preventing InMemoryOrderUpdater#update_shipment_amounts from making d…
Noah-Silvera Oct 25, 2024
66cb920
Rename method that recalculates shipment state
forkata Nov 8, 2024
0d335d2
Rename method that recalculates payment state
forkata Nov 8, 2024
e3d9cfb
Rename update_ private methods
AlistairNorman Nov 22, 2024
5a22afd
Rename recalculate_adjustments
AlistairNorman Nov 22, 2024
51765f8
Remove describe block for private method
AlistairNorman Nov 22, 2024
15f3a0f
Reorder private methods
AlistairNorman Nov 22, 2024
05bc3bf
Test that changes to item totals are respected
adammathys Jan 30, 2025
261aa22
Pass persist flag to legacy promotion recalculator
adammathys Jan 31, 2025
8fd0eb6
Pass persist to promotion.order_adjuster_class
sofiabesenski4 Dec 6, 2024
532a142
Support conditional persist in promotion chooser
AlistairNorman Feb 7, 2025
7abc583
[TODO] Add TODO so we know what to do
forkata Nov 8, 2024
b52d390
Rename order adjuster subject
Noah-Silvera Feb 14, 2025
5bbf0bd
Add missing Promotions::OrderAdjuster spec
Noah-Silvera Feb 14, 2025
c985cff
WIP: Improving the dry run functionality before implementing persist
Noah-Silvera Feb 14, 2025
7f7e255
WIP dealing with additional persistent in order_adjuster related classes
Noah-Silvera Feb 14, 2025
313454e
Set required line item attributes earlier
senemsoy Feb 28, 2025
07add2a
Don't persist line item on promotion application
senemsoy Feb 28, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Conditionally persist Shipment#update_amounts changes
This is in service of supporting the InMemoryOrderUpdater's goal to not do database writes.
  • Loading branch information
Noah-Silvera authored and stewart committed Mar 7, 2025
commit a32dc65858b53c837e43c2d351ee917772dfb63d
4 changes: 2 additions & 2 deletions core/app/models/spree/shipment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -260,10 +260,10 @@ def tracking_url
@tracking_url ||= shipping_method.build_tracking_url(tracking)
end

def update_amounts
def update_amounts(persist: true)
if selected_shipping_rate
self.cost = selected_shipping_rate.cost
if changed?
if changed? && persist
update_columns(
cost:,
updated_at: Time.current
Expand Down
33 changes: 26 additions & 7 deletions core/spec/models/spree/shipment_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -508,22 +508,41 @@
end

describe "#update_amounts" do
let(:shipment) { create(:shipment, cost: 3) }
subject { shipment.update_amounts(persist: persist) }

let(:persist) { true }
let(:shipment) { create(:shipment, cost: 1) }

context 'when the selected shipping rate cost is different than the current shipment cost' do
before { shipment.selected_shipping_rate.update!(cost: 5) }
before { shipment.selected_shipping_rate.update!(cost: 999) }

it "updates the shipments cost" do
it "changes and persists the shipments cost" do
expect {
shipment.update_amounts
}.to change { shipment.reload.cost }.to(5)
subject
}.to change { shipment.reload.cost }.to(999)
end

it 'changes the updated_at column' do
it 'changes and persists the updated_at column' do
expect {
shipment.update_amounts
subject
}.to change { shipment.reload.updated_at }
end

context 'when `persist: false` is passed' do
let(:persist) { false }

it 'does not perform any database writes' do
expect {
subject
}.not_to make_database_queries(manipulative: true)
end

it "changes but does not persist the shipments cost" do
subject
expect(shipment.cost).to eq 999
expect(shipment.reload.cost).to eq 1
end
end
end
end

Expand Down