当我尝试测试名为“设置”的模型时出错,我觉得它与单数和复数模型名称有关,但我该如何解决?
这是spec settings_spec.rb:
require 'spec_helper'
describe Settings do
let!(:settings) { Factory(:settings) }
describe "has a valid factory" do
specify { should be_an_instance_of(Settings) }
end
end
1) Settings has a valid factory
Failure/Error: let!(:settings) { Factory(:settings) }
NameError:
uninitialized constant Setting
# ./spec/models/settings_spec.rb:4:in `block (2 levels) in <top (required)>'
我的模型名为Settings,文件名为settings.rb。谢谢!
答案 0 :(得分:1)
它希望模型名称为Setting
。将模型app/model/setting.rb
重命名为Setting
或转到文件config/initializers/inflections.rb
,然后将设置添加到不可数配置中。
ActiveSupport::Inflector.inflections do |inflect|
inflect.uncountable %w(settings)
end