Skip to content
This repository
Browse code

assets:precompile should not append asset digests when config.assets.…

…digest is false
  • Loading branch information...
commit 58b0c9734777a4610e812a48ee64881b4f88b107 1 parent b93c360
Sam Pohlenz authored September 01, 2011
9  actionpack/lib/sprockets/assets.rake
@@ -13,8 +13,7 @@ namespace :assets do
13 13
       # Ensure that action view is loaded and the appropriate sprockets hooks get executed
14 14
       ActionView::Base
15 15
 
16  
-      # Always calculate digests and compile files
17  
-      Rails.application.config.assets.digest = true
  16
+      # Always compile files
18 17
       Rails.application.config.assets.compile = true
19 18
 
20 19
       config = Rails.application.config
@@ -32,8 +31,10 @@ namespace :assets do
32 31
           end
33 32
 
34 33
           if asset = env.find_asset(logical_path)
35  
-            manifest[logical_path] = asset.digest_path
36  
-            filename = target.join(asset.digest_path)
  34
+            asset_path = config.assets.digest ? asset.digest_path : logical_path
  35
+            manifest[logical_path] = asset_path
  36
+            filename = target.join(asset_path)
  37
+
37 38
             mkdir_p filename.dirname
38 39
             asset.write_to(filename)
39 40
             asset.write_to("#{filename}.gz") if filename.to_s =~ /\.(css|js)$/
26  railties/test/application/assets_test.rb
@@ -67,6 +67,8 @@ def app
67 67
     test "precompile creates a manifest file with all the assets listed" do
68 68
       app_file "app/assets/stylesheets/application.css.erb", "<%= asset_path('rails.png') %>"
69 69
       app_file "app/assets/javascripts/application.js", "alert();"
  70
+      # digest is default in false, we must enable it for test environment
  71
+      app_file "config/initializers/compile.rb", "Rails.application.config.assets.digest = true"
70 72
 
71 73
       capture(:stdout) do
72 74
         Dir.chdir(app_path){ `bundle exec rake assets:precompile` }
@@ -84,6 +86,8 @@ def app
84 86
       app_file "app/assets/javascripts/application.js", "alert();"
85 87
       FileUtils.mkdir "#{app_path}/shared"
86 88
       app_file "config/initializers/manifest.rb", "Rails.application.config.assets.manifest = '#{app_path}/shared'"
  89
+      # digest is default in false, we must enable it for test environment
  90
+      app_file "config/initializers/compile.rb", "Rails.application.config.assets.digest = true"
87 91
 
88 92
       capture(:stdout) do
89 93
         Dir.chdir(app_path){ `bundle exec rake assets:precompile` }
@@ -96,9 +100,12 @@ def app
96 100
       assert_match /application-([0-z]+)\.css/, assets["application.css"]
97 101
     end
98 102
 
  103
+
99 104
     test "the manifest file should be saved by default in the same assets folder" do
100 105
       app_file "app/assets/javascripts/application.js", "alert();"
101 106
       app_file "config/initializers/manifest.rb", "Rails.application.config.assets.prefix = '/x'"
  107
+      # digest is default in false, we must enable it for test environment
  108
+      app_file "config/initializers/compile.rb", "Rails.application.config.assets.digest = true"
102 109
 
103 110
       capture(:stdout) do
104 111
         Dir.chdir(app_path){ `bundle exec rake assets:precompile` }
@@ -109,6 +116,25 @@ def app
109 116
       assert_match /application-([0-z]+)\.js/, assets["application.js"]
110 117
     end
111 118
 
  119
+    test "precompile does not append asset digests when config.assets.digest is false" do
  120
+      app_file "app/assets/stylesheets/application.css.erb", "<%= asset_path('rails.png') %>"
  121
+      app_file "app/assets/javascripts/application.js", "alert();"
  122
+      app_file "config/initializers/compile.rb", "Rails.application.config.assets.digest = false"
  123
+
  124
+      capture(:stdout) do
  125
+        Dir.chdir(app_path){ `bundle exec rake assets:precompile` }
  126
+      end
  127
+
  128
+      assert File.exists?("#{app_path}/public/assets/application.js")
  129
+      assert File.exists?("#{app_path}/public/assets/application.css")
  130
+
  131
+      manifest = "#{app_path}/public/assets/manifest.yml"
  132
+
  133
+      assets = YAML.load_file(manifest)
  134
+      assert_equal "application.js", assets["application.js"]
  135
+      assert_equal "application.css", assets["application.css"]
  136
+    end
  137
+
112 138
     test "assets do not require any assets group gem when manifest file is present" do
113 139
       app_file "app/assets/javascripts/application.js", "alert();"
114 140
 

0 notes on commit 58b0c97

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