Skip to content

Commit

Permalink
Convert tax categories to discard
Browse files Browse the repository at this point in the history
It was missing from the work done in #2354.

With the magic of ResourceController, it will start using
discard when we perform admin destroys, since it now responds
to .discard.
  • Loading branch information
kennyadsl committed Mar 27, 2019
1 parent 767c238 commit 1910b12
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
11 changes: 11 additions & 0 deletions core/app/models/spree/tax_category.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,19 @@
# frozen_string_literal: true

require 'discard'

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

include Discard::Model
self.discard_column = :deleted_at

after_discard do
self.tax_rate_tax_categories = []
end

validates :name, presence: true
validates_uniqueness_of :name, unless: :deleted_at

Expand Down
21 changes: 21 additions & 0 deletions core/spec/models/spree/tax_category_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,25 @@
expect(tax_category.is_default).to be true
end
end

context ".discard" do
let(:tax_category) { create(:tax_category) }

it "set deleted_at correctly" do
tax_category.discard
expect(tax_category.deleted_at).not_to be_blank
end

context "when there are tax_rates associated" do
let(:tax_rate) { create(:tax_rate) }
let(:tax_category) { tax_rate.tax_categories.first }

it 'correctly discard association records' do
expect { tax_category.discard }
.to change { tax_category.tax_rates.size }
.from(1)
.to(0)
end
end
end
end

0 comments on commit 1910b12

Please sign in to comment.