jammit-core 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENSE +22 -0
- data/README +24 -0
- data/README.rdoc +17 -0
- data/Rakefile +59 -0
- data/VERSION +1 -0
- data/bin/jammit +13 -0
- data/lib/assets.example.yml +14 -0
- data/lib/jammit-core.rb +219 -0
- data/lib/jammit-core/cli.rb +87 -0
- data/lib/jammit-core/command_line.rb +79 -0
- data/lib/jammit-core/compressor.rb +214 -0
- data/lib/jammit-core/config.rb +82 -0
- data/lib/jammit-core/dependencies.rb +23 -0
- data/lib/jammit-core/helper.rb +77 -0
- data/lib/jammit-core/jst.js +1 -0
- data/lib/jammit-core/packager.rb +163 -0
- data/lib/jammit-core/routes.rb +16 -0
- data/lib/jammit-core/ui.rb +55 -0
- data/test/config/assets-broken.yml +16 -0
- data/test/config/assets-closure.yml +16 -0
- data/test/config/assets-compression-disabled.yml +16 -0
- data/test/config/assets-css.yml +6 -0
- data/test/config/assets-erb.yml +13 -0
- data/test/config/assets-no-java.yml +16 -0
- data/test/config/assets.yml +13 -0
- data/test/fixtures/jammed/test-closure.js +1 -0
- data/test/fixtures/jammed/test-datauri.css +1 -0
- data/test/fixtures/jammed/test-line-break.css +8 -0
- data/test/fixtures/jammed/test-mhtml.css +17 -0
- data/test/fixtures/jammed/test-uncompressed.css +36 -0
- data/test/fixtures/jammed/test-uncompressed.js +13 -0
- data/test/fixtures/jammed/test.css +1 -0
- data/test/fixtures/jammed/test.js +1 -0
- data/test/fixtures/jammed/test.jst +6 -0
- data/test/fixtures/jammed/test2.jst +6 -0
- data/test/fixtures/src/test1.css +11 -0
- data/test/fixtures/src/test1.js +8 -0
- data/test/fixtures/src/test1.jst +1 -0
- data/test/fixtures/src/test2.css +20 -0
- data/test/fixtures/src/test2.js +5 -0
- data/test/fixtures/src/test2.jst +5 -0
- data/test/fixtures/src/test_fonts.css +5 -0
- data/test/fixtures/tags/css_includes.html +6 -0
- data/test/fixtures/tags/css_individual_includes.html +3 -0
- data/test/fixtures/tags/css_plain_includes.html +1 -0
- data/test/fixtures/tags/css_print.html +6 -0
- data/test/public/embed/DroidSansMono.eot +0 -0
- data/test/public/embed/DroidSansMono.ttf +0 -0
- data/test/public/embed/asterisk_orange.png +0 -0
- data/test/public/embed/asterisk_yellow.png +0 -0
- data/test/test_helper.rb +44 -0
- data/test/unit/command_line_test.rb +28 -0
- data/test/unit/test_closure_compressor.rb +24 -0
- data/test/unit/test_compressor.rb +24 -0
- data/test/unit/test_configuration.rb +71 -0
- data/test/unit/test_in_the_wrong_directory.rb +40 -0
- data/test/unit/test_jammit_helpers.rb +44 -0
- data/test/unit/test_packager.rb +77 -0
- metadata +187 -0
@@ -0,0 +1,6 @@
|
|
1
|
+
(function(){
|
2
|
+
window.JST = window.JST || {};
|
3
|
+
var template = function(str){var fn = new Function('obj', 'var p=[],print=function(){p.push.apply(p,arguments);};with(obj){p.push(\''+str.replace(/[\r\t\n]/g, " ").replace(/'(?=[^%]*%>)/g,"\t").split("'").join("\\'").split("\t").join("'").replace(/<%=(.+?)%>/g,"',$1,'").split("<%").join("');").split("%>").join("p.push('")+"');}return p.join('');"); return fn;};
|
4
|
+
window.JST.test1 = template('<a href="<%= to_somewhere %>"><%= saying_something %></a>');
|
5
|
+
window.JST.test2 = template('<% _([1,2,3]).each(function(num) { %> <li class="number"> <%= num %> </li><% }) %>');
|
6
|
+
})();
|
@@ -0,0 +1,6 @@
|
|
1
|
+
(function(){
|
2
|
+
custom_namespace = custom_namespace || {};
|
3
|
+
var template = function(str){var fn = new Function('obj', 'var p=[],print=function(){p.push.apply(p,arguments);};with(obj){p.push(\''+str.replace(/[\r\t\n]/g, " ").replace(/'(?=[^%]*%>)/g,"\t").split("'").join("\\'").split("\t").join("'").replace(/<%=(.+?)%>/g,"',$1,'").split("<%").join("');").split("%>").join("p.push('")+"');}return p.join('');"); return fn;};
|
4
|
+
custom_namespace.test1 = template('<a href="<%= to_somewhere %>"><%= saying_something %></a>');
|
5
|
+
custom_namespace.test2 = template('<% _([1,2,3]).each(function(num) { %> <li class="number"> <%= num %> </li><% }) %>');
|
6
|
+
})();
|
@@ -0,0 +1 @@
|
|
1
|
+
<a href="<%= to_somewhere %>"><%= saying_something %></a>
|
@@ -0,0 +1,20 @@
|
|
1
|
+
#another {
|
2
|
+
color: white;
|
3
|
+
background: blue;
|
4
|
+
}
|
5
|
+
#css .file {
|
6
|
+
border: 1px solid red;
|
7
|
+
margin-left: 10px;
|
8
|
+
margin-right: 10px;
|
9
|
+
margin-bottom: 45px;
|
10
|
+
margin-top: 45px;
|
11
|
+
}
|
12
|
+
#with_images {
|
13
|
+
background: url(../../public/embed/asterisk_yellow.png);
|
14
|
+
}
|
15
|
+
#and_relative_paths {
|
16
|
+
background: url(../../public/embed/asterisk_orange.png?1010101);
|
17
|
+
}
|
18
|
+
#and_real_urls {
|
19
|
+
background: url(http://example.com/image.png);
|
20
|
+
}
|
@@ -0,0 +1,6 @@
|
|
1
|
+
<!--[if (!IE)|(gte IE 8)]><!-->
|
2
|
+
<link href="/assets/test-datauri.css?101" media="screen" rel="stylesheet" type="text/css" />
|
3
|
+
<!--<![endif]-->
|
4
|
+
<!--[if lte IE 7]>
|
5
|
+
<link href="/assets/test-mhtml.css?101" media="screen" rel="stylesheet" type="text/css" />
|
6
|
+
<![endif]-->
|
@@ -0,0 +1,3 @@
|
|
1
|
+
<link href="/fixtures/src/test1.css?101" media="screen" rel="stylesheet" type="text/css" />
|
2
|
+
<link href="/fixtures/src/test2.css?101" media="screen" rel="stylesheet" type="text/css" />
|
3
|
+
<link href="/fixtures/src/test_fonts.css?101" media="screen" rel="stylesheet" type="text/css" />
|
@@ -0,0 +1 @@
|
|
1
|
+
<link href="/assets/test.css?101" media="screen" rel="stylesheet" type="text/css" />
|
@@ -0,0 +1,6 @@
|
|
1
|
+
<!--[if (!IE)|(gte IE 8)]><!-->
|
2
|
+
<link href="/assets/test-datauri.css?101" media="print" rel="stylesheet" type="text/css" />
|
3
|
+
<!--<![endif]-->
|
4
|
+
<!--[if lte IE 7]>
|
5
|
+
<link href="/assets/test-mhtml.css?101" media="print" rel="stylesheet" type="text/css" />
|
6
|
+
<![endif]-->
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
data/test/test_helper.rb
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
require 'logger'
|
2
|
+
|
3
|
+
ASSET_ROOT = File.expand_path('test')
|
4
|
+
devnull = RUBY_PLATFORM =~ /mswin|mingw|bccwin|wince|emx/ ? 'nul' : '/dev/null'
|
5
|
+
RAILS_DEFAULT_LOGGER = Logger.new(devnull)
|
6
|
+
RAILS_ENV = "test"
|
7
|
+
RAILS_ROOT = File.expand_path('test')
|
8
|
+
ENV["RAILS_ASSET_ID"] = "101"
|
9
|
+
|
10
|
+
require 'lib/jammit'
|
11
|
+
gem 'rails'
|
12
|
+
require 'initializer'
|
13
|
+
Jammit.load_configuration(Jammit::DEFAULT_CONFIG_PATH)
|
14
|
+
|
15
|
+
def glob(g)
|
16
|
+
Dir.glob(g).sort
|
17
|
+
end
|
18
|
+
|
19
|
+
class Test::Unit::TestCase
|
20
|
+
|
21
|
+
PRECACHED_FILES = %w(
|
22
|
+
test/precache/test-datauri.css
|
23
|
+
test/precache/test-datauri.css.gz
|
24
|
+
test/precache/test-mhtml.css
|
25
|
+
test/precache/test-mhtml.css.gz
|
26
|
+
test/precache/test.css
|
27
|
+
test/precache/test.css.gz
|
28
|
+
test/precache/test.js
|
29
|
+
test/precache/test.js.gz
|
30
|
+
test/precache/test.jst
|
31
|
+
test/precache/test.jst.gz
|
32
|
+
)
|
33
|
+
|
34
|
+
PRECACHED_SOURCES = %w(
|
35
|
+
test/precache/test-datauri.css
|
36
|
+
test/precache/test-mhtml.css
|
37
|
+
test/precache/test.css
|
38
|
+
test/precache/test.js
|
39
|
+
test/precache/test.jst
|
40
|
+
)
|
41
|
+
|
42
|
+
include Jammit
|
43
|
+
|
44
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
require 'zlib'
|
3
|
+
|
4
|
+
class CommandLineTest < Test::Unit::TestCase
|
5
|
+
|
6
|
+
def test_version_and_help_can_run
|
7
|
+
assert system('bin/jammit -v') && system('bin/jammit -h')
|
8
|
+
end
|
9
|
+
|
10
|
+
def test_jammit_precaching
|
11
|
+
system('bin/jammit -c test/config/assets.yml -o test/precache -u http://www.example.com')
|
12
|
+
assert PRECACHED_FILES == glob('test/precache/*')
|
13
|
+
assert Zlib::GzipReader.open('test/precache/test-datauri.css.gz') {|f| f.read } == File.read('test/fixtures/jammed/test-datauri.css')
|
14
|
+
assert Zlib::GzipReader.open('test/precache/test.jst.gz') {|f| f.read } == File.read('test/fixtures/jammed/test.jst')
|
15
|
+
FileUtils.rm_r('test/precache')
|
16
|
+
end
|
17
|
+
|
18
|
+
def test_lazy_precaching
|
19
|
+
system('bin/jammit -c test/config/assets.yml -o test/precache -u http://www.example.com')
|
20
|
+
assert PRECACHED_FILES == glob('test/precache/*')
|
21
|
+
mtime = File.mtime(PRECACHED_FILES.first)
|
22
|
+
system('bin/jammit -c test/config/assets.yml -o test/precache -u http://www.example.com')
|
23
|
+
assert File.mtime(PRECACHED_FILES.first) == mtime
|
24
|
+
system('bin/jammit -c test/config/assets.yml -o test/precache -u http://www.example.com --force')
|
25
|
+
assert File.mtime(PRECACHED_FILES.first) > mtime
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class ClosureCompressorTest < Test::Unit::TestCase
|
4
|
+
|
5
|
+
def setup
|
6
|
+
Jammit.load_configuration('test/config/assets-closure.yml').reload!
|
7
|
+
@compressor = Compressor.new
|
8
|
+
end
|
9
|
+
|
10
|
+
def teardown
|
11
|
+
Jammit.load_configuration('test/config/assets.yml').reload!
|
12
|
+
end
|
13
|
+
|
14
|
+
def test_javascript_compression
|
15
|
+
packed = @compressor.compress_js(glob('test/fixtures/src/test*.js'))
|
16
|
+
assert packed == File.read('test/fixtures/jammed/test-closure.js')
|
17
|
+
end
|
18
|
+
|
19
|
+
def test_jst_compilation
|
20
|
+
packed = @compressor.compile_jst(glob('test/fixtures/src/test*.jst'))
|
21
|
+
assert packed == File.read('test/fixtures/jammed/test.jst')
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class CompressorTest < Test::Unit::TestCase
|
4
|
+
|
5
|
+
def setup
|
6
|
+
@compressor = Compressor.new
|
7
|
+
end
|
8
|
+
|
9
|
+
def test_javascript_compression
|
10
|
+
packed = @compressor.compress_js(glob('test/fixtures/src/test*.js'))
|
11
|
+
assert packed == File.read('test/fixtures/jammed/test.js')
|
12
|
+
end
|
13
|
+
|
14
|
+
def test_css_compression
|
15
|
+
packed = @compressor.compress_css(glob('test/fixtures/src/*.css'))
|
16
|
+
assert packed == File.read('test/fixtures/jammed/test.css')
|
17
|
+
end
|
18
|
+
|
19
|
+
def test_jst_compilation
|
20
|
+
packed = @compressor.compile_jst(glob('test/fixtures/src/test*.jst'))
|
21
|
+
assert packed == File.read('test/fixtures/jammed/test.jst')
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
@@ -0,0 +1,71 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class BrokenConfigurationTest < Test::Unit::TestCase
|
4
|
+
|
5
|
+
def setup
|
6
|
+
Jammit.load_configuration('test/config/assets-broken.yml').reload!
|
7
|
+
@compressor = Compressor.new
|
8
|
+
end
|
9
|
+
|
10
|
+
def teardown
|
11
|
+
Jammit.load_configuration('test/config/assets.yml').reload!
|
12
|
+
end
|
13
|
+
|
14
|
+
def test_loading_a_nonexistent_file
|
15
|
+
assert_raises(ConfigurationNotFound) do
|
16
|
+
Jammit.load_configuration('nonexistent/assets.yml')
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def test_loading_a_nonexistent_java
|
21
|
+
Jammit.load_configuration('test/config/assets-no-java.yml')
|
22
|
+
assert !Jammit.compress_assets
|
23
|
+
@compressor = Compressor.new
|
24
|
+
packed = @compressor.compress_js(glob('test/fixtures/src/test*.js'))
|
25
|
+
assert packed == File.read('test/fixtures/jammed/test-uncompressed.js')
|
26
|
+
packed = @compressor.compress_css(glob('test/fixtures/src/*.css'))
|
27
|
+
assert packed == File.read('test/fixtures/jammed/test-uncompressed.css')
|
28
|
+
end
|
29
|
+
|
30
|
+
def test_disabled_compression
|
31
|
+
Jammit.load_configuration('test/config/assets-compression-disabled.yml')
|
32
|
+
assert !Jammit.compress_assets
|
33
|
+
assert !Jammit.gzip_assets
|
34
|
+
@compressor = Compressor.new
|
35
|
+
packed = @compressor.compress_js(glob('test/fixtures/src/test*.js'))
|
36
|
+
assert packed == File.read('test/fixtures/jammed/test-uncompressed.js')
|
37
|
+
packed = @compressor.compress_css(glob('test/fixtures/src/*.css'))
|
38
|
+
assert packed == File.read('test/fixtures/jammed/test-uncompressed.css')
|
39
|
+
end
|
40
|
+
|
41
|
+
def test_css_compression
|
42
|
+
assert Jammit.compress_assets
|
43
|
+
assert Jammit.gzip_assets
|
44
|
+
packed = @compressor.compress_css(glob('test/fixtures/src/*.css'))
|
45
|
+
assert packed == File.read('test/fixtures/jammed/test.css')
|
46
|
+
end
|
47
|
+
|
48
|
+
def test_erb_configuration
|
49
|
+
Jammit.load_configuration('test/config/assets-erb.yml')
|
50
|
+
assert Jammit.compress_assets
|
51
|
+
packed = @compressor.compress_css(glob('test/fixtures/src/*.css'))
|
52
|
+
assert packed == File.read('test/fixtures/jammed/test.css')
|
53
|
+
end
|
54
|
+
|
55
|
+
def test_css_configuration
|
56
|
+
Jammit.load_configuration('test/config/assets-css.yml')
|
57
|
+
packed = Compressor.new.compress_css(glob('test/fixtures/src/*.css'))
|
58
|
+
assert packed == File.read('test/fixtures/jammed/test-line-break.css')
|
59
|
+
end
|
60
|
+
|
61
|
+
def test_javascript_compression
|
62
|
+
packed = @compressor.compress_js(glob('test/fixtures/src/test*.js'))
|
63
|
+
assert packed == File.read('test/fixtures/jammed/test.js')
|
64
|
+
end
|
65
|
+
|
66
|
+
def test_jst_compilation
|
67
|
+
packed = @compressor.compile_jst(glob('test/fixtures/src/test*.jst'))
|
68
|
+
assert packed == File.read('test/fixtures/jammed/test.jst')
|
69
|
+
end
|
70
|
+
|
71
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class WrongDirectoryTest < Test::Unit::TestCase
|
4
|
+
|
5
|
+
def setup
|
6
|
+
@original_dir ||= File.expand_path(Dir.pwd)
|
7
|
+
Dir.chdir('/')
|
8
|
+
end
|
9
|
+
|
10
|
+
def teardown
|
11
|
+
Dir.chdir(@original_dir)
|
12
|
+
end
|
13
|
+
|
14
|
+
def test_fetching_lists_of_individual_urls
|
15
|
+
urls = Jammit.packager.individual_urls(:test, :css)
|
16
|
+
assert urls == ['/fixtures/src/test1.css', '/fixtures/src/test2.css', '/fixtures/src/test_fonts.css']
|
17
|
+
urls = Jammit.packager.individual_urls(:test, :js)
|
18
|
+
assert urls == ['/fixtures/src/test1.js', '/fixtures/src/test2.js']
|
19
|
+
end
|
20
|
+
|
21
|
+
def test_packaging_stylesheets
|
22
|
+
css = Jammit.packager.pack_stylesheets(:test)
|
23
|
+
assert css == File.read("#{ASSET_ROOT}/fixtures/jammed/test.css")
|
24
|
+
css = Jammit.packager.pack_stylesheets(:test, :datauri)
|
25
|
+
assert css == File.read("#{ASSET_ROOT}/fixtures/jammed/test-datauri.css")
|
26
|
+
css = Jammit.packager.pack_stylesheets(:test, :mhtml, 'http://www.example.com')
|
27
|
+
assert css == File.open("#{ASSET_ROOT}/fixtures/jammed/test-mhtml.css", 'rb') {|f| f.read }
|
28
|
+
end
|
29
|
+
|
30
|
+
def test_packaging_javascripts
|
31
|
+
js = Jammit.packager.pack_javascripts(:test)
|
32
|
+
assert js == File.read("#{ASSET_ROOT}/fixtures/jammed/test.js")
|
33
|
+
end
|
34
|
+
|
35
|
+
def test_packaging_templates
|
36
|
+
jst = Jammit.packager.pack_templates(:test)
|
37
|
+
assert jst == File.read("#{ASSET_ROOT}/fixtures/jammed/test.jst")
|
38
|
+
end
|
39
|
+
|
40
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
require 'action_pack'
|
3
|
+
require 'action_view'
|
4
|
+
require 'action_view/base'
|
5
|
+
require 'action_controller'
|
6
|
+
require 'action_controller/base'
|
7
|
+
require 'action_view/test_case'
|
8
|
+
require 'jammit/helper'
|
9
|
+
|
10
|
+
class ActionController::Base
|
11
|
+
cattr_accessor :asset_host
|
12
|
+
end
|
13
|
+
|
14
|
+
class JammitHelpersTest < ActionView::TestCase
|
15
|
+
include ActionView::Helpers::AssetTagHelper
|
16
|
+
include Jammit::Helper
|
17
|
+
|
18
|
+
def test_include_stylesheets
|
19
|
+
assert include_stylesheets(:test) == File.read('test/fixtures/tags/css_includes.html')
|
20
|
+
end
|
21
|
+
|
22
|
+
def test_include_stylesheets_with_options
|
23
|
+
assert include_stylesheets(:test, :media => 'print') == File.read('test/fixtures/tags/css_print.html')
|
24
|
+
end
|
25
|
+
|
26
|
+
def test_include_stylesheets_forcing_embed_assets_off
|
27
|
+
assert include_stylesheets(:test, :embed_assets => false) == File.read('test/fixtures/tags/css_plain_includes.html')
|
28
|
+
end
|
29
|
+
|
30
|
+
def test_include_javascripts
|
31
|
+
assert include_javascripts(:test) == '<script src="/assets/test.js?101" type="text/javascript"></script>'
|
32
|
+
end
|
33
|
+
|
34
|
+
def test_include_templates
|
35
|
+
assert include_templates(:test) == '<script src="/assets/test.jst?101" type="text/javascript"></script>'
|
36
|
+
end
|
37
|
+
|
38
|
+
def test_individual_assets_in_development_do
|
39
|
+
Jammit.instance_variable_set(:@package_assets, false)
|
40
|
+
assert include_stylesheets(:test) == File.read('test/fixtures/tags/css_individual_includes.html')
|
41
|
+
Jammit.reload!
|
42
|
+
end
|
43
|
+
|
44
|
+
end
|
@@ -0,0 +1,77 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
require 'zlib'
|
3
|
+
|
4
|
+
class PackagerTest < Test::Unit::TestCase
|
5
|
+
|
6
|
+
def test_fetching_lists_of_individual_urls
|
7
|
+
urls = Jammit.packager.individual_urls(:test, :css)
|
8
|
+
assert urls == ['/fixtures/src/test1.css', '/fixtures/src/test2.css', '/fixtures/src/test_fonts.css']
|
9
|
+
urls = Jammit.packager.individual_urls(:test, :js)
|
10
|
+
assert urls == ['/fixtures/src/test1.js', '/fixtures/src/test2.js']
|
11
|
+
end
|
12
|
+
|
13
|
+
def test_packaging_stylesheets
|
14
|
+
css = Jammit.packager.pack_stylesheets(:test)
|
15
|
+
assert css == File.read('test/fixtures/jammed/test.css')
|
16
|
+
css = Jammit.packager.pack_stylesheets(:test, :datauri)
|
17
|
+
assert css == File.read('test/fixtures/jammed/test-datauri.css')
|
18
|
+
css = Jammit.packager.pack_stylesheets(:test, :mhtml, 'http://www.example.com')
|
19
|
+
assert css == File.open('test/fixtures/jammed/test-mhtml.css', 'rb') {|f| f.read }
|
20
|
+
end
|
21
|
+
|
22
|
+
def test_packaging_javascripts
|
23
|
+
js = Jammit.packager.pack_javascripts(:test)
|
24
|
+
assert js == File.read('test/fixtures/jammed/test.js')
|
25
|
+
end
|
26
|
+
|
27
|
+
def test_packaging_templates
|
28
|
+
jst = Jammit.packager.pack_templates(:test)
|
29
|
+
assert jst == File.read('test/fixtures/jammed/test.jst')
|
30
|
+
Jammit.set_template_namespace('custom_namespace')
|
31
|
+
jst = Jammit.packager.pack_templates(:test)
|
32
|
+
Jammit.set_template_namespace('window.JST')
|
33
|
+
assert jst == File.read('test/fixtures/jammed/test2.jst')
|
34
|
+
end
|
35
|
+
|
36
|
+
def test_package_caching
|
37
|
+
css = Jammit.packager.pack_stylesheets(:test, :mhtml, 'http://www.example.com')
|
38
|
+
mtime = Time.now
|
39
|
+
Jammit.packager.cache(:test, :css, css, 'test/public', :mhtml, mtime)
|
40
|
+
canonical = File.open('test/fixtures/jammed/test-mhtml.css', 'rb') {|f| f.read }
|
41
|
+
assert File.open('test/public/test-mhtml.css', 'rb') {|f| f.read } == canonical
|
42
|
+
assert Zlib::GzipReader.open('test/public/test-mhtml.css.gz') {|f| f.read } == canonical
|
43
|
+
FileUtils.rm(['test/public/test-mhtml.css', 'test/public/test-mhtml.css.gz'])
|
44
|
+
end
|
45
|
+
|
46
|
+
def test_precache_all
|
47
|
+
Jammit.packager.precache_all('test/precache', 'http://www.example.com')
|
48
|
+
assert PRECACHED_FILES == glob('test/precache/*')
|
49
|
+
assert Zlib::GzipReader.open('test/precache/test-datauri.css.gz') {|f| f.read } == File.read('test/fixtures/jammed/test-datauri.css')
|
50
|
+
assert Zlib::GzipReader.open('test/precache/test.jst.gz') {|f| f.read } == File.read('test/fixtures/jammed/test.jst')
|
51
|
+
ensure
|
52
|
+
begin
|
53
|
+
FileUtils.rm_r('test/precache')
|
54
|
+
rescue Errno::ENOENT => e
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
def test_precache_no_gzip
|
59
|
+
Jammit.load_configuration('test/config/assets-compression-disabled.yml').reload!
|
60
|
+
Jammit.packager.precache_all('test/precache', 'http://www.example.com')
|
61
|
+
assert PRECACHED_SOURCES == glob('test/precache/*')
|
62
|
+
Jammit.load_configuration('test/config/assets.yml').reload!
|
63
|
+
ensure
|
64
|
+
begin
|
65
|
+
FileUtils.rm_r('test/precache')
|
66
|
+
rescue Errno::ENOENT => e
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
def test_exceptions_for_unwritable_directories
|
71
|
+
return unless File.exists?('text/fixtures/unwritable')
|
72
|
+
assert_raises(OutputNotWritable) do
|
73
|
+
Jammit.packager.precache_all('test/fixtures/unwritable')
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
end
|