Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Remove 3.0 related code.

  • Loading branch information...
commit 0b55ebb15000970b72fbd9b0dd078bd4906cdfc6 1 parent 7c11564
@josevalim josevalim authored
View
7 lib/devise.rb
@@ -19,7 +19,6 @@ module Controllers
autoload :InternalHelpers, 'devise/controllers/internal_helpers'
autoload :Rememberable, 'devise/controllers/rememberable'
autoload :ScopedViews, 'devise/controllers/scoped_views'
- autoload :SharedHelpers, 'devise/controllers/shared_helpers'
autoload :UrlHelpers, 'devise/controllers/url_helpers'
end
@@ -202,9 +201,8 @@ module Strategies
@@skip_session_storage = []
# Which formats should be treated as navigational.
- # We need both :"*/*" and "*/*" to work on different Rails versions.
mattr_accessor :navigational_formats
- @@navigational_formats = [:"*/*", "*/*", :html]
+ @@navigational_formats = ["*/*", :html]
# When set to true, signing out a user signs out all other scopes.
mattr_accessor :sign_out_all_scopes
@@ -215,7 +213,8 @@ module Strategies
@@sign_out_via = :get
# The parent controller all Devise controllers inherits from.
- # Defaults to ApplicationController.
+ # Defaults to ApplicationController. This should be set early
+ # in the initialization process and should be set to a string.
mattr_accessor :parent_controller
@@parent_controller = "ApplicationController"
View
9 lib/devise/controllers/internal_helpers.rb
@@ -6,7 +6,6 @@ module Controllers
module InternalHelpers #:nodoc:
extend ActiveSupport::Concern
include Devise::Controllers::ScopedViews
- include Devise::Controllers::SharedHelpers
included do
helper DeviseHelper
@@ -157,6 +156,14 @@ def respond_with_navigational(*args, &block)
format.any(*navigational_formats, &block)
end
end
+
+ def request_format
+ @request_format ||= request.format.try(:ref)
+ end
+
+ def is_navigational_format?
+ Devise.navigational_formats.include?(request.format.try(:ref))
+ end
end
end
end
View
26 lib/devise/controllers/shared_helpers.rb
@@ -1,26 +0,0 @@
-module Devise
- module Controllers
- # Helpers used in both FailureApp and Devise controllers.
- module SharedHelpers
- MIME_REFERENCES = Mime::HTML.respond_to?(:ref)
-
- protected
-
- # Helper used by FailureApp and Devise controllers to retrieve proper formats.
- def request_format
- @request_format ||= if request.format.respond_to?(:ref)
- request.format.ref
- elsif MIME_REFERENCES
- request.format
- elsif request.format # Rails < 3.0.4
- request.format.to_sym
- end
- end
-
- # Check whether it's navigational format, such as :html or :iphone, or not.
- def is_navigational_format?
- Devise.navigational_formats.include?(request_format)
- end
- end
- end
-end
View
9 lib/devise/failure_app.rb
@@ -10,7 +10,6 @@ class FailureApp < ActionController::Metal
include ActionController::UrlFor
include ActionController::Redirecting
include Rails.application.routes.url_helpers
- include Devise::Controllers::SharedHelpers
delegate :flash, :to => :request
@@ -149,5 +148,13 @@ def attempted_path
def store_location!
session["#{scope}_return_to"] = attempted_path if request.get? && !http_auth?
end
+
+ def is_navigational_format?
+ Devise.navigational_formats.include?(request_format)
+ end
+
+ def request_format
+ @request_format ||= request.format.try(:ref)
+ end
end
end
View
5 lib/generators/templates/devise.rb
@@ -201,9 +201,8 @@
# If you have any extra navigational formats, like :iphone or :mobile, you
# should add them to the navigational formats lists.
#
- # The :"*/*" and "*/*" formats below is required to match Internet
- # Explorer requests.
- # config.navigational_formats = [:"*/*", "*/*", :html]
+ # The "*/*" below is required to match Internet Explorer requests.
+ # config.navigational_formats = ["*/*", :html]
# The default HTTP method used to sign out a resource. Default is :delete.
config.sign_out_via = :delete
View
26 test/failure_app_test.rb
@@ -73,14 +73,14 @@ def call_failure(env_params={})
test 'works for any navigational format' do
swap Devise, :navigational_formats => [:xml] do
- call_failure('formats' => :xml)
+ call_failure('formats' => Mime::XML)
assert_equal 302, @response.first
end
end
test 'redirects the correct format if it is a non-html format request' do
swap Devise, :navigational_formats => [:js] do
- call_failure('formats' => :js)
+ call_failure('formats' => Mime::JS)
assert_equal 'http://test.host/users/sign_in.js', @response.second["Location"]
end
end
@@ -88,18 +88,18 @@ def call_failure(env_params={})
context 'For HTTP request' do
test 'return 401 status' do
- call_failure('formats' => :xml)
+ call_failure('formats' => Mime::XML)
assert_equal 401, @response.first
end
test 'return appropriate body for xml' do
- call_failure('formats' => :xml)
+ call_failure('formats' => Mime::XML)
result = %(<?xml version="1.0" encoding="UTF-8"?>\n<errors>\n <error>You need to sign in or sign up before continuing.</error>\n</errors>\n)
assert_equal result, @response.last.body
end
test 'return appropriate body for json' do
- call_failure('formats' => :json)
+ call_failure('formats' => Mime::JSON)
result = %({"error":"You need to sign in or sign up before continuing."})
assert_equal result, @response.last.body
end
@@ -110,26 +110,26 @@ def call_failure(env_params={})
end
test 'return WWW-authenticate headers if model allows' do
- call_failure('formats' => :xml)
+ call_failure('formats' => Mime::XML)
assert_equal 'Basic realm="Application"', @response.second["WWW-Authenticate"]
end
test 'does not return WWW-authenticate headers if model does not allow' do
swap Devise, :http_authenticatable => false do
- call_failure('formats' => :xml)
+ call_failure('formats' => Mime::XML)
assert_nil @response.second["WWW-Authenticate"]
end
end
test 'works for any non navigational format' do
swap Devise, :navigational_formats => [] do
- call_failure('formats' => :html)
+ call_failure('formats' => Mime::HTML)
assert_equal 401, @response.first
end
end
test 'uses the failure message as response body' do
- call_failure('formats' => :xml, 'warden' => OpenStruct.new(:message => :invalid))
+ call_failure('formats' => Mime::XML, 'warden' => OpenStruct.new(:message => :invalid))
assert_match '<error>Invalid email or password.</error>', @response.third.body
end
@@ -137,7 +137,7 @@ def call_failure(env_params={})
context 'when http_authenticatable_on_xhr is false' do
test 'dont return 401 with navigational formats' do
swap Devise, :http_authenticatable_on_xhr => false do
- call_failure('formats' => :html, 'HTTP_X_REQUESTED_WITH' => 'XMLHttpRequest')
+ call_failure('formats' => Mime::HTML, 'HTTP_X_REQUESTED_WITH' => 'XMLHttpRequest')
assert_equal 302, @response.first
assert_equal 'http://test.host/users/sign_in', @response.second["Location"]
end
@@ -145,7 +145,7 @@ def call_failure(env_params={})
test 'dont return 401 with non navigational formats' do
swap Devise, :http_authenticatable_on_xhr => false do
- call_failure('formats' => :json, 'HTTP_X_REQUESTED_WITH' => 'XMLHttpRequest')
+ call_failure('formats' => Mime::JSON, 'HTTP_X_REQUESTED_WITH' => 'XMLHttpRequest')
assert_equal 302, @response.first
assert_equal 'http://test.host/users/sign_in.json', @response.second["Location"]
end
@@ -155,14 +155,14 @@ def call_failure(env_params={})
context 'when http_authenticatable_on_xhr is true' do
test 'return 401' do
swap Devise, :http_authenticatable_on_xhr => true do
- call_failure('formats' => :html, 'HTTP_X_REQUESTED_WITH' => 'XMLHttpRequest')
+ call_failure('formats' => Mime::HTML, 'HTTP_X_REQUESTED_WITH' => 'XMLHttpRequest')
assert_equal 401, @response.first
end
end
test 'skip WWW-Authenticate header' do
swap Devise, :http_authenticatable_on_xhr => true do
- call_failure('formats' => :html, 'HTTP_X_REQUESTED_WITH' => 'XMLHttpRequest')
+ call_failure('formats' => Mime::HTML, 'HTTP_X_REQUESTED_WITH' => 'XMLHttpRequest')
assert_nil @response.second['WWW-Authenticate']
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.