Rails测试问题

Rails测试问题

在Rails2.1下,我的数据库php?name=CRUD" onclick="tagshow(event)" class="t_tag">CRUD操作单元php?name=%B2%E2%CA%D4" onclick="tagshow(event)" class="t_tag">测试一直失败,请高手解答,谢谢。
  测试代码:
 def test_photo_crud
  cat = Photo.new
  cat.filename = 'cat.jpg'
  cat.created_at = DateTime.now
  cat.thumbnail = 't_cat.jpg'
  cat.description = 'This is my cat!'
 
  assert_kind_of Photo, cat
  assert cat.save #此处出错

  assert_not_nil cat2 = Photo.find(cat.id)
  assert_equal cat, cat2
 
  cat2.description = 'A gost of my cat.'
  assert cat2.save
  assert cat2.destroy
 end
  数据库配置:
  test:
   adapter: mysql
   database: photos_test
   username: root
   password: root
   host: localhost
测试结果:
Loaded suite photo_test
Started
..F.
Finished in 0.187 seconds.

 1) Failure:
test_photo_crud(PhotoTest)
  [photo_test.rb:33:in `test_photo_crud'
  c:/ruby/lib/ruby/gems/1.8/gems/activesupport-2.1.0/lib/active_support/testing/setup_and_teardown.rb:33:in `__send__'
  c:/ruby/lib/ruby/gems/1.8/gems/activesupport-2.1.0/lib/active_support/testing/setup_and_teardown.rb:33:in `run']:
<false> is not true.

4 tests, 8 assertions, 1 failures, 0 errors
>Exit code: 1  Time: 11.965
请问可能是什么原因?

已解决,原因是我在Photo.rb中加入了一句validates_presence_of :filename
如果没有包含文件名称就不会把Photo的实例加入到数据库中去。