Commit e9154f46 authored by Oswaldo Ferreira's avatar Oswaldo Ferreira

Allow sending label ids on board creation/update

parent c6570947
...@@ -55,7 +55,7 @@ module EE ...@@ -55,7 +55,7 @@ module EE
end end
def board_params def board_params
params.require(:board).permit(:name, :weight, :milestone_id, :author_id, :assignee_id) params.require(:board).permit(:name, :weight, :milestone_id, :author_id, :assignee_id, label_ids: [])
end end
def find_board def find_board
......
...@@ -38,32 +38,34 @@ describe Projects::BoardsController do ...@@ -38,32 +38,34 @@ describe Projects::BoardsController do
context 'with valid params' do context 'with valid params' do
let(:user) { create(:user) } let(:user) { create(:user) }
let(:milestone) { create(:milestone) } let(:milestone) { create(:milestone) }
let(:label) { create(:label) }
let(:valid_params) do let(:create_params) do
{ name: 'Backend', { name: 'Backend',
weight: 1, weight: 1,
milestone_id: milestone.id, milestone_id: milestone.id,
author_id: user.id, author_id: user.id,
assignee_id: user.id } assignee_id: user.id,
label_ids: [label.id] }
end end
it 'returns a successful 200 response' do it 'returns a successful 200 response' do
create_board valid_params create_board create_params
expect(response).to have_http_status(200) expect(response).to have_http_status(200)
end end
it 'returns the created board' do it 'returns the created board' do
create_board valid_params create_board create_params
expect(response).to match_response_schema('board') expect(response).to match_response_schema('board')
end end
it 'valid board is created' do it 'valid board is created' do
create_board valid_params create_board create_params
expect(Board.count).to eq(1) expect(Board.count).to eq(1)
expect(Board.first).to have_attributes(valid_params) expect(Board.first).to have_attributes(create_params)
end end
end end
...@@ -108,24 +110,42 @@ describe Projects::BoardsController do ...@@ -108,24 +110,42 @@ describe Projects::BoardsController do
describe 'PATCH update' do describe 'PATCH update' do
let(:board) { create(:board, project: project, name: 'Backend') } let(:board) { create(:board, project: project, name: 'Backend') }
let(:user) { create(:user) }
let(:milestone) { create(:milestone) }
let(:label) { create(:label) }
let(:update_params) do
{ name: 'Frontend',
weight: 1,
milestone_id: milestone.id,
author_id: user.id,
assignee_id: user.id,
label_ids: [label.id] }
end
context 'with valid params' do context 'with valid params' do
it 'returns a successful 200 response' do it 'returns a successful 200 response' do
update_board board: board, name: 'Frontend' update_board board, update_params
expect(response).to have_http_status(200) expect(response).to have_http_status(200)
end end
it 'returns the updated board' do it 'returns the updated board' do
update_board board: board, name: 'Frontend' update_board board, update_params
expect(response).to match_response_schema('board') expect(response).to match_response_schema('board')
end end
it 'updates board with valid params' do
update_board board, update_params
expect(board.reload).to have_attributes(update_params)
end
end end
context 'with invalid params' do context 'with invalid params' do
it 'returns an unprocessable entity 422 response' do it 'returns an unprocessable entity 422 response' do
update_board board: board, name: nil update_board board, name: nil
expect(response).to have_http_status(422) expect(response).to have_http_status(422)
end end
...@@ -133,7 +153,7 @@ describe Projects::BoardsController do ...@@ -133,7 +153,7 @@ describe Projects::BoardsController do
context 'with invalid board id' do context 'with invalid board id' do
it 'returns a not found 404 response' do it 'returns a not found 404 response' do
update_board board: 999, name: 'Frontend' update_board 999, name: nil
expect(response).to have_http_status(404) expect(response).to have_http_status(404)
end end
...@@ -146,18 +166,18 @@ describe Projects::BoardsController do ...@@ -146,18 +166,18 @@ describe Projects::BoardsController do
end end
it 'returns a not found 404 response' do it 'returns a not found 404 response' do
update_board board: board, name: 'Backend' update_board board, update_params
expect(response.content_type).to eq 'application/json' expect(response.content_type).to eq 'application/json'
expect(response).to have_http_status(404) expect(response).to have_http_status(404)
end end
end end
def update_board(board:, name:) def update_board(board, update_params)
patch :update, namespace_id: project.namespace.to_param, patch :update, namespace_id: project.namespace.to_param,
project_id: project.to_param, project_id: project.to_param,
id: board.to_param, id: board.to_param,
board: { name: name }, board: update_params,
format: :json format: :json
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