Carrierwave #avatar?当它应该返回true时返回false

时间:2015-03-11 12:41:11

标签: ruby-on-rails carrierwave

项目在这里:https://github.com/pmatsinopoulos/test_carrierwave

我的项目是一个Ruby On Rails项目,它使用ActiveRecord和gem carrierwaveUser模型上存储头像。

我有一个测试用例,当#avatar?返回false时,true会返回require 'test_helper' class UserTest < ActiveSupport::TestCase test "avatar" do @user = User.new @user.name = "George" @user.save! assert_equal false, @user.avatar? # set avatar @user.avatar = File.open("#{Rails.root}/test/files/lion-30-x-30.jpg") @user.save! assert_equal true, @user.avatar? # remove avatar @user.remove_avatar! @user.save! assert_equal false, @user.avatar? # add back again @user.avatar = File.open("#{Rails.root}/test/files/lion-30-x-30.jpg") @user.save! assert_equal true, @user.avatar? end end

以下是测试用例:

{{1}}

上次测试失败。

有人有任何线索吗?有什么帮助吗?

1 个答案:

答案 0 :(得分:1)

在carrierwave上有一个未解决的问题: https://github.com/carrierwaveuploader/carrierwave/issues/401

它提供了一种解决方法(https://github.com/ajahongir):

# remove avatar
@user.remove_avatar!
@user.save!

assert_equal false, @user.avatar?

# add back again
@user = User.find @user
@user.avatar = File.open("#{Rails.root}/test/files/lion-30-x-30.jpg")
@user.save!