2019-04-15 06:17:05 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
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
|
2018-07-11 10:36:08 -04:00
|
|
|
project.add_maintainer(user)
|
2016-08-01 12:09:41 -04:00
|
|
|
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
|
|
|
|
|
2017-12-03 13:56:45 -05:00
|
|
|
it 'sets boards_endpoint instance variable to a boards path' do
|
|
|
|
list_boards
|
|
|
|
|
|
|
|
expect(assigns(:boards_endpoint)).to eq project_boards_path(project)
|
|
|
|
end
|
|
|
|
|
2016-10-05 15:24:29 -04:00
|
|
|
context 'when format is HTML' do
|
|
|
|
it 'renders template' do
|
|
|
|
list_boards
|
|
|
|
|
2018-10-26 08:49:16 -04:00
|
|
|
expect(response).to render_template :index
|
|
|
|
expect(response.content_type).to eq 'text/html'
|
|
|
|
end
|
|
|
|
|
2018-05-22 08:29:46 -04:00
|
|
|
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_gitlab_http_status(404)
|
|
|
|
expect(response.content_type).to eq 'text/html'
|
|
|
|
end
|
|
|
|
end
|
2018-10-26 08:49:16 -04:00
|
|
|
|
|
|
|
context 'when user is signed out' do
|
|
|
|
let(:project) { create(:project, :public) }
|
|
|
|
|
|
|
|
it 'renders template' do
|
|
|
|
sign_out(user)
|
|
|
|
|
|
|
|
board = create(:board, project: project)
|
|
|
|
create(:board_project_recent_visit, project: board.project, board: board, user: user)
|
|
|
|
|
|
|
|
list_boards
|
|
|
|
|
|
|
|
expect(response).to render_template :index
|
|
|
|
expect(response.content_type).to eq 'text/html'
|
|
|
|
end
|
|
|
|
end
|
2016-10-05 15:24:29 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'when format is JSON' do
|
|
|
|
it 'returns a list of project boards' do
|
|
|
|
create_list(:board, 2, project: project)
|
|
|
|
|
2019-06-17 08:58:48 -04:00
|
|
|
expect(Boards::VisitsFinder).not_to receive(:new)
|
2018-10-26 08:49:16 -04:00
|
|
|
|
2016-10-05 15:24:29 -04:00
|
|
|
list_boards format: :json
|
|
|
|
|
|
|
|
expect(response).to match_response_schema('boards')
|
2019-07-16 04:03:49 -04:00
|
|
|
expect(json_response.length).to eq 2
|
2016-10-05 15:24:29 -04:00
|
|
|
end
|
|
|
|
|
2018-05-22 08:29:46 -04:00
|
|
|
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
|
2016-10-05 15:24:29 -04:00
|
|
|
|
2018-05-22 08:29:46 -04:00
|
|
|
it 'returns a not found 404 response' do
|
|
|
|
list_boards format: :json
|
2016-10-05 15:24:29 -04:00
|
|
|
|
2018-05-22 08:29:46 -04:00
|
|
|
expect(response).to have_gitlab_http_status(404)
|
|
|
|
expect(response.content_type).to eq 'application/json'
|
|
|
|
end
|
2016-10-05 15:24:29 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-01-08 04:06:25 -05:00
|
|
|
context 'issues are disabled' do
|
|
|
|
let(:project) { create(:project, :issues_disabled) }
|
|
|
|
|
|
|
|
it 'returns a not found 404 response' do
|
|
|
|
list_boards
|
|
|
|
|
|
|
|
expect(response).to have_gitlab_http_status(404)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-04-09 11:38:58 -04:00
|
|
|
it_behaves_like 'unauthorized when external service denies access' do
|
|
|
|
subject { list_boards }
|
|
|
|
end
|
|
|
|
|
2016-10-05 15:24:29 -04:00
|
|
|
def list_boards(format: :html)
|
2018-12-17 17:52:17 -05:00
|
|
|
get :index, params: {
|
|
|
|
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) }
|
|
|
|
|
2017-12-03 15:46:49 -05:00
|
|
|
it 'sets boards_endpoint instance variable to a boards path' do
|
|
|
|
read_board board: board
|
|
|
|
|
|
|
|
expect(assigns(:boards_endpoint)).to eq project_boards_path(project)
|
|
|
|
end
|
|
|
|
|
2016-10-05 16:08:55 -04:00
|
|
|
context 'when format is HTML' do
|
|
|
|
it 'renders template' do
|
2018-10-26 08:49:16 -04:00
|
|
|
expect { read_board board: board }.to change(BoardProjectRecentVisit, :count).by(1)
|
2016-10-05 16:08:55 -04:00
|
|
|
|
|
|
|
expect(response).to render_template :show
|
|
|
|
expect(response.content_type).to eq 'text/html'
|
|
|
|
end
|
2018-05-22 08:29:46 -04:00
|
|
|
|
|
|
|
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
|
|
|
|
read_board board: board
|
|
|
|
|
|
|
|
expect(response).to have_gitlab_http_status(404)
|
|
|
|
expect(response.content_type).to eq 'text/html'
|
|
|
|
end
|
|
|
|
end
|
2018-10-26 08:49:16 -04:00
|
|
|
|
|
|
|
context 'when user is signed out' do
|
|
|
|
let(:project) { create(:project, :public) }
|
|
|
|
|
|
|
|
it 'does not save visit' do
|
|
|
|
sign_out(user)
|
|
|
|
|
|
|
|
expect { read_board board: board }.to change(BoardProjectRecentVisit, :count).by(0)
|
|
|
|
|
|
|
|
expect(response).to render_template :show
|
|
|
|
expect(response.content_type).to eq 'text/html'
|
|
|
|
end
|
|
|
|
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
|
2018-10-26 08:49:16 -04:00
|
|
|
expect(Boards::Visits::CreateService).not_to receive(:new)
|
|
|
|
|
2016-10-05 16:08:55 -04:00
|
|
|
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
|
|
|
|
2018-05-22 08:29:46 -04:00
|
|
|
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
|
2016-08-08 18:03:41 -04:00
|
|
|
|
2018-05-22 08:29:46 -04:00
|
|
|
it 'returns a not found 404 response' do
|
|
|
|
read_board board: board, format: :json
|
2016-10-05 16:08:55 -04:00
|
|
|
|
2018-05-22 08:29:46 -04:00
|
|
|
expect(response).to have_gitlab_http_status(404)
|
|
|
|
expect(response.content_type).to eq 'application/json'
|
|
|
|
end
|
2016-10-05 16:08:55 -04:00
|
|
|
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
|
|
|
|
2017-10-19 14:28:19 -04:00
|
|
|
expect(response).to have_gitlab_http_status(404)
|
2016-08-17 11:15:51 -04:00
|
|
|
end
|
2016-08-08 18:03:41 -04:00
|
|
|
end
|
|
|
|
|
2016-10-05 16:08:55 -04:00
|
|
|
def read_board(board:, format: :html)
|
2018-12-17 17:52:17 -05:00
|
|
|
get :show, params: {
|
|
|
|
namespace_id: project.namespace,
|
|
|
|
project_id: project,
|
|
|
|
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
|