Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Include asset host in public path cache key. Clear cache between asse…

…t tag tests.

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@7617 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
  • Loading branch information...
commit 40f9fd39f6b471cb35b551b456f2c22d52f1b825 1 parent 605aadb
@jeremy jeremy authored
View
4 actionpack/lib/action_view/base.rb
@@ -223,6 +223,10 @@ module CompiledTemplates #:nodoc:
# Maps template paths / extensions to
@@cached_base_paths = {}
+ # Cache public asset paths
+ cattr_reader :computed_public_paths
+ @@computed_public_paths = {}
+
@@templates_requiring_setup = Set.new(%w(builder rxml rjs))
# Order of template handers checked by #file_exists? depending on the current #template_format
View
22 actionpack/lib/action_view/helpers/asset_tag_helper.rb
@@ -384,8 +384,12 @@ def file_exist?(path)
# a single or wildcarded asset host, if configured, with the correct
# request protocol.
def compute_public_path(source, dir, ext = nil, include_host = true)
- @@computed_public_paths ||= {}
- @@computed_public_paths["#{@controller.request.protocol}#{@controller.request.relative_url_root}#{dir}#{source}#{ext}#{include_host}"] ||=
+ cache_key = [ @controller.request.protocol,
+ ActionController::Base.asset_host,
+ @controller.request.relative_url_root,
+ dir, source, ext, include_host ].join
+
+ ActionView::Base.computed_public_paths[cache_key] ||=
begin
source += ".#{ext}" if File.extname(source).blank? && ext
@@ -426,15 +430,15 @@ def rails_asset_id(source)
if asset_id = ENV["RAILS_ASSET_ID"]
asset_id
else
- @@asset_id_cache[source] ||=
- if file_exist?(path = File.join(ASSETS_DIR, source))
- File.mtime(path).to_i.to_s
- else
- ''
- end
+ path = File.join(ASSETS_DIR, source)
+
+ if File.exist?(path)
+ File.mtime(path).to_i.to_s
+ else
+ ''
+ end
end
end
- @@asset_id_cache = {}
# Break out the asset path rewrite so you wish to put the asset id
# someplace other than the query string.
View
5 actionpack/test/template/asset_tag_helper_test.rb
@@ -33,11 +33,14 @@ def url_for(*args) "http://www.example.com" end
@request = Class.new do
def relative_url_root() "" end
+ def protocol() 'http://' end
end.new
@controller.request = @request
ActionView::Helpers::AssetTagHelper::reset_javascript_include_default
+
+ ActionView::Base.computed_public_paths.clear
end
def teardown
@@ -128,6 +131,8 @@ def test_javascript_include_tag
ENV["RAILS_ASSET_ID"] = ""
JavascriptIncludeToTag.each { |method, tag| assert_dom_equal(tag, eval(method)) }
+ ActionView::Base.computed_public_paths.clear
+
ENV["RAILS_ASSET_ID"] = "1"
assert_dom_equal(%(<script src="/javascripts/prototype.js?1" type="text/javascript"></script>\n<script src="/javascripts/effects.js?1" type="text/javascript"></script>\n<script src="/javascripts/dragdrop.js?1" type="text/javascript"></script>\n<script src="/javascripts/controls.js?1" type="text/javascript"></script>\n<script src="/javascripts/application.js?1" type="text/javascript"></script>), javascript_include_tag(:defaults))
end
Please sign in to comment.
Something went wrong with that request. Please try again.