Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

xxx_cache= unintentionally remove files #2412

Closed
shunichi opened this issue Aug 21, 2019 · 1 comment
Closed

xxx_cache= unintentionally remove files #2412

shunichi opened this issue Aug 21, 2019 · 1 comment

Comments

@shunichi
Copy link

When using cache feature on carrierwave 2.0.0, update action unintentionally remove attached file.

<%= form_for @user, html: { multipart: true } do |f| %>
  <p>
    <label>My Avatar</label>
    <%= f.file_field :avatar %>
    <!-- params[:user][:avatar_cache] is empty string if @user.avatar_cache is nil.-->
    <%= f.hidden_field :avatar_cache %>
  </p>
<% end %>

Here is a test code.

begin
  require "bundler/inline"
rescue LoadError
  $stderr.puts "Bundler version 1.10 or later is required. Please update your Bundler"
  raise
end

gemfile(true) do
  source "https://rubygems.org"

  git_source(:github) { |repo| "https://github.com/#{repo}.git" }

  gem "activerecord", "5.2.3"
  gem "carrierwave", "2.0.0"
  # gem "carrierwave", "1.3.1"
  gem "sqlite3"
end

require "active_record"
require "carrierwave"
require "minitest/autorun"

CarrierWave.root = Dir.pwd
CarrierWave.configure do |config|
  config.storage = :file
  config.enable_processing = false
end

ActiveSupport.on_load :active_record do
  require 'carrierwave/orm/activerecord'
end

class AvatarUploader < CarrierWave::Uploader::Base
end

ActiveRecord::Base.establish_connection(adapter: 'sqlite3', database: ':memory:')
ActiveRecord::Schema.define do
  create_table :users do |t|
    t.column :avatar, :string
  end
end

class User < ActiveRecord::Base
  mount_uploader :avatar, AvatarUploader
end

class BugTest < Minitest::Test
  def test_cache
    user = User.create!(avatar: File.open("./test.jpg"))
    assert user.avatar.present?
    user.update!(avatar_cache: '')
    # Fail on carrierwave 2.0.0
    assert user.avatar.present?
  end
end
@mshibuya
Copy link
Member

Sorry for the issue, this was a regression in 8f18a95.
A fix is in the master so please try it. If everyone's ok, I'll cut a patch release.

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants