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 Tax Categories to discard #3154

Merged
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
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