2
我有幾個自定義驗證器用於驗證回形針附件是一個圖像,不超過5MB。一切正常如預期文件上傳Rspec集成否定測試失敗
雖然我對一件事有點好奇。我的集成測試在上傳失敗後檢查天氣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)
這給它的回形針自己的匹配,看起來像它應該工作,但它也將失敗
幾個看跌語句後,在做任何事情之前,它似乎@user.avatar
產生/avatars/original/missing.png
,所以我想我至少可以確定它沒有改變。