BigW Consortium Gitlab

Update Boards::Lists::GenerateService to generate for a specific board

parent 91107463
module Boards module Boards
module Lists module Lists
class GenerateService < Boards::BaseService class GenerateService < Boards::BaseService
def execute def execute(board)
return false unless board.lists.movable.empty? return false unless board.lists.movable.empty?
List.transaction do List.transaction do
label_params.each { |params| create_list(params) } label_params.each { |params| create_list(board, params) }
end end
true true
...@@ -13,9 +13,9 @@ module Boards ...@@ -13,9 +13,9 @@ module Boards
private private
def create_list(params) def create_list(board, params)
label = find_or_create_label(params) label = find_or_create_label(params)
Lists::CreateService.new(project, current_user, label_id: label.id).execute Lists::CreateService.new(project, current_user, label_id: label.id).execute(board)
end end
def find_or_create_label(params) def find_or_create_label(params)
......
...@@ -2,15 +2,15 @@ require 'spec_helper' ...@@ -2,15 +2,15 @@ require 'spec_helper'
describe Boards::Lists::GenerateService, services: true do describe Boards::Lists::GenerateService, services: true do
describe '#execute' do describe '#execute' do
let(:project) { create(:project_with_board) } let(:project) { create(:empty_project) }
let(:board) { project.board } let(:board) { create(:board, project: project) }
let(:user) { create(:user) } let(:user) { create(:user) }
subject(:service) { described_class.new(project, user) } subject(:service) { described_class.new(project, user) }
context 'when board lists is empty' do context 'when board lists is empty' do
it 'creates the default lists' do it 'creates the default lists' do
expect { service.execute }.to change(board.lists, :count).by(2) expect { service.execute(board) }.to change(board.lists, :count).by(2)
end end
end end
...@@ -18,13 +18,13 @@ describe Boards::Lists::GenerateService, services: true do ...@@ -18,13 +18,13 @@ describe Boards::Lists::GenerateService, services: true do
it 'does not creates the default lists' do it 'does not creates the default lists' do
create(:list, board: board) create(:list, board: board)
expect { service.execute }.not_to change(board.lists, :count) expect { service.execute(board) }.not_to change(board.lists, :count)
end end
end end
context 'when project labels does not contains any list label' do context 'when project labels does not contains any list label' do
it 'creates labels' do it 'creates labels' do
expect { service.execute }.to change(project.labels, :count).by(2) expect { service.execute(board) }.to change(project.labels, :count).by(2)
end end
end end
...@@ -32,7 +32,7 @@ describe Boards::Lists::GenerateService, services: true do ...@@ -32,7 +32,7 @@ describe Boards::Lists::GenerateService, services: true do
it 'creates the missing labels' do it 'creates the missing labels' do
create(:label, project: project, name: 'Doing') create(:label, project: project, name: 'Doing')
expect { service.execute }.to change(project.labels, :count).by(1) expect { service.execute(board) }.to change(project.labels, :count).by(1)
end end
end end
end end
......
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