GitLab steht aufgrund wichtiger Wartungsarbeiten am Montag, den 8. März, zwischen 17:00 und 19:00 Uhr nicht zur Verfügung.

The lists: Backlog, and Done cannot be destroyed

parent 252e93c9
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
......@@ -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
......@@ -3,7 +3,7 @@
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
......
......@@ -31,6 +31,27 @@
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
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment