rack-zippy 1.0.0 → 1.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,3 +1,7 @@
1
+ ## 1.0.1 / 2013-09-06
2
+ - Fix error on request for assets root dir (fixes [#2](https://github.com/eliotsykes/rack-zippy/issues/2))
3
+ - Add MIT license to gemspec (fixes [#1](https://github.com/eliotsykes/rack-zippy/issues/1))
4
+
1
5
  ## 1.0.0 / 2013-08-22
2
6
 
3
7
  Production-ready release
@@ -17,7 +17,7 @@ module Rack
17
17
 
18
18
  file_path = "#{@asset_root}#{path_info}"
19
19
 
20
- if ::File.exists?(file_path)
20
+ if ::File.file?(file_path)
21
21
  headers = { 'Content-Type' => Rack::Mime.mime_type(::File.extname(path_info)) }
22
22
  headers.merge! cache_headers(path_info)
23
23
 
@@ -57,7 +57,7 @@ module Rack
57
57
 
58
58
  STATIC_EXTENSION_REGEX = /\.(?:css|js|html|htm|txt|ico|png|jpg|jpeg|gif|pdf|svg|zip|gz|eps|psd|ai)\z/i
59
59
 
60
- PRECOMPILED_ASSETS_SUBDIR_REGEX = /\A\/assets\//
60
+ PRECOMPILED_ASSETS_SUBDIR_REGEX = /\A\/assets(?:\/|\z)/
61
61
 
62
62
  ACCEPTS_GZIP_REGEX = /\bgzip\b/
63
63
 
@@ -85,8 +85,8 @@ module Rack
85
85
  end
86
86
 
87
87
  def serve?(path_info)
88
- is_compilable_asset = (path_info =~ PRECOMPILED_ASSETS_SUBDIR_REGEX)
89
- if is_compilable_asset
88
+ is_assets_dir_or_below = (path_info =~ PRECOMPILED_ASSETS_SUBDIR_REGEX)
89
+ if is_assets_dir_or_below
90
90
  return should_assets_be_compiled_already?
91
91
  end
92
92
  return has_static_extension?(path_info)
@@ -1,5 +1,5 @@
1
1
  module Rack
2
2
  module Zippy
3
- VERSION = '1.0.0'
3
+ VERSION = '1.0.1'
4
4
  end
5
5
  end
@@ -11,6 +11,7 @@ Gem::Specification.new do |gem|
11
11
  gem.description = %q{Rack middleware for serving static gzipped assets generated by the Rails asset pipeline}
12
12
  gem.summary = %q{Rack middleware for serving static gzipped assets generated by the Rails asset pipeline}
13
13
  gem.homepage = "https://github.com/eliotsykes/rack-zippy"
14
+ gem.license = 'MIT'
14
15
 
15
16
  gem.files = `git ls-files`.split($/)
16
17
  gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
@@ -20,6 +20,36 @@ class Rack::Zippy::AssetServerTest < Test::Unit::TestCase
20
20
  Rack::Zippy::AssetServer.new(rack_app)
21
21
  end
22
22
 
23
+ def test_request_for_non_asset_path_beginning_with_assets_dir_name_bypasses_middleware
24
+ get '/assets-are-great-but-im-not-one'
25
+ assert_underlying_app_responded
26
+ end
27
+
28
+ def test_request_for_subdir_of_assets_responds_404_not_found
29
+ ['/assets/blog', '/assets/blog/logos/'].each do |path|
30
+ local_path = "public#{path}"
31
+ assert File.directory?(local_path)
32
+ get path
33
+ assert_not_found
34
+ end
35
+ end
36
+
37
+ def test_request_for_non_existent_subdir_of_assets_responds_404_not_found
38
+ ['/assets/ghost', '/assets/does/not/exist', '/assets/nothing-here/with-trailing-slash/'].each do |path|
39
+ local_path = "public#{path}"
40
+ assert !File.exists?(local_path)
41
+ get path
42
+ assert_not_found
43
+ end
44
+ end
45
+
46
+ def test_request_for_assets_root_responds_404_not_found
47
+ ['/assets/', '/assets'].each do |assets_root|
48
+ get assets_root
49
+ assert_not_found "'#{assets_root}' assets root request should not be found"
50
+ end
51
+ end
52
+
23
53
  def test_cache_friendly_last_modified_is_not_set_for_files_outside_of_assets_subdir
24
54
  get '/robots.txt'
25
55
  assert_response_ok
@@ -35,8 +65,7 @@ class Rack::Zippy::AssetServerTest < Test::Unit::TestCase
35
65
  def test_does_not_serve_assets_subdir_request_when_assets_compile_enabled
36
66
  ::Rails.configuration.assets.compile = true
37
67
  get '/assets/application.css'
38
- assert_response_ok
39
- assert_equal 'Up above the streets and houses', last_response.body
68
+ assert_underlying_app_responded
40
69
  end
41
70
 
42
71
  def test_serve_returns_true_if_request_has_static_extension
@@ -278,9 +307,9 @@ class Rack::Zippy::AssetServerTest < Test::Unit::TestCase
278
307
  assert_equal ::File.size(path).to_s, last_response.headers['content-length']
279
308
  end
280
309
 
281
- def assert_not_found
282
- assert_equal 404, last_response.status
283
- assert_equal 'Not Found', last_response.body
310
+ def assert_not_found(msg=nil)
311
+ assert_equal 404, last_response.status, msg
312
+ assert_equal 'Not Found', last_response.body, msg
284
313
  end
285
314
 
286
315
  def ensure_correct_working_directory
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rack-zippy
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.0.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-08-22 00:00:00.000000000 Z
12
+ date: 2013-09-06 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description: Rack middleware for serving static gzipped assets generated by the Rails
15
15
  asset pipeline
@@ -33,6 +33,7 @@ files:
33
33
  - test/public/assets/application.css.gz
34
34
  - test/public/assets/application.js
35
35
  - test/public/assets/application.js.gz
36
+ - test/public/assets/blog/logos/logo1.png
36
37
  - test/public/assets/favicon.ico
37
38
  - test/public/assets/rails.png
38
39
  - test/public/favicon.ico
@@ -40,7 +41,8 @@ files:
40
41
  - test/public/thanks.html
41
42
  - test/test_helper.rb
42
43
  homepage: https://github.com/eliotsykes/rack-zippy
43
- licenses: []
44
+ licenses:
45
+ - MIT
44
46
  post_install_message:
45
47
  rdoc_options: []
46
48
  require_paths:
@@ -51,12 +53,18 @@ required_ruby_version: !ruby/object:Gem::Requirement
51
53
  - - ! '>='
52
54
  - !ruby/object:Gem::Version
53
55
  version: '0'
56
+ segments:
57
+ - 0
58
+ hash: 3051334136221018269
54
59
  required_rubygems_version: !ruby/object:Gem::Requirement
55
60
  none: false
56
61
  requirements:
57
62
  - - ! '>='
58
63
  - !ruby/object:Gem::Version
59
64
  version: '0'
65
+ segments:
66
+ - 0
67
+ hash: 3051334136221018269
60
68
  requirements: []
61
69
  rubyforge_project:
62
70
  rubygems_version: 1.8.23
@@ -70,6 +78,7 @@ test_files:
70
78
  - test/public/assets/application.css.gz
71
79
  - test/public/assets/application.js
72
80
  - test/public/assets/application.js.gz
81
+ - test/public/assets/blog/logos/logo1.png
73
82
  - test/public/assets/favicon.ico
74
83
  - test/public/assets/rails.png
75
84
  - test/public/favicon.ico