Skip to content

Commit

Permalink
Merge pull request rails#2448 from igrigorik/master
Browse files Browse the repository at this point in the history
Asset pipeline fixes: clear out tmp cache and use environment in digest generation
  • Loading branch information
josh committed Aug 8, 2011
2 parents 9e51400 + c0bfb5a commit eabc036
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 2 deletions.
2 changes: 1 addition & 1 deletion actionpack/lib/sprockets/assets.rake
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ namespace :assets do
end

desc "Remove compiled assets"
task :clean => :environment do
task :clean => [:environment, 'tmp:cache:clear'] do
assets = Rails.application.config.assets
public_asset_path = Rails.public_path + assets.prefix
rm_rf public_asset_path, :secure => true
Expand Down
1 change: 1 addition & 0 deletions actionpack/lib/sprockets/railtie.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ class Railtie < ::Rails::Railtie
app.assets = Sprockets::Environment.new(app.root.to_s) do |env|
env.static_root = File.join(app.root.join('public'), config.assets.prefix)
env.logger = ::Rails.logger
env.version = ::Rails.env + '-' + config.assets.version

if config.assets.cache_store != false
env.cache = ActiveSupport::Cache.lookup_store(config.assets.cache_store) || ::Rails.cache
Expand Down
13 changes: 13 additions & 0 deletions actionpack/test/template/sprockets_helper_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -205,4 +205,17 @@ def url_for(*args)
stubs(:asset_environment).returns(assets)
assert_match %r{/assets/style-[0-9a-f]+.css}, asset_path("style", "css")
end

test "alternate hash based on environment" do
assets = Sprockets::Environment.new
assets.version = 'development'
assets.append_path(FIXTURES.join("sprockets/alternate/stylesheets"))
stubs(:asset_environment).returns(assets)
dev_path = asset_path("style", "css")

assets.version = 'production'
prod_path = asset_path("style", "css")

assert_not_equal prod_path, dev_path
end
end
2 changes: 1 addition & 1 deletion railties/test/application/assets_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ def app
Dir.chdir(app_path){ `bundle exec rake assets:clean` }
end

files = Dir["#{app_path}/public/assets/**/*"]
files = Dir["#{app_path}/public/assets/**/*", "#{app_path}/tmp/cache/*"]
assert_equal 0, files.length, "Expected no assets, but found #{files.join(', ')}"
end

Expand Down

0 comments on commit eabc036

Please sign in to comment.