Bri*_*ong 3 ruby-on-rails actionmailer
我们正在使用这样的ActionMailer拦截器:
class MailerInterceptor
def self.delivering_email(message)
p 1
if message.to.include?("test2@example.com")
p 2
message.perform_deliveries = false
end
end
end
Mailer.register_interceptor(MailerInterceptor)
Run Code Online (Sandbox Code Playgroud)
但它似乎没有阻止在生产或我们的测试中向该地址发送消息:
require 'spec_helper'
describe "MailerInterceptor" do
it "should block sending to certain addresses" do
expect{ Mailer.user_alert("test1", "test@example.com").deliver }.to change{ ActionMailer::Base.deliveries.count }.by(1)
expect{ Mailer.user_alert("test2", "test2@example.com").deliver }.to_not change{ ActionMailer::Base.deliveries.count }
end
end
Run Code Online (Sandbox Code Playgroud)
这是使用rails 3.2.14.
它在测试的第二行打印"2",但仍然发送电子邮件.有任何想法吗?谢谢!
| 归档时间: |
|
| 查看次数: |
2502 次 |
| 最近记录: |