The lists: Backlog, and Done cannot be destroyed

parent 252e93c9
class Board < ActiveRecord::Base class Board < ActiveRecord::Base
belongs_to :project 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 validates :project, presence: true
end end
...@@ -10,7 +10,15 @@ class List < ActiveRecord::Base ...@@ -10,7 +10,15 @@ class List < ActiveRecord::Base
delegate :name, to: :label, allow_nil: true, prefix: true delegate :name, to: :label, allow_nil: true, prefix: true
before_destroy :can_be_destroyed, unless: :label?
def title def title
label? ? label_name : list_type.humanize label? ? label_name : list_type.humanize
end end
private
def can_be_destroyed
false
end
end end
...@@ -3,7 +3,7 @@ require 'rails_helper' ...@@ -3,7 +3,7 @@ require 'rails_helper'
describe Board do describe Board do
describe 'relationships' do describe 'relationships' do
it { is_expected.to belong_to(:project) } 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 end
describe 'validations' do describe 'validations' do
......
...@@ -31,6 +31,27 @@ describe List do ...@@ -31,6 +31,27 @@ describe List do
it { is_expected.not_to validate_presence_of(:position) } it { is_expected.not_to validate_presence_of(:position) }
end end
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 describe '#title' do
it 'returns label name when list_type is set to label' do it 'returns label name when list_type is set to label' do
subject.list_type = :label 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