Another attempt to fix the misterious loading helpers bug.

This commit is contained in:
José Valim 2011-10-18 08:35:19 +02:00
parent 2a5ad4664b
commit fac02b58bc
5 changed files with 13 additions and 15 deletions

View File

@ -382,10 +382,13 @@ module Devise
# Include helpers in the given scope to AC and AV.
def self.include_helpers(scope)
Rails.application.routes.url_helpers.send :include, scope::UrlHelpers
ActiveSupport.on_load(:action_controller) do
include scope::Helpers if defined?(scope::Helpers)
include scope::UrlHelpers
end
ActiveSupport.on_load(:action_view) do
include scope::UrlHelpers
end
end

View File

@ -41,7 +41,6 @@ module Devise
scope = Devise::Mapping.find_scope!(resource_or_scope)
send("#{action}\#{scope}_#{module_name}_#{path_or_url}", *args)
end
protected :#{method}
URL_HELPERS
end
end

View File

@ -3,10 +3,9 @@ module Devise
module UrlHelpers
def self.define_helpers(mapping)
return unless mapping.omniauthable?
method = "#{mapping.name}_omniauth_authorize_path"
class_eval <<-URL_HELPERS, __FILE__, __LINE__ + 1
def #{method}(provider, params = {})
def #{mapping.name}_omniauth_authorize_path(provider, params = {})
if Devise.omniauth_configs[provider.to_sym]
script_name = request.env["SCRIPT_NAME"]
@ -17,12 +16,9 @@ module Devise
raise ArgumentError, "Could not find omniauth provider \#{provider.inspect}"
end
end
protected :#{method}
URL_HELPERS
end
protected
def omniauth_authorize_path(resource_or_scope, *args)
scope = Devise::Mapping.find_scope!(resource_or_scope)
send("#{scope}_omniauth_authorize_path", *args)

View File

@ -35,7 +35,7 @@ class HelpersTest < ActionController::TestCase
end
test 'resources methods are not controller actions' do
assert @controller.class.action_methods.empty?, "Expected empty, got #{@controller.class.action_methods.inspect}"
assert @controller.class.action_methods.empty?
end
test 'require no authentication tests current mapping' do

View File

@ -28,31 +28,31 @@ class OmniAuthRoutesTest < ActionController::TestCase
end
test 'should generate authorization path' do
assert_match "/users/auth/facebook", @controller.send(:omniauth_authorize_path, :user, :facebook)
assert_match "/users/auth/facebook", @controller.omniauth_authorize_path(:user, :facebook)
assert_raise ArgumentError do
@controller.send :omniauth_authorize_path, :user, :github
@controller.omniauth_authorize_path(:user, :github)
end
end
test 'should generate authorization path for named open_id omniauth' do
assert_match "/users/auth/google", @controller.send(:omniauth_authorize_path, :user, :google)
assert_match "/users/auth/google", @controller.omniauth_authorize_path(:user, :google)
end
test 'should generate authorization path with params' do
assert_match "/users/auth/open_id?openid_url=http%3A%2F%2Fyahoo.com",
@controller.send(:omniauth_authorize_path, :user, :open_id, :openid_url => "http://yahoo.com")
@controller.omniauth_authorize_path(:user, :open_id, :openid_url => "http://yahoo.com")
end
test 'should not add a "?" if no param was sent' do
assert_equal "/users/auth/open_id",
@controller.send(:omniauth_authorize_path, :user, :open_id)
@controller.omniauth_authorize_path(:user, :open_id)
end
test 'should set script name in the path if present' do
@request.env['SCRIPT_NAME'] = '/q'
assert_equal "/q/users/auth/facebook",
@controller.send(:omniauth_authorize_path, :user, :facebook)
@controller.omniauth_authorize_path(:user, :facebook)
end
end