20

I am using devise and I want to be able to skip the confirmation e-mail while I am in development mode. Since my application can't send e-mail while running on my local machine, I will just get the alert message saying that you need to be confirmed before accessing the application.

9 Answers 9

29

Devise has also a method skip_confirmation! that you can call on the model before saving it to avoid sending the mail. It simply sets the confirmed_at attribute which results in skipping the mail sending.

0
26

try Letter Opener gem from Ryan Bates

https://github.com/ryanb/letter_opener

it will open the email in the browser without sending it. You don't want to be skipping stuff out if you're in development because stuff will get missed/forgotten about.

1
  • Not sure about the asker here, but I personally am populating a large app with lots of data. I just had 600+ tabs opened in my browser because I do use letter opener. I agree that in most cases you wouldn't want to skip, in this case I def. need to skip.
    – Sean
    Aug 2, 2016 at 21:12
13

As simple as that

user=User.new
user.email="[email protected]"
user.password="yourPassword"
user.skip_confirmation!
user.save
1
  • 3
    Just as a little FYI, you can put all of that in a block: user = User.new { |u| u.email = '[email protected]'; u.password = 'yourPassword'; u.skip_confirmation! }.save. Blocks are fun!
    – wulftone
    Jul 11, 2013 at 22:29
6

Or you could try MailCatcher in your development environment.

3

If you want a really light weight way to do this, look in your terminal after registering - the rails output shows the email that got sent, you can copy-paste the confirmation link, confirming the account and then continue testing.

crude, but effective.

2

In Rails 3 you can use an "interceptor" to reroute your development emails as described in Railscast 206.

1

Devise uses ActionMailer to send emails. In test mode, ActionMailer shouldn't actually send any emails.

Check out this tutorial for an explanation on ActionMailer and testing environments.

So, depending on the environment, you can basically turn delivery off, while not affecting your actual tests. You just have to specify that option in the environments/test.rb file.

7
  • I see that in the test file it has the following code: # Tell Action Mailer not to deliver emails to the real world. # The :test delivery method accumulates sent emails in the # ActionMailer::Base.deliveries array. config.action_mailer.delivery_method = :test Should I just copy that code snippet to the config/environments/development.rb file
    – tomciopp
    Sep 19, 2011 at 18:35
  • Hmm even if I do turn the delivery off though wouldn't I still need a way to satisfy the confirmable module, as I would still get the same error that I need to be confirmed.
    – tomciopp
    Sep 19, 2011 at 18:40
  • If you mean, a way to satisfy it as far as the tests are concerned, I would just fake the confirmation with a mock object, or by just feeding it the confirmation code from the DB, since the delivery of an actual email isn't what's important in the test. What's important is that the confirmation mechanism works, right? That is, when the proper confirmation code is presented via the confirmation URL, you want to know that some kind of confirmed flag is flipped in the DB?
    – jefflunt
    Sep 19, 2011 at 18:56
  • Oh sorry if I wasn't clear I want to skip the confirmation step entirely when working in development, yet still be able to send confirmation e-mails while in production. Right now if I want to sign up a user I can't because of the confirmable module, and I don't know how to skip over that step in development only.
    – tomciopp
    Sep 19, 2011 at 19:07
  • 1
    I just edited the user in the console in order to bypass the requirement from devise which gave me the result I was looking for.
    – tomciopp
    Sep 19, 2011 at 19:56
1

Take your model for devise. Commonly Its user.rb. And remove or comment the config comfirmable. This will prevent the process of confirmation

0

simmilar to letter_opener gem (recommended by John Beynon above) there is a gem called mailcatcher which works on SMTP level.

basically you configure SMTP on your Rails app to point to port under which mailcatcher run on local machine and you have mailcatcher browser on other port to read the emails

more info https://github.com/sj26/mailcatcher

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.