I have an ActionMailer
class
class UserMailer < ActionMailer::Base
default from: "[email protected]"
def submission_reminder user
@user = user
mail :to => user.email, :subject => "Your timesheet needs to be submitted!"
end
end
If I call UserMailer.submission_reminder(current_user)
in development it returns me a Mail::Message
object like expected.
The place in my application where this method is called is in a module I have in the lib folder:
module TimesheetSubmissionNotifier
def self.send_submission_reminders
User.all.each { |user| UserMailer.submission_reminder(user).deliver }
end
end
When I call TimesheetSubmissionNotifier.send_submission_reminders
in development, UserMailer.submission_remind(user) returns the mail message and deliver is called, everything works as it should.
The problem is when I call TimesheetSubmissionNotifier.send_submission_reminders
through an rspec test, UserMailer.submission_reminder(user)
returns nil.
If I call UserMailer.submission_reminder(user)
directly from an rspec test, it returns the mailer message like expected.
Here are the only lines related to ActionMailer in my config/environment/test.rb:
config.action_mailer.delivery_method = :test
config.action_mailer.default_url_options = { :host => 'localhost:3000' }
Any ideas why the method is returning nil?
UserMailer.submission_reminder(user)
directly from an rspec test works, how are you initializing the user object you pass to the method? You get it from Users table or you build it with a Factory, etc.? – Zheileman