aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--actionpack/lib/sprockets/assets.rake12
-rw-r--r--railties/test/application/assets_test.rb14
2 files changed, 22 insertions, 4 deletions
diff --git a/actionpack/lib/sprockets/assets.rake b/actionpack/lib/sprockets/assets.rake
index 43405f3db9..f3547359cd 100644
--- a/actionpack/lib/sprockets/assets.rake
+++ b/actionpack/lib/sprockets/assets.rake
@@ -62,11 +62,11 @@ namespace :assets do
ruby_rake_task("assets:precompile:nondigest", false) if Rails.application.config.assets.digest
end
- task :primary => ["assets:environment", "tmp:cache:clear"] do
+ task :primary => ["assets:cache:clean"] do
internal_precompile
end
- task :nondigest => ["assets:environment", "tmp:cache:clear"] do
+ task :nondigest => ["assets:cache:clean"] do
internal_precompile(false)
end
end
@@ -77,13 +77,19 @@ namespace :assets do
end
namespace :clean do
- task :all => ["assets:environment", "tmp:cache:clear"] do
+ task :all => ["assets:cache:clean"] do
config = Rails.application.config
public_asset_path = File.join(Rails.public_path, config.assets.prefix)
rm_rf public_asset_path, :secure => true
end
end
+ namespace :cache do
+ task :clean => ["assets:environment"] do
+ Rails.application.assets.cache.clear
+ end
+ end
+
task :environment do
if Rails.application.config.assets.initialize_on_precompile
Rake::Task["environment"].invoke
diff --git a/railties/test/application/assets_test.rb b/railties/test/application/assets_test.rb
index 460c921ec3..01156e1b83 100644
--- a/railties/test/application/assets_test.rb
+++ b/railties/test/application/assets_test.rb
@@ -314,7 +314,7 @@ module ApplicationTests
Dir.chdir(app_path){ `bundle exec rake assets:clean` }
end
- files = Dir["#{app_path}/public/assets/**/*", "#{app_path}/tmp/cache/*"]
+ files = Dir["#{app_path}/public/assets/**/*", "#{app_path}/tmp/cache/assets/*"]
assert_equal 0, files.length, "Expected no assets, but found #{files.join(', ')}"
end
@@ -492,6 +492,18 @@ module ApplicationTests
assert_match 'src="/sub/uri/assets/rails.png"', File.read("#{app_path}/public/assets/app.js")
end
+ test "assets:cache:clean should clean cache" do
+ ENV["RAILS_ENV"] = "production"
+ precompile!
+
+ quietly do
+ Dir.chdir(app_path){ `bundle exec rake assets:cache:clean` }
+ end
+
+ require "#{app_path}/config/environment"
+ assert_equal 0, Dir.entries(Rails.application.assets.cache.cache_path).size - 2 # reject [".", ".."]
+ end
+
private
def app_with_assets_in_view