Skip to content
This repository
Browse code

AssetNotPrecompiledError should be raise when config.assets.digest = …

…false, config.assets.compile = false and manifest file isn't present
  • Loading branch information...
commit 9bc0082f299436552aabd101f5bcb6bc2fbd6a43 1 parent e865d12
Guillermo Iguaran authored September 04, 2011
4  actionpack/lib/sprockets/helpers/rails_helper.rb
@@ -124,7 +124,7 @@ def digest_for(logical_path)
124 124
           end
125 125
 
126 126
           if compile_assets
127  
-            if asset = asset_environment[logical_path]
  127
+            if digest_assets && asset = asset_environment[logical_path]
128 128
               return asset.digest_path
129 129
             end
130 130
             return logical_path
@@ -137,7 +137,7 @@ def rewrite_asset_path(source, dir)
137 137
           if source[0] == ?/
138 138
             source
139 139
           else
140  
-            source = digest_for(source) if digest_assets
  140
+            source = digest_for(source)
141 141
             source = File.join(dir, source)
142 142
             source = "/#{source}" unless source =~ /^\//
143 143
             source
26  railties/test/application/assets_test.rb
@@ -180,6 +180,32 @@ class ::PostsController < ActionController::Base ; end
180 180
       assert_match(/app.js isn't precompiled/, last_response.body)
181 181
     end
182 182
 
  183
+    test "assets raise AssetNotPrecompiledError when manifest file is present and requested file isn't precompiled if digest is disabled" do
  184
+      app_file "app/views/posts/index.html.erb", "<%= javascript_include_tag 'app' %>"
  185
+      app_file "config/initializers/compile.rb", "Rails.application.config.assets.compile = false"
  186
+
  187
+      app_file "config/routes.rb", <<-RUBY
  188
+        AppTemplate::Application.routes.draw do
  189
+          match '/posts', :to => "posts#index"
  190
+        end
  191
+      RUBY
  192
+
  193
+      ENV["RAILS_ENV"] = "development"
  194
+      capture(:stdout) do
  195
+        Dir.chdir(app_path){ `bundle exec rake assets:precompile` }
  196
+      end
  197
+
  198
+      # Create file after of precompile
  199
+      app_file "app/assets/javascripts/app.js", "alert();"
  200
+
  201
+      require "#{app_path}/config/environment"
  202
+      class ::PostsController < ActionController::Base ; end
  203
+
  204
+      get '/posts'
  205
+      assert_match(/AssetNotPrecompiledError/, last_response.body)
  206
+      assert_match(/app.js isn't precompiled/, last_response.body)
  207
+    end
  208
+
183 209
     test "precompile appends the md5 hash to files referenced with asset_path and run in the provided RAILS_ENV" do
184 210
       app_file "app/assets/stylesheets/application.css.erb", "<%= asset_path('rails.png') %>"
185 211
       # digest is default in false, we must enable it for test environment

0 notes on commit 9bc0082

Please sign in to comment.
Something went wrong with that request. Please try again.