Refactor spec for Projects::BoardListsController

parent 75f0bc4a
...@@ -2,6 +2,7 @@ require 'spec_helper' ...@@ -2,6 +2,7 @@ require 'spec_helper'
describe Projects::BoardListsController do describe Projects::BoardListsController do
let(:project) { create(:project_with_board) } let(:project) { create(:project_with_board) }
let(:board) { project.board }
let(:user) { create(:user) } let(:user) { create(:user) }
before do before do
...@@ -14,19 +15,13 @@ describe Projects::BoardListsController do ...@@ -14,19 +15,13 @@ describe Projects::BoardListsController do
let(:label) { create(:label, project: project, name: 'Development') } let(:label) { create(:label, project: project, name: 'Development') }
it 'returns a successful 200 response' do it 'returns a successful 200 response' do
post :create, namespace_id: project.namespace.to_param, create_board_list label_id: label.id
project_id: project.to_param,
list: { label_id: label.id },
format: :json
expect(response).to have_http_status(200) expect(response).to have_http_status(200)
end end
it 'returns the created list' do it 'returns the created list' do
post :create, namespace_id: project.namespace.to_param, create_board_list label_id: label.id
project_id: project.to_param,
list: { label_id: label.id },
format: :json
expect(response).to match_response_schema('list') expect(response).to match_response_schema('list')
end end
...@@ -34,10 +29,7 @@ describe Projects::BoardListsController do ...@@ -34,10 +29,7 @@ describe Projects::BoardListsController do
context 'with invalid params' do context 'with invalid params' do
it 'returns an error' do it 'returns an error' do
post :create, namespace_id: project.namespace.to_param, create_board_list label_id: nil
project_id: project.to_param,
list: { label_id: nil },
format: :json
parsed_response = JSON.parse(response.body) parsed_response = JSON.parse(response.body)
...@@ -45,29 +37,28 @@ describe Projects::BoardListsController do ...@@ -45,29 +37,28 @@ describe Projects::BoardListsController do
expect(response).to have_http_status(422) expect(response).to have_http_status(422)
end end
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 end
describe 'PATCH #update' do describe 'PATCH #update' do
let!(:planning) { create(:list, board: project.board, position: 1) } let!(:planning) { create(:list, board: board, position: 1) }
let!(:development) { create(:list, board: project.board, position: 2) } let!(:development) { create(:list, board: board, position: 2) }
context 'with valid position' do context 'with valid position' do
it 'returns a successful 200 response' do it 'returns a successful 200 response' do
patch :update, namespace_id: project.namespace.to_param, move list: planning, position: 2
project_id: project.to_param,
id: planning.to_param,
list: { position: 2 },
format: :json
expect(response).to have_http_status(200) expect(response).to have_http_status(200)
end end
it 'moves the list to the desired position' do it 'moves the list to the desired position' do
patch :update, namespace_id: project.namespace.to_param, move list: planning, position: 2
project_id: project.to_param,
id: planning.to_param,
list: { position: 2 },
format: :json
expect(planning.reload.position).to eq 2 expect(planning.reload.position).to eq 2
end end
...@@ -75,11 +66,7 @@ describe Projects::BoardListsController do ...@@ -75,11 +66,7 @@ describe Projects::BoardListsController do
context 'with invalid position' do context 'with invalid position' do
it 'returns a unprocessable entity 422 response' do it 'returns a unprocessable entity 422 response' do
patch :update, namespace_id: project.namespace.to_param, move list: planning, position: 6
project_id: project.to_param,
id: planning.to_param,
list: { position: 6 },
format: :json
expect(response).to have_http_status(422) expect(response).to have_http_status(422)
end end
...@@ -87,49 +74,49 @@ describe Projects::BoardListsController do ...@@ -87,49 +74,49 @@ describe Projects::BoardListsController do
context 'with invalid list id' do context 'with invalid list id' do
it 'returns a not found 404 response' do it 'returns a not found 404 response' do
patch :update, namespace_id: project.namespace.to_param, move list: 999, position: 2
project_id: project.to_param,
id: 999,
list: { position: 2 },
format: :json
expect(response).to have_http_status(404) expect(response).to have_http_status(404)
end end
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 end
describe 'DELETE #destroy' do describe 'DELETE #destroy' do
context 'with valid list id' 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 it 'returns a successful 200 response' do
delete :destroy, namespace_id: project.namespace.to_param, remove_board_list list: planning
project_id: project.to_param,
id: planning.to_param,
format: :json
expect(response).to have_http_status(200) expect(response).to have_http_status(200)
end end
it 'removes list from board' do it 'removes list from board' do
expect do expect { remove_board_list list: planning }.to change(board.lists, :size).by(-1)
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)
end end
end end
context 'with invalid list id' do context 'with invalid list id' do
it 'returns a not found 404 response' do it 'returns a not found 404 response' do
delete :destroy, namespace_id: project.namespace.to_param, remove_board_list list: 999
project_id: project.to_param,
id: 999,
format: :json
expect(response).to have_http_status(404) expect(response).to have_http_status(404)
end end
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
end end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment