Skip to content

Commit

Permalink
failure_app now properly handles nil request.format
Browse files Browse the repository at this point in the history
  • Loading branch information
josevalim committed Nov 9, 2010
1 parent 07fedb4 commit 505bd39
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
5 changes: 3 additions & 2 deletions lib/devise/failure_app.rb
Expand Up @@ -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

Expand All @@ -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

Expand Down
5 changes: 5 additions & 0 deletions test/failure_app_test.rb
Expand Up @@ -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"]
Expand Down

0 comments on commit 505bd39

Please sign in to comment.