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

180 lines
5.2 KiB
Ruby
Raw Normal View History

2018-03-27 19:54:05 +05:30
require 'spec_helper'
describe Groups::BoardsController do
let(:group) { create(:group) }
2018-12-13 13:39:08 +05:30
let(:user) { create(:user) }
2018-03-27 19:54:05 +05:30
before do
2018-11-18 11:00:15 +05:30
group.add_maintainer(user)
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
expect(response.content_type).to eq 'text/html'
end
context 'with unauthorized user' do
before do
allow(Ability).to receive(:allowed?).with(user, :read_cross_project, :global).and_return(true)
allow(Ability).to receive(:allowed?).with(user, :read_group, group).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(: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
expect(response.content_type).to eq 'text/html'
end
end
2018-03-27 19:54:05 +05:30
end
context 'when format is JSON' do
it 'return an array with one group board' do
create(:board, group: group)
2018-12-13 13:39:08 +05:30
expect(Boards::Visits::LatestService).not_to receive(:new)
2018-03-27 19:54:05 +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 1
end
context 'with unauthorized user' do
before do
allow(Ability).to receive(:allowed?).with(user, :read_cross_project, :global).and_return(true)
allow(Ability).to receive(:allowed?).with(user, :read_group, group).and_return(false)
end
it 'returns a not found 404 response' do
list_boards format: :json
expect(response).to have_gitlab_http_status(404)
expect(response.content_type).to eq 'application/json'
end
end
end
2019-05-18 00:54:41 +05:30
it_behaves_like 'disabled when using an external authorization service' do
subject { list_boards }
end
2018-03-27 19:54:05 +05:30
def list_boards(format: :html)
2019-02-15 15:39:39 +05:30
get :index, params: { group_id: group }, format: format
2018-03-27 19:54:05 +05:30
end
end
describe 'GET show' do
let!(:board) { create(:board, group: group) }
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
expect(response.content_type).to eq 'text/html'
end
context 'with unauthorized user' do
before do
allow(Ability).to receive(:allowed?).with(user, :read_cross_project, :global).and_return(true)
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
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(: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
expect(response.content_type).to eq 'text/html'
end
end
2018-03-27 19:54:05 +05:30
end
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)
2018-03-27 19:54:05 +05:30
read_board board: board, format: :json
expect(response).to match_response_schema('board')
end
context 'with unauthorized user' do
before do
allow(Ability).to receive(:allowed?).with(user, :read_cross_project, :global).and_return(true)
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
expect(response).to have_gitlab_http_status(404)
expect(response.content_type).to eq 'application/json'
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
expect(response).to have_gitlab_http_status(404)
end
end
2019-05-18 00:54:41 +05:30
it_behaves_like 'disabled when using an external authorization service' do
subject { read_board board: board }
end
2018-03-27 19:54:05 +05:30
def read_board(board:, format: :html)
2019-02-15 15:39:39 +05:30
get :show, params: {
group_id: group,
id: board.to_param
},
2018-03-27 19:54:05 +05:30
format: format
end
end
end