From dcc9b02c2b9254fc4e6e53ba4a2dbc36378540cd Mon Sep 17 00:00:00 2001 From: Nathan Stitt Date: Mon, 23 Sep 2013 13:25:48 -0500 Subject: [PATCH 01/14] javascript_include_tag always adds a .js extension For now work around by by making our own tag. Pull request https://github.com/rails/rails/pull/11707 will correct on next version of Rails --- lib/jammit/helper.rb | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/jammit/helper.rb b/lib/jammit/helper.rb index 530bc1bf..f0413827 100644 --- a/lib/jammit/helper.rb +++ b/lib/jammit/helper.rb @@ -26,10 +26,15 @@ def include_stylesheets(*packages) # except in development, where it references the individual scripts. def include_javascripts(*packages) options = packages.extract_options! + options.merge!(:extname=>false) html_safe packages.map {|pack| should_package? ? Jammit.asset_url(pack, :js) : Jammit.packager.individual_urls(pack.to_sym, :js) }.flatten.map {|pack| - javascript_include_tag pack, options +# tag = javascript_include_tag pack, options + tag = "" + # Rails.logger.warn tag + # Rails.logger.warn + tag }.join("\n") end From a68e62ab3e6c2ed06029919bb059473d177777e6 Mon Sep 17 00:00:00 2001 From: Nathan Stitt Date: Mon, 7 Oct 2013 13:08:18 -0500 Subject: [PATCH 02/14] Remove debugging log statments --- lib/jammit/helper.rb | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/lib/jammit/helper.rb b/lib/jammit/helper.rb index f0413827..60f360b9 100644 --- a/lib/jammit/helper.rb +++ b/lib/jammit/helper.rb @@ -30,11 +30,7 @@ def include_javascripts(*packages) html_safe packages.map {|pack| should_package? ? Jammit.asset_url(pack, :js) : Jammit.packager.individual_urls(pack.to_sym, :js) }.flatten.map {|pack| -# tag = javascript_include_tag pack, options - tag = "" - # Rails.logger.warn tag - # Rails.logger.warn - tag + "" }.join("\n") end From 84fe2fbc9292c642f24b8d47b3e6db1d467207c7 Mon Sep 17 00:00:00 2001 From: Nathan Stitt Date: Wed, 20 Aug 2014 18:08:22 -0500 Subject: [PATCH 03/14] Remove red-green gem It doesn't appear to work with MiniTest --- Rakefile | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/Rakefile b/Rakefile index 277dd2de..7f4b4772 100644 --- a/Rakefile +++ b/Rakefile @@ -4,10 +4,8 @@ desc 'Run all tests' task :test, [:path] do |task, args| ENV['RAILS_ENV'] = 'test' $LOAD_PATH.unshift(File.expand_path('test')) - require 'redgreen' unless Gem::Specification.find_all_by_name('redgreen').empty? - require 'test/unit' if args[:path] - require args[:path] + require_relative args[:path] else Dir['test/*/**/test_*.rb'].each {|test| require "./#{test}" } end From f857fed12bf2f939ead83ce0da86d0118a96b45a Mon Sep 17 00:00:00 2001 From: Nathan Stitt Date: Wed, 20 Aug 2014 18:09:05 -0500 Subject: [PATCH 04/14] Helpers no longer include type attribute Jammit uses Rails tags_with_options for css tags, which no longer not includes the `type="text/css"` attribute --- test/fixtures/jammed/js_test-uglifier.js | 2 +- test/fixtures/tags/css_includes.html | 4 ++-- test/fixtures/tags/css_individual_includes.html | 6 +++--- test/fixtures/tags/css_plain_includes.html | 2 +- test/fixtures/tags/css_print.html | 4 ++-- test/fixtures/tags/js_individual_includes.html | 6 +++--- 6 files changed, 12 insertions(+), 12 deletions(-) diff --git a/test/fixtures/jammed/js_test-uglifier.js b/test/fixtures/jammed/js_test-uglifier.js index ee6d0ad5..efcd97e3 100644 --- a/test/fixtures/jammed/js_test-uglifier.js +++ b/test/fixtures/jammed/js_test-uglifier.js @@ -1 +1 @@ -var myself={sayHi:function(e){console.log("hello, "+e)}},mandelay={name:function(){return this.constructor.prototype}};myself.sayHi(mandelay.name()); \ No newline at end of file +var myself={sayHi:function(n){console.log("hello, "+n)}},mandelay={name:function(){return this.constructor.prototype}};myself.sayHi(mandelay.name()); \ No newline at end of file diff --git a/test/fixtures/tags/css_includes.html b/test/fixtures/tags/css_includes.html index b1c93bf9..8bbcbe3c 100644 --- a/test/fixtures/tags/css_includes.html +++ b/test/fixtures/tags/css_includes.html @@ -1,6 +1,6 @@ - + \ No newline at end of file diff --git a/test/fixtures/tags/css_individual_includes.html b/test/fixtures/tags/css_individual_includes.html index 1bbeb8de..b3ac3f40 100644 --- a/test/fixtures/tags/css_individual_includes.html +++ b/test/fixtures/tags/css_individual_includes.html @@ -1,3 +1,3 @@ - - - \ No newline at end of file + + + \ No newline at end of file diff --git a/test/fixtures/tags/css_plain_includes.html b/test/fixtures/tags/css_plain_includes.html index 3ec720f5..bc60fa82 100644 --- a/test/fixtures/tags/css_plain_includes.html +++ b/test/fixtures/tags/css_plain_includes.html @@ -1 +1 @@ - \ No newline at end of file + \ No newline at end of file diff --git a/test/fixtures/tags/css_print.html b/test/fixtures/tags/css_print.html index c2a8e49c..2626ceff 100644 --- a/test/fixtures/tags/css_print.html +++ b/test/fixtures/tags/css_print.html @@ -1,6 +1,6 @@ - + \ No newline at end of file diff --git a/test/fixtures/tags/js_individual_includes.html b/test/fixtures/tags/js_individual_includes.html index 4784c1b8..b5600339 100644 --- a/test/fixtures/tags/js_individual_includes.html +++ b/test/fixtures/tags/js_individual_includes.html @@ -1,3 +1,3 @@ - - - \ No newline at end of file + + + \ No newline at end of file From 78896bdd6c843084e1c2bfe420f73f2c210d4e66 Mon Sep 17 00:00:00 2001 From: Nathan Stitt Date: Wed, 20 Aug 2014 18:12:33 -0500 Subject: [PATCH 05/14] Test optional gems against their latest versions --- Gemfile | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/Gemfile b/Gemfile index ed7ee908..874889ec 100644 --- a/Gemfile +++ b/Gemfile @@ -3,17 +3,16 @@ source 'http://rubygems.org' gemspec group :development, :test do - gem "rake", "0.9.2.2" - gem "rails", "2.3.14" - gem "cssmin", "1.0.3" - gem "jsmin", "1.0.1" - gem "yui-compressor", "0.11.0" - gem "closure-compiler", "1.1.6" - gem "uglifier", "1.3.0" - gem "sass", "3.2.7" + gem "rake", "~>10.3" + gem "rails", "~>4.0" + gem "cssmin", "~>1.0" + gem "jsmin", "~>1.0.1" + gem "yui-compressor", "~>0.12" + gem "closure-compiler", "~>1.1" + gem "uglifier", "~>2.5" + gem "sass", "~>3.4" end group :development do - gem "RedCloth", "4.2.9" - gem "redgreen", "1.2.2" + gem "RedCloth", "~>4.2" end From ca969bddd60a45460310209dc5c4de027f9d290c Mon Sep 17 00:00:00 2001 From: Nathan Stitt Date: Wed, 20 Aug 2014 18:13:02 -0500 Subject: [PATCH 06/14] Use double quotes for tag attributes This way it matches Rails --- lib/jammit/helper.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/jammit/helper.rb b/lib/jammit/helper.rb index 60f360b9..2dc721c2 100644 --- a/lib/jammit/helper.rb +++ b/lib/jammit/helper.rb @@ -30,7 +30,7 @@ def include_javascripts(*packages) html_safe packages.map {|pack| should_package? ? Jammit.asset_url(pack, :js) : Jammit.packager.individual_urls(pack.to_sym, :js) }.flatten.map {|pack| - "" + "" }.join("\n") end From 2f75f1f9e4ea51de80762febf733c9658c476c8b Mon Sep 17 00:00:00 2001 From: Nathan Stitt Date: Wed, 20 Aug 2014 18:14:44 -0500 Subject: [PATCH 07/14] Convert tests to use MiniTest --- test/test_helper.rb | 5 ++++- test/unit/command_line_test.rb | 2 +- test/unit/test_closure_compressor.rb | 2 +- test/unit/test_compressor.rb | 2 +- test/unit/test_configuration.rb | 4 ++-- test/unit/test_in_the_wrong_directory.rb | 2 +- test/unit/test_packager.rb | 2 +- test/unit/test_sass_compressor.rb | 2 +- test/unit/test_uglifier.rb | 2 +- 9 files changed, 13 insertions(+), 10 deletions(-) diff --git a/test/test_helper.rb b/test/test_helper.rb index b1fe3497..df9249ad 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -15,7 +15,10 @@ def glob(g) Dir.glob(g).sort end -class Test::Unit::TestCase +require 'minitest/autorun' + + +class MiniTest::Test PRECACHED_FILES = %w( test/precache/css_test-datauri.css diff --git a/test/unit/command_line_test.rb b/test/unit/command_line_test.rb index 08ec9ec2..9c748322 100644 --- a/test/unit/command_line_test.rb +++ b/test/unit/command_line_test.rb @@ -1,7 +1,7 @@ require 'test_helper' require 'zlib' -class CommandLineTest < Test::Unit::TestCase +class CommandLineTest < MiniTest::Test def teardown begin diff --git a/test/unit/test_closure_compressor.rb b/test/unit/test_closure_compressor.rb index 6a3dacbc..430ab5c4 100644 --- a/test/unit/test_closure_compressor.rb +++ b/test/unit/test_closure_compressor.rb @@ -1,6 +1,6 @@ require 'test_helper' -class ClosureCompressorTest < Test::Unit::TestCase +class ClosureCompressorTest < MiniTest::Test def setup Jammit.load_configuration('test/config/assets-closure.yml').reload! diff --git a/test/unit/test_compressor.rb b/test/unit/test_compressor.rb index eec8ad67..9e6ffe43 100644 --- a/test/unit/test_compressor.rb +++ b/test/unit/test_compressor.rb @@ -1,6 +1,6 @@ require 'test_helper' -class CompressorTest < Test::Unit::TestCase +class CompressorTest < MiniTest::Test def setup Jammit.load_configuration('test/config/assets.yml') diff --git a/test/unit/test_configuration.rb b/test/unit/test_configuration.rb index 1376a855..0e886897 100644 --- a/test/unit/test_configuration.rb +++ b/test/unit/test_configuration.rb @@ -1,6 +1,6 @@ require 'test_helper' -class BrokenConfigurationTest < Test::Unit::TestCase +class BrokenConfigurationTest < Minitest::Test def setup Jammit.load_configuration('test/config/assets-broken.yml').reload! @@ -14,7 +14,7 @@ def test_loading_a_nonexistent_file end end -class ConfigurationTest < Test::Unit::TestCase +class ConfigurationTest < MiniTest::Test def test_disabled_compression Jammit.load_configuration('test/config/assets-compression-disabled.yml') assert !Jammit.compress_assets diff --git a/test/unit/test_in_the_wrong_directory.rb b/test/unit/test_in_the_wrong_directory.rb index cc7a3929..0c137edd 100644 --- a/test/unit/test_in_the_wrong_directory.rb +++ b/test/unit/test_in_the_wrong_directory.rb @@ -1,6 +1,6 @@ require 'test_helper' -class WrongDirectoryTest < Test::Unit::TestCase +class WrongDirectoryTest < MiniTest::Test def setup Jammit.load_configuration('test/config/assets.yml').reload! diff --git a/test/unit/test_packager.rb b/test/unit/test_packager.rb index 38743ba6..decc744a 100644 --- a/test/unit/test_packager.rb +++ b/test/unit/test_packager.rb @@ -1,7 +1,7 @@ require 'test_helper' require 'zlib' -class PackagerTest < Test::Unit::TestCase +class PackagerTest < MiniTest::Test def setup Jammit.load_configuration('test/config/assets.yml').reload! end diff --git a/test/unit/test_sass_compressor.rb b/test/unit/test_sass_compressor.rb index 3b2b5761..330fa959 100644 --- a/test/unit/test_sass_compressor.rb +++ b/test/unit/test_sass_compressor.rb @@ -1,6 +1,6 @@ require 'test_helper' -class SassCompressorTest < Test::Unit::TestCase +class SassCompressorTest < MiniTest::Test def test_css_compression Jammit.load_configuration('test/config/assets-sass.yml') packed = Compressor.new.compress_css(glob('test/fixtures/src/*.css')) diff --git a/test/unit/test_uglifier.rb b/test/unit/test_uglifier.rb index 61ee4124..baa43040 100644 --- a/test/unit/test_uglifier.rb +++ b/test/unit/test_uglifier.rb @@ -1,6 +1,6 @@ require 'test_helper' -class UglifierText < Test::Unit::TestCase +class UglifierText < MiniTest::Test def setup Jammit.load_configuration('test/config/assets-uglifier.yml').reload! From 279c322791a36c24a1cc2d5276eb48feecf241b1 Mon Sep 17 00:00:00 2001 From: Nathan Stitt Date: Wed, 20 Aug 2014 18:16:02 -0500 Subject: [PATCH 08/14] "expected" argument comes first on assert_equal Also convert a few instances of just assert foo==bar to use assert_equal so a better error message is generated --- test/unit/test_closure_compressor.rb | 4 ++-- test/unit/test_configuration.rb | 6 +++--- test/unit/test_jammit_helpers.rb | 25 +++++++++++++++---------- test/unit/test_uglifier.rb | 4 ++-- 4 files changed, 22 insertions(+), 17 deletions(-) diff --git a/test/unit/test_closure_compressor.rb b/test/unit/test_closure_compressor.rb index 430ab5c4..712a79f3 100644 --- a/test/unit/test_closure_compressor.rb +++ b/test/unit/test_closure_compressor.rb @@ -13,12 +13,12 @@ def teardown def test_javascript_compression packed = @compressor.compress_js(glob('test/fixtures/src/*.js')) - assert packed == File.read('test/fixtures/jammed/js_test-closure.js') + assert_equal File.read('test/fixtures/jammed/js_test-closure.js'), packed end def test_jst_compilation packed = @compressor.compile_jst(glob('test/fixtures/src/*.jst')) - assert packed == File.read('test/fixtures/jammed/jst_test.js') + assert_equal File.read('test/fixtures/jammed/jst_test.js'), packed end end diff --git a/test/unit/test_configuration.rb b/test/unit/test_configuration.rb index 0e886897..aade6b12 100644 --- a/test/unit/test_configuration.rb +++ b/test/unit/test_configuration.rb @@ -22,12 +22,12 @@ def test_disabled_compression @compressor = Compressor.new # Should not compress js. packed = @compressor.compress_js(glob('test/fixtures/src/*.js')) - assert_equal packed, File.read('test/fixtures/jammed/js_test-uncompressed.js') + assert_equal File.read('test/fixtures/jammed/js_test-uncompressed.js'), packed # Nothing should change with jst. packed = @compressor.compile_jst(glob('test/fixtures/src/*.jst')) - assert_equal packed, File.read('test/fixtures/jammed/jst_test.js') + assert_equal File.read('test/fixtures/jammed/jst_test.js'), packed packed = @compressor.compress_css(glob('test/fixtures/src/*.css')) - assert_equal packed, File.open('test/fixtures/jammed/css_test-uncompressed.css', 'rb') {|f| f.read } + assert_equal packed, File.read('test/fixtures/jammed/css_test-uncompressed.css', { encoding: 'UTF-8'}) end def test_css_compression diff --git a/test/unit/test_jammit_helpers.rb b/test/unit/test_jammit_helpers.rb index c7ca9739..bad96468 100644 --- a/test/unit/test_jammit_helpers.rb +++ b/test/unit/test_jammit_helpers.rb @@ -36,41 +36,46 @@ def setup end def test_include_stylesheets - assert include_stylesheets(:css_test) == File.read('test/fixtures/tags/css_includes.html') + File.write('test/fixtures/tags/css_includes.html', include_stylesheets(:css_test) ) + assert_equal File.read('test/fixtures/tags/css_includes.html'), include_stylesheets(:css_test) end def test_include_stylesheets_with_options - assert include_stylesheets(:css_test, :media => 'print') == File.read('test/fixtures/tags/css_print.html') + assert_equal File.read('test/fixtures/tags/css_print.html'), include_stylesheets(:css_test, :media => 'print') end def test_include_stylesheets_forcing_embed_assets_off - assert include_stylesheets(:css_test, :embed_assets => false) == File.read('test/fixtures/tags/css_plain_includes.html') + assert_equal File.read('test/fixtures/tags/css_plain_includes.html'), include_stylesheets(:css_test, :embed_assets => false) end def test_include_javascripts - assert include_javascripts(:js_test) == '' + assert_equal '', include_javascripts(:js_test) end def test_include_templates - assert include_javascripts(:jst_test) == '' + assert_equal '', include_javascripts(:jst_test) end def test_include_templates_with_diff_ext - assert include_javascripts(:jst_test_diff_ext) == '' + assert_equal '', include_javascripts(:jst_test_diff_ext) end def test_individual_assets_in_development Jammit.instance_variable_set(:@package_assets, false) - assert include_stylesheets(:css_test) == File.read('test/fixtures/tags/css_individual_includes.html') - assert include_javascripts(:js_test_with_templates) == File.read('test/fixtures/tags/js_individual_includes.html') + asset = File.read('test/fixtures/tags/css_individual_includes.html') + assert_equal asset, include_stylesheets(:css_test) + asset = File.read('test/fixtures/tags/js_individual_includes.html') + assert_equal asset, include_javascripts(:js_test_with_templates) ensure Jammit.reload! end def test_individual_assets_while_debugging @debug = true - assert include_stylesheets(:css_test) == File.read('test/fixtures/tags/css_individual_includes.html') - assert include_javascripts(:js_test_with_templates) == File.read('test/fixtures/tags/js_individual_includes.html') + asset = File.read('test/fixtures/tags/css_individual_includes.html') + assert_equal asset, include_stylesheets(:css_test) + asset = File.read('test/fixtures/tags/js_individual_includes.html') + assert_equal asset, include_javascripts(:js_test_with_templates) @debug = false end diff --git a/test/unit/test_uglifier.rb b/test/unit/test_uglifier.rb index baa43040..ddbbda9b 100644 --- a/test/unit/test_uglifier.rb +++ b/test/unit/test_uglifier.rb @@ -18,7 +18,7 @@ def test_javascript_compression def test_jst_compilation packed = @compressor.compile_jst(glob('test/fixtures/src/*.jst')) - assert packed == File.read('test/fixtures/jammed/jst_test.js') + assert_equal packed, File.read('test/fixtures/jammed/jst_test.js') end -end \ No newline at end of file +end From feb999db9502be698d9016e9c50177ec670cce5c Mon Sep 17 00:00:00 2001 From: Nathan Stitt Date: Wed, 20 Aug 2014 18:18:20 -0500 Subject: [PATCH 09/14] Test jammit controller under Rails 4 --- test/unit/test_jammit_controller.rb | 27 ++++++++++++--------------- 1 file changed, 12 insertions(+), 15 deletions(-) diff --git a/test/unit/test_jammit_controller.rb b/test/unit/test_jammit_controller.rb index 3a66ab5b..29950935 100644 --- a/test/unit/test_jammit_controller.rb +++ b/test/unit/test_jammit_controller.rb @@ -6,6 +6,7 @@ require 'action_controller/test_case' require 'jammit/controller' require 'jammit/routes' +require 'action_dispatch' class JammitController def self.controller_path @@ -15,31 +16,27 @@ def self.controller_path class JammitControllerTest < ActionController::TestCase - CACHE_DIR = '/tmp/jammit_controller_test' - def setup - FileUtils.mkdir_p CACHE_DIR - ActionController::Base.page_cache_directory = CACHE_DIR - ActionController::Routing::Routes.draw do |map| - Jammit::Routes.draw(map) + # Perform the routing setup that Rails needs to test the controller + @routes = ::ActionDispatch::Routing::RouteSet.new + @routes.draw do + get "/package/:package.:extension", + :to => 'jammit#package', :as => :jammit, :constraints => { + :extension => /.+/ + } end - Jammit.load_configuration('test/config/assets.yml').reload! - end - - def teardown - FileUtils.remove_entry_secure CACHE_DIR end def test_package_with_jst get(:package, :package => 'jst_test', :extension => 'jst') - assert @response.headers['Content-Type'] =~ /text\/javascript/ - assert @response.body == File.read("#{ASSET_ROOT}/fixtures/jammed/jst_test.js") + assert_match( /text\/javascript/, @response.headers['Content-Type'] ) + assert_equal( File.read("#{ASSET_ROOT}/fixtures/jammed/jst_test.js"), @response.body ) end def test_package_with_jst_mixed get(:package, :package => 'js_test_with_templates', :extension => 'jst') - assert @response.headers['Content-Type'] =~ /text\/javascript/ - assert @response.body == File.read("#{ASSET_ROOT}/fixtures/jammed/jst_test.js") + assert_match( /text\/javascript/, @response.headers['Content-Type'] ) + assert_equal( File.read("#{ASSET_ROOT}/fixtures/jammed/jst_test.js"), @response.body ) end end From 09df60a00e4077b509b4dc84664fdadf62bfa6ea Mon Sep 17 00:00:00 2001 From: Nathan Stitt Date: Wed, 20 Aug 2014 18:15:05 -0500 Subject: [PATCH 10/14] Supply "importer" argument for CssParser >= 3.4 When Sass implemented source map support in version 3.4, the signature of Sass::SCSS::CssParser.new changed to require 3 arguments --- lib/jammit/sass_compressor.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/jammit/sass_compressor.rb b/lib/jammit/sass_compressor.rb index 38ea68a9..c5ae2161 100644 --- a/lib/jammit/sass_compressor.rb +++ b/lib/jammit/sass_compressor.rb @@ -10,8 +10,8 @@ def initialize(options = {}) # Compresses +css+ using sass' CSS parser, and returns the # compressed css. def compress(css) - root_node = ::Sass::SCSS::CssParser.new(css, 'jammit-combined-input').parse + root_node = ::Sass::SCSS::CssParser.new(css, 'jammit-combined-input', "jammit").parse root_node.options = {:style => :compressed} root_node.render.strip end -end \ No newline at end of file +end From 72e32c357177ec3bdfabf653122c970fd0a89a8b Mon Sep 17 00:00:00 2001 From: Nathan Stitt Date: Thu, 21 Aug 2014 16:55:40 -0500 Subject: [PATCH 11/14] Add url_options method to Jammit controller test Since Rails has not been "booted", it doesn't setup the "url_for" method which is called internally by the default url_options method. Over-ridding it with a blank definition allows the controller's methods to be tested --- test/unit/test_jammit_controller.rb | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/test/unit/test_jammit_controller.rb b/test/unit/test_jammit_controller.rb index 29950935..6869c893 100644 --- a/test/unit/test_jammit_controller.rb +++ b/test/unit/test_jammit_controller.rb @@ -12,11 +12,20 @@ class JammitController def self.controller_path "jammit" end + # Tests needs this defined otherwise it will call + # the parent ActionController::UrlFor#url_options + # That method doesn't work since it depends on + # Rail's boot process defining the routes + def url_options + {} + end end class JammitControllerTest < ActionController::TestCase def setup + Jammit.load_configuration('test/config/assets.yml') + # Perform the routing setup that Rails needs to test the controller @routes = ::ActionDispatch::Routing::RouteSet.new @routes.draw do @@ -29,14 +38,14 @@ def setup def test_package_with_jst get(:package, :package => 'jst_test', :extension => 'jst') - assert_match( /text\/javascript/, @response.headers['Content-Type'] ) assert_equal( File.read("#{ASSET_ROOT}/fixtures/jammed/jst_test.js"), @response.body ) + assert_match( /text\/javascript/, @response.headers['Content-Type'] ) end def test_package_with_jst_mixed get(:package, :package => 'js_test_with_templates', :extension => 'jst') - assert_match( /text\/javascript/, @response.headers['Content-Type'] ) assert_equal( File.read("#{ASSET_ROOT}/fixtures/jammed/jst_test.js"), @response.body ) + assert_match( /text\/javascript/, @response.headers['Content-Type'] ) end end From 4bfb1725b7ac56e573441de5d3dfafda6a11aeef Mon Sep 17 00:00:00 2001 From: Barry Paul Date: Thu, 8 Jan 2015 11:45:01 -0800 Subject: [PATCH 12/14] Add timestamped urls to packages for cache busting --- lib/jammit/helper.rb | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/lib/jammit/helper.rb b/lib/jammit/helper.rb index 2dc721c2..7c02018a 100644 --- a/lib/jammit/helper.rb +++ b/lib/jammit/helper.rb @@ -28,7 +28,7 @@ def include_javascripts(*packages) options = packages.extract_options! options.merge!(:extname=>false) html_safe packages.map {|pack| - should_package? ? Jammit.asset_url(pack, :js) : Jammit.packager.individual_urls(pack.to_sym, :js) + should_package? ? timestamped_url(pack, :js) : Jammit.packager.individual_urls(pack.to_sym, :js) }.flatten.map {|pack| "" }.join("\n") @@ -43,6 +43,13 @@ def include_templates(*packages) private + def timestamped_url(file, ext) + path = File.join(Jammit.public_root, Jammit.filename(file, ext)) + mtime = File.exist?(path) ? File.mtime(path).to_i.to_s : '' + Jammit.asset_url(pack, :js, nil, mtime) + end + + def should_package? Jammit.package_assets && !(Jammit.allow_debugging && params[:debug_assets]) end @@ -75,7 +82,7 @@ def embedded_image_stylesheets(packages, options) # yielding each package to a block. def tags_with_options(packages, options) packages.dup.map {|package| - yield package + yield timestamped_url(package, :css) }.flatten.map {|package| stylesheet_link_tag package, options }.join("\n") From 0f975145d701203e659f1ba1efc3deb96bd20fc7 Mon Sep 17 00:00:00 2001 From: Barry Paul Date: Thu, 8 Jan 2015 11:54:05 -0800 Subject: [PATCH 13/14] Fix typo --- lib/jammit/helper.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/jammit/helper.rb b/lib/jammit/helper.rb index 7c02018a..a7bf7bea 100644 --- a/lib/jammit/helper.rb +++ b/lib/jammit/helper.rb @@ -45,8 +45,8 @@ def include_templates(*packages) def timestamped_url(file, ext) path = File.join(Jammit.public_root, Jammit.filename(file, ext)) - mtime = File.exist?(path) ? File.mtime(path).to_i.to_s : '' - Jammit.asset_url(pack, :js, nil, mtime) + mtime = File.exist?(path) ? File.mtime(path).to_i.to_s : 'xxxx' + Jammit.asset_url(file, :js, nil, mtime) end From cc21c1bcfb4abab7d1b71ab1e80a7e5a467bae25 Mon Sep 17 00:00:00 2001 From: Barry Paul Date: Thu, 8 Jan 2015 12:16:03 -0800 Subject: [PATCH 14/14] Fix css files and make sure we use the jammit config asset path --- lib/jammit/helper.rb | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/jammit/helper.rb b/lib/jammit/helper.rb index a7bf7bea..6ec32cc9 100644 --- a/lib/jammit/helper.rb +++ b/lib/jammit/helper.rb @@ -44,9 +44,9 @@ def include_templates(*packages) private def timestamped_url(file, ext) - path = File.join(Jammit.public_root, Jammit.filename(file, ext)) - mtime = File.exist?(path) ? File.mtime(path).to_i.to_s : 'xxxx' - Jammit.asset_url(file, :js, nil, mtime) + path = File.join(Jammit.public_root, Jammit.package_path, Jammit.filename(file, ext)) + mtime = File.exist?(path) ? File.mtime(path).to_i.to_s : 'xxx' + Jammit.asset_url(file, ext, nil, mtime) end @@ -65,7 +65,7 @@ def individual_stylesheets(packages, options) # HTML tags for the stylesheet packages. def packaged_stylesheets(packages, options) - tags_with_options(packages, options) {|p| Jammit.asset_url(p, :css) } + tags_with_options(packages, options) {|p| timestamped_url(p, :css) } end # HTML tags for the 'datauri', and 'mhtml' versions of the packaged @@ -82,7 +82,7 @@ def embedded_image_stylesheets(packages, options) # yielding each package to a block. def tags_with_options(packages, options) packages.dup.map {|package| - yield timestamped_url(package, :css) + yield package }.flatten.map {|package| stylesheet_link_tag package, options }.join("\n")