skip confirmation e-mail in development with devise
I am using devise and I want t开发者_StackOverflow中文版o 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.
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.
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.
As simple as that
user=User.new
user.email="you@email.id"
user.password="yourPassword"
user.skip_confirmation!
user.save
Or you could try MailCatcher in your development environment.
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.
In Rails 3 you can use an "interceptor" to reroute your development emails as described in Railscast 206.
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.
Take your model for devise. Commonly Its user.rb. And remove or comment the config comfirmable. This will prevent the process of confirmation
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
精彩评论