Ruby on rails 服务对象方法打破集成测试Rails 4.2
我有一个Rails 4.2的集成测试,它在没有服务对象方法的情况下工作,但是当我试图将一些逻辑考虑到服务对象中时出现了一个错误。错误为“NameError:未初始化的常量LeadsController::SendEmailConfirmation” 这适用于测试:Ruby on rails 服务对象方法打破集成测试Rails 4.2,ruby-on-rails,integration-testing,minitest,Ruby On Rails,Integration Testing,Minitest,我有一个Rails 4.2的集成测试,它在没有服务对象方法的情况下工作,但是当我试图将一些逻辑考虑到服务对象中时出现了一个错误。错误为“NameError:未初始化的常量LeadsController::SendEmailConfirmation” 这适用于测试: def create @lead = Lead.new(lead_params) if @lead.save LeadMailer.email_confirmation(@lead).deliver_now f
def create
@lead = Lead.new(lead_params)
if @lead.save
LeadMailer.email_confirmation(@lead).deliver_now
flash[:success] = "Thank you for subscribing"
redirect_to root_path
else
render 'new'
end
end
def create
@lead = Lead.new(lead_params)
if @lead.save
SendEmailConfirmation.call(@lead) # This is the problem method
flash[:success] = "Thank you for subscribing!"
redirect_to root_path
else
render 'new'
end
end
这不适用于测试:
def create
@lead = Lead.new(lead_params)
if @lead.save
LeadMailer.email_confirmation(@lead).deliver_now
flash[:success] = "Thank you for subscribing"
redirect_to root_path
else
render 'new'
end
end
def create
@lead = Lead.new(lead_params)
if @lead.save
SendEmailConfirmation.call(@lead) # This is the problem method
flash[:success] = "Thank you for subscribing!"
redirect_to root_path
else
render 'new'
end
end
发送电子邮件\u confirmation.rb:
class SendEmailConfirmation
def self.call(lead)
LeadMailer.email_confirmation(lead).deliver_now
lead.confirmation_sent_at = Time.zone.now
lead.save
end
end
似乎服务对象本身可以工作,但测试无法识别该方法
关于我缺少的内容有什么想法吗?当您为服务对象指定绝对名称空间时,它应该可以工作
::SendEmailConfirmation.call(@lead) # Note the "::"