diff --git a/app/models/reviewable.rb b/app/models/reviewable.rb index b955e77af0d..13a15fe9220 100644 --- a/app/models/reviewable.rb +++ b/app/models/reviewable.rb @@ -28,8 +28,8 @@ class Reviewable < ActiveRecord::Base belongs_to :topic belongs_to :category - has_many :reviewable_histories - has_many :reviewable_scores, -> { order(created_at: :desc) } + has_many :reviewable_histories, dependent: :destroy + has_many :reviewable_scores, -> { order(created_at: :desc) }, dependent: :destroy enum :status, { pending: 0, diff --git a/spec/models/reviewable_spec.rb b/spec/models/reviewable_spec.rb index 53a6bcd2523..0334b66f341 100644 --- a/spec/models/reviewable_spec.rb +++ b/spec/models/reviewable_spec.rb @@ -7,6 +7,9 @@ RSpec.describe Reviewable, type: :model do let(:reviewable) { Fabricate.build(:reviewable, created_by: admin) } + it { is_expected.to have_many(:reviewable_scores).dependent(:destroy) } + it { is_expected.to have_many(:reviewable_histories).dependent(:destroy) } + it "can create a reviewable object" do expect(reviewable).to be_present expect(reviewable.pending?).to eq(true)