1
votes

I'm using the Seed-Fu gem to populate my database. So, I have this in one of my seed files:

User.seed_once(:email) do |user|
  user.id = 1
  user.email = "[email protected]"
  user.first_name = "First"
  user.last_name = "Last"
  user.confirmation_sent_at = Time.zone.now - 1.hour
  user.confirmed_at = Time.zone.now
  user.roles = [root,staff]
  user.permissions = Permission.all
end

From what I've read, that should prevent Devise from sending a confirmation email. However, it is not, so (since I'm using the Letter Opener gem) my browser is being flooded with confirmation emails. Anyone know why this is happening and how I can convince Devise to not send these emails whilst I'm seeding?

SOLUTION:

Based on anothermh's answer below, I added Devise::Mailer.perform_deliveries = false to the top of this fixture file. Then, I found my final fixture file and added Devise::Mailer.perform_deliveries = true to the end of that to make sure emails would be sent when actually using the app. Thank you so much, folks!

2

2 Answers

1
votes

You just need to call the confirm method on user object. See the below code

user.confirm

So in your case the code will be like

User.seed_once(:email) do |user|
  user.id = 1
  user.email = "[email protected]"
  user.first_name = "First"
  user.last_name = "Last"
  user.confirm 
  user.roles = [root,staff]
  user.permissions = Permission.all
end
0
votes

You can turn off email sends from Devise in tests. Specifically, you'll need to have this set somewhere:

Devise::Mailer.delivery_method = :test
Devise::Mailer.perform_deliveries = false

For example, if you're doing this with rspec then you would likely put it into spec/rails_helper.rb.