debian-mirror-gitlab/spec/controllers/boards/lists_controller_spec.rb

253 lines
7.2 KiB
Ruby
Raw Normal View History

2016-09-13 17:45:13 +05:30
require 'spec_helper'
2018-03-17 18:26:18 +05:30
describe Boards::ListsController do
2017-09-10 17:25:29 +05:30
let(:project) { create(:project) }
2016-11-03 12:29:30 +05:30
let(:board) { create(:board, project: project) }
2016-09-13 17:45:13 +05:30
let(:user) { create(:user) }
let(:guest) { create(:user) }
before do
2018-03-17 18:26:18 +05:30
project.add_master(user)
project.add_guest(guest)
2016-09-13 17:45:13 +05:30
end
describe 'GET index' do
it 'returns a successful 200 response' do
2016-11-03 12:29:30 +05:30
read_board_list user: user, board: board
2016-09-13 17:45:13 +05:30
2018-03-17 18:26:18 +05:30
expect(response).to have_gitlab_http_status(200)
2016-09-13 17:45:13 +05:30
expect(response.content_type).to eq 'application/json'
end
it 'returns a list of board lists' do
create(:list, board: board)
2016-11-03 12:29:30 +05:30
read_board_list user: user, board: board
2016-09-13 17:45:13 +05:30
parsed_response = JSON.parse(response.body)
expect(response).to match_response_schema('lists')
2017-09-10 17:25:29 +05:30
expect(parsed_response.length).to eq 3
2016-09-13 17:45:13 +05:30
end
context 'with unauthorized user' do
before do
2016-09-29 09:46:39 +05:30
allow(Ability).to receive(:allowed?).with(user, :read_project, project).and_return(true)
allow(Ability).to receive(:allowed?).with(user, :read_list, project).and_return(false)
2016-09-13 17:45:13 +05:30
end
2016-09-29 09:46:39 +05:30
it 'returns a forbidden 403 response' do
2016-11-03 12:29:30 +05:30
read_board_list user: user, board: board
2016-09-13 17:45:13 +05:30
2018-03-17 18:26:18 +05:30
expect(response).to have_gitlab_http_status(403)
2016-09-13 17:45:13 +05:30
end
end
2016-11-03 12:29:30 +05:30
def read_board_list(user:, board:)
2016-09-13 17:45:13 +05:30
sign_in(user)
get :index, namespace_id: project.namespace.to_param,
2017-08-17 22:00:37 +05:30
project_id: project,
2016-11-03 12:29:30 +05:30
board_id: board.to_param,
2016-09-13 17:45:13 +05:30
format: :json
end
end
describe 'POST create' do
context 'with valid params' do
2016-09-29 09:46:39 +05:30
let(:label) { create(:label, project: project, name: 'Development') }
2016-09-13 17:45:13 +05:30
it 'returns a successful 200 response' do
2016-11-03 12:29:30 +05:30
create_board_list user: user, board: board, label_id: label.id
2016-09-13 17:45:13 +05:30
2018-03-17 18:26:18 +05:30
expect(response).to have_gitlab_http_status(200)
2016-09-13 17:45:13 +05:30
end
it 'returns the created list' do
2016-11-03 12:29:30 +05:30
create_board_list user: user, board: board, label_id: label.id
2016-09-13 17:45:13 +05:30
expect(response).to match_response_schema('list')
end
end
context 'with invalid params' do
2016-09-29 09:46:39 +05:30
context 'when label is nil' do
it 'returns a not found 404 response' do
2016-11-03 12:29:30 +05:30
create_board_list user: user, board: board, label_id: nil
2016-09-29 09:46:39 +05:30
2018-03-17 18:26:18 +05:30
expect(response).to have_gitlab_http_status(404)
2016-09-29 09:46:39 +05:30
end
end
2016-09-13 17:45:13 +05:30
2016-09-29 09:46:39 +05:30
context 'when label that does not belongs to project' do
it 'returns a not found 404 response' do
label = create(:label, name: 'Development')
2016-09-13 17:45:13 +05:30
2016-11-03 12:29:30 +05:30
create_board_list user: user, board: board, label_id: label.id
2016-09-29 09:46:39 +05:30
2018-03-17 18:26:18 +05:30
expect(response).to have_gitlab_http_status(404)
2016-09-29 09:46:39 +05:30
end
2016-09-13 17:45:13 +05:30
end
end
context 'with unauthorized user' do
2016-09-29 09:46:39 +05:30
it 'returns a forbidden 403 response' do
label = create(:label, project: project, name: 'Development')
2016-09-13 17:45:13 +05:30
2016-11-03 12:29:30 +05:30
create_board_list user: guest, board: board, label_id: label.id
2016-09-13 17:45:13 +05:30
2018-03-17 18:26:18 +05:30
expect(response).to have_gitlab_http_status(403)
2016-09-13 17:45:13 +05:30
end
end
2016-11-03 12:29:30 +05:30
def create_board_list(user:, board:, label_id:)
2016-09-13 17:45:13 +05:30
sign_in(user)
post :create, namespace_id: project.namespace.to_param,
2017-08-17 22:00:37 +05:30
project_id: project,
2016-11-03 12:29:30 +05:30
board_id: board.to_param,
2016-09-13 17:45:13 +05:30
list: { label_id: label_id },
format: :json
end
end
describe 'PATCH update' do
let!(:planning) { create(:list, board: board, position: 0) }
let!(:development) { create(:list, board: board, position: 1) }
context 'with valid position' do
it 'returns a successful 200 response' do
2016-11-03 12:29:30 +05:30
move user: user, board: board, list: planning, position: 1
2016-09-13 17:45:13 +05:30
2018-03-17 18:26:18 +05:30
expect(response).to have_gitlab_http_status(200)
2016-09-13 17:45:13 +05:30
end
it 'moves the list to the desired position' do
2016-11-03 12:29:30 +05:30
move user: user, board: board, list: planning, position: 1
2016-09-13 17:45:13 +05:30
expect(planning.reload.position).to eq 1
end
end
context 'with invalid position' do
2016-09-29 09:46:39 +05:30
it 'returns an unprocessable entity 422 response' do
2016-11-03 12:29:30 +05:30
move user: user, board: board, list: planning, position: 6
2016-09-13 17:45:13 +05:30
2018-03-17 18:26:18 +05:30
expect(response).to have_gitlab_http_status(422)
2016-09-13 17:45:13 +05:30
end
end
context 'with invalid list id' do
it 'returns a not found 404 response' do
2016-11-03 12:29:30 +05:30
move user: user, board: board, list: 999, position: 1
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
context 'with unauthorized user' do
2016-09-29 09:46:39 +05:30
it 'returns a forbidden 403 response' do
2016-11-03 12:29:30 +05:30
move user: guest, board: board, list: planning, position: 6
2016-09-13 17:45:13 +05:30
2018-03-17 18:26:18 +05:30
expect(response).to have_gitlab_http_status(403)
2016-09-13 17:45:13 +05:30
end
end
2016-11-03 12:29:30 +05:30
def move(user:, board:, list:, position:)
2016-09-13 17:45:13 +05:30
sign_in(user)
patch :update, namespace_id: project.namespace.to_param,
2017-08-17 22:00:37 +05:30
project_id: project,
2016-11-03 12:29:30 +05:30
board_id: board.to_param,
2016-09-13 17:45:13 +05:30
id: list.to_param,
list: { position: position },
format: :json
end
end
describe 'DELETE destroy' do
let!(:planning) { create(:list, board: board, position: 0) }
context 'with valid list id' do
it 'returns a successful 200 response' do
2016-11-03 12:29:30 +05:30
remove_board_list user: user, board: board, list: planning
2016-09-13 17:45:13 +05:30
2018-03-17 18:26:18 +05:30
expect(response).to have_gitlab_http_status(200)
2016-09-13 17:45:13 +05:30
end
it 'removes list from board' do
2016-11-03 12:29:30 +05:30
expect { remove_board_list user: user, board: board, list: planning }.to change(board.lists, :size).by(-1)
2016-09-13 17:45:13 +05:30
end
end
context 'with invalid list id' do
it 'returns a not found 404 response' do
2016-11-03 12:29:30 +05:30
remove_board_list user: user, board: board, list: 999
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
context 'with unauthorized user' do
2016-09-29 09:46:39 +05:30
it 'returns a forbidden 403 response' do
2016-11-03 12:29:30 +05:30
remove_board_list user: guest, board: board, list: planning
2016-09-13 17:45:13 +05:30
2018-03-17 18:26:18 +05:30
expect(response).to have_gitlab_http_status(403)
2016-09-13 17:45:13 +05:30
end
end
2016-11-03 12:29:30 +05:30
def remove_board_list(user:, board:, list:)
2016-09-13 17:45:13 +05:30
sign_in(user)
delete :destroy, namespace_id: project.namespace.to_param,
2017-08-17 22:00:37 +05:30
project_id: project,
2016-11-03 12:29:30 +05:30
board_id: board.to_param,
2016-09-13 17:45:13 +05:30
id: list.to_param,
format: :json
end
end
describe 'POST generate' do
context 'when board lists is empty' do
it 'returns a successful 200 response' do
2016-11-03 12:29:30 +05:30
generate_default_lists user: user, board: board
2016-09-13 17:45:13 +05:30
2018-03-17 18:26:18 +05:30
expect(response).to have_gitlab_http_status(200)
2016-09-13 17:45:13 +05:30
end
it 'returns the defaults lists' do
2016-11-03 12:29:30 +05:30
generate_default_lists user: user, board: board
2016-09-13 17:45:13 +05:30
expect(response).to match_response_schema('lists')
end
end
context 'when board lists is not empty' do
2016-09-29 09:46:39 +05:30
it 'returns an unprocessable entity 422 response' do
2016-09-13 17:45:13 +05:30
create(:list, board: board)
2016-11-03 12:29:30 +05:30
generate_default_lists user: user, board: board
2016-09-13 17:45:13 +05:30
2018-03-17 18:26:18 +05:30
expect(response).to have_gitlab_http_status(422)
2016-09-13 17:45:13 +05:30
end
end
context 'with unauthorized user' do
2016-09-29 09:46:39 +05:30
it 'returns a forbidden 403 response' do
2016-11-03 12:29:30 +05:30
generate_default_lists user: guest, board: board
2016-09-13 17:45:13 +05:30
2018-03-17 18:26:18 +05:30
expect(response).to have_gitlab_http_status(403)
2016-09-13 17:45:13 +05:30
end
end
2016-11-03 12:29:30 +05:30
def generate_default_lists(user:, board:)
2016-09-13 17:45:13 +05:30
sign_in(user)
post :generate, namespace_id: project.namespace.to_param,
2017-08-17 22:00:37 +05:30
project_id: project,
2016-11-03 12:29:30 +05:30
board_id: board.to_param,
2016-09-13 17:45:13 +05:30
format: :json
end
end
end