Ruby on Rails | Screencasts | Download | Documentation | Weblog | Community | Source

Ticket #9834 (closed defect: fixed)

Opened 2 years ago

Last modified 2 years ago

[PATCH] Code in boot.rb that supposedly reads environment.rb for RAILS_GEM_VERSION is broken

Reported by: alexch Assigned to: core
Priority: normal Milestone: 1.2.6
Component: Railties Version: 1.2.3
Severity: normal Keywords:
Cc: thewoolleyman@gmail.com

Description

If you install Rails 1.2.4 on your system, then running any Rails project that was built with 1.2.3 will magically use version 1.2.4 even if you have explicitly declared RAILS_GEM_VERSION = ' 1.2.3' in your environment.rb. This may only happen in environments that load boot.rb explicitly; I noticed it when running our app under mongrel but it seemed to work ok in unit tests.

The workaround is simple, if maddening: you must put a space character at the beginning of the following line in your environment.rb:

RAILS_GEM_VERSION = '1.2.3' unless defined? RAILS_GEM_VERSION

This bug is present in both Rails 1.2.3 and Rails 1.2.4 (meaning that projects generated with Rails 1.2.4 have the same buggy code in boot.rb and therefore the line in the generated environment.rb will be missed).

I've attached a patch with tests.

Attachments

boot_test.rb (0.7 kB) - added by alexch on 10/09/07 21:31:42.
boot.rb (1.5 kB) - added by alexch on 10/10/07 01:05:54.
boot.rb.diff (1.6 kB) - added by alexch on 10/10/07 01:06:00.
rails_boot_patch_from_chad.diff (3.2 kB) - added by thewoolleyman on 10/19/07 05:43:18.
enhancement of alex's patch, incorporates [7832], doesn't match double-quoted version after all

Change History

10/09/07 21:31:42 changed by alexch

  • attachment boot_test.rb added.

10/09/07 21:35:19 changed by alexch

By the way, the flaw was in the regexp

/[^#]RAILS_GEM_VERSION = '([\d.]+)'/

That first character class ("not hash") would not match the beginning of a line. That's why the workaround is to put a space in.

I refactored a fair bit both for clarity, and to extract a method that could be unit tested.

10/09/07 21:35:43 changed by alexch

  • component changed from ActiveRecord to Railties.

10/09/07 21:36:03 changed by alexch

  • version changed from edge to 1.2.3.

10/09/07 22:35:19 changed by bitsweat

Please attach patches instead of the entire file. Thanks!

10/10/07 00:58:07 changed by alexch

OK, I've attached a patch for boot.rb. boot_test.rb is entirely new and I have no idea where it would go in your test hierarchy.

10/10/07 01:05:54 changed by alexch

  • attachment boot.rb added.

10/10/07 01:06:00 changed by alexch

  • attachment boot.rb.diff added.

10/10/07 01:06:46 changed by alexch

Oops, I left a print statement in there. New versions of boot.rb and boot.rb.diff uploaded.

10/18/07 09:45:40 changed by thewoolleyman

Hi,

I've made a new patch for this: rails_boot_patch_from_chad.diff. It's a cleaner version of Alex's patch:

* Still fixes original bug * Handles double-quoted version as well as single-quoted * made against latest trunk as of this comment * includes both the file and test diffs, in the correct location relative to source root * has cleaner and more detailed tests

Let me know if this has any problems, I can clean it up.

10/19/07 00:53:33 changed by thewoolleyman

  • cc set to thewoolleyman@gmail.com.

10/19/07 05:43:18 changed by thewoolleyman

  • attachment rails_boot_patch_from_chad.diff added.

enhancement of alex's patch, incorporates [7832], doesn't match double-quoted version after all

10/19/07 05:45:24 changed by thewoolleyman

I updated this one more time to remove the support for double-quoted versions. That's probably not a good idea after all, since any string interpolation would not be evaluated anyway. Best not to even hint that it's possible.

10/19/07 05:47:38 changed by thewoolleyman

  • summary changed from Code in boot.rb that supposedly reads environment.rb for RAILS_GEM_VERSION is broken to [PATCH] Code in boot.rb that supposedly reads environment.rb for RAILS_GEM_VERSION is broken.

10/23/07 05:36:56 changed by bitsweat

  • status changed from new to closed.
  • resolution set to fixed.

(In [7998]) Refactor and test boot.rb. Include tests from and closes #9834.