Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

[Bug]: remove_attachment error with ruby 3.2 #620

Closed
arrowcircle opened this issue Jan 13, 2023 · 2 comments
Closed

[Bug]: remove_attachment error with ruby 3.2 #620

arrowcircle opened this issue Jan 13, 2023 · 2 comments
Labels

Comments

@arrowcircle
Copy link

Report

When using remove_attachment plugin with ruby 3.2 this code fails

object.remove_file = true

with error:

NoMethodError:
       undefined method `=~' for true:TrueClass

Expected Behavior

It should work properly and remove file with true value

Actual Behavior

It works with ruby 3.2 only when passing:

object.remove_file = "true"

Steps to Reproduce the Problem

require 'bundler/inline'

gemfile do
  source "https://rubygems.org"
  gem "activerecord"
  gem "shrine"
  gem "sqlite3"
end

require "active_record"
require "shrine"
require "shrine/storage/memory"
require "down"

Shrine.storages = {
  cache: Shrine::Storage::Memory.new,
  store: Shrine::Storage::Memory.new,
}

Shrine.plugin :activerecord

class MyUploader < Shrine
  plugin :remove_attachment
end

ActiveRecord::Base.establish_connection(adapter: "sqlite3", database: ":memory:")
ActiveRecord::Base.connection.create_table(:posts) { |t| t.text :image_data }

class Post < ActiveRecord::Base
  include MyUploader::Attachment(:image)
end

post = Post.create(image: Down.download("https://picsum.photos/200/300"))
post.remove_image = true

Ruby Version

3.2.0

Shrine Version

3.4.0

Anything else?

No response

@janko
Copy link
Member

janko commented Jan 13, 2023

Thanks for reporting. I honestly didn't intend for it to work with actual boolean values, but it accidentally does work, and you're right that it should continue working. The error happens because Ruby 3.2 removed Object#=~, which is what made it work before. I will push a fix shortly.

@janko janko closed this as completed in 004ffc8 Jan 13, 2023
@rince
Copy link

rince commented May 19, 2023

@janko
Thanks for fixing!
Could you update the gem version?
I can use this change if I specify the github master branch in the Gemfile, but I would prefer to avoid it if possible.

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

No branches or pull requests

3 participants