简体   繁体   中英

How to add Devise Confirmable to an existing Rails app

I'm working on an existing Rails app (30+ models, 30+ controllers) and trying to implement Devise's confirmable (right now users are not prompted to create a password during sign up).

My issue is that two (seemingly) small actions cause 300 specs to start failing... and I'm hoping for any advice from more experienced hands to help save me from going too far down any rabbit holes.

The two actions:

(1) within user.rb I add :confirmable to the devise configuration:

devise :database_authenticatable, :recoverable, :rememberable, :confirmable, ...

(2) within devise.rb I uncomment out the allow_unconfirmed_access config:

config.allow_unconfirmed_access_for = 2.days

These two actions cause almost 1/4 of all my specs to start failing. Before I start diving into every spec and making changes, could someone please just let me know what I'm missing or point me in the right direction?

UPDATE I've narrowed the cause down to what I believe is an Admin permissions issue. Specs that are targeting normal users are passing, however any tests that require admin login are now failing (eg specs where the expected response is 200 instead are returning 302 or 401...)

In my factory for normal users I am including confirmed_at to eq Time.now . This is how I am building admins:

  factory :admin_user, :parent => :user do
    email ADMIN_USER_EMAIL
  end

Where ADMIN_USER_EMAIL is an ENV variable referencing an actual admin email address. Since it's inheriting from :parent => :user I'm not sure what else to try to confirm the admins??

Alright, it was a lame question anyway, but I got to the bottom of what caused 319 specs to break.

One of the features of Devise's :confirmable is that not only do accounts need to be confirmed, but any changes to the account need to be confirmed as well.

Specs where a user factory stub was being updated/assigned (whether the update was user.email= or gift_payment.user.xyz= etc) resulted in an undefined method for nil class .

So I went into my factories.rb and spec_utilities.rb and all the individual specs to make sure user.confirm! was being called.

Changing the factories and utility methods got the 319 errors down to about 30, and from there I had to go into each spec and sprinkled confirm! in various places.

Still not sure if my approach is off-base but I'm down to 0 failing specs... (for now).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM