rack-fonts 0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/Changelog.md +10 -0
- data/Gemfile +3 -0
- data/LICENSE +20 -0
- data/README.md +44 -0
- data/RakeFile +11 -0
- data/examples/config.ru +47 -0
- data/lib/rack-fonts.rb +72 -0
- data/test/assets/Forum-Font-License-OFL.txt +94 -0
- data/test/assets/Forum.eot +0 -0
- data/test/assets/Forum.otf +0 -0
- data/test/assets/Forum.svg +10501 -0
- data/test/assets/Forum.ttf +0 -0
- data/test/assets/Forum.woff +0 -0
- data/test/assets/sample.css +4 -0
- data/test/assets/sample.js +2 -0
- data/test/rack-fonts_test.rb +146 -0
- data/test/test_helper.rb +3 -0
- metadata +123 -0
Binary file
|
Binary file
|
@@ -0,0 +1,146 @@
|
|
1
|
+
require './test/test_helper'
|
2
|
+
require 'rack/mock'
|
3
|
+
|
4
|
+
class RackFontsTest < MiniTest::Unit::TestCase
|
5
|
+
|
6
|
+
# test original app responds unaltered
|
7
|
+
|
8
|
+
def test_the_original_app_responds_unaltered_headers
|
9
|
+
@res = request.get('/')
|
10
|
+
assert_status 200
|
11
|
+
assert_equal 2, @res.headers.keys.size
|
12
|
+
assert_h 'Content-Type', 'text/html'
|
13
|
+
assert_h 'Content-Length', '11'
|
14
|
+
end
|
15
|
+
|
16
|
+
def test_original_app_responds_unaltered_content
|
17
|
+
@res = request.get('/')
|
18
|
+
assert_equal 'Hello World', @res.body
|
19
|
+
end
|
20
|
+
|
21
|
+
# testing content types
|
22
|
+
|
23
|
+
def test_css_file
|
24
|
+
@res = request.get('/assets/sample.css')
|
25
|
+
assert_status 200
|
26
|
+
assert_h 'Content-Type', 'text/css'
|
27
|
+
assert_equal asset_file_content('sample.css'), @res.body
|
28
|
+
end
|
29
|
+
|
30
|
+
def test_js_file
|
31
|
+
@res = request.get('/assets/sample.js')
|
32
|
+
assert_status 200
|
33
|
+
assert_h 'Content-Type', 'application/javascript'
|
34
|
+
assert_equal asset_file_content('sample.js'), @res.body
|
35
|
+
end
|
36
|
+
|
37
|
+
def test_ttf_file
|
38
|
+
@res = request.get('/assets/Forum.ttf')
|
39
|
+
assert_status 200
|
40
|
+
assert_h 'Content-Type', 'font/truetype'
|
41
|
+
assert_equal asset_file_content('Forum.ttf'), @res.body
|
42
|
+
end
|
43
|
+
|
44
|
+
def test_otf_file
|
45
|
+
@res = request.get('/assets/Forum.otf')
|
46
|
+
assert_status 200
|
47
|
+
assert_h 'Content-Type', 'font/opentype'
|
48
|
+
assert_equal asset_file_content('Forum.otf'), @res.body
|
49
|
+
end
|
50
|
+
|
51
|
+
def test_woff_file
|
52
|
+
@res = request.get('/assets/Forum.woff')
|
53
|
+
assert_status 200
|
54
|
+
assert_h 'Content-Type', 'font/woff'
|
55
|
+
assert_equal asset_file_content('Forum.woff'), @res.body
|
56
|
+
end
|
57
|
+
|
58
|
+
def test_eot_file
|
59
|
+
@res = request.get('/assets/Forum.eot')
|
60
|
+
assert_status 200
|
61
|
+
assert_h 'Content-Type', 'application/vnd.ms-fontobject'
|
62
|
+
assert_equal asset_file_content('Forum.eot'), @res.body
|
63
|
+
end
|
64
|
+
|
65
|
+
def test_svg_file
|
66
|
+
@res = request.get('/assets/Forum.svg')
|
67
|
+
assert_status 200
|
68
|
+
assert_h 'Content-Type', 'image/svg+xml'
|
69
|
+
assert_equal asset_file_content('Forum.svg'), @res.body
|
70
|
+
end
|
71
|
+
|
72
|
+
def test_wildcard_access_control_allow_origin
|
73
|
+
@res = request.get('/assets/Forum.svg')
|
74
|
+
assert_status 200
|
75
|
+
assert_h 'Access-Control-Allow-Origin', '*'
|
76
|
+
end
|
77
|
+
|
78
|
+
def test_cache_control_lasts_a_year
|
79
|
+
@res = request.get('/assets/Forum.svg')
|
80
|
+
assert_status 200
|
81
|
+
assert_h 'Cache-Control', 'public, max-age=31536000'
|
82
|
+
end
|
83
|
+
|
84
|
+
def test_expires_in_a_year
|
85
|
+
@res = request.get('/assets/Forum.svg')
|
86
|
+
assert_status 200
|
87
|
+
assert_h 'Expires', (Time.now + 31536000).httpdate
|
88
|
+
end
|
89
|
+
|
90
|
+
def test_allows_customizing_cache_time
|
91
|
+
custom_cache_time = 3600
|
92
|
+
web_app = lambda { |env| [ 200, {}, ["Hello World"] ] }
|
93
|
+
app = Rack::Fonts.new(web_app, :urls => %w[/], :root => assets_dir, :cache_time => custom_cache_time)
|
94
|
+
request = Rack::MockRequest.new(app)
|
95
|
+
res = request.get('/Forum.svg')
|
96
|
+
|
97
|
+
assert_equal 200, res.status
|
98
|
+
assert_equal((Time.now + custom_cache_time).httpdate, res.headers['Expires'])
|
99
|
+
assert_equal "public, max-age=#{custom_cache_time}", res.headers['Cache-Control']
|
100
|
+
end
|
101
|
+
|
102
|
+
# helpers
|
103
|
+
|
104
|
+
def assert_h(header, expected)
|
105
|
+
error_msg = "Response header #{header} returns #{@res[header]}, but should be #{expected}"
|
106
|
+
assert_equal expected, @res.headers[header], error_msg
|
107
|
+
end
|
108
|
+
|
109
|
+
def assert_status(expected)
|
110
|
+
assert_equal expected, @res.status
|
111
|
+
end
|
112
|
+
|
113
|
+
def inspect(obj)
|
114
|
+
require 'yaml'
|
115
|
+
puts obj.to_yaml
|
116
|
+
end
|
117
|
+
|
118
|
+
def asset_file_content(filename)
|
119
|
+
path = File.join(assets_dir, filename)
|
120
|
+
open(path, "rb") {|io| io.read }
|
121
|
+
end
|
122
|
+
|
123
|
+
def assets_dir
|
124
|
+
File.join tests_dir, 'assets'
|
125
|
+
end
|
126
|
+
|
127
|
+
def tests_dir
|
128
|
+
File.dirname(File.expand_path(__FILE__))
|
129
|
+
end
|
130
|
+
|
131
|
+
def request(options = {})
|
132
|
+
web_app = lambda do |env|
|
133
|
+
[
|
134
|
+
200,
|
135
|
+
{
|
136
|
+
'Content-Type' => 'text/html',
|
137
|
+
'Content-Length' => '11'
|
138
|
+
},
|
139
|
+
["Hello World"]
|
140
|
+
]
|
141
|
+
end
|
142
|
+
app = Rack::Fonts.new(web_app, {:urls => ['/assets'], :root => tests_dir})
|
143
|
+
request = Rack::MockRequest.new(app)
|
144
|
+
end
|
145
|
+
|
146
|
+
end
|
data/test/test_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,123 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rack-fonts
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 0
|
7
|
+
- 1
|
8
|
+
version: "0.1"
|
9
|
+
platform: ruby
|
10
|
+
authors:
|
11
|
+
- Raul Murciano
|
12
|
+
autorequire:
|
13
|
+
bindir: bin
|
14
|
+
cert_chain: []
|
15
|
+
|
16
|
+
date: 2011-07-09 00:00:00 -07:00
|
17
|
+
default_executable:
|
18
|
+
dependencies:
|
19
|
+
- !ruby/object:Gem::Dependency
|
20
|
+
name: rack
|
21
|
+
prerelease: false
|
22
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
23
|
+
none: false
|
24
|
+
requirements:
|
25
|
+
- - ">="
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
segments:
|
28
|
+
- 1
|
29
|
+
- 2
|
30
|
+
- 3
|
31
|
+
version: 1.2.3
|
32
|
+
type: :runtime
|
33
|
+
version_requirements: *id001
|
34
|
+
- !ruby/object:Gem::Dependency
|
35
|
+
name: minitest
|
36
|
+
prerelease: false
|
37
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
38
|
+
none: false
|
39
|
+
requirements:
|
40
|
+
- - ">"
|
41
|
+
- !ruby/object:Gem::Version
|
42
|
+
segments:
|
43
|
+
- 2
|
44
|
+
- 0
|
45
|
+
version: "2.0"
|
46
|
+
type: :development
|
47
|
+
version_requirements: *id002
|
48
|
+
- !ruby/object:Gem::Dependency
|
49
|
+
name: rack-test
|
50
|
+
prerelease: false
|
51
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
52
|
+
none: false
|
53
|
+
requirements:
|
54
|
+
- - ">="
|
55
|
+
- !ruby/object:Gem::Version
|
56
|
+
segments:
|
57
|
+
- 0
|
58
|
+
- 6
|
59
|
+
- 0
|
60
|
+
version: 0.6.0
|
61
|
+
type: :development
|
62
|
+
version_requirements: *id003
|
63
|
+
description: Wraps Rack::Static by adding useful headers to serve web fonts.
|
64
|
+
email:
|
65
|
+
- raul@murciano.net
|
66
|
+
executables: []
|
67
|
+
|
68
|
+
extensions: []
|
69
|
+
|
70
|
+
extra_rdoc_files: []
|
71
|
+
|
72
|
+
files:
|
73
|
+
- lib/rack-fonts.rb
|
74
|
+
- test/assets/Forum-Font-License-OFL.txt
|
75
|
+
- test/assets/Forum.eot
|
76
|
+
- test/assets/Forum.otf
|
77
|
+
- test/assets/Forum.svg
|
78
|
+
- test/assets/Forum.ttf
|
79
|
+
- test/assets/Forum.woff
|
80
|
+
- test/assets/sample.css
|
81
|
+
- test/assets/sample.js
|
82
|
+
- test/rack-fonts_test.rb
|
83
|
+
- test/test_helper.rb
|
84
|
+
- examples/config.ru
|
85
|
+
- Changelog.md
|
86
|
+
- Gemfile
|
87
|
+
- LICENSE
|
88
|
+
- RakeFile
|
89
|
+
- README.md
|
90
|
+
has_rdoc: true
|
91
|
+
homepage: http://github.com/raul/rack-assets
|
92
|
+
licenses: []
|
93
|
+
|
94
|
+
post_install_message:
|
95
|
+
rdoc_options: []
|
96
|
+
|
97
|
+
require_paths:
|
98
|
+
- lib
|
99
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
100
|
+
none: false
|
101
|
+
requirements:
|
102
|
+
- - ">="
|
103
|
+
- !ruby/object:Gem::Version
|
104
|
+
segments:
|
105
|
+
- 0
|
106
|
+
version: "0"
|
107
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
108
|
+
none: false
|
109
|
+
requirements:
|
110
|
+
- - ">="
|
111
|
+
- !ruby/object:Gem::Version
|
112
|
+
segments:
|
113
|
+
- 0
|
114
|
+
version: "0"
|
115
|
+
requirements: []
|
116
|
+
|
117
|
+
rubyforge_project: rack-fonts
|
118
|
+
rubygems_version: 1.3.7
|
119
|
+
signing_key:
|
120
|
+
specification_version: 3
|
121
|
+
summary: Rack middleware to serve static files, with special love to web fonts.
|
122
|
+
test_files: []
|
123
|
+
|