私は次のクラスを持っています:
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 のサブクラスであるため、新しいメソッドを定義する必要があります。ここで何が間違っていますか?