2016-08-01 15:23:16 -04:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2017-08-31 14:18:35 -04:00
|
|
|
describe Boards::ListsController do
|
2017-08-02 15:55:11 -04:00
|
|
|
let(:project) { create(:project) }
|
2016-10-06 16:14:39 -04:00
|
|
|
let(:board) { create(:board, project: project) }
|
2016-08-01 15:23:16 -04:00
|
|
|
let(:user) { create(:user) }
|
2016-08-08 18:03:41 -04:00
|
|
|
let(:guest) { create(:user) }
|
2016-08-01 15:23:16 -04:00
|
|
|
|
|
|
|
before do
|
|
|
|
project.team << [user, :master]
|
2016-08-08 18:03:41 -04:00
|
|
|
project.team << [guest, :guest]
|
2016-08-01 15:23:16 -04:00
|
|
|
end
|
2016-08-15 18:50:23 -04:00
|
|
|
|
2016-08-17 10:55:12 -04:00
|
|
|
describe 'GET index' do
|
2016-08-15 18:50:23 -04:00
|
|
|
it 'returns a successful 200 response' do
|
2016-10-05 18:25:29 -04:00
|
|
|
read_board_list user: user, board: board
|
2016-08-15 18:50:23 -04:00
|
|
|
|
2017-10-19 14:28:19 -04:00
|
|
|
expect(response).to have_gitlab_http_status(200)
|
2016-08-15 18:50:23 -04:00
|
|
|
expect(response.content_type).to eq 'application/json'
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns a list of board lists' do
|
|
|
|
create(:list, board: board)
|
|
|
|
|
2016-10-05 18:25:29 -04:00
|
|
|
read_board_list user: user, board: board
|
2016-08-15 18:50:23 -04:00
|
|
|
|
|
|
|
parsed_response = JSON.parse(response.body)
|
|
|
|
|
2016-08-16 10:13:21 -04:00
|
|
|
expect(response).to match_response_schema('lists')
|
2017-05-31 10:34:02 -04:00
|
|
|
expect(parsed_response.length).to eq 3
|
2016-08-15 18:50:23 -04:00
|
|
|
end
|
|
|
|
|
2016-08-17 11:15:51 -04:00
|
|
|
context 'with unauthorized user' do
|
|
|
|
before do
|
2016-08-08 14:55:13 -04:00
|
|
|
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-08-17 11:15:51 -04:00
|
|
|
end
|
2016-08-15 18:50:23 -04:00
|
|
|
|
2016-08-22 10:50:41 -04:00
|
|
|
it 'returns a forbidden 403 response' do
|
2016-10-05 18:25:29 -04:00
|
|
|
read_board_list user: user, board: board
|
2016-08-15 18:50:23 -04:00
|
|
|
|
2017-10-19 14:28:19 -04:00
|
|
|
expect(response).to have_gitlab_http_status(403)
|
2016-08-17 11:15:51 -04:00
|
|
|
end
|
2016-08-15 18:50:23 -04:00
|
|
|
end
|
|
|
|
|
2016-10-05 18:25:29 -04:00
|
|
|
def read_board_list(user:, board:)
|
2016-08-15 18:50:23 -04:00
|
|
|
sign_in(user)
|
|
|
|
|
|
|
|
get :index, namespace_id: project.namespace.to_param,
|
2017-02-23 18:55:01 -05:00
|
|
|
project_id: project,
|
2016-10-05 18:25:29 -04:00
|
|
|
board_id: board.to_param,
|
2016-08-15 18:50:23 -04:00
|
|
|
format: :json
|
|
|
|
end
|
|
|
|
end
|
2016-08-01 15:23:16 -04:00
|
|
|
|
2016-08-17 10:55:12 -04:00
|
|
|
describe 'POST create' do
|
2016-08-08 18:03:41 -04:00
|
|
|
context 'with valid params' do
|
2016-08-22 10:50:41 -04:00
|
|
|
let(:label) { create(:label, project: project, name: 'Development') }
|
|
|
|
|
2016-08-01 15:23:16 -04:00
|
|
|
it 'returns a successful 200 response' do
|
2016-10-05 18:25:29 -04:00
|
|
|
create_board_list user: user, board: board, label_id: label.id
|
2016-08-01 15:23:16 -04:00
|
|
|
|
2017-10-19 14:28:19 -04:00
|
|
|
expect(response).to have_gitlab_http_status(200)
|
2016-08-01 15:23:16 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns the created list' do
|
2016-10-05 18:25:29 -04:00
|
|
|
create_board_list user: user, board: board, label_id: label.id
|
2016-08-01 15:23:16 -04:00
|
|
|
|
|
|
|
expect(response).to match_response_schema('list')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'with invalid params' do
|
2016-08-22 10:50:41 -04:00
|
|
|
context 'when label is nil' do
|
|
|
|
it 'returns a not found 404 response' do
|
2016-10-05 18:25:29 -04:00
|
|
|
create_board_list user: user, board: board, label_id: nil
|
2016-08-22 10:50:41 -04:00
|
|
|
|
2017-10-19 14:28:19 -04:00
|
|
|
expect(response).to have_gitlab_http_status(404)
|
2016-08-22 10:50:41 -04:00
|
|
|
end
|
|
|
|
end
|
2016-08-01 15:23:16 -04:00
|
|
|
|
2016-08-22 10:50:41 -04:00
|
|
|
context 'when label that does not belongs to project' do
|
|
|
|
it 'returns a not found 404 response' do
|
|
|
|
label = create(:label, name: 'Development')
|
2016-08-01 15:23:16 -04:00
|
|
|
|
2016-10-05 18:25:29 -04:00
|
|
|
create_board_list user: user, board: board, label_id: label.id
|
2016-08-22 10:50:41 -04:00
|
|
|
|
2017-10-19 14:28:19 -04:00
|
|
|
expect(response).to have_gitlab_http_status(404)
|
2016-08-22 10:50:41 -04:00
|
|
|
end
|
2016-08-01 15:23:16 -04:00
|
|
|
end
|
|
|
|
end
|
2016-08-02 22:01:45 -04:00
|
|
|
|
2016-08-08 18:03:41 -04:00
|
|
|
context 'with unauthorized user' do
|
2016-08-22 10:50:41 -04:00
|
|
|
it 'returns a forbidden 403 response' do
|
|
|
|
label = create(:label, project: project, name: 'Development')
|
2016-08-08 18:03:41 -04:00
|
|
|
|
2016-10-05 18:25:29 -04:00
|
|
|
create_board_list user: guest, board: board, label_id: label.id
|
2016-08-08 18:03:41 -04:00
|
|
|
|
2017-10-19 14:28:19 -04:00
|
|
|
expect(response).to have_gitlab_http_status(403)
|
2016-08-08 18:03:41 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-10-05 18:25:29 -04:00
|
|
|
def create_board_list(user:, board:, label_id:)
|
2016-08-08 18:03:41 -04:00
|
|
|
sign_in(user)
|
|
|
|
|
2016-08-02 22:01:45 -04:00
|
|
|
post :create, namespace_id: project.namespace.to_param,
|
2017-02-23 18:55:01 -05:00
|
|
|
project_id: project,
|
2016-10-05 18:25:29 -04:00
|
|
|
board_id: board.to_param,
|
2016-08-02 22:01:45 -04:00
|
|
|
list: { label_id: label_id },
|
|
|
|
format: :json
|
|
|
|
end
|
2016-08-01 15:23:16 -04:00
|
|
|
end
|
2016-08-01 16:11:56 -04:00
|
|
|
|
2016-08-17 10:55:12 -04:00
|
|
|
describe 'PATCH update' do
|
2016-08-03 11:09:03 -04:00
|
|
|
let!(:planning) { create(:list, board: board, position: 0) }
|
|
|
|
let!(:development) { create(:list, board: board, position: 1) }
|
2016-08-01 16:11:56 -04:00
|
|
|
|
|
|
|
context 'with valid position' do
|
|
|
|
it 'returns a successful 200 response' do
|
2016-10-05 18:25:29 -04:00
|
|
|
move user: user, board: board, list: planning, position: 1
|
2016-08-01 16:11:56 -04:00
|
|
|
|
2017-10-19 14:28:19 -04:00
|
|
|
expect(response).to have_gitlab_http_status(200)
|
2016-08-01 16:11:56 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'moves the list to the desired position' do
|
2016-10-05 18:25:29 -04:00
|
|
|
move user: user, board: board, list: planning, position: 1
|
2016-08-01 16:11:56 -04:00
|
|
|
|
2016-08-03 11:09:03 -04:00
|
|
|
expect(planning.reload.position).to eq 1
|
2016-08-01 16:11:56 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'with invalid position' do
|
2016-08-22 10:50:41 -04:00
|
|
|
it 'returns an unprocessable entity 422 response' do
|
2016-10-05 18:25:29 -04:00
|
|
|
move user: user, board: board, list: planning, position: 6
|
2016-08-01 16:11:56 -04:00
|
|
|
|
2017-10-19 14:28:19 -04:00
|
|
|
expect(response).to have_gitlab_http_status(422)
|
2016-08-01 16:11:56 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'with invalid list id' do
|
|
|
|
it 'returns a not found 404 response' do
|
2016-10-05 18:25:29 -04:00
|
|
|
move user: user, board: board, list: 999, position: 1
|
2016-08-01 16:11:56 -04:00
|
|
|
|
2017-10-19 14:28:19 -04:00
|
|
|
expect(response).to have_gitlab_http_status(404)
|
2016-08-01 16:11:56 -04:00
|
|
|
end
|
|
|
|
end
|
2016-08-02 22:01:45 -04:00
|
|
|
|
2016-08-08 18:03:41 -04:00
|
|
|
context 'with unauthorized user' do
|
2016-08-22 10:50:41 -04:00
|
|
|
it 'returns a forbidden 403 response' do
|
2016-10-05 18:25:29 -04:00
|
|
|
move user: guest, board: board, list: planning, position: 6
|
2016-08-08 18:03:41 -04:00
|
|
|
|
2017-10-19 14:28:19 -04:00
|
|
|
expect(response).to have_gitlab_http_status(403)
|
2016-08-08 18:03:41 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-10-05 18:25:29 -04:00
|
|
|
def move(user:, board:, list:, position:)
|
2016-08-08 18:03:41 -04:00
|
|
|
sign_in(user)
|
|
|
|
|
2016-08-02 22:01:45 -04:00
|
|
|
patch :update, namespace_id: project.namespace.to_param,
|
2017-02-23 18:55:01 -05:00
|
|
|
project_id: project,
|
2016-10-05 18:25:29 -04:00
|
|
|
board_id: board.to_param,
|
2016-08-02 22:01:45 -04:00
|
|
|
id: list.to_param,
|
|
|
|
list: { position: position },
|
|
|
|
format: :json
|
|
|
|
end
|
2016-08-01 16:11:56 -04:00
|
|
|
end
|
2016-08-01 17:44:33 -04:00
|
|
|
|
2016-08-17 10:55:12 -04:00
|
|
|
describe 'DELETE destroy' do
|
2016-08-08 18:03:41 -04:00
|
|
|
let!(:planning) { create(:list, board: board, position: 0) }
|
2016-08-01 17:44:33 -04:00
|
|
|
|
2016-08-08 18:03:41 -04:00
|
|
|
context 'with valid list id' do
|
2016-08-01 17:44:33 -04:00
|
|
|
it 'returns a successful 200 response' do
|
2016-10-05 18:25:29 -04:00
|
|
|
remove_board_list user: user, board: board, list: planning
|
2016-08-01 17:44:33 -04:00
|
|
|
|
2017-10-19 14:28:19 -04:00
|
|
|
expect(response).to have_gitlab_http_status(200)
|
2016-08-01 17:44:33 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'removes list from board' do
|
2016-10-05 18:25:29 -04:00
|
|
|
expect { remove_board_list user: user, board: board, list: planning }.to change(board.lists, :size).by(-1)
|
2016-08-01 17:44:33 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'with invalid list id' do
|
|
|
|
it 'returns a not found 404 response' do
|
2016-10-05 18:25:29 -04:00
|
|
|
remove_board_list user: user, board: board, list: 999
|
2016-08-01 17:44:33 -04:00
|
|
|
|
2017-10-19 14:28:19 -04:00
|
|
|
expect(response).to have_gitlab_http_status(404)
|
2016-08-01 17:44:33 -04:00
|
|
|
end
|
|
|
|
end
|
2016-08-02 22:01:45 -04:00
|
|
|
|
2016-08-08 18:03:41 -04:00
|
|
|
context 'with unauthorized user' do
|
2016-08-22 10:50:41 -04:00
|
|
|
it 'returns a forbidden 403 response' do
|
2016-10-05 18:25:29 -04:00
|
|
|
remove_board_list user: guest, board: board, list: planning
|
2016-08-08 18:03:41 -04:00
|
|
|
|
2017-10-19 14:28:19 -04:00
|
|
|
expect(response).to have_gitlab_http_status(403)
|
2016-08-08 18:03:41 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-10-05 18:25:29 -04:00
|
|
|
def remove_board_list(user:, board:, list:)
|
2016-08-08 18:03:41 -04:00
|
|
|
sign_in(user)
|
|
|
|
|
2016-08-02 22:01:45 -04:00
|
|
|
delete :destroy, namespace_id: project.namespace.to_param,
|
2017-02-23 18:55:01 -05:00
|
|
|
project_id: project,
|
2016-10-05 18:25:29 -04:00
|
|
|
board_id: board.to_param,
|
2016-08-02 22:01:45 -04:00
|
|
|
id: list.to_param,
|
|
|
|
format: :json
|
|
|
|
end
|
2016-08-01 16:11:56 -04:00
|
|
|
end
|
2016-08-08 15:49:09 -04:00
|
|
|
|
2016-08-17 10:55:12 -04:00
|
|
|
describe 'POST generate' do
|
2016-08-08 15:49:09 -04:00
|
|
|
context 'when board lists is empty' do
|
|
|
|
it 'returns a successful 200 response' do
|
2016-10-05 18:25:29 -04:00
|
|
|
generate_default_lists user: user, board: board
|
2016-08-08 15:49:09 -04:00
|
|
|
|
2017-10-19 14:28:19 -04:00
|
|
|
expect(response).to have_gitlab_http_status(200)
|
2016-08-08 15:49:09 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns the defaults lists' do
|
2016-10-05 18:25:29 -04:00
|
|
|
generate_default_lists user: user, board: board
|
2016-08-08 15:49:09 -04:00
|
|
|
|
2016-08-16 10:13:21 -04:00
|
|
|
expect(response).to match_response_schema('lists')
|
2016-08-08 15:49:09 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when board lists is not empty' do
|
2016-08-22 10:50:41 -04:00
|
|
|
it 'returns an unprocessable entity 422 response' do
|
2016-08-08 15:49:09 -04:00
|
|
|
create(:list, board: board)
|
|
|
|
|
2016-10-05 18:25:29 -04:00
|
|
|
generate_default_lists user: user, board: board
|
2016-08-08 15:49:09 -04:00
|
|
|
|
2017-10-19 14:28:19 -04:00
|
|
|
expect(response).to have_gitlab_http_status(422)
|
2016-08-08 15:49:09 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-08-08 18:03:41 -04:00
|
|
|
context 'with unauthorized user' do
|
2016-08-22 10:50:41 -04:00
|
|
|
it 'returns a forbidden 403 response' do
|
2016-10-05 18:25:29 -04:00
|
|
|
generate_default_lists user: guest, board: board
|
2016-08-08 18:03:41 -04:00
|
|
|
|
2017-10-19 14:28:19 -04:00
|
|
|
expect(response).to have_gitlab_http_status(403)
|
2016-08-08 18:03:41 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-10-05 22:50:35 -04:00
|
|
|
def generate_default_lists(user:, board:)
|
2016-08-08 18:03:41 -04:00
|
|
|
sign_in(user)
|
|
|
|
|
2016-08-08 15:49:09 -04:00
|
|
|
post :generate, namespace_id: project.namespace.to_param,
|
2017-02-23 18:55:01 -05:00
|
|
|
project_id: project,
|
2016-10-05 18:25:29 -04:00
|
|
|
board_id: board.to_param,
|
2016-08-08 15:49:09 -04:00
|
|
|
format: :json
|
|
|
|
end
|
|
|
|
end
|
2016-08-01 15:23:16 -04:00
|
|
|
end
|