载波#avatar? returns false 当它应该返回 true

Carrierwave #avatar? returns false when it should be returning true

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

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

我有一个测试用例,其中 #avatar? returns 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

上次测试失败。

有人知道吗?有帮助吗?

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!