Commit ef3eb79a authored by Bob Van Landuyt's avatar Bob Van Landuyt

Reject creating boards when the feature is not available

parent e5da0e50
...@@ -3,6 +3,7 @@ module EE ...@@ -3,6 +3,7 @@ module EE
module BoardsController module BoardsController
extend ActiveSupport::Concern extend ActiveSupport::Concern
prepended do prepended do
before_action :check_multiple_issue_boards_available!, only: [:create]
before_action :authorize_admin_board!, only: [:create, :update, :destroy] before_action :authorize_admin_board!, only: [:create, :update, :destroy]
before_action :find_board, only: [:update, :destroy] before_action :find_board, only: [:update, :destroy]
end end
......
...@@ -30,40 +30,54 @@ describe Projects::BoardsController do # rubocop:disable RSpec/FilePath ...@@ -30,40 +30,54 @@ describe Projects::BoardsController do # rubocop:disable RSpec/FilePath
end end
describe 'POST create' do describe 'POST create' do
context 'with valid params' do context 'with the multiple issue boards available' do
it 'returns a successful 200 response' do before do
create_board name: 'Backend' stub_licensed_features(multiple_issue_boards: true)
end
expect(response).to have_http_status(200) context 'with valid params' do
it 'returns a successful 200 response' do
create_board name: 'Backend'
expect(response).to have_http_status(200)
end
it 'returns the created board' do
create_board name: 'Backend'
expect(response).to match_response_schema('board')
end
end end
it 'returns the created board' do context 'with invalid params' do
create_board name: 'Backend' it 'returns an unprocessable entity 422 response' do
create_board name: nil
expect(response).to match_response_schema('board') expect(response).to have_http_status(422)
end
end end
end
context 'with invalid params' do context 'with unauthorized user' do
it 'returns an unprocessable entity 422 response' do before do
create_board name: nil allow(Ability).to receive(:allowed?).with(user, :read_project, project).and_return(true)
allow(Ability).to receive(:allowed?).with(user, :admin_board, project).and_return(false)
end
expect(response).to have_http_status(422) it 'returns a not found 404 response' do
create_board name: 'Backend'
expect(response.content_type).to eq 'application/json'
expect(response).to have_http_status(404)
end
end end
end end
context 'with unauthorized user' do it 'renders a 404 when multiple issue boards are not available' do
before do stub_licensed_features(multiple_issue_boards: false)
allow(Ability).to receive(:allowed?).with(user, :read_project, project).and_return(true)
allow(Ability).to receive(:allowed?).with(user, :admin_board, project).and_return(false)
end
it 'returns a not found 404 response' do create_board name: 'Backend'
create_board name: 'Backend'
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
def create_board(name:) def create_board(name:)
......
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