rails-api / active_model_serializers

ActiveModel::Serializer implementation and Rails hooks
MIT License
5.32k stars 1.39k forks source link

Fix checking of method defined or not #2427

Closed y-yagi closed 2 years ago

y-yagi commented 2 years ago

The Module#method_defined? works for an instance method. But with_unbundled_env defines as a class method. Therefore, the current check doesn't work as expected.

require "bundler"

puts Bundler.method_defined?(:with_unbundled_env) # => false
puts Bundler.respond_to?(:with_unbundled_env)     # => true

This fixes the following message that shows when running a test.

[DEPRECATED] `Bundler.with_clean_env` has been deprecated in favor of `Bundler.with_unbundled_env`. If you instead want the environment before bundler was originally loaded, use `Bundler.with_original_env` (called at /home/y-yagi/src/github.com/rails-api/active_model_serializers/Rakefile:68)