Browse files

Merge pull request #2860 from guilleiguaran/fix-assets-behavior

Fix AssetNotPrecompiledError behavior
  • Loading branch information...
2 parents a1fa756 + 9bc0082 commit 6521cf3316ac5378d2b6019c303a003f527b7646 @spastorino spastorino committed Sep 4, 2011
Showing with 28 additions and 2 deletions.
  1. +2 −2 actionpack/lib/sprockets/helpers/rails_helper.rb
  2. +26 −0 railties/test/application/assets_test.rb
View
4 actionpack/lib/sprockets/helpers/rails_helper.rb
@@ -124,7 +124,7 @@ def digest_for(logical_path)
end
if compile_assets
- if asset = asset_environment[logical_path]
+ if digest_assets && asset = asset_environment[logical_path]
return asset.digest_path
end
return logical_path
@@ -137,7 +137,7 @@ def rewrite_asset_path(source, dir)
if source[0] == ?/
source
else
- source = digest_for(source) if digest_assets
+ source = digest_for(source)
source = File.join(dir, source)
source = "/#{source}" unless source =~ /^\//
source
View
26 railties/test/application/assets_test.rb
@@ -180,6 +180,32 @@ class ::PostsController < ActionController::Base ; end
assert_match(/app.js isn't precompiled/, last_response.body)
end
+ test "assets raise AssetNotPrecompiledError when manifest file is present and requested file isn't precompiled if digest is disabled" do
+ app_file "app/views/posts/index.html.erb", "<%= javascript_include_tag 'app' %>"
+ app_file "config/initializers/compile.rb", "Rails.application.config.assets.compile = false"
+
+ app_file "config/routes.rb", <<-RUBY
+ AppTemplate::Application.routes.draw do
+ match '/posts', :to => "posts#index"
+ end
+ RUBY
+
+ ENV["RAILS_ENV"] = "development"
+ capture(:stdout) do
+ Dir.chdir(app_path){ `bundle exec rake assets:precompile` }
+ end
+
+ # Create file after of precompile
+ app_file "app/assets/javascripts/app.js", "alert();"
+
+ require "#{app_path}/config/environment"
+ class ::PostsController < ActionController::Base ; end
+
+ get '/posts'
+ assert_match(/AssetNotPrecompiledError/, last_response.body)
+ assert_match(/app.js isn't precompiled/, last_response.body)
+ end
+
test "precompile appends the md5 hash to files referenced with asset_path and run in the provided RAILS_ENV" do
app_file "app/assets/stylesheets/application.css.erb", "<%= asset_path('rails.png') %>"
# digest is default in false, we must enable it for test environment

0 comments on commit 6521cf3

Please sign in to comment.