diff options
author | Douglas Barbosa Alexandre <dbalexandre@gmail.com> | 2016-07-28 01:36:38 -0300 |
---|---|---|
committer | Douglas Barbosa Alexandre <dbalexandre@gmail.com> | 2016-08-17 12:58:57 -0300 |
commit | 4180a15c568a16371e14a869166827a7998e993b (patch) | |
tree | 1350671f879f8f4e382e65ccf9226bf5feed29c7 | |
parent | b23683b00b4bccad3b6f29d722b9e45a7264c1bd (diff) | |
download | gitlab-ce-4180a15c568a16371e14a869166827a7998e993b.tar.gz |
Create Backlog/Done lists when creating a new board
-rw-r--r-- | app/services/boards/create_service.rb | 13 | ||||
-rw-r--r-- | spec/services/boards/create_service_spec.rb | 32 |
2 files changed, 32 insertions, 13 deletions
diff --git a/app/services/boards/create_service.rb b/app/services/boards/create_service.rb index 9c1c2da079d..44e937af8c6 100644 --- a/app/services/boards/create_service.rb +++ b/app/services/boards/create_service.rb @@ -5,15 +5,18 @@ module Boards end def execute - if project.board.present? - project.board - else - project.create_board - end + create_board! unless project.board.present? + project.board end private attr_reader :project + + def create_board! + project.create_board + project.board.lists.create(list_type: :backlog, position: 0) + project.board.lists.create(list_type: :done, position: 1) + end end end diff --git a/spec/services/boards/create_service_spec.rb b/spec/services/boards/create_service_spec.rb index ac614f5416a..e0ce580aa45 100644 --- a/spec/services/boards/create_service_spec.rb +++ b/spec/services/boards/create_service_spec.rb @@ -2,18 +2,34 @@ require 'spec_helper' describe Boards::CreateService, services: true do describe '#execute' do - it 'creates a new board when project does not has one' do - project = create(:empty_project, board: nil) - service = described_class.new(project) + subject(:service) { described_class.new(project) } - expect { service.execute }.to change(Board, :count).by(1) + context 'when project does not have a board' do + let(:project) { create(:empty_project, board: nil) } + + it 'creates a new board' do + expect { service.execute }.to change(Board, :count).by(1) + end + + it 'creates default lists' do + service.execute + + expect(project.board.lists.size).to eq 2 + expect(project.board.lists.first).to be_backlog + expect(project.board.lists.last).to be_done + end end - it 'returns project board when project has one' do - project = create(:project_with_board) - service = described_class.new(project) + context 'when project has a board' do + let!(:project) { create(:project_with_board) } + + it 'does not create a new board' do + expect { service.execute }.not_to change(Board, :count) + end - expect(service.execute).to eq project.board + it 'does not create board lists' do + expect { service.execute }.not_to change(project.board.lists, :count) + end end end end |