Commit ae70b705 authored by Brett Walker's avatar Brett Walker

Allow Boards::ListService to find a single board

parent d6ed219c
......@@ -5,13 +5,7 @@ module Boards
def execute(create_default_board: true)
create_board! if create_default_board && parent.boards.empty?
if parent.multiple_issue_boards_available?
boards
else
# When multiple issue boards are not available
# a user is only allowed to view the default shown board
first_board
end
find_boards
end
private
......@@ -27,5 +21,18 @@ module Boards
def create_board!
Boards::CreateService.new(parent, current_user).execute
end
def find_boards
found =
if parent.multiple_issue_boards_available?
boards
else
# When multiple issue boards are not available
# a user is only allowed to view the default shown board
first_board
end
params[:board_id].present? ? [found.find(params[:board_id])] : found
end
end
end
......@@ -50,5 +50,20 @@ RSpec.shared_examples 'multiple boards list service' do
it 'returns boards ordered by name' do
expect(service.execute).to eq [board_a, board_B, board_c]
end
context 'when wanting a specific board' do
it 'returns board specified by id' do
service = described_class.new(parent, double, board_id: board_c.id)
expect(service.execute).to eq [board_c]
end
it 'raises exception when board is not found' do
outside_board = create(:board, resource_parent: create(:project), name: 'outside board')
service = described_class.new(parent, double, board_id: outside_board.id)
expect { service.execute }.to raise_exception(ActiveRecord::RecordNotFound)
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