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

This commit is contained in:
Douglas Barbosa Alexandre 2016-10-05 17:08:55 -03:00
parent ecf4c10e9c
commit 723ed9cc3a
2 changed files with 41 additions and 11 deletions

View file

@ -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

View file

@ -57,15 +57,23 @@ 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)
let!(:board) { create(:board, project: project) }
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
it 'renders HTML template' do
read_board
context 'when format is JSON' do
it 'returns project board' do
read_board board: board, format: :json
expect(response).to render_template :show
expect(response.content_type).to eq 'text/html'
expect(response).to match_response_schema('board')
end
end
context 'with unauthorized user' 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
def read_board(format: :html)
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(board:, format: :html)
get :show, namespace_id: project.namespace.to_param,
project_id: project.to_param,
id: board.to_param,
format: format
end
end