Skip to content

Commit

Permalink
Merge pull request spree#762 from mabotelh/master
Browse files Browse the repository at this point in the history
Tax Category removal causes issue if there are Tax Rates children
  • Loading branch information
schof committed Nov 15, 2011
2 parents 9f5c71b + ed5914b commit 9fe705f
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
2 changes: 1 addition & 1 deletion core/app/models/spree/tax_category.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ module Spree
class TaxCategory < ActiveRecord::Base
validates :name, :presence => true, :uniqueness => true

has_many :tax_rates
has_many :tax_rates, :dependent => :restrict

before_save :set_default_category

Expand Down
10 changes: 10 additions & 0 deletions core/spec/models/tax_category_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,5 +51,15 @@

end

context 'delete' do
let!(:tax_category) {Factory(:tax_category)}
let!(:tax_rate) {Factory(:tax_rate, :tax_category => tax_category)}
it "should not allow deletion when tax rates are assigned" do
p tax_category.inspect
lambda {tax_category.destroy}.should raise_error ActiveRecord::DeleteRestrictionError
p tax_category.inspect
end
end


end

0 comments on commit 9fe705f

Please sign in to comment.