1
0
Fork 0
mirror of https://github.com/heartcombo/devise.git synced 2022-11-09 12:18:31 -05:00

Merge branch 'deprecating-ausence-of-required-fields'

This commit is contained in:
Rodrigo Flores 2012-03-03 15:16:07 -03:00
commit 617a8876a6
5 changed files with 50 additions and 7 deletions

View file

@ -161,4 +161,4 @@ MESSAGE
super
end
end
end
end

View file

@ -1,4 +1,3 @@
<% ActiveSupport::Deprecation.warn "Rendering partials devise/_links.erb is deprecated" \
"please use devise/shared/_links.erb instead." %>
<%= render "shared/links" %>
<% end %>
"please use devise/shared/_links.erb instead."%>
<%= render "shared/links" %>

View file

@ -55,8 +55,12 @@ module Devise
klass.devise_modules.each do |mod|
instance = klass.new
const_get(mod.to_s.classify).required_fields(klass).each do |field|
failed_attributes << field unless instance.respond_to?(field)
if const_get(mod.to_s.classify).respond_to?(:required_fields)
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
@ -114,4 +118,4 @@ module Devise
end
end
require 'devise/models/authenticatable'
require 'devise/models/authenticatable'

View file

@ -157,4 +157,23 @@ class CheckFieldsTest < ActiveSupport::TestCase
Devise::Models.check_fields!(Magician)
end
end
test "doesn't raise 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
attr_accessor :encrypted_password, :email
devise :database_authenticatable
end
swap_module_method_existence Devise::Models::DatabaseAuthenticatable, :required_fields do
assert_deprecated do
Devise::Models.check_fields!(driver)
end
end
end
end

View file

@ -67,4 +67,25 @@ class ActiveSupport::TestCase
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
end