rails/rails — pull request #7494 by route (2012-08-31 08:05:47+00:00)
Title: Sprockets-rails tests fail

Method invalid_asset_host! was delegated to controller but sprockets
compile assets in their own scope without controller and request. And if we set asset_host
with second parameter it should raise error through invalid_asset_host!.
But since controller is nil it cannot be reached.

Original issue in sprockets-rails tests:
```
test_0010_stylesheets served without a controller in scope cannot access the request(SprocketsHelperTest) [/Users/route/Projects/sprockets-rails/test/sprockets_helper_test.rb:127]:
[ActionController::RoutingError] exception expected, not
Class:
Message: <"ActionView::AssetPaths#invalid_asset_host! delegated to controller.invalid_asset_host!, but controller is nil: #\"/Users/route/Projects/sprockets-rails/test/fixtures/public\", :javascripts_dir=>\"/Users/route/Projects/sprockets-rails/test/fixtures/public/javascripts\", :stylesheets_dir=>\"/Users/route/Projects/sprockets-rails/test/fixtures/public/stylesheets\", :assets=>{:digest=>true, :compile=>true}, :perform_caching=>true, :asset_host=>#}, @controller=nil, @asset_environment=#, @asset_digests=nil, @compile_assets=true, @digest_assets=true>">
---Backtrace---
/Users/route/Projects/rails/actionpack/lib/action_view/asset_paths.rb:14:in `rescue in invalid_asset_host!'
/Users/route/Projects/rails/actionpack/lib/action_view/asset_paths.rb:11:in `invalid_asset_host!'
/Users/route/Projects/rails/actionpack/lib/action_view/asset_paths.rb:113:in `compute_asset_host'
/Users/route/Projects/rails/actionpack/lib/action_view/asset_paths.rb:72:in `rewrite_host_and_protocol'
/Users/route/Projects/rails/actionpack/lib/action_view/asset_paths.rb:33:in `compute_public_path'
/Users/route/Projects/sprockets-rails/lib/sprockets/rails/helpers/rails_helper.rb:57:in `asset_path'
/Users/route/Projects/sprockets-rails/test/sprockets_helper_test.rb:128:in `block (2 levels) in '
---------------
```

After adding :allow_nil => true the issue is still here
```
1) Failure:
test_0010_stylesheets served without a controller in scope cannot access the request(SprocketsHelperTest) [/Users/route/Projects/sprockets-rails/test/sprockets_helper_test.rb:127]:
[ActionController::RoutingError] exception expected, not
Class:
Message: <"This should not have been called.">
---Backtrace---
/Users/route/Projects/sprockets-rails/test/sprockets_helper_test.rb:125:in `block (2 levels) in '
/Users/route/Projects/rails/actionpack/lib/action_view/asset_paths.rb:116:in `call'
/Users/route/Projects/rails/actionpack/lib/action_view/asset_paths.rb:116:in `compute_asset_host'
/Users/route/Projects/rails/actionpack/lib/action_view/asset_paths.rb:72:in `rewrite_host_and_protocol'
/Users/route/Projects/rails/actionpack/lib/action_view/asset_paths.rb:33:in `compute_public_path'
/Users/route/Projects/sprockets-rails/lib/sprockets/rails/helpers/rails_helper.rb:57:in `asset_path'
/Users/route/Projects/sprockets-rails/test/sprockets_helper_test.rb:128:in `block (2 levels) in '
---------------
```

For now this issue isn't resolved in this PR because I haven't idea how to raise exception through controller that is nil, I think the raise should be in actionview, but since we decoupling it from actionpack we cannot use ActionController::RoutingError. Any suggestions?

/cc @drogus