【发布时间】:2012-05-23 15:13:49
【问题描述】:
我有几个自定义验证器,用于验证回形针附件是否为图像且不超过 5MB。一切都按预期进行
不过,我对一件事有点好奇。我的集成测试在上传失败后检查天气 user.avatar 为零,并且它返回某种随机的东西。
测试:
it 'Does not allow a non-image file to be uploaded as an avatar' do
visit edit_user_path(@user)
attach_file('user_avatar', File.dirname(__FILE__)+'/users_spec.rb')
click_button 'Update'
page.should have_content "Avatar must be an image"
@user.reload
@user.avatar.should be_nil
end
结果:
1) Users Avatars Does not allow a non-image file to be uploaded as an avatar
Failure/Error: @user.avatar.should be_nil
expected: nil
got: /avatars/original/missing.png
# ./spec/requests/users_spec.rb:147:in `block (3 levels) in <top (required)>'
我猜这是某种默认占位符回形针粘在那里,但是当我转到用户 show 页面时,@user.avatar 是 nil 符合预期。什么给了?
我也试过了,结果一样
@user.should_not have_attached_file(:avatar)
鉴于它是回形针自己的匹配器,它似乎应该可以工作,但它也失败了
在几个 puts 语句之后,@user.avatar 出现 /avatars/original/missing.png 在对其进行任何处理之前,所以我想我至少可以确定它没有改变。
【问题讨论】:
标签: ruby-on-rails rspec paperclip integration-testing