From 4a45eb9899f0ca5cfb0ab391cee3fe84ac24b3aa Mon Sep 17 00:00:00 2001 From: Ed Saunders Date: Mon, 7 Dec 2015 16:50:14 +0000 Subject: [PATCH] Allow resources with no email field to be recoverable The current implementation is opinionated about the resource should have an "email" column on it if it is to be recoverable, which isn't necessarily the case. For example, developers may decide to pull emails out into their own model or have some other way of communicating password resets to their users (e.g. text message) I'm not sure there's an easy test to put together for this case, as minitest doesn't make it very easy to stub the "email_changed?" to raise an error. Happy to look into building another model in the "test/rails_app" if you want to have this properly tested though? Or for a nice way to get calls to "email_changed?" to raise; minitest isn't a test framework I'm overly familiar with :). As a side note, it would be nice if the Validatable module also took this into account, I may raise another PR for that. This comes off the back of comments on this commit: https://github.com/plataformatec/devise/commit/e641b4b7b97159054b7d92fb14df557ac18ae6f4 --- lib/devise/models/recoverable.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/devise/models/recoverable.rb b/lib/devise/models/recoverable.rb index d6782977..9762eaef 100644 --- a/lib/devise/models/recoverable.rb +++ b/lib/devise/models/recoverable.rb @@ -28,7 +28,7 @@ module Devise included do before_save do - if email_changed? || encrypted_password_changed? + if (respond_to?(:email_changed?) && email_changed?) || encrypted_password_changed? clear_reset_password_token end end