Permalink
Browse files

rake assets:precompile executes in production environment as default …

…if RAILS_ENV was not provided
  • Loading branch information...
1 parent 81151eb commit 28e250e645e7b36bebb91005e66cb54be66ba928 @spastorino spastorino committed Aug 15, 2011
Showing with 23 additions and 11 deletions.
  1. +4 −4 actionpack/lib/sprockets/assets.rake
  2. +19 −7 railties/test/application/assets_test.rb
@@ -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
+end
@@ -46,28 +46,40 @@ def app
assert defined?(Uglifier)
end
- test "assets are compiled properly" do
+ test "precompile creates the file, 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

0 comments on commit 28e250e

Please sign in to comment.