Refactor spec for Projects::BoardListsController

This commit is contained in:
Douglas Barbosa Alexandre 2016-08-02 23:01:45 -03:00
parent 75f0bc4af8
commit 64d7559532

View file

@ -2,6 +2,7 @@ require 'spec_helper'
describe Projects::BoardListsController do
let(:project) { create(:project_with_board) }
let(:board) { project.board }
let(:user) { create(:user) }
before do
@ -14,19 +15,13 @@ describe Projects::BoardListsController do
let(:label) { create(:label, project: project, name: 'Development') }
it 'returns a successful 200 response' do
post :create, namespace_id: project.namespace.to_param,
project_id: project.to_param,
list: { label_id: label.id },
format: :json
create_board_list label_id: label.id
expect(response).to have_http_status(200)
end
it 'returns the created list' do
post :create, namespace_id: project.namespace.to_param,
project_id: project.to_param,
list: { label_id: label.id },
format: :json
create_board_list label_id: label.id
expect(response).to match_response_schema('list')
end
@ -34,10 +29,7 @@ describe Projects::BoardListsController do
context 'with invalid params' do
it 'returns an error' do
post :create, namespace_id: project.namespace.to_param,
project_id: project.to_param,
list: { label_id: nil },
format: :json
create_board_list label_id: nil
parsed_response = JSON.parse(response.body)
@ -45,29 +37,28 @@ describe Projects::BoardListsController do
expect(response).to have_http_status(422)
end
end
def create_board_list(label_id:)
post :create, namespace_id: project.namespace.to_param,
project_id: project.to_param,
list: { label_id: label_id },
format: :json
end
end
describe 'PATCH #update' do
let!(:planning) { create(:list, board: project.board, position: 1) }
let!(:development) { create(:list, board: project.board, position: 2) }
let!(:planning) { create(:list, board: board, position: 1) }
let!(:development) { create(:list, board: board, position: 2) }
context 'with valid position' do
it 'returns a successful 200 response' do
patch :update, namespace_id: project.namespace.to_param,
project_id: project.to_param,
id: planning.to_param,
list: { position: 2 },
format: :json
move list: planning, position: 2
expect(response).to have_http_status(200)
end
it 'moves the list to the desired position' do
patch :update, namespace_id: project.namespace.to_param,
project_id: project.to_param,
id: planning.to_param,
list: { position: 2 },
format: :json
move list: planning, position: 2
expect(planning.reload.position).to eq 2
end
@ -75,11 +66,7 @@ describe Projects::BoardListsController do
context 'with invalid position' do
it 'returns a unprocessable entity 422 response' do
patch :update, namespace_id: project.namespace.to_param,
project_id: project.to_param,
id: planning.to_param,
list: { position: 6 },
format: :json
move list: planning, position: 6
expect(response).to have_http_status(422)
end
@ -87,49 +74,49 @@ describe Projects::BoardListsController do
context 'with invalid list id' do
it 'returns a not found 404 response' do
patch :update, namespace_id: project.namespace.to_param,
project_id: project.to_param,
id: 999,
list: { position: 2 },
format: :json
move list: 999, position: 2
expect(response).to have_http_status(404)
end
end
def move(list:, position:)
patch :update, namespace_id: project.namespace.to_param,
project_id: project.to_param,
id: list.to_param,
list: { position: position },
format: :json
end
end
describe 'DELETE #destroy' do
context 'with valid list id' do
let!(:planning) { create(:list, board: project.board, position: 1) }
let!(:planning) { create(:list, board: board, position: 1) }
it 'returns a successful 200 response' do
delete :destroy, namespace_id: project.namespace.to_param,
project_id: project.to_param,
id: planning.to_param,
format: :json
remove_board_list list: planning
expect(response).to have_http_status(200)
end
it 'removes list from board' do
expect do
delete :destroy, namespace_id: project.namespace.to_param,
project_id: project.to_param,
id: planning.to_param,
format: :json
end.to change(project.board.lists, :size).by(-1)
expect { remove_board_list list: planning }.to change(board.lists, :size).by(-1)
end
end
context 'with invalid list id' do
it 'returns a not found 404 response' do
delete :destroy, namespace_id: project.namespace.to_param,
project_id: project.to_param,
id: 999,
format: :json
remove_board_list list: 999
expect(response).to have_http_status(404)
end
end
def remove_board_list(list)
delete :destroy, namespace_id: project.namespace.to_param,
project_id: project.to_param,
id: list.to_param,
format: :json
end
end
end