carrierwaveuploader / carrierwave

Classier solution for file uploads for Rails, Sinatra and other Ruby web frameworks
https://github.com/carrierwaveuploader/carrierwave
8.78k stars 1.65k forks source link

ActiveRecord mount_uploader causes private method removal from receiver #2490

Open scashin133 opened 4 years ago

scashin133 commented 4 years ago

This issue is a little deep but I'll attempt to explain. I was able to reproduce this problem with a spec in the activerecord_spec file by adding the folling under the describe '#mount_uploader' do block:

context "model has private methods" do
  before do
    Event.define_method(:test_a_method) {}
    Event.send(:private, :test_a_method)
  end

  it "maintains private methods after singleton method is called" do
    expect(@event.private_methods(false)).to include(:test_a_method)
    @event.singleton_class
    expect(@event.private_methods(false)).to include(:test_a_method)
  end
end

This spec fails on the second expect call since test_a_method no longer gets returned. This is causing issues for us due to the use of the workflow gem. Specifically the has_callback? method stopped being able to find the private methods in our models. The private method is still there is true is passed instead but the purpose of the code in the workflow gem is to only load private methods in the immediate class.

If I revert the changes done in https://github.com/carrierwaveuploader/carrierwave/commit/eb9c52e6f0fc8310233354304877d7c42a4e3e3a then this code works again. I am still unsure as to why loading the singleton class would cause the private method to no longer show up on the receiver. I will continue attempting to find a fix, but I wanted to post this issue to see if others have ideas for how to address this problem.

Let me know if you'd prefer a PR showcasing the spec and how it fails.

danielricecodes commented 2 years ago

I'm pretty concerned no one is replying to these issues. Is this gem abandonware now?