aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack
diff options
context:
space:
mode:
Diffstat (limited to 'actionpack')
-rw-r--r--actionpack/lib/action_view/helpers/sprockets_helper.rb16
-rw-r--r--actionpack/test/fixtures/sprockets/app/assets/javascripts/application.js0
-rw-r--r--actionpack/test/fixtures/sprockets/app/assets/javascripts/dir/xmlhr.js0
-rw-r--r--actionpack/test/fixtures/sprockets/app/assets/javascripts/xmlhr.js0
-rw-r--r--actionpack/test/fixtures/sprockets/app/assets/stylesheets/application.css0
-rw-r--r--actionpack/test/fixtures/sprockets/app/assets/stylesheets/dir/style.css0
-rw-r--r--actionpack/test/fixtures/sprockets/app/assets/stylesheets/style.css0
-rw-r--r--actionpack/test/template/sprockets_helper_test.rb93
8 files changed, 104 insertions, 5 deletions
diff --git a/actionpack/lib/action_view/helpers/sprockets_helper.rb b/actionpack/lib/action_view/helpers/sprockets_helper.rb
index bfc396fad5..f6f4f06d6e 100644
--- a/actionpack/lib/action_view/helpers/sprockets_helper.rb
+++ b/actionpack/lib/action_view/helpers/sprockets_helper.rb
@@ -9,7 +9,7 @@ module ActionView
def sprockets_javascript_include_tag(source, options = {})
options = {
- 'type' => "application/javascript",
+ 'type' => "text/javascript",
'src' => sprockets_javascript_path(source)
}.merge(options.stringify_keys)
@@ -33,6 +33,8 @@ module ActionView
private
def compute_sprockets_path(source, dir, default_ext)
+ source = source.to_s
+
return source if URI.parse(source).host
# Add /javscripts to relative paths
@@ -46,15 +48,15 @@ module ActionView
end
# Fingerprint url
- source = Rails.application.assets.path(source)
+ source = assets.path(source)
host = compute_asset_host(source)
- if controller.respond_to?(:request) && host && URI.parse(host).host.nil?
- host = "#{controller.request.protocol}#{host}"
+ if controller.respond_to?(:request) && host && URI.parse(host).host
+ source = "#{controller.request.protocol}#{host}#{source}"
end
- "#{host}#{source}"
+ source
end
def compute_asset_host(source)
@@ -72,6 +74,10 @@ module ActionView
end
end
end
+
+ def assets
+ Rails.application.assets
+ end
end
end
end
diff --git a/actionpack/test/fixtures/sprockets/app/assets/javascripts/application.js b/actionpack/test/fixtures/sprockets/app/assets/javascripts/application.js
new file mode 100644
index 0000000000..e69de29bb2
--- /dev/null
+++ b/actionpack/test/fixtures/sprockets/app/assets/javascripts/application.js
diff --git a/actionpack/test/fixtures/sprockets/app/assets/javascripts/dir/xmlhr.js b/actionpack/test/fixtures/sprockets/app/assets/javascripts/dir/xmlhr.js
new file mode 100644
index 0000000000..e69de29bb2
--- /dev/null
+++ b/actionpack/test/fixtures/sprockets/app/assets/javascripts/dir/xmlhr.js
diff --git a/actionpack/test/fixtures/sprockets/app/assets/javascripts/xmlhr.js b/actionpack/test/fixtures/sprockets/app/assets/javascripts/xmlhr.js
new file mode 100644
index 0000000000..e69de29bb2
--- /dev/null
+++ b/actionpack/test/fixtures/sprockets/app/assets/javascripts/xmlhr.js
diff --git a/actionpack/test/fixtures/sprockets/app/assets/stylesheets/application.css b/actionpack/test/fixtures/sprockets/app/assets/stylesheets/application.css
new file mode 100644
index 0000000000..e69de29bb2
--- /dev/null
+++ b/actionpack/test/fixtures/sprockets/app/assets/stylesheets/application.css
diff --git a/actionpack/test/fixtures/sprockets/app/assets/stylesheets/dir/style.css b/actionpack/test/fixtures/sprockets/app/assets/stylesheets/dir/style.css
new file mode 100644
index 0000000000..e69de29bb2
--- /dev/null
+++ b/actionpack/test/fixtures/sprockets/app/assets/stylesheets/dir/style.css
diff --git a/actionpack/test/fixtures/sprockets/app/assets/stylesheets/style.css b/actionpack/test/fixtures/sprockets/app/assets/stylesheets/style.css
new file mode 100644
index 0000000000..e69de29bb2
--- /dev/null
+++ b/actionpack/test/fixtures/sprockets/app/assets/stylesheets/style.css
diff --git a/actionpack/test/template/sprockets_helper_test.rb b/actionpack/test/template/sprockets_helper_test.rb
new file mode 100644
index 0000000000..f6fd4f5bb4
--- /dev/null
+++ b/actionpack/test/template/sprockets_helper_test.rb
@@ -0,0 +1,93 @@
+require 'abstract_unit'
+require 'sprockets'
+
+class SprocketsHelperTest < ActionView::TestCase
+ tests ActionView::Helpers::SprocketsHelper
+
+ attr_accessor :assets
+
+ def setup
+ super
+
+ @controller = BasicController.new
+
+ @request = Class.new do
+ def protocol() 'http://' end
+ def ssl?() false end
+ def host_with_port() 'localhost' end
+ end.new
+
+ @controller.request = @request
+
+ @assets = Sprockets::Environment.new
+ @assets.paths << FIXTURES.join("sprockets/app/assets")
+ end
+
+ def url_for(*args)
+ "http://www.example.com"
+ end
+
+ test "javascript path" do
+ assert_equal "/javascripts/application-d41d8cd98f00b204e9800998ecf8427e.js",
+ sprockets_javascript_path(:application)
+
+ assert_equal "/javascripts/xmlhr-d41d8cd98f00b204e9800998ecf8427e.js",
+ sprockets_javascript_path("xmlhr")
+ assert_equal "/javascripts/dir/xmlhr-d41d8cd98f00b204e9800998ecf8427e.js",
+ sprockets_javascript_path("dir/xmlhr.js")
+
+ assert_equal "/dir/xmlhr.js",
+ sprockets_javascript_path("/dir/xmlhr")
+
+ assert_equal "http://www.railsapplication.com/js/xmlhr",
+ sprockets_javascript_path("http://www.railsapplication.com/js/xmlhr")
+ assert_equal "http://www.railsapplication.com/js/xmlhr.js",
+ sprockets_javascript_path("http://www.railsapplication.com/js/xmlhr.js")
+ end
+
+ test "javascript include tag" do
+ assert_equal '<script src="/javascripts/application-d41d8cd98f00b204e9800998ecf8427e.js" type="text/javascript"></script>',
+ sprockets_javascript_include_tag(:application)
+
+ assert_equal '<script src="/javascripts/xmlhr-d41d8cd98f00b204e9800998ecf8427e.js" type="text/javascript"></script>',
+ sprockets_javascript_include_tag("xmlhr")
+ assert_equal '<script src="/javascripts/xmlhr-d41d8cd98f00b204e9800998ecf8427e.js" type="text/javascript"></script>',
+ sprockets_javascript_include_tag("xmlhr.js")
+ assert_equal '<script src="http://www.railsapplication.com/xmlhr" type="text/javascript"></script>',
+ sprockets_javascript_include_tag("http://www.railsapplication.com/xmlhr")
+ end
+
+ test "stylesheet path" do
+ assert_equal "/stylesheets/application-d41d8cd98f00b204e9800998ecf8427e.css",
+ sprockets_stylesheet_path(:application)
+
+ assert_equal "/stylesheets/style-d41d8cd98f00b204e9800998ecf8427e.css",
+ sprockets_stylesheet_path("style")
+ assert_equal "/stylesheets/dir/style-d41d8cd98f00b204e9800998ecf8427e.css",
+ sprockets_stylesheet_path("dir/style.css")
+ assert_equal "/dir/style.css",
+ sprockets_stylesheet_path("/dir/style.css")
+
+ assert_equal "http://www.railsapplication.com/css/style",
+ sprockets_stylesheet_path("http://www.railsapplication.com/css/style")
+ assert_equal "http://www.railsapplication.com/css/style.css",
+ sprockets_stylesheet_path("http://www.railsapplication.com/css/style.css")
+ end
+
+ test "stylesheet link tag" do
+ assert_equal '<link href="/stylesheets/application-d41d8cd98f00b204e9800998ecf8427e.css" media="screen" rel="stylesheet" type="text/css" />',
+ sprockets_stylesheet_link_tag(:application)
+
+ assert_equal '<link href="/stylesheets/style-d41d8cd98f00b204e9800998ecf8427e.css" media="screen" rel="stylesheet" type="text/css" />',
+ sprockets_stylesheet_link_tag("style")
+ assert_equal '<link href="/stylesheets/style-d41d8cd98f00b204e9800998ecf8427e.css" media="screen" rel="stylesheet" type="text/css" />',
+ sprockets_stylesheet_link_tag("style.css")
+
+ assert_equal '<link href="http://www.railsapplication.com/style.css" media="screen" rel="stylesheet" type="text/css" />',
+ sprockets_stylesheet_link_tag("http://www.railsapplication.com/style.css")
+ assert_equal '<link href="/stylesheets/style-d41d8cd98f00b204e9800998ecf8427e.css" media="all" rel="stylesheet" type="text/css" />',
+ sprockets_stylesheet_link_tag("style", :media => "all")
+ assert_equal '<link href="/stylesheets/style-d41d8cd98f00b204e9800998ecf8427e.css" media="print" rel="stylesheet" type="text/css" />',
+ sprockets_stylesheet_link_tag("style", :media => "print")
+ end
+end