sprockets-rails 0.0.1 → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (48) hide show
  1. data/MIT-LICENSE +1 -1
  2. data/README.rdoc +3 -0
  3. data/Rakefile +15 -31
  4. data/lib/sprockets/rails/bootstrap.rb +41 -0
  5. data/lib/sprockets/rails/compressors.rb +87 -0
  6. data/lib/sprockets/rails/helpers/isolated_helper.rb +15 -0
  7. data/lib/sprockets/rails/helpers/rails_helper.rb +169 -0
  8. data/lib/sprockets/rails/helpers.rb +8 -0
  9. data/lib/sprockets/rails/railtie.rb +64 -0
  10. data/lib/sprockets/rails/static_compiler.rb +64 -0
  11. data/lib/sprockets/rails/version.rb +5 -0
  12. data/lib/sprockets-rails.rb +5 -6
  13. data/lib/tasks/assets.rake +105 -0
  14. data/test/abstract_unit.rb +145 -0
  15. data/test/assets_debugging_test.rb +65 -0
  16. data/test/assets_test.rb +532 -0
  17. data/test/fixtures/alternate/stylesheets/style.css +1 -0
  18. data/{generators/sprockets_rails/templates/application.js → test/fixtures/app/fonts/dir/font.ttf} +0 -0
  19. data/test/fixtures/app/fonts/font.ttf +0 -0
  20. data/test/fixtures/app/images/logo.png +0 -0
  21. data/test/fixtures/app/javascripts/application.js +1 -0
  22. data/test/fixtures/app/javascripts/dir/xmlhr.js +0 -0
  23. data/test/fixtures/app/javascripts/extra.js +0 -0
  24. data/test/fixtures/app/javascripts/xmlhr.js +0 -0
  25. data/test/fixtures/app/stylesheets/application.css +1 -0
  26. data/test/fixtures/app/stylesheets/dir/style.css +0 -0
  27. data/test/fixtures/app/stylesheets/extra.css +0 -0
  28. data/test/fixtures/app/stylesheets/style.css +0 -0
  29. data/test/sprockets_compressors_test.rb +27 -0
  30. data/test/sprockets_helper_test.rb +345 -0
  31. data/test/sprockets_helper_with_routes_test.rb +60 -0
  32. data/test/test_helper.rb +84 -0
  33. metadata +116 -65
  34. data/.gitignore +0 -5
  35. data/README.textile +0 -91
  36. data/VERSION +0 -1
  37. data/config/sprockets.yml +0 -10
  38. data/generators/sprockets_rails/sprockets_rails_generator.rb +0 -13
  39. data/init.rb +0 -1
  40. data/install.rb +0 -13
  41. data/lib/sprocket.rb +0 -74
  42. data/lib/sprockets_application.rb +0 -8
  43. data/lib/sprockets_controller.rb +0 -12
  44. data/lib/sprockets_helper.rb +0 -9
  45. data/recipes/sprockets_tasks.rb +0 -17
  46. data/sprockets-rails.gemspec +0 -60
  47. data/tasks/sprockets_tasks.rake +0 -27
  48. data/test/sprockets_test.rb +0 -8
