我正在阅读有关reform
gem 的教程,但遇到了错误。
资料来源: http ://culttt.com/2016/02/10/using-form-objects-in-ruby-on-rails-with-reform/
错误:
NameError:未初始化的常量 ArticleFormTest::Article test/forms/article_form_test.rb:8:in `setup'
我的理解是,这来自@model = Article.new
以下结果:
require 'test_helper'
class ArticleFormTest < ActiveSupport::TestCase
def setup
@model = Article.new
@form = ArticleForm.new(@model)
end
test "should require title" do
@form.validate({})
assert_includes(@form.errors[:title], "can\'t be blank")
end
end
我已经设置article_form.rb
,(见下文)。所以我不确定为什么会这样。
require "reform/form/validation/unique_validator.rb"
class ArticleForm < Reform::Form
property :title, presence: true, unique: true
property :markdown, presence: true
property :published_at, presence: true
property :user, presence: true
end
谁能告诉我可能做错了什么?
更新
下面根据请求添加。
test_helper.rb
ENV['RAILS_ENV'] ||= 'test'
require File.expand_path('../../config/environment', __FILE__)
require 'rails/test_help'
class ActiveSupport::TestCase
# Setup all fixtures in test/fixtures/*.yml for all tests in alphabetical order.
fixtures :all
# Add more helper methods to be used by all tests here...
end