aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--actionpack/lib/sprockets/assets.rake8
-rw-r--r--railties/test/application/assets_test.rb26
2 files changed, 23 insertions, 11 deletions
diff --git a/actionpack/lib/sprockets/assets.rake b/actionpack/lib/sprockets/assets.rake
index 50af88c44f..9b2646b0a2 100644
--- a/actionpack/lib/sprockets/assets.rake
+++ b/actionpack/lib/sprockets/assets.rake
@@ -3,9 +3,9 @@ namespace :assets do
task :precompile do
# We need to do this dance because RAILS_GROUPS is used
# too early in the boot process and changing here is already too late.
- if ENV["RAILS_GROUPS"].to_s.empty?
- ENV["RAILS_GROUPS"] = "assets"
- ENV["RAILS_ENV"] ||= "production"
+ if ENV["RAILS_GROUPS"].to_s.empty? || ENV["RAILS_ENV"].to_s.empty?
+ ENV["RAILS_GROUPS"] ||= "assets"
+ ENV["RAILS_ENV"] ||= "production"
Kernel.exec $0, *ARGV
else
Rake::Task["environment"].invoke
@@ -24,4 +24,4 @@ namespace :assets do
public_asset_path = Rails.public_path + assets.prefix
rm_rf public_asset_path, :secure => true
end
-end \ No newline at end of file
+end
diff --git a/railties/test/application/assets_test.rb b/railties/test/application/assets_test.rb
index 38dd3f5a3f..ccc03f8d9c 100644
--- a/railties/test/application/assets_test.rb
+++ b/railties/test/application/assets_test.rb
@@ -46,28 +46,40 @@ module ApplicationTests
assert defined?(Uglifier)
end
- test "precompile creates the file and gives it the original asset's content" do
+ test "precompile creates the filem, gives it the original asset's content and run in production as default" do
app_file "app/assets/javascripts/application.js", "alert();"
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
- files = Dir["#{app_path}/public/assets/application-*.js"]
- files << Dir["#{app_path}/public/assets/foo/application-*.js"].first
+ files = Dir["#{app_path}/public/assets/application-b29a188b3d9c74ef7cbb7ddf9e99f953.js"]
+ files << Dir["#{app_path}/public/assets/foo/application-b29a188b3d9c74ef7cbb7ddf9e99f953.js"].first
files.each do |file|
assert_not_nil file, "Expected application.js asset to be generated, but none found"
- assert_equal "alert();\n", File.read(file)
+ assert_equal "alert()", File.read(file)
end
end
- test "precompile appends the md5 hash to files referenced with asset_path" do
+ test "precompile appends the md5 hash to files referenced with asset_path and run in the provided RAILS_ENV" do
app_file "app/assets/stylesheets/application.css.erb", "<%= asset_path('rails.png') %>"
+ # capture(:stdout) do
+ Dir.chdir(app_path){ `bundle exec rake assets:precompile RAILS_ENV=test` }
+ # end
+ file = Dir["#{app_path}/public/assets/application-4bd8b7059c5336ec7ad515c9dbd59974.css"].first
+ assert_match /\/assets\/rails-([0-z]+)\.png/, File.read(file)
+ end
+
+ test "precompile appends the md5 hash to files referenced with asset_path and run in production as default even using RAILS_GROUPS=assets" do
+ app_file "app/assets/stylesheets/application.css.erb", "<%= asset_path('rails.png') %>"
+
+ ENV["RAILS_ENV"] = nil
capture(:stdout) do
- Dir.chdir(app_path){ `bundle exec rake assets:precompile` }
+ Dir.chdir(app_path){ `bundle exec rake assets:precompile RAILS_GROUPS=assets` }
end
- file = Dir["#{app_path}/public/assets/application-*.css"].first
+ file = Dir["#{app_path}/public/assets/application-8d301a938f1abfd789bbec87ed1ef770.css"].first
assert_match /\/assets\/rails-([0-z]+)\.png/, File.read(file)
end