cloudinary / cloudinary_gem

Cloudinary GEM for Ruby on Rails integration
https://cloudinary.com
420 stars 285 forks source link

Fix obtaining identifier on rails >= 6.1 #493

Closed david-zw-liu closed 2 years ago

david-zw-liu commented 2 years ago

Brief Summary of Changes

This PR is fixing the bug from my previous PR. (https://github.com/cloudinary/cloudinary_gem/pull/489) I found the issue I fixed in my previous PR is reproduced after I upgraded my project to Rails 6.1.

And I did some research and noticed that there is an API change between Rails 6.0 and 6.1.

Rails 6.0

# activerecord/lib/active_record/attribute_methods/read.rb

def _read_attribute(attr_name, &block) # :nodoc
  sync_with_transaction_state if @transaction_state&.finalized?
  @attributes.fetch_value(attr_name.to_s, &block)
end

Rails 6.1

# activerecord/lib/active_record/attribute_methods/read.rb

def _read_attribute(attr_name, &block) # :nodoc
  @attributes.fetch_value(attr_name, &block)
end

The attr_name is no longer converted to String type. That led to fetching the incorrect identifier after storage. So I change the code to use the public method read_attribute for avoiding internal API changes.

What does this PR address?

Are tests included?

Reviewer, please note:

Checklist: