bug: don't 500 when URL is not present

This commit is contained in:
Peter Bhat Harkins 2019-04-29 20:51:51 -05:00
parent dc06ff4ce6
commit a000fbf0af
2 changed files with 15 additions and 0 deletions

View File

@ -335,6 +335,7 @@ class StoriesController < ApplicationController
end
def check_url_dupe
raise ActionController::ParameterMissing.new("No URL") unless story_params[:url].present?
@story = Story.new(story_params)
@story.already_posted_recently?

View File

@ -56,6 +56,20 @@ describe StoriesController do
expect(json.fetch("title")).to eq "some other title"
expect(json.fetch("similar_stories").count).to eq(0)
end
it "throws a 400 if there's no URL present" do
expect {
post :check_url_dupe,
format: :json,
params: { story: { url: "" } }
}.to raise_error(ActionController::ParameterMissing)
expect {
post :check_url_dupe,
format: :json,
params: { story: {} }
}.to raise_error(ActionController::ParameterMissing)
end
end
end