NotFound middleware dropped. Status 404 fixed. fixes #119

Ivan Youroff committed Oct 09, 2013
commit 7e4dad5a3e29e668e679e1da1820a56db2de02ee
Showing 4 changed files with 16 additions and 22 deletions
locomotive/wagon/server.rb b/lib/locomotive/wagon/server.rb +0 -1
@@ @@ -74,7 +74,6 @@ module Locomotive::Wagon
use Page
use TemplatizedPage
- use NotFound
run Renderer.new
end
locomotive/wagon/server/not_found.rb b/lib/locomotive/wagon/server/not_found.rb +0 -19
@@ @@ -1,19 +0,0 @@
- module Locomotive::Wagon
- class Server
-
- class NotFound < Middleware
-
- def call(env)
- self.set_accessors(env)
-
- if self.page.nil?
- self.log "Page not found"
- env['wagon.page'] = self.mounting_point.pages['404']
- end
-
- app.call(env)
- end
-
- end
- end
- end
\ No newline at end of file
locomotive/wagon/server/renderer.rb b/lib/locomotive/wagon/server/renderer.rb +9 -2
@@ @@ -18,8 +18,7 @@ module Locomotive::Wagon
[200, { 'Content-Type' => type }, [html]]
end
else
- # no page at all, even not the 404 page
- [404, { 'Content-Type' => 'text/html' }, ['Page not found']]
+ [404, { 'Content-Type' => 'text/html' }, [self.render_404]]
end
end
@@ @@ -33,6 +32,14 @@ module Locomotive::Wagon
raise RendererException.new(e, self.page.title, self.page.template, context)
end
end
+
+ def render_404
+ if self.page = self.mounting_point.pages['404']
+ self.render_page
+ else
+ 'Page not found'
+ end
+ end
# Build the Liquid context used to render the Locomotive page. It
# stores both assigns and registers.
spec/integration/server/basic_spec.rb +7 -0
@@ @@ -19,6 +19,13 @@ describe Locomotive::Wagon::Server do
it 'shows the 404 page' do
get '/void'
+ last_response.status.should eq(404)
+ last_response.body.should =~ /page not found/
+ end
+
+ it 'shows the 404 page with 200 status code when its called explicitly' do
+ get '/404'
+ last_response.status.should eq(200)
last_response.body.should =~ /page not found/
end