Skip to content

bug: Old uploads stay in storage after update #159

@avgerin0s

Description

@avgerin0s

When updating a document's attachment, the old attachment does not get deleted.

An example application that demonstrates this bug can be found here.

The related test looks like this

test "it deletes old images upon update" do
    doc = Zedocument.new

    # Initial image and creation
    doc.remote_filename_url = "https://www.ruby-lang.org/images/header-ruby-logo.png"
    doc.save

    old_path = doc.filename.path

    assert(File.exists?(old_path))

    # Update the image
    doc.remote_filename_url = "http://memesvault.com/wp-content/uploads/Wat-Meme-Old-Lady-01.jpg"
    doc.save

    new_path = doc.filename.path

    assert_not_equal(new_path, old_path)

    assert(File.exists?(new_path))
    assert_not(File.exists?(old_path))
  end

An example workaround I used for a forked version is this for carrierwave-mongoid as well as this for carrierwave because mongoid returns a Hash as with Strings keys for changes.

If you agree with those changes I can craft a PR for carrierwave-mongoid and I can merge the carrierwave changes.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions