change error type

This commit is contained in:
Steffen Kötte 2016-02-01 16:08:33 +01:00
parent 98a75e5931
commit 6fb0f7b6ce
2 changed files with 7 additions and 6 deletions

View File

@ -7,7 +7,7 @@ module Travis::API::V3
raise LoginRequired unless access_control.logged_in? or access_control.full_access? raise LoginRequired unless access_control.logged_in? or access_control.full_access?
raise NotFound unless repository = find(:repository) raise NotFound unless repository = find(:repository)
raise NotFound unless branch = find(:branch, repository) raise NotFound unless branch = find(:branch, repository)
raise ArgumentError, 'interval must be "daily", "weekly" or "monthly"' unless ["daily", "weekly", "monthly"].include?(params["interval"]) raise Error.new('Invalid value for interval. Interval must be "daily", "weekly" or "monthly"!', status: 422) unless ["daily", "weekly", "monthly"].include?(params["interval"])
access_control.permissions(repository).create_cron! access_control.permissions(repository).create_cron!
if branch.cron if branch.cron

View File

@ -55,11 +55,12 @@ describe Travis::API::V3::Services::Cron::Create do
describe "creating a cron job with a wrong interval" do describe "creating a cron job with a wrong interval" do
before { last_cron } before { last_cron }
before { Travis::API::V3::Models::Permission.create(repository: repo, user: repo.owner, push: true) } before { Travis::API::V3::Models::Permission.create(repository: repo, user: repo.owner, push: true) }
it "raises an error" do before { post("/v3/repo/#{repo.id}/branch/#{branch.name}/cron", wrong_options, headers) }
expect { example { expect(parsed_body).to be == {
post("/v3/repo/#{repo.id}/branch/#{branch.name}/cron", wrong_options, headers) "@type" => "error",
}.to raise_error(ArgumentError, 'interval must be "daily", "weekly" or "monthly"') "error_type" => "error",
end "error_message" => "Invalid value for interval. Interval must be \"daily\", \"weekly\" or \"monthly\"!"
}}
end end
describe "try creating a cron job without login" do describe "try creating a cron job without login" do