@@ -0,0 +1,532 @@
1
+ # -*- coding: utf-8 -*-
2
+ require File.expand_path(File.dirname(__FILE__) + "/abstract_unit")
3
+ require 'rack/test'
4
+
5
+ module ApplicationTests
6
+ class AssetsTest < ActiveSupport::TestCase
7
+ include ActiveSupport::Testing::Isolation
8
+ include Rack::Test::Methods
9
+
10
+ def setup
11
+ build_app(:initializers => true)
12
+ boot_rails
13
+ end
14
+
15
+ def teardown
16
+ teardown_app
17
+ end
18
+
19
+ def precompile!
20
+ quietly do
21
+ Dir.chdir(app_path){ `bundle exec rake assets:precompile` }
22
+ end
23
+ end
24
+
25
+ test "assets routes have higher priority" do
26
+ app_file "app/assets/javascripts/demo.js.erb", "a = <%= image_path('rails.png').inspect %>;"
27
+
28
+ app_file 'config/routes.rb', <<-RUBY
29
+ AppTemplate::Application.routes.draw do
30
+ match '*path', :to => lambda { |env| [200, { "Content-Type" => "text/html" }, "Not an asset"] }
31
+ end
32
+ RUBY
33
+
34
+ require "#{app_path}/config/environment"
35
+
36
+ get "/assets/demo.js"
37
+ assert_equal 'a = "/assets/rails.png";', last_response.body.strip
38
+ end
39
+
40
+ test "assets do not require compressors until it is used" do
41
+ app_file "app/assets/javascripts/demo.js.erb", "<%= :alert %>();"
42
+ add_to_env_config "production", "config.assets.compile = true"
43
+
44
+ ENV["RAILS_ENV"] = "production"
45
+ require "#{app_path}/config/environment"
46
+
47
+ assert !defined?(Uglifier)
48
+ get "/assets/demo.js"
49
+ assert_match "alert()", last_response.body
50
+ assert defined?(Uglifier)
51
+ end
52
+
53
+ test "precompile creates the file, gives it the original asset's content and run in production as default" do
54
+ app_file "app/assets/javascripts/application.js", "alert();"
55
+ app_file "app/assets/javascripts/foo/application.js", "alert();"
56
+
57
+ ENV["RAILS_ENV"] = nil
58
+ precompile!
59
+
60
+ files = Dir["#{app_path}/public/assets/application-*.js"]
61
+ files << Dir["#{app_path}/public/assets/application.js"].first
62
+ files << Dir["#{app_path}/public/assets/foo/application-*.js"].first
63
+ files << Dir["#{app_path}/public/assets/foo/application.js"].first
64
+ files.each do |file|
65
+ assert_not_nil file, "Expected application.js asset to be generated, but none found"
66
+ assert_equal "alert();", File.read(file)
67
+ end
68
+ end
69
+
70
+ test "precompile application.js and application.css and all other non JS/CSS files" do
71
+ app_file "app/assets/javascripts/application.js", "alert();"
72
+ app_file "app/assets/stylesheets/application.css", "body{}"
73
+
74
+ app_file "app/assets/javascripts/someapplication.js", "alert();"
75
+ app_file "app/assets/stylesheets/someapplication.css", "body{}"
76
+
77
+ app_file "app/assets/javascripts/something.min.js", "alert();"
78
+ app_file "app/assets/stylesheets/something.min.css", "body{}"
79
+
80
+ app_file "app/assets/javascripts/something.else.js.erb", "alert();"
81
+ app_file "app/assets/stylesheets/something.else.css.erb", "body{}"
82
+
83
+ images_should_compile = ["a.png", "happyface.png", "happy_face.png", "happy.face.png",
84
+ "happy-face.png", "happy.happy_face.png", "happy_happy.face.png",
85
+ "happy.happy.face.png", "happy", "happy.face", "-happyface",
86
+ "-happy.png", "-happy.face.png", "_happyface", "_happy.face.png",
87
+ "_happy.png"]
88
+
89
+ images_should_compile.each do |filename|
90
+ app_file "app/assets/images/#{filename}", "happy"
91
+ end
92
+
93
+ precompile!
94
+
95
+ images_should_compile.each do |filename|
96
+ assert File.exists?("#{app_path}/public/assets/#{filename}")
97
+ end
98
+
99
+ assert File.exists?("#{app_path}/public/assets/application.js")
100
+ assert File.exists?("#{app_path}/public/assets/application.css")
101
+
102
+ assert !File.exists?("#{app_path}/public/assets/someapplication.js")
103
+ assert !File.exists?("#{app_path}/public/assets/someapplication.css")
104
+
105
+ assert !File.exists?("#{app_path}/public/assets/something.min.js")
106
+ assert !File.exists?("#{app_path}/public/assets/something.min.css")
107
+
108
+ assert !File.exists?("#{app_path}/public/assets/something.else.js")
109
+ assert !File.exists?("#{app_path}/public/assets/something.else.css")
110
+ end
111
+
112
+ test "asset pipeline should use a Sprockets::Index when config.assets.digest is true" do
113
+ add_to_config "config.assets.digest = true"
114
+ add_to_config "config.action_controller.perform_caching = false"
115
+
116
+ ENV["RAILS_ENV"] = "production"
117
+ require "#{app_path}/config/environment"
118
+
119
+ assert_equal Sprockets::Index, Rails.application.assets.class
120
+ end
121
+
122
+ test "precompile creates a manifest file with all the assets listed" do
123
+ app_file "app/assets/stylesheets/application.css.erb", "<%= asset_path('rails.png') %>"
124
+ app_file "app/assets/javascripts/application.js", "alert();"
125
+ # digest is default in false, we must enable it for test environment
126
+ add_to_config "config.assets.digest = true"
127
+
128
+ precompile!
129
+ manifest = "#{app_path}/public/assets/manifest.yml"
130
+
131
+ assets = YAML.load_file(manifest)
132
+ assert_match(/application-([0-z]+)\.js/, assets["application.js"])
133
+ assert_match(/application-([0-z]+)\.css/, assets["application.css"])
134
+ end
135
+
136
+ test "precompile creates a manifest file in a custom path with all the assets listed" do
137
+ app_file "app/assets/stylesheets/application.css.erb", "<%= asset_path('rails.png') %>"
138
+ app_file "app/assets/javascripts/application.js", "alert();"
139
+ # digest is default in false, we must enable it for test environment
140
+ add_to_config "config.assets.digest = true"
141
+ add_to_config "config.assets.manifest = '#{app_path}/shared'"
142
+
143
+ precompile!
144
+ manifest = "#{app_path}/shared/manifest.yml"
145
+
146
+ assets = YAML.load_file(manifest)
147
+ assert_match(/application-([0-z]+)\.js/, assets["application.js"])
148
+ assert_match(/application-([0-z]+)\.css/, assets["application.css"])
149
+ end
150
+
151
+ test "the manifest file should be saved by default in the same assets folder" do
152
+ app_file "app/assets/javascripts/application.js", "alert();"
153
+ # digest is default in false, we must enable it for test environment
154
+ add_to_config "config.assets.digest = true"
155
+ add_to_config "config.assets.prefix = '/x'"
156
+
157
+ precompile!
158
+
159
+ manifest = "#{app_path}/public/x/manifest.yml"
160
+ assets = YAML.load_file(manifest)
161
+ assert_match(/application-([0-z]+)\.js/, assets["application.js"])
162
+ end
163
+
164
+ test "precompile does not append asset digests when config.assets.digest is false" do
165
+ app_file "app/assets/stylesheets/application.css.erb", "<%= asset_path('rails.png') %>"
166
+ app_file "app/assets/javascripts/application.js", "alert();"
167
+ add_to_config "config.assets.digest = false"
168
+
169
+ precompile!
170
+
171
+ assert File.exists?("#{app_path}/public/assets/application.js")
172
+ assert File.exists?("#{app_path}/public/assets/application.css")
173
+
174
+ manifest = "#{app_path}/public/assets/manifest.yml"
175
+
176
+ assets = YAML.load_file(manifest)
177
+ assert_equal "application.js", assets["application.js"]
178
+ assert_equal "application.css", assets["application.css"]
179
+ end
180
+
181
+ test "assets do not require any assets group gem when manifest file is present" do
182
+ app_file "app/assets/javascripts/application.js", "alert();"
183
+ add_to_env_config "production", "config.serve_static_assets = true"
184
+
185
+ ENV["RAILS_ENV"] = "production"
186
+ precompile!
187
+
188
+ manifest = "#{app_path}/public/assets/manifest.yml"
189
+ assets = YAML.load_file(manifest)
190
+ asset_path = assets["application.js"]
191
+
192
+ require "#{app_path}/config/environment"
193
+
194
+ # Checking if Uglifier is defined we can know if Sprockets was reached or not
195
+ assert !defined?(Uglifier)
196
+ get "/assets/#{asset_path}"
197
+ assert_match "alert()", last_response.body
198
+ assert !defined?(Uglifier)
199
+ end
200
+
201
+ test "assets raise AssetNotPrecompiledError when manifest file is present and requested file isn't precompiled" do
202
+ app_file "app/views/posts/index.html.erb", "<%= javascript_include_tag 'app' %>"
203
+
204
+ app_file "config/routes.rb", <<-RUBY
205
+ AppTemplate::Application.routes.draw do
206
+ match '/posts', :to => "posts#index"
207
+ end
208
+ RUBY
209
+
210
+ ENV["RAILS_ENV"] = "production"
211
+ precompile!
212
+
213
+ # Create file after of precompile
214
+ app_file "app/assets/javascripts/app.js", "alert();"
215
+
216
+ require "#{app_path}/config/environment"
217
+ class ::PostsController < ActionController::Base
218
+ def show_detailed_exceptions?() true end
219
+ end
220
+
221
+ get '/posts'
222
+ assert_match(/AssetNotPrecompiledError/, last_response.body)
223
+ assert_match(/app.js isn't precompiled/, last_response.body)
224
+ end
225
+
226
+ test "assets raise AssetNotPrecompiledError when manifest file is present and requested file isn't precompiled if digest is disabled" do
227
+ app_file "app/views/posts/index.html.erb", "<%= javascript_include_tag 'app' %>"
228
+ add_to_config "config.assets.compile = false"
229
+
230
+ app_file "config/routes.rb", <<-RUBY
231
+ AppTemplate::Application.routes.draw do
232
+ match '/posts', :to => "posts#index"
233
+ end
234
+ RUBY
235
+
236
+ ENV["RAILS_ENV"] = "development"
237
+ precompile!
238
+
239
+ # Create file after of precompile
240
+ app_file "app/assets/javascripts/app.js", "alert();"
241
+
242
+ require "#{app_path}/config/environment"
243
+ class ::PostsController < ActionController::Base ; end
244
+
245
+ get '/posts'
246
+ assert_match(/AssetNotPrecompiledError/, last_response.body)
247
+ assert_match(/app.js isn't precompiled/, last_response.body)
248
+ end
249
+
250
+ test "precompile properly refers files referenced with asset_path and and run in the provided RAILS_ENV" do
251
+ app_file "app/assets/stylesheets/application.css.erb", "<%= asset_path('rails.png') %>"
252
+ # digest is default in false, we must enable it for test environment
253
+ add_to_env_config "test", "config.assets.digest = true"
254
+
255
+ quietly do
256
+ Dir.chdir(app_path){ `bundle exec rake assets:precompile RAILS_ENV=test` }
257
+ end
258
+ file = Dir["#{app_path}/public/assets/application.css"].first
259
+ assert_match(/\/assets\/rails\.png/, File.read(file))
260
+ file = Dir["#{app_path}/public/assets/application-*.css"].first
261
+ assert_match(/\/assets\/rails-([0-z]+)\.png/, File.read(file))
262
+ end
263
+
264
+ test "precompile shouldn't use the digests present in manifest.yml" do
265
+ app_file "app/assets/stylesheets/application.css.erb", "<%= asset_path('rails.png') %>"
266
+
267
+ ENV["RAILS_ENV"] = "production"
268
+ precompile!
269
+
270
+ manifest = "#{app_path}/public/assets/manifest.yml"
271
+ assets = YAML.load_file(manifest)
272
+ asset_path = assets["application.css"]
273
+
274
+ app_file "app/assets/images/rails.png", "image changed"
275
+
276
+ precompile!
277
+ assets = YAML.load_file(manifest)
278
+
279
+ assert_not_equal asset_path, assets["application.css"]
280
+ end
281
+
282
+ test "precompile appends the md5 hash to files referenced with asset_path and run in production as default even using RAILS_GROUPS=assets" do
283
+ app_file "app/assets/stylesheets/application.css.erb", "<%= asset_path('rails.png') %>"
284
+ add_to_config "config.assets.compile = true"
285
+
286
+ ENV["RAILS_ENV"] = nil
287
+ quietly do
288
+ Dir.chdir(app_path){ `bundle exec rake assets:precompile RAILS_GROUPS=assets` }
289
+ end
290
+ file = Dir["#{app_path}/public/assets/application-*.css"].first
291
+ assert_match(/\/assets\/rails-([0-z]+)\.png/, File.read(file))
292
+ end
293
+
294
+ test "precompile should handle utf8 filenames" do
295
+ filename = "レイルズ.png"
296
+ app_file "app/assets/images/#{filename}", "not a image really"
297
+ add_to_config "config.assets.precompile = [ /\.png$/, /application.(css|js)$/ ]"
298
+
299
+ precompile!
300
+ require "#{app_path}/config/environment"
301
+
302
+ get "/assets/#{URI.parser.escape(filename)}"
303
+ assert_match "not a image really", last_response.body
304
+ assert File.exists?("#{app_path}/public/assets/#{filename}")
305
+ end
306
+
307
+ test "assets are cleaned up properly" do
308
+ app_file "public/assets/application.js", "alert();"
309
+ app_file "public/assets/application.css", "a { color: green; }"
310
+ app_file "public/assets/subdir/broken.png", "not really an image file"
311
+
312
+ quietly do
313
+ Dir.chdir(app_path){ `bundle exec rake assets:clean` }
314
+ end
315
+
316
+ files = Dir["#{app_path}/public/assets/**/*", "#{app_path}/tmp/cache/assets/*"]
317
+ assert_equal 0, files.length, "Expected no assets, but found #{files.join(', ')}"
318
+ end
319
+
320
+ test "assets routes are not drawn when compilation is disabled" do
321
+ app_file "app/assets/javascripts/demo.js.erb", "<%= :alert %>();"
322
+ add_to_config "config.assets.compile = false"
323
+
324
+ ENV["RAILS_ENV"] = "production"
325
+ require "#{app_path}/config/environment"
326
+
327
+ get "/assets/demo.js"
328
+ assert_equal 404, last_response.status
329
+ end
330
+
331
+ test "does not stream session cookies back" do
332
+ app_file "app/assets/javascripts/demo.js.erb", "<%= :alert %>();"
333
+
334
+ app_file "config/routes.rb", <<-RUBY
335
+ AppTemplate::Application.routes.draw do
336
+ match '/omg', :to => "omg#index"
337
+ end
338
+ RUBY
339
+
340
+ require "#{app_path}/config/environment"
341
+
342
+ class ::OmgController < ActionController::Base
343
+ def index
344
+ flash[:cool_story] = true
345
+ render :text => "ok"
346
+ end
347
+ end
348
+
349
+ get "/omg"
350
+ assert_equal 'ok', last_response.body
351
+
352
+ get "/assets/demo.js"
353
+ assert_match "alert()", last_response.body
354
+ assert_equal nil, last_response.headers["Set-Cookie"]
355
+ end
356
+
357
+ test "files in any assets/ directories are not added to Sprockets" do
358
+ %w[app lib vendor].each do |dir|
359
+ app_file "#{dir}/assets/#{dir}_test.erb", "testing"
360
+ end
361
+
362
+ app_file "app/assets/javascripts/demo.js", "alert();"
363
+
364
+ require "#{app_path}/config/environment"
365
+
366
+ get "/assets/demo.js"
367
+ assert_match "alert();", last_response.body
368
+ assert_equal 200, last_response.status
369
+ end
370
+
371
+ test "assets are concatenated when debug is off and compile is off either if debug_assets param is provided" do
372
+ app_with_assets_in_view
373
+
374
+ # config.assets.debug and config.assets.compile are false for production environment
375
+ ENV["RAILS_ENV"] = "production"
376
+ precompile!
377
+
378
+ require "#{app_path}/config/environment"
379
+
380
+ class ::PostsController < ActionController::Base ; end
381
+
382
+ # the debug_assets params isn't used if compile is off
383
+ get '/posts?debug_assets=true'
384
+ assert_match(/<script src="\/assets\/application-([0-z]+)\.js" type="text\/javascript"><\/script>/, last_response.body)
385
+ assert_no_match(/<script src="\/assets\/xmlhr-([0-z]+)\.js" type="text\/javascript"><\/script>/, last_response.body)
386
+ end
387
+
388
+ test "assets aren't concatened when compile is true is on and debug_assets params is true" do
389
+ app_with_assets_in_view
390
+ add_to_env_config "production", "config.assets.compile = true"
391
+ add_to_env_config "production", "config.assets.allow_debugging = true"
392
+
393
+ ENV["RAILS_ENV"] = "production"
394
+ require "#{app_path}/config/environment"
395
+
396
+ class ::PostsController < ActionController::Base ; end
397
+
398
+ get '/posts?debug_assets=true'
399
+ assert_match(/<script src="\/assets\/application-([0-z]+)\.js\?body=1" type="text\/javascript"><\/script>/, last_response.body)
400
+ assert_match(/<script src="\/assets\/xmlhr-([0-z]+)\.js\?body=1" type="text\/javascript"><\/script>/, last_response.body)
401
+ end
402
+
403
+ test "assets can access model information when precompiling" do
404
+ app_file "app/models/post.rb", "class Post; end"
405
+ app_file "app/assets/javascripts/application.js", "//= require_tree ."
406
+ app_file "app/assets/javascripts/xmlhr.js.erb", "<%= Post.name %>"
407
+
408
+ add_to_config "config.assets.digest = false"
409
+ precompile!
410
+ assert_equal "Post;\n", File.read("#{app_path}/public/assets/application.js")
411
+ end
412
+
413
+ test "assets can't access model information when precompiling if not initializing the app" do
414
+ app_file "app/models/post.rb", "class Post; end"
415
+ app_file "app/assets/javascripts/application.js", "//= require_tree ."
416
+ app_file "app/assets/javascripts/xmlhr.js.erb", "<%= defined?(Post) || :NoPost %>"
417
+
418
+ add_to_config "config.assets.digest = false"
419
+ add_to_config "config.assets.initialize_on_precompile = false"
420
+
421
+ precompile!
422
+ assert_equal "NoPost;\n", File.read("#{app_path}/public/assets/application.js")
423
+ end
424
+
425
+ test "initialization on the assets group should set assets_dir" do
426
+ require "#{app_path}/config/application"
427
+ Rails.application.initialize!(:assets)
428
+ assert_not_nil Rails.application.config.action_controller.assets_dir
429
+ end
430
+
431
+ test "enhancements to assets:precompile should only run once" do
432
+ app_file "lib/tasks/enhance.rake", "Rake::Task['assets:precompile'].enhance { puts 'enhancement' }"
433
+ output = precompile!
434
+ assert_equal 1, output.scan("enhancement").size
435
+ end
436
+
437
+ test "digested assets are not mistakenly removed" do
438
+ app_file "app/assets/application.js", "alert();"
439
+ add_to_config "config.assets.compile = true"
440
+ add_to_config "config.assets.digest = true"
441
+
442
+ quietly do
443
+ Dir.chdir(app_path){ `bundle exec rake assets:clean assets:precompile` }
444
+ end
445
+
446
+ files = Dir["#{app_path}/public/assets/application-*.js"]
447
+ assert_equal 1, files.length, "Expected digested application.js asset to be generated, but none found"
448
+ end
449
+
450
+ test "digested assets are removed from configured path" do
451
+ app_file "public/production_assets/application.js", "alert();"
452
+ add_to_env_config "production", "config.assets.prefix = 'production_assets'"
453
+
454
+ ENV["RAILS_ENV"] = nil
455
+ quietly do
456
+ Dir.chdir(app_path){ `bundle exec rake assets:clean` }
457
+ end
458
+
459
+ files = Dir["#{app_path}/public/production_assets/application.js"]
460
+ assert_equal 0, files.length, "Expected application.js asset to be removed, but still exists"
461
+ end
462
+
463
+ test "asset urls should use the request's protocol by default" do
464
+ app_with_assets_in_view
465
+ add_to_config "config.asset_host = 'example.com'"
466
+ require "#{app_path}/config/environment"
467
+ class ::PostsController < ActionController::Base; end
468
+
469
+ get '/posts', {}, {'HTTPS'=>'off'}
470
+ assert_match('src="http://example.com/assets/application.js', last_response.body)
471
+ get '/posts', {}, {'HTTPS'=>'on'}
472
+ assert_match('src="https://example.com/assets/application.js', last_response.body)
473
+ end
474
+
475
+ test "asset urls should be protocol-relative if no request is in scope" do
476
+ app_file "app/assets/javascripts/image_loader.js.erb", 'var src="<%= image_path("rails.png") %>";'
477
+ add_to_config "config.assets.precompile = %w{image_loader.js}"
478
+ add_to_config "config.asset_host = 'example.com'"
479
+ precompile!
480
+
481
+ assert_match 'src="//example.com/assets/rails.png"', File.read("#{app_path}/public/assets/image_loader.js")
482
+ end
483
+
484
+ test "asset paths should use RAILS_RELATIVE_URL_ROOT by default" do
485
+ ENV["RAILS_RELATIVE_URL_ROOT"] = "/sub/uri"
486
+
487
+ app_file "app/assets/javascripts/app.js.erb", 'var src="<%= image_path("rails.png") %>";'
488
+ add_to_config "config.assets.precompile = %w{app.js}"
489
+ precompile!
490
+
491
+ assert_match 'src="/sub/uri/assets/rails.png"', File.read("#{app_path}/public/assets/app.js")
492
+ end
493
+
494
+ test "html assets are compiled when executing precompile" do
495
+ app_file "app/assets/pages/page.html.erb", "<%= javascript_include_tag :application %>"
496
+ ENV["RAILS_ENV"] = "production"
497
+ ENV["RAILS_GROUP"] = "assets"
498
+
499
+ quietly do
500
+ Dir.chdir(app_path){ `bundle exec rake assets:precompile` }
501
+ end
502
+
503
+ assert File.exists?("#{app_path}/public/assets/page.html")
504
+ end
505
+
506
+ test "assets:cache:clean should clean cache" do
507
+ ENV["RAILS_ENV"] = "production"
508
+ precompile!
509
+
510
+ quietly do
511
+ Dir.chdir(app_path){ `bundle exec rake assets:cache:clean` }
512
+ end
513
+
514
+ require "#{app_path}/config/environment"
515
+ assert_equal 0, Dir.entries(Rails.application.assets.cache.cache_path).size - 2 # reject [".", ".."]
516
+ end
517
+
518
+ private
519
+
520
+ def app_with_assets_in_view
521
+ app_file "app/assets/javascripts/application.js", "//= require_tree ."
522
+ app_file "app/assets/javascripts/xmlhr.js", "function f1() { alert(); }"
523
+ app_file "app/views/posts/index.html.erb", "<%= javascript_include_tag 'application' %>"
524
+
525
+ app_file "config/routes.rb", <<-RUBY
526
+ AppTemplate::Application.routes.draw do
527
+ match '/posts', :to => "posts#index"
528
+ end
529
+ RUBY
530
+ end
531
+ end
532
+ end
@@ -0,0 +1 @@
1
+ /* Different from other style.css */
File without changes
Binary file
@@ -0,0 +1 @@
1
+ //= require xmlhr
File without changes
File without changes
File without changes
@@ -0,0 +1 @@
1
+ /*= require style */
File without changes
File without changes
File without changes
@@ -0,0 +1,27 @@
1
+ require File.expand_path(File.dirname(__FILE__) + "/test_helper")
2
+
3
+ class CompressorsTest < ActiveSupport::TestCase
4
+ def test_register_css_compressor
5
+ Sprockets::Rails::Compressors.register_css_compressor(:null, Sprockets::Rails::NullCompressor)
6
+ compressor = Sprockets::Rails::Compressors.registered_css_compressor(:null)
7
+ assert_kind_of Sprockets::Rails::NullCompressor, compressor
8
+ end
9
+
10
+ def test_register_js_compressor
11
+ Sprockets::Rails::Compressors.register_js_compressor(:uglifier, 'Uglifier', :require => 'uglifier')
12
+ compressor = Sprockets::Rails::Compressors.registered_js_compressor(:uglifier)
13
+ assert_kind_of Uglifier, compressor
14
+ end
15
+
16
+ def test_register_default_css_compressor
17
+ Sprockets::Rails::Compressors.register_css_compressor(:null, Sprockets::Rails::NullCompressor, :default => true)
18
+ compressor = Sprockets::Rails::Compressors.registered_css_compressor(:default)
19
+ assert_kind_of Sprockets::Rails::NullCompressor, compressor
20
+ end
21
+
22
+ def test_register_default_js_compressor
23
+ Sprockets::Rails::Compressors.register_js_compressor(:null, Sprockets::Rails::NullCompressor, :default => true)
24
+ compressor = Sprockets::Rails::Compressors.registered_js_compressor(:default)
25
+ assert_kind_of Sprockets::Rails::NullCompressor, compressor
26
+ end
27
+ end