test/asset_host_test.rb in sinatra-assetpack-0.2.2 vs test/asset_host_test.rb in sinatra-assetpack-0.2.3

- old
+ new

@@ -1,13 +1,9 @@ require File.expand_path('../test_helper', __FILE__) class AssetHostTest < UnitTest - class TestApp < UnitTest::App - register Sinatra::AssetPack - - set :root, File.join(File.dirname(__FILE__), "app") - + class App < Main assets { serve '/css', :from => 'app/css' serve '/js', :from => 'app/js' serve '/images', :from => 'app/images' @@ -22,26 +18,26 @@ get('/helper/img') { img '/images/background.jpg' } end def app - TestApp + App end test "hosts sets option" do assert app.assets.asset_hosts.include? '//cdn-0.example.org' assert app.assets.asset_hosts.include? '//cdn-1.example.org' end test "host gets added to css source path" do app.stubs(:development?).returns(false) - assert TestApp.assets.packages['a.css'].to_production_html =~ %r{href='//cdn-[0|1].example.org/assets/a.[a-f0-9]{32}.css'} + assert App.assets.packages['a.css'].to_production_html('/') =~ %r{href='//cdn-[0|1].example.org/assets/a.[a-f0-9]{32}.css'} end test "host gets added to js source path" do app.stubs(:development?).returns(false) - assert TestApp.assets.packages['b.js'].to_production_html =~ %r{src='//cdn-[0|1].example.org/assets/b.[a-f0-9]{32}.js'} + assert App.assets.packages['b.js'].to_production_html('/') =~ %r{src='//cdn-[0|1].example.org/assets/b.[a-f0-9]{32}.js'} end test "host gets added to image helper path in production" do app.stubs(:development?).returns(false) get '/helper/img' @@ -55,23 +51,23 @@ end test "host gets added to css image path in production" do app.stubs(:development?).returns(false) get '/css/style.css' - assert body.include?('background: url(//cdn-1.example.org/images/background.b1946ac92492d2347c6235b4d2611184.jpg)') + assert body =~ /background: url\(\/\/cdn-[0|1].example.org\/images\/background.[a-f0-9]{32}.jpg\)/ # does not alter non-existing files (design or flaw???) assert body.include?('background: url(/images/404.png)') end test "do not add asset host to filename in dev mode" do app.stubs(:development?).returns(true) file = '/js/hello.js' - assert !(Sinatra::AssetPack::HtmlHelpers.get_file_uri(file, TestApp.assets) =~ /cdn-[0|1].example.org/) + assert !(Sinatra::AssetPack::HtmlHelpers.get_file_uri(file, App.assets) =~ /cdn-[0|1].example.org/) end test "add asset host to filename in production/qa mode" do app.stubs(:development?).returns(false) file = '/js/hello.js' - assert Sinatra::AssetPack::HtmlHelpers.get_file_uri(file, TestApp.assets) =~ /cdn-[0|1].example.org/ + assert Sinatra::AssetPack::HtmlHelpers.get_file_uri(file, App.assets) =~ /cdn-[0|1].example.org/ end end