Testing (RSpec) with Devise's confirmable module

后端 未结 7 1109
不思量自难忘°
不思量自难忘° 2020-12-24 13:06

It\'s my understanding that Rails\' testing environment is torn down and rebuilt before each test...so how do I test a controller that requires that a user be logged in and

7条回答
  •  星月不相逢
    2020-12-24 13:58

    For Devise 4.2 it's now confirm (not confirm!).

    Source

    4.2.0 - 2016-07-01

    Remove the Devise::Models::Confirmable#confirm! method, use confirm instead.

    Code below also prevents mailers from being generated thanks to after(:build) vs after(:create) for setting confirmed_at

    FactoryGirl.define do
      factory :user do
        after(:build)   { |u| u.skip_confirmation_notification! }
        after(:create)  { |u| u.confirm }
        ...
      end
    end
    

提交回复
热议问题