diff --git a/lib/devise.rb b/lib/devise.rb index fec35b59..34dc0ef6 100644 --- a/lib/devise.rb +++ b/lib/devise.rb @@ -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 diff --git a/lib/devise/controllers/url_helpers.rb b/lib/devise/controllers/url_helpers.rb index 20bca1bc..3438769d 100644 --- a/lib/devise/controllers/url_helpers.rb +++ b/lib/devise/controllers/url_helpers.rb @@ -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 diff --git a/lib/devise/omniauth/url_helpers.rb b/lib/devise/omniauth/url_helpers.rb index 4bbf763b..58cc1392 100644 --- a/lib/devise/omniauth/url_helpers.rb +++ b/lib/devise/omniauth/url_helpers.rb @@ -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) diff --git a/test/controllers/internal_helpers_test.rb b/test/controllers/internal_helpers_test.rb index 3771278c..30f45609 100644 --- a/test/controllers/internal_helpers_test.rb +++ b/test/controllers/internal_helpers_test.rb @@ -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 diff --git a/test/omniauth/url_helpers_test.rb b/test/omniauth/url_helpers_test.rb index f981e8ca..a9c6a966 100644 --- a/test/omniauth/url_helpers_test.rb +++ b/test/omniauth/url_helpers_test.rb @@ -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