Commit 86ed8b3d authored by Stan Hu's avatar Stan Hu

Fix creation of push rules via POST API

If the `max_file_size` parameter were not specified, Grape would
default that value to `nil`, which prevents the model from being
validated and saved. As a result, users would see a JSON response
that had an `id` of `nil`, and the push rule was never created.

Closes #2820
parent b339a870
---
title: Fix creation of push rules via POST API
merge_request:
author:
......@@ -42,7 +42,7 @@ module API
if user_project.push_rule
error!("Project push rule exists", 422)
else
push_rule = user_project.create_push_rule(declared_params)
push_rule = user_project.create_push_rule(declared_params(include_missing: false))
present push_rule, with: Entities::ProjectPushRule
end
end
......
......@@ -59,6 +59,16 @@ describe API::ProjectPushRule, 'ProjectPushRule', api: true do
end
end
it 'adds push rule to project with no file size' do
post api("/projects/#{project.id}/push_rule", user),
commit_message_regex: 'JIRA\-\d+'
expect(response).to have_http_status(201)
expect(json_response['project_id']).to eq(project.id)
expect(json_response['commit_message_regex']).to eq('JIRA\-\d+')
expect(json_response['max_file_size']).to eq(0)
end
it 'returns 400 if no parameter is given' do
post api("/projects/#{project.id}/push_rule", user)
......
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