Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

This project is archived and is in readonly mode.

TemplateRunner adds gems to environment file in reverse of written order

#2861

Each successive gem command in an app template places the corresponding config.gem line above the previous one.

This makes the environment file's config.gem lines the reverse order of the app templates gem commands, potentially causing requirement failures.

Example app template gem commands:

gem 'authlogic'
gem 'authlogic-oid', :lib => "authlogic_openid"
gem 'somegem'

Creates these environment.rb lines:

config.gem 'somegem'
config.gem 'authlogic-oid', :lib => 'authlogic_openid'
config.gem 'authlogic'

Running the rake gems task then would abort at that authlogic-oid line with:

rake aborted!
undefined method add_acts_as_authentic_module' for ActiveRecord::Base:Class</code>
</pre>


I can't think of an easy fix other than some sort of counter to keep track of how many lines have been added after the sentinel.
For now I'll just have to construct my templates in reverse order as needed.

Reported by CS Merritt (csmosx) · June 30th, 2009 @ 09:52 PM

State: hold
Milestone: 2.x
Assigned to: Pratik Pratik
Importance: none

Activity

  1. Yehuda Katz (wycats)
    Yehuda Katz (wycats)
    • State changed from new to verified

    Templates are going to be reworked in Rails 3 by José Valim (as part of his GSoC project). Pratik, do you think we should fix this on the 2.3 branch?

    July 1st, 2009 @ 07:49 PM

  2. Pratik
    Pratik
    • State changed from verified to open

    Patch please :)

    July 1st, 2009 @ 07:57 PM

  3. Yehuda Katz (wycats)
    Yehuda Katz (wycats)
    • State changed from open to hold

    We looked into this a bit. The problem is that Rails inserts all new text at the top of the environment, using a regex sentinel that looks for the initializer start. The solution is non-trivial, but a patch would be welcome :)

    July 1st, 2009 @ 08:43 PM

  4. CS Merritt (csmosx)
    CS Merritt (csmosx)

    Here's a patch... or two.

    template_gem_order_fix just fixes the gem ordering problem.

    template_env_order_fix applies both the gem fix and the same fix to route, which had the same ordering problem and used the same function (gsub_file) which I replaced (with regex_file_splice).

    Thanks =)

    July 3rd, 2009 @ 06:25 AM