gpt4 book ai didi

Redmine 插件中的 ActionMailer 错误

转载 作者:行者123 更新时间:2023-12-02 05:05:50 26 4
gpt4 key购买 nike

我在 app/models 中有以下邮件代码。

class Mailman < ActionMailer::Base

default :from => "xyz"
# Sends an Email reminder to all the users who missed a pickup date
def check_out_reminder(reservation)
recipient = reservation.user.mail
subject = "Checkout Reminder for '#{reservation.bookable.name}'."
mail(:to => recipient, :subject => subject)
end

def check_in_reminder(reservation)
recipient = reservation.user.mail
subject = "Checkin Reminder for '#{reservation.bookable.name}'."
mail(:to => recipient, :subject => subject)
end

end

我在 test/unit 中有测试代码:

require File.expand_path('../../test_helper', __FILE__)

class MailmanTest < ActionMailer::TestCase
fixtures :reservations

def test_check_out_reminder
reservation = Reservation.first
# Send the email, then test that it got queued
Mailman.check_out_reminder(reservation).deliver
assert !ActionMailer::Base.deliveries.empty?
end

end

执行测试却报错:

test_check_out_reminder(MailmanTest):
NoMethodError: undefined method `mail' for nil:NilClass
/Users/myth/Learn/Code/redmine/plugins/redmine_asset_tracker/app/models/mailman.rb:9:in `check_out_reminder'
/Users/myth/.rvm/gems/ruby-1.9.3-p0/gems/actionpack-3.2.3/lib/abstract_controller/base.rb:167:in `process_action'
/Users/myth/.rvm/gems/ruby-1.9.3-p0/gems/actionpack-3.2.3/lib/abstract_controller/base.rb:121:in `process'
/Users/myth/.rvm/gems/ruby-1.9.3-p0/gems/actionpack-3.2.3/lib/abstract_controller/rendering.rb:45:in `process'
/Users/myth/.rvm/gems/ruby-1.9.3-p0/gems/actionmailer-3.2.3/lib/action_mailer/base.rb:456:in `process'
/Users/myth/.rvm/gems/ruby-1.9.3-p0/gems/actionmailer-3.2.3/lib/action_mailer/base.rb:451:in `initialize'
/Users/myth/.rvm/gems/ruby-1.9.3-p0/gems/actionmailer-3.2.3/lib/action_mailer/base.rb:438:in `new'
/Users/myth/.rvm/gems/ruby-1.9.3-p0/gems/actionmailer-3.2.3/lib/action_mailer/base.rb:438:in `method_missing'
/Users/myth/Learn/Code/redmine/plugins/redmine_asset_tracker/test/unit/mailer_test.rb:9:in `test_check_out_reminder'
/Users/myth/.rvm/gems/ruby-1.9.3-p0/gems/mocha-0.11.4/lib/mocha/integration/mini_test/version_230_to_262.rb:28:in `run'

为什么即使我继承了正确的类,也无法识别邮件方法?

最佳答案

问题是缺少夹具。recipient = reservation.user.mail 行导致错误,而不是 Action Mailer 的 mail(:to => recipient, :subject => subject)

关于Redmine 插件中的 ActionMailer 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11869436/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com