Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

ActionView decoupling and sprockets-rails tests fail #7494

Merged
merged 1 commit into from

3 participants

@route

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(request) 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: <RuntimeError>
Message: <"ActionView::AssetPaths#invalid_asset_host! delegated to controller.invalid_asset_host!, but controller is nil: #<Sprockets::Rails::Helpers::RailsHelper::AssetPaths:0x007febc3838270 @config={:assets_dir=>\"/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=>#<Proc:0x007febc3832f50@/Users/route/Projects/sprockets-rails/test/sprockets_helper_test.rb:124>}, @controller=nil, @asset_environment=#<Sprockets::Environment:0x3ff5e2546448 root=\"/Users/route/Projects/sprockets-rails\", paths=[\"/Users/route/Projects/sprockets-rails/test/fixtures/app/javascripts\", \"/Users/route/Projects/sprockets-rails/test/fixtures/app/stylesheets\", \"/Users/route/Projects/sprockets-rails/test/fixtures/app/images\", \"/Users/route/Projects/sprockets-rails/test/fixtures/app/fonts\"], digest=\"35721b5cd45ee6e140910c90f9c6d639\">, @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 <class:SprocketsHelperTest>'
---------------

I revert that commit 7185e35 and since invalid_asset_host! is used only in action_view I think this method should be there, I renamed class of error to get rid of actionpack dependence.

@steveklabnik
Collaborator

#7482 claims that the tests pass.

@route

Yep that's right, tests pass in rails but there's one test in sprockets-rails that fails. And it happened after actionview decoupling.

@steveklabnik
Collaborator

Ah, okay. I misread. :)

@route

It's ok ;)

@route

I've updated description and commit. /cc @drogus

@drogus
Collaborator

@route thanks for the fix, I have misunderstood the intention of this code at first. Could you rename the error to ActionView::MissingRequestError ? I think it communicates the problem better, RequestError seems to me like "request is there, but there is some problem with it".

Thanks!

@route route Sprockets-rails tests fail
Method invalid_asset_host! was delegated to controller but sprockets
compile assets in their own scope without controller. 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.
3a6e8e4
@route

Good idea, I hesitated with name.. All done!

@drogus drogus merged commit 2a95a66 into from
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Sep 1, 2012
  1. @route

    Sprockets-rails tests fail

    route authored
    Method invalid_asset_host! was delegated to controller but sprockets
    compile assets in their own scope without controller. 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.
This page is out of date. Refresh to see the latest.
View
1  actionpack/lib/action_controller.rb
@@ -12,7 +12,6 @@ module ActionController
autoload :Middleware
autoload_under "metal" do
- autoload :AssetPaths
autoload :Compatibility
autoload :ConditionalGet
autoload :Cookies
View
2  actionpack/lib/action_controller/base.rb
@@ -183,8 +183,8 @@ def self.without_modules(*modules)
MODULES = [
AbstractController::Layouts,
AbstractController::Translation,
+ AbstractController::AssetPaths,
- AssetPaths,
Helpers,
HideActions,
UrlFor,
View
13 actionpack/lib/action_controller/metal/asset_paths.rb
@@ -1,13 +0,0 @@
-require 'action_controller/metal/exceptions'
-
-module ActionController
- module AssetPaths
- extend ActiveSupport::Concern
-
- include AbstractController::AssetPaths
-
- def invalid_asset_host!(help_message)
- raise ActionController::RoutingError, "This asset host cannot be computed without a request in scope. #{help_message}"
- end
- end
-end
View
1  actionpack/lib/action_view.rb
@@ -71,6 +71,7 @@ module ActionView
autoload :MissingTemplate
autoload :ActionViewError
autoload :EncodingError
+ autoload :MissingRequestError
autoload :TemplateError
autoload :WrongEncodingError
end
View
8 actionpack/lib/action_view/asset_paths.rb
@@ -1,6 +1,6 @@
require 'zlib'
require 'active_support/core_ext/file'
-require 'active_support/core_ext/module/delegation'
+require 'action_controller/metal/exceptions'
module ActionView
class AssetPaths #:nodoc:
@@ -8,8 +8,6 @@ class AssetPaths #:nodoc:
attr_reader :config, :controller
- delegate :invalid_asset_host!, :to => :controller, :prefix => false
-
def initialize(config, controller = nil)
@config = config
@controller = controller
@@ -99,6 +97,10 @@ def default_protocol
@config.default_asset_host_protocol || (has_request? ? :request : :relative)
end
+ def invalid_asset_host!(help_message)
+ raise ActionView::MissingRequestError, "This asset host cannot be computed without a request in scope. #{help_message}"
+ end
+
# Pick an asset host for this source. Returns +nil+ if no host is set,
# the host if no wildcard is set, the host interpolated with the
# numbers 0-3 if it contains <tt>%d</tt> (the number is the source hash mod 4),
View
3  actionpack/lib/action_view/template/error.rb
@@ -8,6 +8,9 @@ class ActionViewError < StandardError #:nodoc:
class EncodingError < StandardError #:nodoc:
end
+ class MissingRequestError < StandardError #:nodoc:
+ end
+
class WrongEncodingError < EncodingError #:nodoc:
def initialize(string, encoding)
@string, @encoding = string, encoding
Something went wrong with that request. Please try again.