Deprecation warning on module doesn't have a required_fields method
This commit is contained in:
parent
ba80074b7b
commit
ecfc7d752a
|
@ -161,4 +161,4 @@ MESSAGE
|
||||||
super
|
super
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -55,8 +55,12 @@ module Devise
|
||||||
klass.devise_modules.each do |mod|
|
klass.devise_modules.each do |mod|
|
||||||
instance = klass.new
|
instance = klass.new
|
||||||
|
|
||||||
const_get(mod.to_s.classify).required_fields(klass).each do |field|
|
if const_get(mod.to_s.classify).respond_to?(:required_fields)
|
||||||
failed_attributes << field unless instance.respond_to?(field)
|
const_get(mod.to_s.classify).required_fields(klass).each do |field|
|
||||||
|
failed_attributes << field unless instance.respond_to?(field)
|
||||||
|
end
|
||||||
|
else
|
||||||
|
ActiveSupport::Deprecation.warn "The module #{mod} doesn't implement self.required_fields(klass). Devise uses required_fields to warn developers of any missing fields in their models. Please implement #{mod}.required_fields(klass) that returns an array of symbols with the required fields."
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -114,4 +118,4 @@ module Devise
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
require 'devise/models/authenticatable'
|
require 'devise/models/authenticatable'
|
||||||
|
|
|
@ -108,6 +108,27 @@ class ActiveRecordTest < ActiveSupport::TestCase
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def swap_module_method_existence(klass, method)
|
||||||
|
klass.module_eval %Q[
|
||||||
|
class << self
|
||||||
|
alias #{method}_referenced #{method}
|
||||||
|
undef #{method}
|
||||||
|
end
|
||||||
|
]
|
||||||
|
|
||||||
|
begin
|
||||||
|
yield if block_given?
|
||||||
|
ensure
|
||||||
|
|
||||||
|
klass.module_eval %Q[
|
||||||
|
class << self
|
||||||
|
alias #{method} #{method}_referenced
|
||||||
|
undef #{method}_referenced
|
||||||
|
end
|
||||||
|
]
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
class CheckFieldsTest < ActiveSupport::TestCase
|
class CheckFieldsTest < ActiveSupport::TestCase
|
||||||
test 'checks if the class respond_to the required fields' do
|
test 'checks if the class respond_to the required fields' do
|
||||||
Player = Class.new do
|
Player = Class.new do
|
||||||
|
@ -157,4 +178,21 @@ class CheckFieldsTest < ActiveSupport::TestCase
|
||||||
Devise::Models.check_fields!(Magician)
|
Devise::Models.check_fields!(Magician)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
test "doesn't raises a NoMethodError exception when the module doesn't have a required_field(klass) class method" do
|
||||||
|
Driver = Class.new do
|
||||||
|
extend Devise::Models
|
||||||
|
|
||||||
|
def self.before_validation(instance)
|
||||||
|
end
|
||||||
|
|
||||||
|
devise :database_authenticatable
|
||||||
|
end
|
||||||
|
|
||||||
|
swap_module_method_existence Devise::Models::DatabaseAuthenticatable, :required_fields do
|
||||||
|
assert_deprecated "DEPRECATION WARNING: The module database_authenticatable doesn't implement self.required_fields(klass). Devise uses required_fields to warn developers of any missing fields in their models. Please implement database_authenticatable.required_fields(klass) that returns an array of symbols with the required fields." do
|
||||||
|
Devise::Models.check_fields!(Driver)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue