aboutsummaryrefslogtreecommitdiffstats
path: root/railties/test/application/assets_test.rb
diff options
context:
space:
mode:
Diffstat (limited to 'railties/test/application/assets_test.rb')
-rw-r--r--railties/test/application/assets_test.rb44
1 files changed, 35 insertions, 9 deletions
diff --git a/railties/test/application/assets_test.rb b/railties/test/application/assets_test.rb
index 6fd8808aaa..2c9ebbf327 100644
--- a/railties/test/application/assets_test.rb
+++ b/railties/test/application/assets_test.rb
@@ -28,7 +28,7 @@ module ApplicationTests
end
test "assets routes have higher priority" do
- app_file "app/assets/javascripts/demo.js.erb", "<%= :alert %>();"
+ app_file "app/assets/javascripts/demo.js.erb", "a = <%= image_path('rails.png').inspect %>;"
app_file 'config/routes.rb', <<-RUBY
AppTemplate::Application.routes.draw do
@@ -39,7 +39,7 @@ module ApplicationTests
require "#{app_path}/config/environment"
get "/assets/demo.js"
- assert_match "alert()", last_response.body
+ assert_equal 'a = "/assets/rails.png";', last_response.body.strip
end
test "assets do not require compressors until it is used" do
@@ -247,7 +247,7 @@ module ApplicationTests
test "precompile properly refers files referenced with asset_path and 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
- add_to_config "config.assets.digest = true"
+ add_to_env_config "test", "config.assets.digest = true"
quietly do
Dir.chdir(app_path){ `bundle exec rake assets:precompile RAILS_ENV=test` }
@@ -289,16 +289,16 @@ module ApplicationTests
end
test "precompile should handle utf8 filenames" do
- app_file "app/assets/images/レイルズ.png", "not a image really"
+ filename = "レイルズ.png"
+ app_file "app/assets/images/#{filename}", "not a image really"
add_to_config "config.assets.precompile = [ /\.png$$/, /application.(css|js)$/ ]"
precompile!
- assert File.exists?("#{app_path}/public/assets/レイルズ.png")
-
- manifest = "#{app_path}/public/assets/manifest.yml"
+ require "#{app_path}/config/environment"
- assets = YAML.load_file(manifest)
- assert_equal "レイルズ.png", assets["レイルズ.png"]
+ get "/assets/#{URI.escape(filename)}"
+ assert_match "not a image really", last_response.body
+ assert File.exists?("#{app_path}/public/assets/#{filename}")
end
test "assets are cleaned up properly" do
@@ -425,6 +425,32 @@ module ApplicationTests
assert_equal 1, output.scan("enhancement").size
end
+ test "digested assets are not mistakenly removed" do
+ app_file "app/assets/application.js", "alert();"
+ add_to_config "config.assets.compile = true"
+ add_to_config "config.assets.digest = true"
+
+ quietly do
+ Dir.chdir(app_path){ `bundle exec rake assets:clean assets:precompile` }
+ end
+
+ files = Dir["#{app_path}/public/assets/application-*.js"]
+ assert_equal 1, files.length, "Expected digested application.js asset to be generated, but none found"
+ end
+
+ test "digested assets are removed from configured path" do
+ app_file "public/production_assets/application.js", "alert();"
+ add_to_env_config "production", "config.assets.prefix = 'production_assets'"
+
+ ENV["RAILS_ENV"] = nil
+ quietly do
+ Dir.chdir(app_path){ `bundle exec rake assets:clean` }
+ end
+
+ files = Dir["#{app_path}/public/production_assets/application.js"]
+ assert_equal 0, files.length, "Expected application.js asset to be removed, but still exists"
+ end
+
private
def app_with_assets_in_view