如何编写测试 mail_form gem?Вut 测试给出错误。如何关联 OrderForm 和 MailForm?我有:型号:
class OrderForm < MailForm::Base
attributes :name
attributes :email
attributes :phone_number
attributes :order_name
attributes :address
attributes :file_1, attachment: true
def mail_attachments
[:file_1]
end
控制器,其中:
class OrdersController < ApplicationController
def create
@order_form = OrderForm.new(params[:order_form])
@order_form.deliver
redirect_to root_path, notice: 'Заявка отправлена'
end
end
结束视图(发信形式):orders/new.html.haml_spec.rb
=form_for @order_form, url: orders_path, method: :post do |f|
=f.text_field :name, placeholder: 'ФИО', class: 'gui-input'
=f.text_field :email, placeholder: 'Email', class: 'gui-input'
=f.text_field :phone_number, placeholder: 'Номер телефона',
最后我写测试:
require 'rails_helper'
RSpec.describe "orders/new", type: :view do
it do
assign(:order, build(:order))
render
expect(rendered).to have_field :name
end
end