From dbee233d0acad1447d40902be52459aee86a104b Mon Sep 17 00:00:00 2001 From: did Date: Thu, 28 Jul 2011 13:51:59 +0200 Subject: [PATCH] add test for the issue #146 --- lib/locomotive/render.rb | 10 ++++++---- spec/lib/locomotive/render_spec.rb | 6 ++++++ 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/lib/locomotive/render.rb b/lib/locomotive/render.rb index 4601dbec..5cdfdaef 100644 --- a/lib/locomotive/render.rb +++ b/lib/locomotive/render.rb @@ -9,7 +9,7 @@ module Locomotive def render_locomotive_page if request.fullpath =~ /^\/admin\// - render :template => "/admin/errors/404", :layout => '/admin/layouts/box', :status => :not_found + render :template => '/admin/errors/404', :layout => '/admin/layouts/box', :status => :not_found else @page = locomotive_page @@ -24,13 +24,15 @@ module Locomotive end def render_no_page_error - render :template => "/admin/errors/no_page", :layout => false + render :template => '/admin/errors/no_page', :layout => false end def locomotive_page path = (params[:path] || request.fullpath).clone # TODO: params[:path] is more consistent - path.gsub!(/\.[a-zA-Z][a-zA-Z0-9]{2,}$/, '') - path.gsub!(/^\//, '') + path = path.split('?').first # take everything before the query string or the lookup fails + path.gsub!(/\.[a-zA-Z][a-zA-Z0-9]{2,}$/, '') # remove the page extension + path.gsub!(/^\//, '') # remove the leading slash + path = 'index' if path.blank? if path != 'index' diff --git a/spec/lib/locomotive/render_spec.rb b/spec/lib/locomotive/render_spec.rb index e1b73cc6..f704bfd2 100644 --- a/spec/lib/locomotive/render_spec.rb +++ b/spec/lib/locomotive/render_spec.rb @@ -93,6 +93,12 @@ describe 'Locomotive rendering system' do @controller.send(:locomotive_page).should_not be_nil end + it 'does not include the query string' do + @controller.request.fullpath = '/about_us/team.html?some=params&we=use' + @controller.current_site.pages.expects(:any_in).with({ :fullpath => %w{about_us/team about_us/content_type_template} }).returns([@page]) + @controller.send(:locomotive_page).should_not be_nil + end + it 'should return the 404 page if the page does not exist' do @controller.request.fullpath = '/contact' (klass = Page).expects(:published).returns([true])