From b50394bf844d0520d5dca485b169bba87f6d009a Mon Sep 17 00:00:00 2001 From: Guillermo Iguaran Date: Thu, 15 Sep 2011 19:55:52 -0500 Subject: config.action_controller.asset_host shouldn't set to nil during precompile --- railties/test/application/assets_test.rb | 14 -------------- 1 file changed, 14 deletions(-) (limited to 'railties/test') diff --git a/railties/test/application/assets_test.rb b/railties/test/application/assets_test.rb index 959914bcea..dfd950aae3 100644 --- a/railties/test/application/assets_test.rb +++ b/railties/test/application/assets_test.rb @@ -270,20 +270,6 @@ module ApplicationTests assert_match(/\/assets\/rails-([0-z]+)\.png/, File.read(file)) end - test "precompile ignore asset_host" do - app_file "app/assets/javascripts/application.css.erb", "<%= asset_path 'rails.png' %>" - add_to_config "config.action_controller.asset_host = Proc.new { |source, request| 'http://www.example.com/' }" - - capture(:stdout) do - Dir.chdir(app_path){ `bundle exec rake assets:precompile` } - end - - file = Dir["#{app_path}/public/assets/application.css"].first - content = File.read(file) - assert_match(/\/assets\/rails.png/, content) - assert_no_match(/www\.example\.com/, content) - end - test "precompile should handle utf8 filenames" do app_file "app/assets/images/レイルズ.png", "not a image really" add_to_config "config.assets.precompile = [ /\.png$$/, /application.(css|js)$/ ]" -- cgit v1.2.3 From 6e63e029b335b1a5dfce43c20de27ca6fae29fa4 Mon Sep 17 00:00:00 2001 From: Alex Yakoubian Date: Wed, 14 Sep 2011 23:14:23 -0700 Subject: Default precompile regexp that properly matches application.js and application.css --- railties/test/application/assets_test.rb | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'railties/test') diff --git a/railties/test/application/assets_test.rb b/railties/test/application/assets_test.rb index dfd950aae3..a62ef1e70e 100644 --- a/railties/test/application/assets_test.rb +++ b/railties/test/application/assets_test.rb @@ -68,6 +68,10 @@ module ApplicationTests test "precompile application.js and application.css and all other files not ending with .js or .css by default" do app_file "app/assets/javascripts/application.js", "alert();" app_file "app/assets/stylesheets/application.css", "body{}" + + app_file "app/assets/javascripts/someapplication.js", "alert();" + app_file "app/assets/stylesheets/someapplication.css", "body{}" + app_file "app/assets/javascripts/something.min.js", "alert();" app_file "app/assets/stylesheets/something.min.css", "body{}" @@ -87,8 +91,13 @@ module ApplicationTests images_should_compile.each do |filename| assert File.exists?("#{app_path}/public/assets/#{filename}") end + assert File.exists?("#{app_path}/public/assets/application.js") assert File.exists?("#{app_path}/public/assets/application.css") + + assert !File.exists?("#{app_path}/public/assets/someapplication.js") + assert !File.exists?("#{app_path}/public/assets/someapplication.css") + assert !File.exists?("#{app_path}/public/assets/something.min.js") assert !File.exists?("#{app_path}/public/assets/something.min.css") end -- cgit v1.2.3 From 9d46823b5d00e78c6ffaaae731a9a7acf6bb2b14 Mon Sep 17 00:00:00 2001 From: Terence Lee Date: Thu, 22 Sep 2011 12:03:59 -0500 Subject: set env to let rails know we're precompiling --- railties/test/application/assets_test.rb | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'railties/test') diff --git a/railties/test/application/assets_test.rb b/railties/test/application/assets_test.rb index a62ef1e70e..c4a24f0f73 100644 --- a/railties/test/application/assets_test.rb +++ b/railties/test/application/assets_test.rb @@ -102,6 +102,15 @@ module ApplicationTests assert !File.exists?("#{app_path}/public/assets/something.min.css") end + test "precompile sets flag notifying rails its precompiling" do + compile = < Date: Sat, 24 Sep 2011 01:56:49 +0200 Subject: `rake assets:precompile` loads the application but does not initialize it. To the app developer, this means configuration add in config/initializers/* will not be executed. Plugins developers need to special case their initializers that are meant to be run in the assets group by adding :group => :assets. Conflicts: railties/CHANGELOG railties/test/application/assets_test.rb --- railties/test/application/assets_test.rb | 110 ++++++++++++++++++++----------- railties/test/initializable_test.rb | 2 +- railties/test/isolation/abstract_unit.rb | 9 +++ 3 files changed, 82 insertions(+), 39 deletions(-) (limited to 'railties/test') diff --git a/railties/test/application/assets_test.rb b/railties/test/application/assets_test.rb index c4a24f0f73..fb570d8f47 100644 --- a/railties/test/application/assets_test.rb +++ b/railties/test/application/assets_test.rb @@ -21,6 +21,12 @@ module ApplicationTests @app ||= Rails.application end + def precompile! + capture(:stdout) do + Dir.chdir(app_path){ `bundle exec rake assets:precompile` } + end + end + test "assets routes have higher priority" do app_file "app/assets/javascripts/demo.js.erb", "<%= :alert %>();" @@ -38,7 +44,7 @@ module ApplicationTests test "assets do not require compressors until it is used" do app_file "app/assets/javascripts/demo.js.erb", "<%= :alert %>();" - app_file "config/initializers/compile.rb", "Rails.application.config.assets.compile = true" + add_to_env_config "production", "config.assets.compile = true" ENV["RAILS_ENV"] = "production" require "#{app_path}/config/environment" @@ -54,9 +60,8 @@ module ApplicationTests app_file "app/assets/javascripts/foo/application.js", "alert();" ENV["RAILS_ENV"] = nil - capture(:stdout) do - Dir.chdir(app_path){ `bundle exec rake assets:precompile` } - end + precompile! + files = Dir["#{app_path}/public/assets/application-*.js"] files << Dir["#{app_path}/public/assets/foo/application-*.js"].first files.each do |file| @@ -80,13 +85,12 @@ module ApplicationTests "happy.happy.face.png", "happy", "happy.face", "-happyface", "-happy.png", "-happy.face.png", "_happyface", "_happy.face.png", "_happy.png"] + images_should_compile.each do |filename| app_file "app/assets/images/#{filename}", "happy" end - capture(:stdout) do - Dir.chdir(app_path){ `bundle exec rake assets:precompile` } - end + precompile! images_should_compile.each do |filename| assert File.exists?("#{app_path}/public/assets/#{filename}") @@ -103,11 +107,12 @@ module ApplicationTests end test "precompile sets flag notifying rails its precompiling" do - compile = < :assets do + raise "ENV RAILS_ASSETS_PRECOMPILE not set" unless ENV["RAILS_ASSETS_PRECOMPILE"] + end + RUBY + precompile! assert $?.success? end @@ -127,9 +132,7 @@ COMPILE # digest is default in false, we must enable it for test environment add_to_config "config.assets.digest = true" - capture(:stdout) do - Dir.chdir(app_path){ `bundle exec rake assets:precompile` } - end + precompile! manifest = "#{app_path}/public/assets/manifest.yml" @@ -146,9 +149,7 @@ COMPILE add_to_config "config.assets.manifest = '#{app_path}/shared'" FileUtils.mkdir "#{app_path}/shared" - capture(:stdout) do - Dir.chdir(app_path){ `bundle exec rake assets:precompile` } - end + precompile! manifest = "#{app_path}/shared/manifest.yml" @@ -164,9 +165,7 @@ COMPILE add_to_config "config.assets.digest = true" add_to_config "config.assets.prefix = '/x'" - capture(:stdout) do - Dir.chdir(app_path){ `bundle exec rake assets:precompile` } - end + precompile! manifest = "#{app_path}/public/x/manifest.yml" assets = YAML.load_file(manifest) @@ -178,9 +177,7 @@ COMPILE app_file "app/assets/javascripts/application.js", "alert();" add_to_config "config.assets.digest = false" - capture(:stdout) do - Dir.chdir(app_path){ `bundle exec rake assets:precompile` } - end + precompile! assert File.exists?("#{app_path}/public/assets/application.js") assert File.exists?("#{app_path}/public/assets/application.css") @@ -194,12 +191,11 @@ COMPILE test "assets do not require any assets group gem when manifest file is present" do app_file "app/assets/javascripts/application.js", "alert();" - app_file "config/initializers/serve_static_assets.rb", "Rails.application.config.serve_static_assets = true" + add_to_env_config "production", "config.serve_static_assets = true" ENV["RAILS_ENV"] = "production" - capture(:stdout) do - Dir.chdir(app_path){ `bundle exec rake assets:precompile` } - end + precompile! + manifest = "#{app_path}/public/assets/manifest.yml" assets = YAML.load_file(manifest) asset_path = assets["application.js"] @@ -223,9 +219,7 @@ COMPILE RUBY ENV["RAILS_ENV"] = "production" - capture(:stdout) do - Dir.chdir(app_path){ `bundle exec rake assets:precompile` } - end + precompile! # Create file after of precompile app_file "app/assets/javascripts/app.js", "alert();" @@ -249,9 +243,7 @@ COMPILE RUBY ENV["RAILS_ENV"] = "development" - capture(:stdout) do - Dir.chdir(app_path){ `bundle exec rake assets:precompile` } - end + precompile! # Create file after of precompile app_file "app/assets/javascripts/app.js", "alert();" @@ -292,10 +284,7 @@ COMPILE app_file "app/assets/images/レイルズ.png", "not a image really" add_to_config "config.assets.precompile = [ /\.png$$/, /application.(css|js)$/ ]" - capture(:stdout) do - Dir.chdir(app_path){ `bundle exec rake assets:precompile` } - end - + precompile! assert File.exists?("#{app_path}/public/assets/レイルズ.png") manifest = "#{app_path}/public/assets/manifest.yml" @@ -367,5 +356,50 @@ COMPILE assert_match "alert();", last_response.body assert_equal 200, last_response.status end + + test "assets are concatenated when debug is off and compile is off either if debug_assets param is provided" do + app_with_assets_in_view + + # config.assets.debug and config.assets.compile are false for production environment + ENV["RAILS_ENV"] = "production" + precompile! + + require "#{app_path}/config/environment" + + class ::PostsController < ActionController::Base ; end + + # the debug_assets params isn't used if compile is off + get '/posts?debug_assets=true' + assert_match(/