summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDouglas Barbosa Alexandre <dbalexandre@gmail.com>2016-07-31 20:48:00 -0300
committerDouglas Barbosa Alexandre <dbalexandre@gmail.com>2016-08-17 12:58:57 -0300
commit4b75c75018c9a3eac7a2c8b1772a10c98ea3bdc0 (patch)
tree141c6c6db67a03d44980b77b7a6f5e24d6ec628d
parent252e93c9e664e595ea9b4987f14ca8fb21a0e307 (diff)
downloadgitlab-ce-4b75c75018c9a3eac7a2c8b1772a10c98ea3bdc0.tar.gz
The lists: Backlog, and Done cannot be destroyed
-rw-r--r--app/models/board.rb2
-rw-r--r--app/models/list.rb8
-rw-r--r--spec/models/board_spec.rb2
-rw-r--r--spec/models/list_spec.rb21
4 files changed, 31 insertions, 2 deletions
diff --git a/app/models/board.rb b/app/models/board.rb
index d6358fb15e8..3240c4bede3 100644
--- a/app/models/board.rb
+++ b/app/models/board.rb
@@ -1,7 +1,7 @@
class Board < ActiveRecord::Base
belongs_to :project
- has_many :lists, -> { order(:list_type, :position) }, dependent: :destroy
+ has_many :lists, -> { order(:list_type, :position) }, dependent: :delete_all
validates :project, presence: true
end
diff --git a/app/models/list.rb b/app/models/list.rb
index b4fdab7893a..f2a59d18c46 100644
--- a/app/models/list.rb
+++ b/app/models/list.rb
@@ -10,7 +10,15 @@ class List < ActiveRecord::Base
delegate :name, to: :label, allow_nil: true, prefix: true
+ before_destroy :can_be_destroyed, unless: :label?
+
def title
label? ? label_name : list_type.humanize
end
+
+ private
+
+ def can_be_destroyed
+ false
+ end
end
diff --git a/spec/models/board_spec.rb b/spec/models/board_spec.rb
index 23a91619a27..12d29540137 100644
--- a/spec/models/board_spec.rb
+++ b/spec/models/board_spec.rb
@@ -3,7 +3,7 @@ require 'rails_helper'
describe Board do
describe 'relationships' do
it { is_expected.to belong_to(:project) }
- it { is_expected.to have_many(:lists).order(list_type: :asc, position: :asc).dependent(:destroy) }
+ it { is_expected.to have_many(:lists).order(list_type: :asc, position: :asc).dependent(:delete_all) }
end
describe 'validations' do
diff --git a/spec/models/list_spec.rb b/spec/models/list_spec.rb
index 689011454d3..45c07a679cb 100644
--- a/spec/models/list_spec.rb
+++ b/spec/models/list_spec.rb
@@ -31,6 +31,27 @@ describe List do
it { is_expected.not_to validate_presence_of(:position) }
end
end
+
+ describe '#destroy' do
+ it 'can be destroyed when when list_type is set to label' do
+ subject = create(:label_list)
+
+ expect(subject.destroy).to be_truthy
+ end
+
+ it 'can not be destroyed when list_type is set to backlog' do
+ subject = create(:backlog_list)
+
+ expect(subject.destroy).to be_falsey
+ end
+
+ it 'can not be destroyed when when list_type is set to done' do
+ subject = create(:done_list)
+
+ expect(subject.destroy).to be_falsey
+ end
+ end
+
describe '#title' do
it 'returns label name when list_type is set to label' do
subject.list_type = :label