Skip to content

Commit

Permalink
Merge pull request #3154 from nebulab/kennyadsl/discard-tax-categories
Browse files Browse the repository at this point in the history
Convert Tax Categories to discard
  • Loading branch information
kennyadsl authored Apr 3, 2019
2 parents f06cb3c + 1910b12 commit 45f58f6
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 45f58f6

Please sign in to comment.