Fix broken StoriesController#show article with bad chars (#6248) [deploy]
This commit is contained in:
parent
3e8e7fb093
commit
e9a0efbbf2
3 changed files with 13 additions and 0 deletions
|
|
@ -20,6 +20,10 @@ class ApplicationController < ActionController::Base
|
|||
raise NotAuthorizedError, "Unauthorized"
|
||||
end
|
||||
|
||||
def bad_request
|
||||
render json: "Error: Bad Request", status: :bad_request
|
||||
end
|
||||
|
||||
def authenticate_user!
|
||||
return if current_user
|
||||
|
||||
|
|
|
|||
|
|
@ -14,6 +14,8 @@ class StoriesController < ApplicationController
|
|||
before_action :authenticate_user!, except: %i[index search show]
|
||||
before_action :set_cache_control_headers, only: %i[index search show]
|
||||
|
||||
rescue_from ArgumentError, with: :bad_request
|
||||
|
||||
def index
|
||||
@page = (params[:page] || 1).to_i
|
||||
@article_index = true
|
||||
|
|
|
|||
|
|
@ -119,6 +119,13 @@ RSpec.describe "StoriesShow", type: :request do
|
|||
get article.path
|
||||
expect(response.body).not_to include('"canonical" href="' + article.canonical_url.to_s + '"')
|
||||
end
|
||||
|
||||
it "handles invalid slug characters" do
|
||||
allow(Article).to receive(:find_by).and_raise(ArgumentError)
|
||||
get article.path
|
||||
|
||||
expect(response.status).to be(400)
|
||||
end
|
||||
end
|
||||
|
||||
describe "GET /:username (org)" do
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue