@@ -216,6 +216,79 @@ module Pageflow
216216 expect ( response . body ) . to include ( 'Not Found' )
217217 end
218218
219+ it 'renders custom 404 entry when site has custom_404_entry configured' do
220+ site = create ( :site , cname : 'my.example.com' )
221+ custom_404_entry = create ( :entry , :published ,
222+ type_name : 'test' ,
223+ title : 'Custom 404' ,
224+ site :)
225+ site . update! ( custom_404_entry :)
226+
227+ get ( 'http://my.example.com/non-existent-entry' )
228+
229+ expect ( response . status ) . to eq ( 404 )
230+ expect ( response . body ) . to include ( 'Custom 404 published rendered by entry type frontend app' )
231+ end
232+
233+ it 'falls back to default 404 when site has no custom_404_entry' do
234+ create ( :site , cname : 'my.example.com' )
235+
236+ get ( 'http://my.example.com/non-existent-entry' )
237+
238+ expect ( response . status ) . to eq ( 404 )
239+ expect ( response . body ) . to include ( "The page you've requested cannot be found." )
240+ end
241+
242+ it 'renders site-specific custom 404 entry' do
243+ site1 = create ( :site , cname : 'site1.example.com' )
244+ site2 = create ( :site , cname : 'site2.example.com' )
245+
246+ custom_404_entry1 = create ( :entry , :published ,
247+ type_name : 'test' ,
248+ title : 'Site 1 Not Found' ,
249+ site : site1 )
250+ custom_404_entry2 = create ( :entry , :published ,
251+ type_name : 'test' ,
252+ title : 'Site 2 Not Found' ,
253+ site : site2 )
254+
255+ site1 . update! ( custom_404_entry : custom_404_entry1 )
256+ site2 . update! ( custom_404_entry : custom_404_entry2 )
257+
258+ get ( 'http://site1.example.com/non-existent' )
259+ expect ( response . status ) . to eq ( 404 )
260+ expect ( response . body ) . to include ( 'Site 1 Not Found' )
261+
262+ get ( 'http://site2.example.com/non-existent' )
263+ expect ( response . status ) . to eq ( 404 )
264+ expect ( response . body ) . to include ( 'Site 2 Not Found' )
265+ end
266+
267+ it 'falls back to default 404 when custom_404_entry is not published' do
268+ site = create ( :site , cname : 'my.example.com' )
269+ unpublished_404_entry = create ( :entry , type_name : 'test' , site :)
270+ site . update! ( custom_404_entry : unpublished_404_entry )
271+
272+ get ( 'http://my.example.com/non-existent-entry' )
273+
274+ expect ( response . status ) . to eq ( 404 )
275+ expect ( response . body ) . to include ( "The page you've requested cannot be found." )
276+ end
277+
278+ it 'falls back to default 404 when custom_404_entry is password protected' do
279+ site = create ( :site , cname : 'my.example.com' )
280+ password_protected_404_entry = create ( :entry , :published_with_password ,
281+ type_name : 'test' ,
282+ password : 'secret123' ,
283+ site :)
284+ site . update! ( custom_404_entry : password_protected_404_entry )
285+
286+ get ( 'http://my.example.com/non-existent-entry' )
287+
288+ expect ( response . status ) . to eq ( 404 )
289+ expect ( response . body ) . to include ( "The page you've requested cannot be found." )
290+ end
291+
219292 it 'responds with forbidden for entry published with password' do
220293 entry = create ( :entry , :published_with_password ,
221294 password : 'abc123abc' ,
0 commit comments