我在seeds.rb文件中写了一些带有一些方法的ruby类
负责在数据库中的不同表中上传内容
现在我已经为该类中的方法编写了一些测试..
但在运行我的测试后,我得到的错误就像是
------------------- -------------------错误
未捕获的异常:未初始化的常量“ModelName”
---------------test file -----------------
require_relative "../../db/seeds"
require "minitest_helper"
it "should create a object" do
object = class_name.new('file_name.csv')
object1 = object.find_and_create_object('Region', :name => 'region_name')
object1.id.wont_be_nil
end
--------------------seeds.rb file ---------------
module Gen
def find_or_create_object(model_name, attributes)
target_model = model_name.classify.constantize
target_model.where(attributes).first_or_create
end
end
class class_name
include Gen
def create_object
find_or_create_object('modelname',{value_hash})
end
end
but if i am running db:seed then everything is working ...(no error) ---