Permalink
Browse files

failure_app now properly handles nil request.format

  • Loading branch information...
josevalim committed Nov 9, 2010
1 parent 07fedb4 commit 505bd3970098d4c27a41c43e483e034147358b02
Showing with 8 additions and 2 deletions.
  1. +3 −2 lib/devise/failure_app.rb
  2. +5 −0 test/failure_app_test.rb
@@ -79,7 +79,7 @@ def http_auth?
if request.xhr?
Devise.http_authenticatable_on_xhr
else
- !Devise.navigational_formats.include?(request.format.to_sym)
+ !(request.format && Devise.navigational_formats.include?(request.format.to_sym))
end
end
@@ -90,7 +90,8 @@ def http_auth_header?
end
def http_auth_body
- method = :"to_#{request.format.to_sym}"
+ return i18n_message unless request.format
+ method = "to_#{request.format.to_sym}"
{}.respond_to?(method) ? { :error => i18n_message }.send(method) : i18n_message
end
View
@@ -77,6 +77,11 @@ def call_failure(env_params={})
assert_equal 401, @response.first
end
+ test 'return 401 status for unknown formats' do
+ call_failure 'formats' => []
+ assert_equal 401, @response.first
+ end
+
test 'return WWW-authenticate headers if model allows' do
call_failure('formats' => :xml)
assert_equal 'Basic realm="Application"', @response.second["WWW-Authenticate"]

0 comments on commit 505bd39

Please sign in to comment.