Paperclip Rspec测试:为什么缺少attr_accessor?

cit*_*raL 1 testing rspec paperclip ruby-on-rails-3

我有一组传递的Rspec用户模型测试,直到我有了paperclip属性"profile picture".

回形针一切都很好,效果很好,但我希望我的测试也能更新通过.我刚刚将此行添加到user_spec文件的@attr:

:avatar => File.new (Rails.root + "public/images/Default_profile_picture.jpg")
Run Code Online (Sandbox Code Playgroud)

在before_each循环中,为用户模型创建一组标准的工作属性.

当我运行测试时,所有测试都会给出错误消息:

User model missing required attr_accessor for 'avatar_file_name' ... 
Run Code Online (Sandbox Code Playgroud)

将paperclip的字段作为attr_accessor放在模型中会使问题在测试中消失,但我认为我不应该在我的模型中执行此操作(如果我这样做,则无法正常工作).

有没有人知道为什么我在测试时收到这些错误消息?...(我在spec/helper中包含了配置行Shoulda :: Matchers和需要的回形针)

感谢您发布的任何答案!

cit*_*raL 8

只是我忘了跑

rake db:test:prepare
Run Code Online (Sandbox Code Playgroud)

在运行我的测试之前: - /