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

Convert shipping methods, payment methods, and tax rates to discard #2487

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ class ShippingMethodsController < ResourceController
before_action :set_zones, only: [:create, :update]

def destroy
@object.paranoia_destroy
@object.discard

flash[:success] = flash_message_for(@object, :successfully_removed)

Expand Down
2 changes: 1 addition & 1 deletion backend/spec/features/admin/orders/payments_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@
end

before do
payment_method.paranoia_destroy
payment_method.discard
visit spree.admin_order_payments_path(order.reload)
end

Expand Down
6 changes: 6 additions & 0 deletions core/app/models/spree/payment_method.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
require 'discard'
require 'spree/preferences/statically_configurable'

module Spree
Expand All @@ -16,6 +17,11 @@ class PaymentMethod < Spree::Base
preference :test_mode, :boolean, default: true

acts_as_paranoid
include Spree::ParanoiaDeprecations

include Discard::Model
self.discard_column = :deleted_at

acts_as_list
DISPLAY = [:both, :front_end, :back_end]

Expand Down
7 changes: 7 additions & 0 deletions core/app/models/spree/shipping_method.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
require 'discard'

module Spree
# Represents a means of having a shipment delivered, such as FedEx or UPS.
#
class ShippingMethod < Spree::Base
acts_as_paranoid
include Spree::ParanoiaDeprecations

include Discard::Model
self.discard_column = :deleted_at

include Spree::CalculatedAdjustments
DISPLAY = ActiveSupport::Deprecation::DeprecatedObjectProxy.new(
[:both, :front_end, :back_end],
Expand Down
7 changes: 7 additions & 0 deletions core/app/models/spree/tax_rate.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
require 'discard'

module Spree
class TaxRate < Spree::Base
acts_as_paranoid
include Spree::ParanoiaDeprecations

include Discard::Model
self.discard_column = :deleted_at

# Need to deal with adjustments before calculator is destroyed.
before_destroy :remove_adjustments_from_incomplete_orders
before_discard :remove_adjustments_from_incomplete_orders

include Spree::CalculatedAdjustments
include Spree::AdjustmentSource
Expand Down
2 changes: 1 addition & 1 deletion core/spec/models/spree/payment_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1261,7 +1261,7 @@
before do
gateway.save!
payment.save!
gateway.paranoia_destroy!
gateway.discard
end

it "works with a soft deleted payment method" do
Expand Down
2 changes: 1 addition & 1 deletion core/spec/models/spree/shipping_method_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ class DummyShippingCalculator < Spree::ShippingCalculator
context "soft deletion" do
let(:shipping_method) { create(:shipping_method) }
it "soft-deletes when destroy is called" do
shipping_method.paranoia_destroy
shipping_method.discard
expect(shipping_method.deleted_at).not_to be_blank
end
end
Expand Down
12 changes: 6 additions & 6 deletions core/spec/models/spree/tax/taxation_integration_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -646,16 +646,16 @@
expect(line_item.additional_tax_total).to eq(3)
end

it "should delete adjustments for open order when taxrate is deleted" do
new_york_books_tax.paranoia_destroy!
federal_books_tax.paranoia_destroy!
it "should delete adjustments for open order when taxrate is soft-deleted" do
new_york_books_tax.discard
federal_books_tax.discard
expect(line_item.adjustments.count).to eq(0)
end

it "should not delete adjustments for complete order when taxrate is deleted" do
it "should not delete adjustments for complete order when taxrate is soft-deleted" do
order.update_column :completed_at, Time.now
new_york_books_tax.paranoia_destroy!
federal_books_tax.paranoia_destroy!
new_york_books_tax.discard
federal_books_tax.discard
expect(line_item.adjustments.count).to eq(2)
end

Expand Down