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

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