mirror of
https://github.com/heartcombo/devise.git
synced 2026-01-09 23:08:05 -05:00
Merge pull request #3504 from scottjacobsen/devise_scope_override
Allow objects to specify their devise scope
This commit is contained in:
@@ -31,6 +31,7 @@ module Devise
|
||||
# Receives an object and find a scope for it. If a scope cannot be found,
|
||||
# raises an error. If a symbol is given, it's considered to be the scope.
|
||||
def self.find_scope!(obj)
|
||||
obj = obj.devise_scope if obj.respond_to?(:devise_scope)
|
||||
case obj
|
||||
when String, Symbol
|
||||
return obj.to_sym
|
||||
|
||||
@@ -71,6 +71,12 @@ class MappingTest < ActiveSupport::TestCase
|
||||
assert_equal :user, Devise::Mapping.find_scope!(Class.new(User).new)
|
||||
end
|
||||
|
||||
test 'find scope uses devise_scope' do
|
||||
user = User.new
|
||||
def user.devise_scope; :special_scope; end
|
||||
assert_equal :special_scope, Devise::Mapping.find_scope!(user)
|
||||
end
|
||||
|
||||
test 'find scope raises an error if cannot be found' do
|
||||
assert_raise RuntimeError do
|
||||
Devise::Mapping.find_scope!(String)
|
||||
|
||||
Reference in New Issue
Block a user