add test for the issue #146

This commit is contained in:
did 2011-07-28 13:51:59 +02:00
parent 4c8272dfa0
commit dbee233d0a
2 changed files with 12 additions and 4 deletions

View File

@ -9,7 +9,7 @@ module Locomotive
def render_locomotive_page def render_locomotive_page
if request.fullpath =~ /^\/admin\// 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 else
@page = locomotive_page @page = locomotive_page
@ -24,13 +24,15 @@ module Locomotive
end end
def render_no_page_error def render_no_page_error
render :template => "/admin/errors/no_page", :layout => false render :template => '/admin/errors/no_page', :layout => false
end end
def locomotive_page def locomotive_page
path = (params[:path] || request.fullpath).clone # TODO: params[:path] is more consistent path = (params[:path] || request.fullpath).clone # TODO: params[:path] is more consistent
path.gsub!(/\.[a-zA-Z][a-zA-Z0-9]{2,}$/, '') path = path.split('?').first # take everything before the query string or the lookup fails
path.gsub!(/^\//, '') 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? path = 'index' if path.blank?
if path != 'index' if path != 'index'

View File

@ -93,6 +93,12 @@ describe 'Locomotive rendering system' do
@controller.send(:locomotive_page).should_not be_nil @controller.send(:locomotive_page).should_not be_nil
end 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 it 'should return the 404 page if the page does not exist' do
@controller.request.fullpath = '/contact' @controller.request.fullpath = '/contact'
(klass = Page).expects(:published).returns([true]) (klass = Page).expects(:published).returns([true])