From 2e5d0c31899f007a5ca6ff2f9af5664cf19fed3b Mon Sep 17 00:00:00 2001 From: Gaspard Bucher Date: Tue, 28 Sep 2010 15:59:34 +0200 Subject: [PATCH] Fixed 500 instead of not found error when +notFound template does not exist, fixed expire on assets when site is private. --- lib/zena/use/rendering.rb | 9 +++++---- lib/zena/use/zafu_templates.rb | 2 +- test/integration/navigation_test.rb | 8 ++++++++ 3 files changed, 14 insertions(+), 5 deletions(-) diff --git a/lib/zena/use/rendering.rb b/lib/zena/use/rendering.rb index b224fb6f..57ac125f 100644 --- a/lib/zena/use/rendering.rb +++ b/lib/zena/use/rendering.rb @@ -134,6 +134,11 @@ def render_and_cache(options={}) # Cache page content into a static file in the current sites directory : SITES_ROOT/test.host/public def cache_page(opts={}) + if cachestamp_format?(params['format']) + headers['Expires'] = (Time.now + 365*24*3600).strftime("%a, %d %b %Y %H:%M:%S GMT") + headers['Cache-Control'] = (!current_site.authentication? && @node.public?) ? 'public' : 'private' + end + return unless perform_caching && caching_allowed(:authenticated => opts.delete(:authenticated)) url = page_cache_file(opts.delete(:url)) opts = {:expire_after => nil, @@ -142,10 +147,6 @@ def cache_page(opts={}) :node_id => @node[:id] }.merge(opts) secure!(CachedPage) { CachedPage.create(opts) } - if cachestamp_format?(params['format']) - headers['Expires'] = (Time.now + 365*24*3600).strftime("%a, %d %b %Y %H:%M:%S GMT") - headers['Cache-Control'] = 'public' - end end # Return true if we can cache the current page diff --git a/lib/zena/use/zafu_templates.rb b/lib/zena/use/zafu_templates.rb index 5ebef606..8ce980a1 100644 --- a/lib/zena/use/zafu_templates.rb +++ b/lib/zena/use/zafu_templates.rb @@ -141,7 +141,7 @@ def valid_template?(content, opts) def default_template_url(opts = {}) if opts[:format] && opts[:format] != 'html' raise ActiveRecord::RecordNotFound - elsif %w{+login +index +adminLayout +popupLayout}.include?(opts[:mode]) + elsif %w{+login +index +adminLayout +popupLayout +notFound}.include?(opts[:mode]) zafu_url ="$default/Node-#{opts[:mode]}" elsif opts[:mode] raise ActiveRecord::RecordNotFound diff --git a/test/integration/navigation_test.rb b/test/integration/navigation_test.rb index 49c28aff..70dfc702 100644 --- a/test/integration/navigation_test.rb +++ b/test/integration/navigation_test.rb @@ -239,6 +239,14 @@ def test_bad_url get 'http://test.host/en/node1.html' assert_response :missing end + + def test_bad_url_without_notFound_template + $_test_site = 'zena' + Node.connection.execute "UPDATE nodes SET kpath='N' where id = #{nodes_id(:Node_not_found_zafu)}" + post 'http://test.host/session', :login=>'tiger', :password=>'tiger' + get 'http://test.host/oo/node1.html' + assert_response :missing + end def test_bad_zip get 'http://test.host/1'