From b6652abc7cf9d00660bdbf0275df4a3e5e9afad2 Mon Sep 17 00:00:00 2001 From: Prem Sichanugrist Date: Sun, 16 Jan 2011 02:00:23 +0700 Subject: [PATCH] Add `navigational_formats` internal helper which filters out wildcard MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: José Valim --- lib/devise/controllers/internal_helpers.rb | 7 ++++++- test/controllers/internal_helpers_test.rb | 7 +++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/lib/devise/controllers/internal_helpers.rb b/lib/devise/controllers/internal_helpers.rb index 6d47421e..9094b2d0 100644 --- a/lib/devise/controllers/internal_helpers.rb +++ b/lib/devise/controllers/internal_helpers.rb @@ -59,7 +59,12 @@ module Devise # Check whether it's navigational format, such as :html or :iphone, or not. def is_navigational_format? - Devise.navigational_formats.include?(request.format.to_sym) + navigational_formats.include?(request.format.to_sym) + end + + # Returns real navigational formats which supported by Rails + def navigational_formats + @navigational_formats ||= Devise.navigational_formats.select{ |format| Mime::EXTENSION_LOOKUP[format.to_s] } end def unknown_action!(msg) diff --git a/test/controllers/internal_helpers_test.rb b/test/controllers/internal_helpers_test.rb index 0731aadf..518b887f 100644 --- a/test/controllers/internal_helpers_test.rb +++ b/test/controllers/internal_helpers_test.rb @@ -69,4 +69,11 @@ class HelpersTest < ActionController::TestCase assert flash[:notice] == 'non-blank' MyController.send(:protected, :set_flash_message) end + + test 'navigational_formats not returning a wild card' do + MyController.send(:public, :navigational_formats) + Devise.navigational_formats = [:"*/*", :html] + assert_not @controller.navigational_formats.include?(:"*/*") + MyController.send(:protected, :navigational_formats) + end end