Compare commits

...

3 Commits

Author SHA1 Message Date
José Valim
c698e44d10 Release v1.4.8. 2011-10-10 14:44:07 +02:00
José Valim
3e1b142392 Update docs and CHANGELOG. 2011-10-10 14:43:52 +02:00
José Valim
49807cf0b7 Try to fix the misterious case where some url helpers are not defined. 2011-10-09 17:14:37 +02:00
8 changed files with 40 additions and 18 deletions

View File

@@ -1,3 +1,11 @@
== 1.4.8
* enhancements
* Add docs for assets pipeline and Heroku
* bug fix
* confirmation_url was not being set under some circumstances
== 1.4.7
* bug fix

View File

@@ -382,13 +382,10 @@ 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

@@ -24,25 +24,31 @@ module Devise
end
end
def self.generate_helpers!
mappings = Devise.mappings.values.map(&:used_helpers).flatten.uniq
routes = Devise::URL_HELPERS.slice(*mappings)
def self.generate_helpers!(routes=nil)
routes ||= begin
mappings = Devise.mappings.values.map(&:used_helpers).flatten.uniq
Devise::URL_HELPERS.slice(*mappings)
end
routes.each do |module_name, actions|
[:path, :url].each do |path_or_url|
actions.each do |action|
action = action ? "#{action}_" : ""
method = "#{action}#{module_name}_#{path_or_url}"
class_eval <<-URL_HELPERS, __FILE__, __LINE__ + 1
def #{action}#{module_name}_#{path_or_url}(resource_or_scope, *args)
def #{method}(resource_or_scope, *args)
scope = Devise::Mapping.find_scope!(resource_or_scope)
send("#{action}\#{scope}_#{module_name}_#{path_or_url}", *args)
end
protected :#{method}
URL_HELPERS
end
end
end
end
generate_helpers!(Devise::URL_HELPERS)
end
end
end

View File

@@ -3,9 +3,10 @@ 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 #{mapping.name}_omniauth_authorize_path(provider, params = {})
def #{method}(provider, params = {})
if Devise.omniauth_configs[provider.to_sym]
script_name = request.env["SCRIPT_NAME"]
@@ -16,9 +17,12 @@ 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

@@ -1,3 +1,3 @@
module Devise
VERSION = "1.4.7".freeze
VERSION = "1.4.8".freeze
end

View File

@@ -22,4 +22,11 @@ Some setup you must do manually if you haven't yet:
<p class="notice"><%= notice %></p>
<p class="alert"><%= alert %></p>
4. If you are deploying Rails 3.1 on Heroku, you may want to set:
config.assets.initialize_on_precompile = false
On config/application.rb forcing your application to not access the DB
or load models when precompiling your assets.
===============================================================================

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?
assert @controller.class.action_methods.empty?, "Expected empty, got #{@controller.class.action_methods.inspect}"
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.omniauth_authorize_path(:user, :facebook)
assert_match "/users/auth/facebook", @controller.send(:omniauth_authorize_path, :user, :facebook)
assert_raise ArgumentError do
@controller.omniauth_authorize_path(:user, :github)
@controller.send :omniauth_authorize_path, :user, :github
end
end
test 'should generate authorization path for named open_id omniauth' do
assert_match "/users/auth/google", @controller.omniauth_authorize_path(:user, :google)
assert_match "/users/auth/google", @controller.send(: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.omniauth_authorize_path(:user, :open_id, :openid_url => "http://yahoo.com")
@controller.send(: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.omniauth_authorize_path(:user, :open_id)
@controller.send(: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.omniauth_authorize_path(:user, :facebook)
@controller.send(:omniauth_authorize_path, :user, :facebook)
end
end