Skip to content

Commit

Permalink
Fixed [headers] rendering on Status change.
Browse files Browse the repository at this point in the history
  • Loading branch information
gaspard committed Jul 10, 2013
1 parent bfd8c9d commit ed1590f
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 3 deletions.
1 change: 1 addition & 0 deletions History.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
* Fixed cached path in vhost file.
* Added "uuid" method (generates a unique id). <== TODO: Document
* Added support for JSON String in [string_hash] <== TODO: Document
* Fixed [headers] when 'Status' is set (change to redirect on 300).

== 1.2.4 2013-06-13

Expand Down
32 changes: 31 additions & 1 deletion lib/zena/use/rendering.rb
Original file line number Diff line number Diff line change
Expand Up @@ -184,8 +184,19 @@ def render_and_cache(options={})
if filename = zafu_headers.delete('filename')
result[:filename] = filename
end


status = zafu_headers.delete('Status')
headers.merge!(zafu_headers)

if (status.to_i / 100) == 3
redirect_to zafu_headers.delete('Location'), :status => status.to_i
else
render :status => status.to_i
end

headers.merge!(zafu_headers)

return
end

if data = result.delete(:data)
Expand All @@ -205,7 +216,26 @@ def render_and_cache(options={})
render_to_string :file => template_url(opts), :layout => false
else
render :file => template_url(opts), :layout => false, :status => opts[:status]

if status = zafu_headers.delete('Status')
# reset rendering
response.content_type = nil
erase_render_results
reset_variables_added_to_assigns

if (status.to_i / 100) == 3
redirect_to zafu_headers.delete('Location'), :status => status.to_i
else
render :status => status.to_i
end

headers.merge!(zafu_headers)

return
end

headers.merge!(zafu_headers)

cache_page(:url => opts[:cache_url]) if opts[:cache]
end
end
Expand Down
2 changes: 1 addition & 1 deletion locale/en/zena.po
Original file line number Diff line number Diff line change
Expand Up @@ -480,7 +480,7 @@ msgstr "Acl with highest priority is tested first."
#: app/views/acls/_form.rhtml:47
msgid "acl_query_help"
msgstr ""
"SQLiss query to fetch all the nodes for which this acl authorizes access."
"SQLiss query to fetch all the nodes for which this acl authorizes access (Ruby)."

#: lib/zena/use/display.rb:282
msgid "acls"
Expand Down
2 changes: 1 addition & 1 deletion locale/it/zena.po
Original file line number Diff line number Diff line change
Expand Up @@ -480,7 +480,7 @@ msgstr "Acl with highest priority is tested first."

#: app/views/acls/_form.rhtml:47
msgid "acl_query_help"
msgstr "SQLiss query to fetch all the nodes for which this acl authorizes access."
msgstr "SQLiss query to fetch all the nodes for which this acl authorizes access (Ruby)."

#: lib/zena/use/display.rb:282
msgid "acls"
Expand Down
37 changes: 37 additions & 0 deletions test/integration/navigation_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -473,6 +473,43 @@ def test_cache_query_string
end
end
end

def test_not_cache_on_redirect
login(:lion)
t = secure(Template) {
Template.create(
:parent_id => nodes_id(:default),
:title => 'Node-headers.zafu',
:text => %q{<r:headers Location='/login' Status='303'/>DUMMY BODY},
:v_status => Zena::Status::Pub
)
}

without_files('test.host/public') do
without_files('/test.host/zafu') do
preserving_files('/test.host/data') do
with_caching do
login(:anon)
base = "#{SITES_ROOT}#{visitor.site.public_path}"

c = '/fr/page18.html'
assert !File.exists?(base + c), "No cached file #{c} yet"
get "http://test.host#{c}"
assert_response :success
assert File.exists?(base + c), "Cached file #{c} created"

c = '/fr/page18_headers.html'
assert !File.exists?(base + c), "No cached file #{c} yet"
get "http://test.host#{c}"
assert_equal '<html><body>You are being <a href="http://test.host/login">redirected</a>.</body></html>', response.body
assert_response :redirect
assert_redirected_to '/login'
assert !File.exists?(base + c), "No cached file #{c} created"
end
end
end
end
end

def test_should_not_change_session_lang_on_login
get 'http://test.host/'
Expand Down

0 comments on commit ed1590f

Please sign in to comment.