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

132 lines
3.9 KiB
Ruby
Raw Normal View History

2019-07-31 22:56:46 +05:30
# frozen_string_literal: true
2018-03-27 19:54:05 +05:30
require 'spec_helper'
2020-06-23 00:09:42 +05:30
RSpec.describe Groups::BoardsController do
2022-11-25 23:54:43 +05:30
let_it_be(:group) { create(:group) }
let_it_be(:user) { create(:user) }
2018-03-27 19:54:05 +05:30
2022-11-25 23:54:43 +05:30
before_all do
2018-11-18 11:00:15 +05:30
group.add_maintainer(user)
2022-11-25 23:54:43 +05:30
end
before do
2018-03-27 19:54:05 +05:30
sign_in(user)
end
describe 'GET index' do
it 'creates a new board when group does not have one' do
expect { list_boards }.to change(group.boards, :count).by(1)
end
context 'when format is HTML' do
it 'renders template' do
list_boards
expect(response).to render_template :index
2021-02-22 17:27:13 +05:30
expect(response.media_type).to eq 'text/html'
2018-03-27 19:54:05 +05:30
end
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-03-27 19:54:05 +05:30
allow(Ability).to receive(:allowed?).with(user, :read_cross_project, :global).and_return(true)
2020-03-13 15:44:24 +05:30
allow(Ability).to receive(:allowed?).with(user, :read_group, group).and_return(true)
2021-04-17 20:07:23 +05:30
allow(Ability).to receive(:allowed?).with(user, :read_issue_board, group).and_return(false)
2018-03-27 19:54:05 +05:30
end
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)
2021-02-22 17:27:13 +05:30
expect(response.media_type).to eq 'text/html'
2018-03-27 19:54:05 +05:30
end
end
2018-12-13 13:39:08 +05:30
context 'when user is signed out' do
let(:group) { create(:group, :public) }
it 'renders template' do
sign_out(user)
board = create(:board, group: group)
create(:board_group_recent_visit, group: board.group, board: board, user: user)
list_boards
expect(response).to render_template :index
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
2018-03-27 19:54:05 +05:30
end
2019-07-07 11:18:12 +05:30
it_behaves_like 'disabled when using an external authorization service' do
subject { list_boards }
end
2022-11-25 23:54:43 +05:30
def list_boards
get :index, params: { group_id: group }
2018-03-27 19:54:05 +05:30
end
end
describe 'GET show' do
2022-11-25 23:54:43 +05:30
let_it_be(:board) { create(:board, group: group) }
2018-03-27 19:54:05 +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(BoardGroupRecentVisit, :count).by(1)
2018-03-27 19:54:05 +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-03-27 19:54:05 +05:30
end
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-03-27 19:54:05 +05:30
allow(Ability).to receive(:allowed?).with(user, :read_cross_project, :global).and_return(true)
2020-03-13 15:44:24 +05:30
allow(Ability).to receive(:allowed?).with(user, :read_group, group).and_return(true)
2021-04-17 20:07:23 +05:30
allow(Ability).to receive(:allowed?).with(user, :read_issue_board, group).and_return(false)
2018-03-27 19:54:05 +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-03-27 19:54:05 +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, group: create(:group, :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(BoardGroupRecentVisit, :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
2018-03-27 19:54:05 +05:30
end
context 'when board does not belong to group' do
it 'returns a not found 404 response' do
another_board = create(:board)
2022-11-25 23:54:43 +05:30
get :show, params: { group_id: group, id: another_board.to_param }
2018-03-27 19:54:05 +05:30
2020-03-13 15:44:24 +05:30
expect(response).to have_gitlab_http_status(:not_found)
2018-03-27 19:54:05 +05:30
end
end
2019-07-07 11:18:12 +05:30
it_behaves_like 'disabled when using an external authorization service' do
subject { read_board board: board }
end
2022-11-25 23:54:43 +05:30
def read_board(board:)
get :show, params: { group_id: board.group, id: board.to_param }
2018-03-27 19:54:05 +05:30
end
end
end