我有以下课程:
class CachedObject < ActiveRecord::Base
attr_accessible :key, :value
validates_presence_of :key
validates_uniqueness_of :key
serialize :value
end
我正在运行以下单元测试:
class CachedObjectTest < ActiveSupport::TestCase
setup do
@cached_object = CachedObject.new
end
test "key should set" do
@cached_object.key = 'test'
assert @cached_object.save
end
test "value should set" do
offer = new Offer
@cached_object.value = offer
assert @cached_object.save
end
end
我收到此错误:
NoMethodError: undefined method `new' for #<CachedObjectTest:0x007fb1f1c82f08>
这对我来说毫无意义。CachedObject 是 ActiveRecord 的子类,因此它应该定义新方法。我在这里做错了什么?