How to get rid of email regex message on Devise?

2019-06-24 05:09发布

问题:

I'm using Devise Token Auth gem and, everytime I run my test suite in Rails 4.2.5 app, I'm getting this deprecation warning from Devise:

DEPRECATION WARNING: [Devise] config.email_regexp will have a new default on Devise 4.1 To keep the current behavior please set in your config/initializers/devise.rb the following:

Devise.setup do |config|
   config.email_regexp = /\A[^@\s]+@([^@\s]+\.)+[^@\W]+\z/
end

If you want to use the new default:

Devise.setup do |config|
   config.email_regexp = /\A[^@\s]+@[^@\s]+\z/
end

. (called from block in tsort_each at /usr/local/lib/ruby/2.2.0/tsort.rb:226)

I've already added config/initializers/devise.rb file manually and have set email_regex as suggested by the message above, but the annoying message persists.

How can I disable this message?

回答1:

Related with this post, you can manage deprecation warnings according to th environment in which you are working, as said in rails guides:

active_support.deprecation_behavior Sets up deprecation reporting for environments, defaulting to :log for development, :notify for production and :stderr for test. If a value isn't set for config.active_support.deprecation then this initializer will prompt the user to configure this line in the current environment's config/environments file. Can be set to an array of values.

So just change in config/environments/test.rb the value :stderr for :log

Rails.application.configure do
   ...
   # Print deprecation notices to the stderr.
   config.active_support.deprecation = :log
   ...
end

And with this the depecation warning will be in the log/test.log instead in the console output