brendon / acts_as_list

An ActiveRecord plugin for managing lists.
http://brendon.github.io/acts_as_list/
MIT License
2.05k stars 356 forks source link

bundle console cannot be started once acts_as_list required #386

Closed rdvdijk closed 4 years ago

rdvdijk commented 4 years ago

Using this minimal Gemfile, the bundle console command fails:

source "https://rubygems.org"
gem "activerecord"
gem "acts_as_list"

Running:

bundle update
bundle console

Results in a large Bundler error message, the backtrace section shows:

NameError: uninitialized constant ActiveRecord::Acts::List::ScopeMethodDefiner::ActiveSupport
  /home/username/.gem/ruby/2.7.1/gems/acts_as_list-1.0.2/lib/acts_as_list/active_record/acts/scope_method_definer.rb:4:in `<module:ScopeMethodDefiner>'
  /home/username/.gem/ruby/2.7.1/gems/acts_as_list-1.0.2/lib/acts_as_list/active_record/acts/scope_method_definer.rb:3:in `<top (required)>'
  /home/username/.gem/ruby/2.7.1/gems/acts_as_list-1.0.2/lib/acts_as_list.rb:5:in `require'
  /home/username/.gem/ruby/2.7.1/gems/acts_as_list-1.0.2/lib/acts_as_list.rb:5:in `<top (required)>'
  /home/username/.gem/ruby/2.7.1/gems/bundler-2.1.4/lib/bundler/runtime.rb:74:in `require'
  /home/username/.gem/ruby/2.7.1/gems/bundler-2.1.4/lib/bundler/runtime.rb:74:in `block (2 levels) in require'
  /home/username/.gem/ruby/2.7.1/gems/bundler-2.1.4/lib/bundler/runtime.rb:69:in `each'
  /home/username/.gem/ruby/2.7.1/gems/bundler-2.1.4/lib/bundler/runtime.rb:69:in `block in require'
  /home/username/.gem/ruby/2.7.1/gems/bundler-2.1.4/lib/bundler/runtime.rb:58:in `each'
  /home/username/.gem/ruby/2.7.1/gems/bundler-2.1.4/lib/bundler/runtime.rb:58:in `require'
  /home/username/.gem/ruby/2.7.1/gems/bundler-2.1.4/lib/bundler.rb:174:in `require'
  /home/username/.gem/ruby/2.7.1/gems/bundler-2.1.4/lib/bundler/cli/console.rb:15:in `run'
  /home/username/.gem/ruby/2.7.1/gems/bundler-2.1.4/lib/bundler/cli.rb:506:in `console'
  /home/username/.gem/ruby/2.7.1/gems/bundler-2.1.4/lib/bundler/vendor/thor/lib/thor/command.rb:27:in `run'
  /home/username/.gem/ruby/2.7.1/gems/bundler-2.1.4/lib/bundler/vendor/thor/lib/thor/invocation.rb:127:in `invoke_command'
  /home/username/.gem/ruby/2.7.1/gems/bundler-2.1.4/lib/bundler/vendor/thor/lib/thor.rb:399:in `dispatch'
  /home/username/.gem/ruby/2.7.1/gems/bundler-2.1.4/lib/bundler/cli.rb:30:in `dispatch'
  /home/username/.gem/ruby/2.7.1/gems/bundler-2.1.4/lib/bundler/vendor/thor/lib/thor/base.rb:476:in `start'
  /home/username/.gem/ruby/2.7.1/gems/bundler-2.1.4/lib/bundler/cli.rb:24:in `start'
  /home/username/.gem/ruby/2.7.1/gems/bundler-2.1.4/exe/bundle:46:in `block in <top (required)>'
  /home/username/.gem/ruby/2.7.1/gems/bundler-2.1.4/lib/bundler/friendly_errors.rb:123:in `with_friendly_errors'
  /home/username/.gem/ruby/2.7.1/gems/bundler-2.1.4/exe/bundle:34:in `<top (required)>'
  /home/username/.gem/ruby/2.7.1/bin/bundle:23:in `load'
  /home/username/.gem/ruby/2.7.1/bin/bundle:23:in `<main>'

As the backtrace shows, this is using Ruby 2.7.1, Bundler 2.1.4 and acts_as_list 1.0.2. I've tried older versions of ActiveRecord and Bundler, but bundle console always fails.

brendon commented 4 years ago

That's interesting. By the looks of the error message ActiveSupport isn't available (which is correct per your gemfile). It first looks in the global namespace then looks off the current class, that's why it's trying for ActiveRecord::Acts::List::ScopeMethodDefiner::ActiveSupport which doesn't exist.

Try including ActiveSupport and see how you get on. I guess since we're now using ActiveSupport we should add that as a dependency.

brendon commented 4 years ago

Actually ActiveSupport is required by by ActiveRecord so it's strange that it's not being installed when you bundle. Can you confirm if it's installed or not?

rdvdijk commented 4 years ago

It is installed. The only way to make this work is changing the Gemfile to:

source "https://rubygems.org"
gem "activerecord"
gem "acts_as_list", require: false

Adding gem "activesupport" to the Gemfile as you suggested I also did try earlier, but did not work.

brendon commented 4 years ago

Sounds like it's something to do with the require order then :) If you manage to figure it out let me know :) We have had problems like this in the past, so it's worth checking through the old Issues and PR's. It's certainly a strange one.

rdvdijk commented 4 years ago

Did some initial Bundler debugging, in the require method mentioned in the backtrace:

/home/username/.gem/ruby/2.7.1/gems/bundler-2.1.4/lib/bundler/runtime.rb:74:in `require'

Using this Gemfile:

source "https://rubygems.org"
gem "activerecord"
gem "activesupport"
gem "acts_as_list"

I see that the activerecord, activesupport and acts_as_list gems are loaded in that order, so activesupport is indeed required before acts_as_list is loaded. But still the exception occurs. Does ActiveSupport somehow not actually create ActiveSupport in the global namespace?

rdvdijk commented 4 years ago

One fix I could come up with is adding a require to lib/acts_as_list/active_record/acts/scope_method_definer.rb:

# frozen_string_literal: true
require 'active_support/inflector'

module ActiveRecord::Acts::List::ScopeMethodDefiner #:nodoc:
  extend ActiveSupport::Inflector

Would that be an acceptable fix? If so, I can open a pull request for this.

brendon commented 4 years ago

Thanks for that @rdvdijk. That seems like a reasonable solution :)