debian-mirror-gitlab/spec/controllers/projects/boards_controller_spec.rb

221 lines
6.5 KiB
Ruby
Raw Normal View History

2016-09-13 17:45:13 +05:30
require 'spec_helper'
describe Projects::BoardsController do
2017-09-10 17:25:29 +05:30
let(:project) { create(:project) }
2016-09-13 17:45:13 +05:30
let(:user) { create(:user) }
before do
2018-11-18 11:00:15 +05:30
project.add_maintainer(user)
2016-09-13 17:45:13 +05:30
sign_in(user)
end
2016-11-03 12:29:30 +05:30
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
2018-03-17 18:26:18 +05:30
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-11-03 12:29:30 +05:30
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
2018-11-08 19:23:39 +05:30
2018-12-13 13:39:08 +05:30
it 'redirects to latest visited board' do
board = create(:board, project: project)
create(:board_project_recent_visit, project: board.project, board: board, user: user)
list_boards
expect(response).to redirect_to(namespace_project_board_path(id: board.id))
end
it 'renders template if visited board is not found' do
temporary_board = create(:board, project: project)
visited = create(:board_project_recent_visit, project: temporary_board.project, board: temporary_board, user: user)
temporary_board.delete
allow_any_instance_of(Boards::Visits::LatestService).to receive(:execute).and_return(visited)
list_boards
expect(response).to render_template :index
expect(response.content_type).to eq 'text/html'
end
2018-11-08 19:23:39 +05:30
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-12-13 13:39:08 +05:30
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-11-03 12:29:30 +05:30
end
context 'when format is JSON' do
it 'returns a list of project boards' do
create_list(:board, 2, project: project)
2018-12-13 13:39:08 +05:30
expect(Boards::Visits::LatestService).not_to receive(:new)
2016-11-03 12:29:30 +05:30
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
2018-11-08 19:23:39 +05:30
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-11-03 12:29:30 +05:30
2018-11-08 19:23:39 +05:30
it 'returns a not found 404 response' do
list_boards format: :json
2016-11-03 12:29:30 +05:30
2018-11-08 19:23:39 +05:30
expect(response).to have_gitlab_http_status(404)
expect(response.content_type).to eq 'application/json'
end
2018-03-17 18:26:18 +05:30
end
end
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)
2016-11-03 12:29:30 +05:30
end
end
def list_boards(format: :html)
2019-02-15 15:39:39 +05:30
get :index, params: {
namespace_id: project.namespace,
project_id: project
},
2016-11-03 12:29:30 +05:30
format: format
end
end
2016-09-13 17:45:13 +05:30
describe 'GET show' do
2016-11-03 12:29:30 +05:30
let!(:board) { create(:board, project: project) }
2018-03-17 18:26:18 +05:30
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-11-03 12:29:30 +05:30
context 'when format is HTML' do
it 'renders template' do
2018-12-13 13:39:08 +05:30
expect { read_board board: board }.to change(BoardProjectRecentVisit, :count).by(1)
2016-11-03 12:29:30 +05:30
expect(response).to render_template :show
expect(response.content_type).to eq 'text/html'
end
2018-11-08 19:23:39 +05:30
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-12-13 13:39:08 +05:30
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-09-13 17:45:13 +05:30
end
2016-11-03 12:29:30 +05:30
context 'when format is JSON' do
it 'returns project board' do
2018-12-13 13:39:08 +05:30
expect(Boards::Visits::CreateService).not_to receive(:new)
2016-11-03 12:29:30 +05:30
read_board board: board, format: :json
2016-09-13 17:45:13 +05:30
2016-11-03 12:29:30 +05:30
expect(response).to match_response_schema('board')
end
2016-09-13 17:45:13 +05:30
2018-11-08 19:23:39 +05:30
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-09-13 17:45:13 +05:30
2018-11-08 19:23:39 +05:30
it 'returns a not found 404 response' do
read_board board: board, format: :json
2016-11-03 12:29:30 +05:30
2018-11-08 19:23:39 +05:30
expect(response).to have_gitlab_http_status(404)
expect(response.content_type).to eq 'application/json'
end
2016-11-03 12:29:30 +05:30
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-09-13 17:45:13 +05:30
2018-03-17 18:26:18 +05:30
expect(response).to have_gitlab_http_status(404)
2016-09-13 17:45:13 +05:30
end
end
2016-11-03 12:29:30 +05:30
def read_board(board:, format: :html)
2019-02-15 15:39:39 +05:30
get :show, params: {
namespace_id: project.namespace,
project_id: project,
id: board.to_param
},
2016-09-13 17:45:13 +05:30
format: format
end
end
end