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 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 diff --git a/lib/jammit/helper.rb b/lib/jammit/helper.rb index 530bc1bf..6ec32cc9 100644 --- a/lib/jammit/helper.rb +++ b/lib/jammit/helper.rb @@ -26,10 +26,11 @@ 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) + should_package? ? timestamped_url(pack, :js) : Jammit.packager.individual_urls(pack.to_sym, :js) }.flatten.map {|pack| - javascript_include_tag pack, options + "" }.join("\n") end @@ -42,6 +43,13 @@ def include_templates(*packages) private + def timestamped_url(file, ext) + 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 + + def should_package? Jammit.package_assets && !(Jammit.allow_debugging && params[:debug_assets]) end @@ -57,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 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 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 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..712a79f3 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! @@ -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_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..aade6b12 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 @@ -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_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_jammit_controller.rb b/test/unit/test_jammit_controller.rb index 3a66ab5b..6869c893 100644 --- a/test/unit/test_jammit_controller.rb +++ b/test/unit/test_jammit_controller.rb @@ -6,40 +6,46 @@ require 'action_controller/test_case' require 'jammit/controller' require 'jammit/routes' +require 'action_dispatch' 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 - 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) + 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 + 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_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 @response.headers['Content-Type'] =~ /text\/javascript/ - assert @response.body == File.read("#{ASSET_ROOT}/fixtures/jammed/jst_test.js") + assert_equal( File.read("#{ASSET_ROOT}/fixtures/jammed/jst_test.js"), @response.body ) + assert_match( /text\/javascript/, @response.headers['Content-Type'] ) end end 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_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..ddbbda9b 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! @@ -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