From 1af295fc9a6772e587e438254cfe354e6da0fa19 Mon Sep 17 00:00:00 2001 From: Joshua Peek Date: Tue, 29 Mar 2011 15:42:31 -0500 Subject: Tests for SprocketsHelper --- .../app/assets/javascripts/application.js | 0 .../sprockets/app/assets/javascripts/dir/xmlhr.js | 0 .../sprockets/app/assets/javascripts/xmlhr.js | 0 .../app/assets/stylesheets/application.css | 0 .../sprockets/app/assets/stylesheets/dir/style.css | 0 .../sprockets/app/assets/stylesheets/style.css | 0 actionpack/test/template/sprockets_helper_test.rb | 93 ++++++++++++++++++++++ 7 files changed, 93 insertions(+) create mode 100644 actionpack/test/fixtures/sprockets/app/assets/javascripts/application.js create mode 100644 actionpack/test/fixtures/sprockets/app/assets/javascripts/dir/xmlhr.js create mode 100644 actionpack/test/fixtures/sprockets/app/assets/javascripts/xmlhr.js create mode 100644 actionpack/test/fixtures/sprockets/app/assets/stylesheets/application.css create mode 100644 actionpack/test/fixtures/sprockets/app/assets/stylesheets/dir/style.css create mode 100644 actionpack/test/fixtures/sprockets/app/assets/stylesheets/style.css create mode 100644 actionpack/test/template/sprockets_helper_test.rb (limited to 'actionpack/test') 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 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 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 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 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 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 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 '', + sprockets_javascript_include_tag(:application) + + assert_equal '', + sprockets_javascript_include_tag("xmlhr") + assert_equal '', + sprockets_javascript_include_tag("xmlhr.js") + assert_equal '', + 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 '', + sprockets_stylesheet_link_tag(:application) + + assert_equal '', + sprockets_stylesheet_link_tag("style") + assert_equal '', + sprockets_stylesheet_link_tag("style.css") + + assert_equal '', + sprockets_stylesheet_link_tag("http://www.railsapplication.com/style.css") + assert_equal '', + sprockets_stylesheet_link_tag("style", :media => "all") + assert_equal '', + sprockets_stylesheet_link_tag("style", :media => "print") + end +end -- cgit v1.2.3