我有“控制器/users_controller.rb”
def create
user = User.new(person_params)
if user.save
EmailSendJob.perform_later(user.email, 'random_password')
end
end
我有'mailers/user_mailer.rb'
def user_new(user_to, password)
@password = password
mail to: user_to, subject: "Password for you"
end
我有“工作/email_send_job.rb”
def perform(email, password)
UserMailer.user_new(email, password).deliver_now
end
我该如何进行测试?谢谢
我看到了“电子邮件规范”,但我的代码无法理解
我有'spec/controllers/users_controller_spec.rb'
require "spec_helper"
require "rails_helper"
require "email_spec"
describe UsersController do
User.delete_all
before(:all) do
@email_for_test = "222@222@mail.ru"
@user = User.new
@user.email = "2@2.ru"
@user.name = "test"
@user.save
end
it "create" do
post :create, params: {user: {email: @email_for_test,
name:"test",
description: "test"}}
user = User.last
expect(user.email).to eq(@email_for_test)
last_delivery = ActionMailer::Base.deliveries.last
last_delivery.body.raw_source.should include "This is the text of the email"
end
end
ActionMailer::Base.deliveries.last 不起作用
也许你有例子。我会很感激