2019-04-15 06:17:05 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2018-02-19 14:06:16 -05:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2020-06-03 23:08:05 -04:00
|
|
|
RSpec.describe Groups::BoardsController do
|
2018-02-19 14:06:16 -05:00
|
|
|
let(:group) { create(:group) }
|
2018-10-26 08:49:16 -04:00
|
|
|
let(:user) { create(:user) }
|
2018-02-19 14:06:16 -05:00
|
|
|
|
|
|
|
before do
|
2018-07-11 10:36:08 -04:00
|
|
|
group.add_maintainer(user)
|
2018-02-19 14:06:16 -05:00
|
|
|
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
|
2020-12-02 10:09:37 -05:00
|
|
|
expect(response.media_type).to eq 'text/html'
|
2018-02-19 14:06:16 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'with unauthorized user' do
|
|
|
|
before do
|
2020-04-03 14:10:03 -04:00
|
|
|
expect(Ability).to receive(:allowed?).with(user, :log_in, :global).and_call_original
|
2018-02-19 14:06:16 -05:00
|
|
|
allow(Ability).to receive(:allowed?).with(user, :read_cross_project, :global).and_return(true)
|
2020-02-10 22:09:13 -05:00
|
|
|
allow(Ability).to receive(:allowed?).with(user, :read_group, group).and_return(true)
|
2021-03-02 19:10:50 -05:00
|
|
|
allow(Ability).to receive(:allowed?).with(user, :read_issue_board, group).and_return(false)
|
2018-02-19 14:06:16 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns a not found 404 response' do
|
|
|
|
list_boards
|
|
|
|
|
2020-02-06 04:09:06 -05:00
|
|
|
expect(response).to have_gitlab_http_status(:not_found)
|
2020-12-02 10:09:37 -05:00
|
|
|
expect(response.media_type).to eq 'text/html'
|
2018-02-19 14:06:16 -05:00
|
|
|
end
|
|
|
|
end
|
2018-10-26 08:49:16 -04:00
|
|
|
|
|
|
|
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
|
2020-12-02 10:09:37 -05:00
|
|
|
expect(response.media_type).to eq 'text/html'
|
2018-10-26 08:49:16 -04:00
|
|
|
end
|
|
|
|
end
|
2018-02-19 14:06:16 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'when format is JSON' do
|
|
|
|
it 'return an array with one group board' do
|
|
|
|
create(:board, group: group)
|
|
|
|
|
2019-06-17 08:58:48 -04:00
|
|
|
expect(Boards::VisitsFinder).not_to receive(:new)
|
2018-10-26 08:49:16 -04:00
|
|
|
|
2018-02-19 14:06:16 -05: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 1
|
2018-02-19 14:06:16 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'with unauthorized user' do
|
|
|
|
before do
|
2020-04-03 14:10:03 -04:00
|
|
|
expect(Ability).to receive(:allowed?).with(user, :log_in, :global).and_call_original
|
2018-02-19 14:06:16 -05:00
|
|
|
allow(Ability).to receive(:allowed?).with(user, :read_cross_project, :global).and_return(true)
|
2020-02-10 22:09:13 -05:00
|
|
|
allow(Ability).to receive(:allowed?).with(user, :read_group, group).and_return(true)
|
2021-03-02 19:10:50 -05:00
|
|
|
allow(Ability).to receive(:allowed?).with(user, :read_issue_board, group).and_return(false)
|
2018-02-19 14:06:16 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns a not found 404 response' do
|
|
|
|
list_boards format: :json
|
|
|
|
|
2020-02-06 04:09:06 -05:00
|
|
|
expect(response).to have_gitlab_http_status(:not_found)
|
2020-12-02 10:09:37 -05:00
|
|
|
expect(response.media_type).to eq 'application/json'
|
2018-02-19 14:06:16 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-04-09 11:38:58 -04:00
|
|
|
it_behaves_like 'disabled when using an external authorization service' do
|
|
|
|
subject { list_boards }
|
|
|
|
end
|
|
|
|
|
2018-02-19 14:06:16 -05:00
|
|
|
def list_boards(format: :html)
|
2018-12-17 17:52:17 -05:00
|
|
|
get :index, params: { group_id: group }, format: format
|
2018-02-19 14:06:16 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'GET show' do
|
|
|
|
let!(:board) { create(:board, group: group) }
|
|
|
|
|
|
|
|
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(BoardGroupRecentVisit, :count).by(1)
|
2018-02-19 14:06:16 -05:00
|
|
|
|
|
|
|
expect(response).to render_template :show
|
2020-12-02 10:09:37 -05:00
|
|
|
expect(response.media_type).to eq 'text/html'
|
2018-02-19 14:06:16 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'with unauthorized user' do
|
|
|
|
before do
|
2020-04-03 14:10:03 -04:00
|
|
|
expect(Ability).to receive(:allowed?).with(user, :log_in, :global).and_call_original
|
2018-02-19 14:06:16 -05:00
|
|
|
allow(Ability).to receive(:allowed?).with(user, :read_cross_project, :global).and_return(true)
|
2020-02-10 22:09:13 -05:00
|
|
|
allow(Ability).to receive(:allowed?).with(user, :read_group, group).and_return(true)
|
2021-03-02 19:10:50 -05:00
|
|
|
allow(Ability).to receive(:allowed?).with(user, :read_issue_board, group).and_return(false)
|
2018-02-19 14:06:16 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns a not found 404 response' do
|
|
|
|
read_board board: board
|
|
|
|
|
2020-02-06 04:09:06 -05:00
|
|
|
expect(response).to have_gitlab_http_status(:not_found)
|
2020-12-02 10:09:37 -05:00
|
|
|
expect(response.media_type).to eq 'text/html'
|
2018-02-19 14:06:16 -05:00
|
|
|
end
|
|
|
|
end
|
2018-10-26 08:49:16 -04:00
|
|
|
|
|
|
|
context 'when user is signed out' do
|
|
|
|
let(:group) { create(:group, :public) }
|
|
|
|
|
|
|
|
it 'does not save visit' do
|
|
|
|
sign_out(user)
|
|
|
|
|
|
|
|
expect { read_board board: board }.to change(BoardGroupRecentVisit, :count).by(0)
|
|
|
|
|
|
|
|
expect(response).to render_template :show
|
2020-12-02 10:09:37 -05:00
|
|
|
expect(response.media_type).to eq 'text/html'
|
2018-10-26 08:49:16 -04:00
|
|
|
end
|
|
|
|
end
|
2018-02-19 14:06:16 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
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)
|
|
|
|
|
2018-02-19 14:06:16 -05:00
|
|
|
read_board board: board, format: :json
|
|
|
|
|
|
|
|
expect(response).to match_response_schema('board')
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'with unauthorized user' do
|
|
|
|
before do
|
2020-04-03 14:10:03 -04:00
|
|
|
expect(Ability).to receive(:allowed?).with(user, :log_in, :global).and_call_original
|
2018-02-19 14:06:16 -05:00
|
|
|
allow(Ability).to receive(:allowed?).with(user, :read_cross_project, :global).and_return(true)
|
2020-02-10 22:09:13 -05:00
|
|
|
allow(Ability).to receive(:allowed?).with(user, :read_group, group).and_return(true)
|
2018-02-19 14:06:16 -05:00
|
|
|
allow(Ability).to receive(:allowed?).with(user, :read_group, group).and_return(false)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns a not found 404 response' do
|
|
|
|
read_board board: board, format: :json
|
|
|
|
|
2020-02-06 04:09:06 -05:00
|
|
|
expect(response).to have_gitlab_http_status(:not_found)
|
2020-12-02 10:09:37 -05:00
|
|
|
expect(response.media_type).to eq 'application/json'
|
2018-02-19 14:06:16 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when board does not belong to group' do
|
|
|
|
it 'returns a not found 404 response' do
|
|
|
|
another_board = create(:board)
|
|
|
|
|
|
|
|
read_board board: another_board
|
|
|
|
|
2020-02-06 04:09:06 -05:00
|
|
|
expect(response).to have_gitlab_http_status(:not_found)
|
2018-02-19 14:06:16 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-04-09 11:38:58 -04:00
|
|
|
it_behaves_like 'disabled when using an external authorization service' do
|
|
|
|
subject { read_board board: board }
|
|
|
|
end
|
|
|
|
|
2018-02-19 14:06:16 -05:00
|
|
|
def read_board(board:, format: :html)
|
2018-12-17 17:52:17 -05:00
|
|
|
get :show, params: {
|
|
|
|
group_id: group,
|
|
|
|
id: board.to_param
|
|
|
|
},
|
2018-02-19 14:06:16 -05:00
|
|
|
format: format
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|