Return a 404 response If @event is Not Found (#5798) [deploy]

This commit is contained in:
Fran Zekan 2020-02-03 17:30:52 +01:00 committed by GitHub
parent 29e46000a5
commit cba4e99525
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 1 deletions

View file

@ -10,6 +10,6 @@ class EventsController < ApplicationController
end
def show
@event = Event.find_by(slug: params[:id])
@event = Event.find_by!(slug: params[:id])
end
end

View file

@ -15,10 +15,18 @@ RSpec.describe "Events", type: :request do
get "/events"
expect(response.body).not_to include(unpublished_event.title)
end
end
describe "GET events#show" do
it "returns event show page" do
get "/events/#{event.slug}"
expect(response.body).to include event.title
end
it "renders not_found" do
expect do
get "/events/NotSlug-#{event.slug}"
end.to raise_error(ActiveRecord::RecordNotFound)
end
end
end