Skip to content

Commit

Permalink
Products also need to destroy dependent models.
Browse files Browse the repository at this point in the history
This is related to #739 and #738.
  • Loading branch information
KingTiger001 committed Jan 25, 2017
1 parent 0177fcd commit 92c28c8
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
2 changes: 2 additions & 0 deletions spec/example_app/app/models/product.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
class Product < ActiveRecord::Base
has_many :line_items, dependent: :destroy

validates :description, presence: true
validates :image_url, presence: true
validates :name, presence: true
Expand Down
12 changes: 12 additions & 0 deletions spec/models/product_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,16 @@
it { should validate_uniqueness_of(:slug) }
end
end

it "deletes associated line_items when deleted itself" do
product = create(:product)
customer = create(:customer)
order = create(:order, customer: customer)
create(:line_item, product: product, order: order)

product.destroy

expect(Product.all).to be_empty
end

end

0 comments on commit 92c28c8

Please sign in to comment.