2016-08-01 12:09:41 -04:00
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
describe Projects::BoardsController do
|
2017-08-02 15:55:11 -04:00
|
|
|
let(:project) { create(:project) }
|
2016-08-01 12:09:41 -04:00
|
|
|
let(:user) { create(:user) }
|
|
|
|
|
|
|
|
before do
|
|
|
|
project.team << [user, :master]
|
|
|
|
sign_in(user)
|
|
|
|
end
|
|
|
|
|
2016-10-05 15:24:29 -04:00
|
|
|
describe 'GET index' do
|
|
|
|
it 'creates a new project board when project does not have one' do
|
|
|
|
expect { list_boards }.to change(project.boards, :count).by(1)
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when format is HTML' do
|
|
|
|
it 'renders template' do
|
|
|
|
list_boards
|
|
|
|
|
|
|
|
expect(response).to render_template :index
|
|
|
|
expect(response.content_type).to eq 'text/html'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when format is JSON' do
|
|
|
|
it 'returns a list of project boards' do
|
|
|
|
create_list(:board, 2, project: project)
|
|
|
|
|
|
|
|
list_boards format: :json
|
|
|
|
|
|
|
|
parsed_response = JSON.parse(response.body)
|
|
|
|
|
|
|
|
expect(response).to match_response_schema('boards')
|
|
|
|
expect(parsed_response.length).to eq 2
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'with unauthorized user' do
|
|
|
|
before do
|
|
|
|
allow(Ability).to receive(:allowed?).with(user, :read_project, project).and_return(true)
|
|
|
|
allow(Ability).to receive(:allowed?).with(user, :read_board, project).and_return(false)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns a not found 404 response' do
|
|
|
|
list_boards
|
|
|
|
|
|
|
|
expect(response).to have_http_status(404)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def list_boards(format: :html)
|
2017-02-23 18:55:01 -05:00
|
|
|
get :index, namespace_id: project.namespace,
|
|
|
|
project_id: project,
|
2016-10-05 15:24:29 -04:00
|
|
|
format: format
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-08-17 10:55:12 -04:00
|
|
|
describe 'GET show' do
|
2016-10-05 16:08:55 -04:00
|
|
|
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
|
2016-08-01 12:31:58 -04:00
|
|
|
end
|
|
|
|
|
2016-10-05 16:08:55 -04:00
|
|
|
context 'when format is JSON' do
|
|
|
|
it 'returns project board' do
|
|
|
|
read_board board: board, format: :json
|
2016-08-01 12:09:41 -04:00
|
|
|
|
2016-10-05 16:08:55 -04:00
|
|
|
expect(response).to match_response_schema('board')
|
|
|
|
end
|
2016-08-01 14:41:30 -04:00
|
|
|
end
|
|
|
|
|
2016-08-17 11:15:51 -04:00
|
|
|
context 'with unauthorized user' do
|
|
|
|
before do
|
2016-08-08 14:55:13 -04:00
|
|
|
allow(Ability).to receive(:allowed?).with(user, :read_project, project).and_return(true)
|
|
|
|
allow(Ability).to receive(:allowed?).with(user, :read_board, project).and_return(false)
|
2016-08-17 11:15:51 -04:00
|
|
|
end
|
2016-08-08 18:03:41 -04:00
|
|
|
|
2016-10-05 16:08:55 -04:00
|
|
|
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
|
2016-08-08 18:03:41 -04:00
|
|
|
|
2016-08-17 11:15:51 -04:00
|
|
|
expect(response).to have_http_status(404)
|
|
|
|
end
|
2016-08-08 18:03:41 -04:00
|
|
|
end
|
|
|
|
|
2016-10-05 16:08:55 -04:00
|
|
|
def read_board(board:, format: :html)
|
2017-02-23 18:55:01 -05:00
|
|
|
get :show, namespace_id: project.namespace,
|
|
|
|
project_id: project,
|
2016-10-05 16:08:55 -04:00
|
|
|
id: board.to_param,
|
2016-08-08 18:03:41 -04:00
|
|
|
format: format
|
2016-08-01 12:09:41 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|