Update Projects::BoardsController#show to look up for a specific board

parent ecf4c10e
......@@ -9,13 +9,20 @@ class Projects::BoardsController < Projects::ApplicationController
respond_to do |format|
format.html
format.json do
render json: @boards.as_json(only: [:id, :name])
render json: serialize_as_json(@boards)
end
end
end
def show
::Boards::CreateService.new(project, current_user).execute
@board = project.boards.find(params[:id])
respond_to do |format|
format.html
format.json do
render json: serialize_as_json(@board)
end
end
end
private
......@@ -23,4 +30,8 @@ class Projects::BoardsController < Projects::ApplicationController
def authorize_read_board!
return access_denied! unless can?(current_user, :read_board, project)
end
def serialize_as_json(resource)
resource.as_json(only: [:id, :name])
end
end
......@@ -57,16 +57,24 @@ describe Projects::BoardsController do
end
describe 'GET show' do
it 'creates a new board when project does not have one' do
expect { read_board }.to change(Board, :count).by(1)
end
let!(:board) { create(:board, project: project) }
it 'renders HTML template' do
read_board
context 'when format is HTML' do
it 'renders template' do
read_board board: board
expect(response).to render_template :show
expect(response.content_type).to eq 'text/html'
end
end
context 'when format is JSON' do
it 'returns project board' do
read_board board: board, format: :json
expect(response).to match_response_schema('board')
end
end
context 'with unauthorized user' do
before do
......@@ -74,16 +82,27 @@ describe Projects::BoardsController do
allow(Ability).to receive(:allowed?).with(user, :read_board, project).and_return(false)
end
it 'returns a successful 404 response' do
read_board
it 'returns a not found 404 response' do
read_board board: board
expect(response).to have_http_status(404)
end
end
context 'when board does not belong to project' do
it 'returns a not found 404 response' do
another_board = create(:board)
read_board board: another_board
expect(response).to have_http_status(404)
end
end
def read_board(format: :html)
def read_board(board:, format: :html)
get :show, namespace_id: project.namespace.to_param,
project_id: project.to_param,
id: board.to_param,
format: format
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