Return 404 NotFound error if ClassifiedListing is not found during delete (#5646)

This commit is contained in:
Nadiya Karachevska 2020-01-22 20:07:44 +02:00 committed by Ben Halpern
parent 1297f1cb3e
commit e49b0e81e5
2 changed files with 15 additions and 0 deletions

View file

@ -59,6 +59,7 @@ class ClassifiedListingsController < ApplicationController
def delete_confirm
@classified_listing = ClassifiedListing.find_by(slug: params[:slug])
not_found unless @classified_listing
authorize @classified_listing
end

View file

@ -476,4 +476,18 @@ RSpec.describe "ClassifiedListings", type: :request do
end
end
end
describe "GET /delete_confirm" do
let!(:listing) { create(:classified_listing, user: user) }
before { sign_in user }
context "without classified listing" do
it "renders not_found" do
expect do
get "/listings/#{listing.category}/#{listing.slug}_1/delete_confirm"
end.to raise_error(ActiveRecord::RecordNotFound)
end
end
end
end