From e23d1706faa7fe100d5db3d2e4f83198f7bfa900 Mon Sep 17 00:00:00 2001 From: Douglas Barbosa Alexandre Date: Mon, 8 Aug 2016 16:14:22 -0300 Subject: [PATCH] Destroy related lists when a label is removed --- app/models/label.rb | 2 ++ spec/models/label_spec.rb | 2 ++ 2 files changed, 4 insertions(+) diff --git a/app/models/label.rb b/app/models/label.rb index 35e678001dc..a23140b7d64 100644 --- a/app/models/label.rb +++ b/app/models/label.rb @@ -13,6 +13,8 @@ class Label < ActiveRecord::Base default_value_for :color, DEFAULT_COLOR belongs_to :project + + has_many :lists, dependent: :destroy has_many :label_links, dependent: :destroy has_many :issues, through: :label_links, source: :target, source_type: 'Issue' has_many :merge_requests, through: :label_links, source: :target, source_type: 'MergeRequest' diff --git a/spec/models/label_spec.rb b/spec/models/label_spec.rb index 2a09063f857..5a5d1a5d60c 100644 --- a/spec/models/label_spec.rb +++ b/spec/models/label_spec.rb @@ -5,8 +5,10 @@ describe Label, models: true do describe 'associations' do it { is_expected.to belong_to(:project) } + it { is_expected.to have_many(:label_links).dependent(:destroy) } it { is_expected.to have_many(:issues).through(:label_links).source(:target) } + it { is_expected.to have_many(:lists).dependent(:destroy) } end describe 'modules' do