#324 open
Bruce Williams

Gem dependencies inconsistently load rails/init.rb

Reported by Bruce Williams | June 3rd, 2008 @ 03:26 PM | in 2.1.1

Gems unpacked with gems:unpack inconsistently load rails/init.rbfrom the unpacked gem and from the system gem (and in the case of an unpacked gem with no system gem present, the file isn't loaded at all).

This was tested with a small test gem [attached] on 2.1 stable and HEAD today at 7cfa6ec8a37b70ec302f09929df5160ac42971e7.

Each file in the gem outputs the filename at the beginning and end when loaded. I've also included what the output looks like when used from vendor/plugins, simply for comparison.

Traditional vendor/plugins

Expected output (init.rb just requires rails/init.rb)

LOADING /Users/bruce/Development/test2.1/vendor/plugins/unpack_testing/init.rb

LOADING /Users/bruce/Development/test2.1/vendor/plugins/unpack_testing/rails/init.rb

LOADING /Users/bruce/Development/test2.1/vendor/plugins/unpack_testing/lib/unpack_testing.rb

LOADED /Users/bruce/Development/test2.1/vendor/plugins/unpack_testing/lib/unpack_testing.rb

LOADING /Users/bruce/Development/test2.1/vendor/plugins/unpack_testing/lib/unpack_testing/autoloaded_constant.rb

LOADED /Users/bruce/Development/test2.1/vendor/plugins/unpack_testing/lib/unpack_testing/autoloaded_constant.rb

LOADED /Users/bruce/Development/test2.1/vendor/plugins/unpack_testing/rails/init.rb

LOADED /Users/bruce/Development/test2.1/vendor/plugins/unpack_testing/init.rb

config.gem (not unpacked)

Expected output.

LOADING /Library/Ruby/Gems/1.8/gems/unpack_testing-0.0.001/lib/unpack_testing.rb

LOADED /Library/Ruby/Gems/1.8/gems/unpack_testing-0.0.001/lib/unpack_testing.rb

LOADING /Library/Ruby/Gems/1.8/gems/unpack_testing-0.0.001/rails/init.rb

LOADING /Library/Ruby/Gems/1.8/gems/unpack_testing-0.0.001/lib/unpack_testing/autoloaded_constant.rb

LOADED /Library/Ruby/Gems/1.8/gems/unpack_testing-0.0.001/lib/unpack_testing/autoloaded_constant.rb

LOADED /Library/Ruby/Gems/1.8/gems/unpack_testing-0.0.001/rails/init.rb

config.gem (unpacked, gem still present on system)

Files loaded from both the unpacked gem and system gem.

LOADING /Users/bruce/Development/test2.1/vendor/gems/unpack_testing-0.0.001/lib/unpack_testing.rb

LOADED /Users/bruce/Development/test2.1/vendor/gems/unpack_testing-0.0.001/lib/unpack_testing.rb

LOADING /Library/Ruby/Gems/1.8/gems/unpack_testing-0.0.001/rails/init.rb

LOADING /Library/Ruby/Gems/1.8/gems/unpack_testing-0.0.001/lib/unpack_testing/autoloaded_constant.rb

LOADED /Library/Ruby/Gems/1.8/gems/unpack_testing-0.0.001/lib/unpack_testing/autoloaded_constant.rb

LOADED /Library/Ruby/Gems/1.8/gems/unpack_testing-0.0.001/rails/init.rb

config.gem (unpacked, gem not present on system)

rails/init.rb not loaded.

LOADING /Users/bruce/Development/test2.1/vendor/gems/unpack_testing-0.0.001/lib/unpack_testing.rb

LOADED /Users/bruce/Development/test2.1/vendor/gems/unpack_testing-0.0.001/lib/unpack_testing.rb

Comments and changes to this ticket

  • david (at loudthinking)

    david (at loudthinking) June 3rd, 2008 @ 03:46 PM

      • → Assigned user changed from “” to “rick”
  • rick

    rick June 8th, 2008 @ 12:31 PM

      • → State changed from “new” to “open”

    Okay, I'm seeing two issues here:

    • Frozen gems aren't getting their specs loaded, so unpacked gems aren't getting their rails/init.rb files run.
    • The system gem specs are still loaded, so their init.rb files are run.
  • rick

    rick June 8th, 2008 @ 01:05 PM

      • → State changed from “open” to “verified”

    Bruce, can you (and any other interested parties) try the commit from my rails fork? Assuming this works well, I'll push this to the main rails repo.

  • Bruce Williams

    Bruce Williams June 8th, 2008 @ 01:31 PM

    Rick; will give it a shot -- results shortly.

  • Bruce Williams

    Bruce Williams June 8th, 2008 @ 02:08 PM

    Rick, it looks like you've fixed the loading from both the unpacked and system gem when both are present, but autoloading doesn't seem to be functioning correctly (See #3 below).

    Also, rails/init.rb doesn't seem to be loaded at all from unpacked gems when the system gem is not present (See #4 below).

    Testing notes: Generated a fresh app from railties/bin/rails using a clone of your fork, tossed the rails source in vendor/rails, and used the unpack_testing gem attached to the ticket. Please let me know if this seems like the wrong way to go about it.

    In vendor/plugins

    (Just for reference). Expected result. This was working before.

    bruce@riyah Development/bug-324 % ruby script/console

    Loading development environment (Rails 2.1.0)

    LOADING /Users/bruce/Development/bug-324/vendor/plugins/unpack_testing/rails/init.rb

    LOADING /Users/bruce/Development/bug-324/vendor/plugins/unpack_testing/lib/unpack_testing.rb

    LOADED /Users/bruce/Development/bug-324/vendor/plugins/unpack_testing/lib/unpack_testing.rb

    LOADING /Users/bruce/Development/bug-324/vendor/plugins/unpack_testing/lib/unpack_testing/autoloaded_constant.rb

    LOADED /Users/bruce/Development/bug-324/vendor/plugins/unpack_testing/lib/unpack_testing/autoloaded_constant.rb

    LOADED /Users/bruce/Development/bug-324/vendor/plugins/unpack_testing/rails/init.rb

    >>

    #2, Plain gem dependency

    Expected result. rails/init.rb loaded, and autoloading of UnpackTesting::AutoloadedConstant succeeds. This was working before.

    bruce@riyah Development/bug-324 % ruby script/console

    Loading development environment (Rails 2.1.0)

    LOADING /Library/Ruby/Gems/1.8/gems/unpack_testing-0.0.001/lib/unpack_testing.rb

    LOADED /Library/Ruby/Gems/1.8/gems/unpack_testing-0.0.001/lib/unpack_testing.rb

    LOADING /Library/Ruby/Gems/1.8/gems/unpack_testing-0.0.001/rails/init.rb

    LOADING /Library/Ruby/Gems/1.8/gems/unpack_testing-0.0.001/lib/unpack_testing/autoloaded_constant.rb

    LOADED /Library/Ruby/Gems/1.8/gems/unpack_testing-0.0.001/lib/unpack_testing/autoloaded_constant.rb

    LOADED /Library/Ruby/Gems/1.8/gems/unpack_testing-0.0.001/rails/init.rb

    >>

    #3, Unpacked, gem still present on system

    rails/init.rb loaded from the right place, but autoloading of UnpackTesting::AutoloadedConstant fails (looks like it's using a plain vendor/ load path, incorrectly guessing the constant?)

    bruce@riyah Development/bug-324 % ruby script/console

    Loading development environment (Rails 2.1.0)

    LOADING /Users/bruce/Development/bug-324/vendor/gems/unpack_testing-0.0.001/lib/unpack_testing.rb

    LOADED /Users/bruce/Development/bug-324/vendor/gems/unpack_testing-0.0.001/lib/unpack_testing.rb

    LOADING /Users/bruce/Development/bug-324/vendor/gems/unpack_testing-0.0.001/rails/init.rb

    /Users/bruce/Development/bug-324/vendor/rails/activerecord/lib/../../activesupport/lib/active_support/dependencies.rb:116:in `qualified_const_defined?':NameError: "Gems::UnpackTesting-0.0.001::Lib::UnpackTesting" is not a valid constant name!

    >>

    #4, Unpacked, gem not present on system

    rails/init.rb not loaded at all.

    bruce@riyah Development/bug-324 % ruby script/console

    Loading development environment (Rails 2.1.0)

    LOADING /Users/bruce/Development/bug-324/vendor/gems/unpack_testing-0.0.001/lib/unpack_testing.rb

    LOADED /Users/bruce/Development/bug-324/vendor/gems/unpack_testing-0.0.001/lib/unpack_testing.rb

    >>

  • Repository

    Repository June 19th, 2008 @ 12:01 PM

      • → State changed from “verified” to “resolved”

    (from [faad1e32a8ab81890018ba89d191607778830cf0]) Fix discrepancies with loading rails/init.rb from gems. [#324 state:resolved]

    http://github.com/rails/rails/co...

  • rick

    rick June 19th, 2008 @ 12:10 PM

      • → State changed from “resolved” to “open”
      • → Milestone cleared.
  • rick

    rick June 19th, 2008 @ 12:10 PM

      • → Milestone changed from “” to “2.1.1”
  • Repository

    Repository June 19th, 2008 @ 12:12 PM

      • → State changed from “open” to “resolved”

    (from [e1bd75a92285c29269270e708e49d7cd5fabac36]) Fix discrepancies with loading rails/init.rb from gems. [#324 state:resolved]

    http://github.com/rails/rails/co...

  • Bruce Williams

    Bruce Williams June 19th, 2008 @ 12:46 PM

    As of 10c581a6deed66e8b62de6e7a3621a63de90baad (HEAD as of now), I'm still seeing the same behavior in unpacked gems as mentioned in my last comment. I also tested this against e1bd75a92285c29269270e708e49d7cd5fabac36 with the same results.

    • When unpacked with the system gem still present, autoloading fails (attempts to build constants such as Gems::UnpackTesting-0.0.001::Lib::UnpackTesting)
    • When unpacked without the system gem present, rails/init.rb isn't loaded.

    Did your testing show different results? I'm generating a fresh app using railties/bin/rails and tossing the repo in at vendor/rails.

  • Jeremy Kemper

    Jeremy Kemper June 23rd, 2008 @ 08:01 PM

      • → State changed from “resolved” to “open”

    I'm having the same issue with - in the constant name. Trying to autoload constants from an a path that doesn't convert into a module name.

  • Stephan Kaag

    Stephan Kaag July 2nd, 2008 @ 01:33 PM

      • → Tag changed from “” to “2.1-stable bug dependencies edge”

    Is there a any progress?

  • Ramon Salvadó

    Ramon Salvadó July 24th, 2008 @ 08:28 AM

    Instead of unpacking gems we could just install them in vendor/gems using the gem command (or unpack could just do a gem install):

    Ex: gem install -i gems activesupport activerecord (From RAILS_ROOT)

    Then we could just do something:

    Gem.path.unshift(RAILS_ROOT + "vendor/gems")
    

    This is how merb do it afaik, is there any reason for not doing it? seems better than the current way to me.

  • Bruce Williams

    Bruce Williams August 1st, 2008 @ 12:03 PM

    Ramon, if you think that's a better way, by all means add an enhancement ticket so it can be discussed.

    The resolution of this issue (the breakage of a feature in 2.1) is a different concern.

Please Login or create a free account to add a new comment.

You can update this ticket by sending an email to from your email client. (help)

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

Source available from github

The Git repository resides at http://github.com/rails

Check out the current development trunk (Edge Rails) with:

git clone git://github.com/rails/rails.git

The latest development for the 1.2.x and 2.0.x releases are on the 1-2-stable and 2-0-stable branches.

Creating a bug report

When creating a bug report, be sure to include as much relevant information as possible. Post the code sample that causes the problem. Preferably, alter the unit tests and show through either changed or added tests how the expected behavior is not occuring.

Security vulnerabilities should be reported via an email to security@rubyonrails.org, do not use trac for reporting security vulnerabilities. All content in trac is publicly available as soon as it is posted.

Then don't get your hopes up. Unless you have a "Code Red, Mission Critical, The World is Coming to an End" kinda bug, you're creating this ticket in the hope that others with the same problem will be able to collaborate with you on solving it. Do not expect that the ticket automatically will see any activity or that others will jump to fix it. Creating a ticket like this is mostly to help yourself start on the path of fixing the problem and for others to sign on to with a "I'm having this problem too".

Shared Ticket Bins

Attachments