documentcloud / jammit

Industrial Strength Asset Packaging for Rails
http://documentcloud.github.com/jammit/
MIT License
1.16k stars 197 forks source link

Jammit not setting the correct ASSET_ROOT when running individual tests #136

Closed james2m closed 13 years ago

james2m commented 13 years ago

Because test_helper.rb relies on Rails.root being set it defaults to the current directory. So running individual tests will set the ASSET_ROOT based on the current directory.

I'm not sure why the ASSET_ROOT uses the current directory if it can't find Rails.root. I would have thought it would be better to then look for RAILS_ROOT and use that if Rails.root doesn't exist yet.

To overcome this for the moment I am overriding ASSET_ROOT in test_helper.rb;

  module Jammit
    ASSET_ROOT = File.expand_path('../..', __FILE__)
  end
jashkenas commented 13 years ago

I'm sorry, but what exactly is the bug you're reporting, or change you're proposing here?

james2m commented 13 years ago

In jammit.rb:11

ASSET_ROOT  = File.expand_path((defined?(Rails) && Rails.root.to_s.length > 0) ? Rails.root : ".") unless defined?(ASSET_ROOT)

If Rails.root isn't set it uses the present working directory '.' surely you should first check for RAILS_ROOT and use that first.

The lack of check for RAILS_ROOT causes tests to fail when a view is rendered if the test isn't run from the root of the application for example if you run the test stand alone from within textmate.

jashkenas commented 13 years ago

Sure thing .. here's the fallback for the regular RAILS_ROOT:

aaaceb7373a5e193cd6c97b25400a08fbb8d8c5f

james2m commented 13 years ago

Cool. Thanks.