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 that user can't be created without Device's confirmable module getting in the way?
Devise's recommended method (below) creates a new user which is then sent an email by Devise's confirmable
module. How do I get around this so I'm not 'creating' a user each time...or if I am I can get an object to test w/out "simulating" a new email for each spec?
before(:each) do
@user = Factory.create(:user)
sign_in @user
end
I'm sure I'm overlooking something painfully obvious as this must be a very common spec for anyone using Devise with confirmable...
In your test environment ActionMailer::Base.delivery_method
should be set to :test
, which means that these emails will not be sent out. If this setting is set to something else such as smtp
by way of a configuration in say config/environments.rb
, then emails will be sent out.
If that setting's already there, then to use the User
object (as in, to be actually able to log in) you'll need to call confirm!
on it:
user = User.first
user.confirm!
for latest FactoryGirl version:
FactoryGirl.define do
factory :confirmed_user, :parent => :user do
after(:create) { |user| user.confirm }
end
end
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With