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

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

159 lines
4.7 KiB
Ruby
Raw Permalink Normal View History

2019-07-31 22:56:46 +05:30
# frozen_string_literal: true
2016-09-13 17:45:13 +05:30
require 'spec_helper'
2020-06-23 00:09:42 +05:30
RSpec.describe Projects::BoardsController do
2022-11-25 23:54:43 +05:30
let_it_be(:project) { create(:project) }
let_it_be(:user) { create(:user) }
2016-09-13 17:45:13 +05:30
2022-11-25 23:54:43 +05:30
before_all do
2018-11-18 11:00:15 +05:30
project.add_maintainer(user)
2022-11-25 23:54:43 +05:30
end
before do
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
2022-11-25 23:54:43 +05:30
it 'renders template' do
2018-03-17 18:26:18 +05:30
list_boards
2022-11-25 23:54:43 +05:30
expect(response).to render_template :index
expect(response.media_type).to eq 'text/html'
2018-03-17 18:26:18 +05:30
end
2022-11-25 23:54:43 +05:30
context 'when there are recently visited boards' do
let_it_be(:boards) { create_list(:board, 3, resource_parent: project) }
2016-11-03 12:29:30 +05:30
2022-11-25 23:54:43 +05:30
before_all do
visit_board(boards[2], Time.current + 1.minute)
visit_board(boards[0], Time.current + 2.minutes)
visit_board(boards[1], Time.current + 5.minutes)
2016-11-03 12:29:30 +05:30
end
2018-11-08 19:23:39 +05:30
2022-11-25 23:54:43 +05:30
it 'redirects to latest visited board' do
list_boards
2018-11-08 19:23:39 +05:30
2022-11-25 23:54:43 +05:30
expect(response).to redirect_to(
namespace_project_board_path(namespace_id: project.namespace, project_id: project, id: boards[1].id)
)
2018-11-08 19:23:39 +05:30
end
2018-12-13 13:39:08 +05:30
2022-11-25 23:54:43 +05:30
def visit_board(board, time)
create(:board_project_recent_visit, project: project, board: board, user: user, updated_at: time)
end
end
2018-12-13 13:39:08 +05:30
2022-11-25 23:54:43 +05:30
context 'with unauthorized user' do
before do
expect(Ability).to receive(:allowed?).with(user, :log_in, :global).and_call_original
allow(Ability).to receive(:allowed?).with(user, :read_project, project).and_return(true)
allow(Ability).to receive(:allowed?).with(user, :read_issue_board, project).and_return(false)
end
2018-12-13 13:39:08 +05:30
2022-11-25 23:54:43 +05:30
it 'returns a not found 404 response' do
list_boards
2018-12-13 13:39:08 +05:30
2022-11-25 23:54:43 +05:30
expect(response).to have_gitlab_http_status(:not_found)
expect(response.media_type).to eq 'text/html'
2018-12-13 13:39:08 +05:30
end
2016-11-03 12:29:30 +05:30
end
2022-11-25 23:54:43 +05:30
context 'when user is signed out' do
let(:project) { create(:project, :public) }
2016-11-03 12:29:30 +05:30
2022-11-25 23:54:43 +05:30
it 'renders template' do
sign_out(user)
2016-11-03 12:29:30 +05:30
2022-11-25 23:54:43 +05:30
board = create(:board, project: project)
create(:board_project_recent_visit, project: board.project, board: board, user: user)
2016-11-03 12:29:30 +05:30
2022-11-25 23:54:43 +05:30
list_boards
2016-11-03 12:29:30 +05:30
2022-11-25 23:54:43 +05:30
expect(response).to render_template :index
expect(response.media_type).to eq 'text/html'
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
2020-03-13 15:44:24 +05:30
expect(response).to have_gitlab_http_status(:not_found)
2016-11-03 12:29:30 +05:30
end
end
2019-07-07 11:18:12 +05:30
it_behaves_like 'unauthorized when external service denies access' do
subject { list_boards }
end
2022-11-25 23:54:43 +05:30
def list_boards
2019-02-15 15:39:39 +05:30
get :index, params: {
namespace_id: project.namespace,
project_id: project
2022-11-25 23:54:43 +05:30
}
2016-11-03 12:29:30 +05:30
end
end
2016-09-13 17:45:13 +05:30
describe 'GET show' do
2022-11-25 23:54:43 +05:30
let_it_be(:board) { create(:board, project: project) }
2018-03-17 18:26:18 +05:30
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
2021-02-22 17:27:13 +05:30
expect(response.media_type).to eq 'text/html'
2016-11-03 12:29:30 +05:30
end
2018-11-08 19:23:39 +05:30
context 'with unauthorized user' do
before do
2020-04-22 19:07:51 +05:30
expect(Ability).to receive(:allowed?).with(user, :log_in, :global).and_call_original
2018-11-08 19:23:39 +05:30
allow(Ability).to receive(:allowed?).with(user, :read_project, project).and_return(true)
2021-04-17 20:07:23 +05:30
allow(Ability).to receive(:allowed?).with(user, :read_issue_board, project).and_return(false)
2018-11-08 19:23:39 +05:30
end
it 'returns a not found 404 response' do
read_board board: board
2020-03-13 15:44:24 +05:30
expect(response).to have_gitlab_http_status(:not_found)
2021-02-22 17:27:13 +05:30
expect(response.media_type).to eq 'text/html'
2018-11-08 19:23:39 +05:30
end
end
2018-12-13 13:39:08 +05:30
context 'when user is signed out' do
2022-11-25 23:54:43 +05:30
let(:public_board) { create(:board, project: create(:project, :public)) }
2018-12-13 13:39:08 +05:30
it 'does not save visit' do
sign_out(user)
2022-11-25 23:54:43 +05:30
expect { read_board board: public_board }.to change(BoardProjectRecentVisit, :count).by(0)
2018-12-13 13:39:08 +05:30
expect(response).to render_template :show
2021-02-22 17:27:13 +05:30
expect(response.media_type).to eq 'text/html'
2018-12-13 13:39:08 +05:30
end
end
2016-09-13 17:45:13 +05:30
end
2016-11-03 12:29:30 +05:30
context 'when board does not belong to project' do
it 'returns a not found 404 response' do
another_board = create(:board)
2022-11-25 23:54:43 +05:30
get :show, params: { namespace_id: project.namespace, project_id: project, id: another_board.to_param }
2016-09-13 17:45:13 +05:30
2020-03-13 15:44:24 +05:30
expect(response).to have_gitlab_http_status(:not_found)
2016-09-13 17:45:13 +05:30
end
end
2022-11-25 23:54:43 +05:30
def read_board(board:)
get :show, params: { namespace_id: board.project.namespace, project_id: board.project, id: board.to_param }
2016-09-13 17:45:13 +05:30
end
end
end