rack-zippy 3.0.1 → 4.0.0

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,4 +1,5 @@
1
1
  require_relative 'test_helper'
2
+ require 'rack-zippy/configuration'
2
3
 
3
4
  module Rack
4
5
  module Zippy
@@ -0,0 +1 @@
1
+ this,is,report,csv
@@ -0,0 +1,60 @@
1
+ require_relative 'test_helper'
2
+
3
+ module Rails
4
+ class Railtie
5
+ def self.config
6
+ OpenStruct.new(after_initialize: true)
7
+ end
8
+ end
9
+
10
+ def self.version
11
+ raise 'Stub Rails.version'
12
+ end
13
+ end
14
+
15
+ require 'rack-zippy/railtie'
16
+
17
+ module Rack
18
+ module Zippy
19
+ class RailtieTest < TestCase
20
+
21
+ def teardown
22
+ Rack::Zippy::Railtie.skip_version_check = false
23
+ end
24
+
25
+ def test_upgrade_rails_or_downgrade_zippy_recommendation_for_rails_versions_below_4_2
26
+ with_rails_version('4.1.99') do
27
+ assert_output("[rack-zippy] This version of rack-zippy does not support Rails. Your choices include: 1) [RECOMMENDED] Upgrade to Rails 4.2 or above and use Rails' built-in ActionDispatch::Static middleware to serve gzipped files. or 2) Specify an earlier version of rack-zippy (~> '3.0.1') in your Gemfile that does support Rails\n") { Rack::Zippy::Railtie.version_check }
28
+ end
29
+ end
30
+
31
+ versions = ['4.2.0', '5.0.0', '10.0.0']
32
+ versions.each do |version|
33
+ test "remove zippy recommendation printed for Rails versions #{version}" do
34
+ with_rails_version(version) do
35
+ assert_output("[rack-zippy] rack-zippy is not supported for this version of Rails. Rails now supports serving gzipped files using its own ActionDispatch::Static middleware. It is strongly recommended you remove rack-zippy from your app and use ActionDispatch::Static in its place.\n") { Rack::Zippy::Railtie.version_check }
36
+ end
37
+ end
38
+ end
39
+
40
+ def test_config_silences_remove_zippy_recommendation_for_rails_versions_4_2_and_above
41
+ versions = ['4.2.0', '5.0.0', '10.0.0']
42
+ versions.each do |version|
43
+ with_rails_version(version) do
44
+ Rack::Zippy::Railtie.skip_version_check = true
45
+ assert_silent { Rack::Zippy::Railtie.version_check }
46
+ end
47
+ end
48
+ end
49
+
50
+ private
51
+
52
+ def with_rails_version(version)
53
+ Rails.stub :version, version do
54
+ yield
55
+ end
56
+ end
57
+
58
+ end
59
+ end
60
+ end
@@ -3,35 +3,13 @@ require 'bundler/setup'
3
3
 
4
4
  Bundler.require :default, :development
5
5
 
6
- require 'test/unit'
6
+ require 'minitest/autorun'
7
7
  require 'rack/test'
8
+ require 'active_support/testing/declarative'
8
9
 
9
- module RailsEnvironmentStub
10
10
 
11
- @@public_path = '/default/path/to/public/set/in/test_helper'
12
-
13
- @@configuration = Struct.new(:assets).new
14
- @@configuration.assets = Struct.new(:compile).new
15
-
16
- def self.configuration
17
- @@configuration
18
- end
19
-
20
- def self.public_path
21
- @@public_path
22
- end
23
-
24
- def self.public_path=(path)
25
- @@public_path = path
26
- end
27
-
28
- def self.version
29
- return 'Rails.version stub'
30
- end
31
-
32
- end
33
-
34
- class TestCase < ::Test::Unit::TestCase
11
+ class TestCase < ::Minitest::Test
12
+ extend ActiveSupport::Testing::Declarative
35
13
 
36
14
  DURATIONS_IN_SECS = {:year => 31536000, :month => 2678400, :day => 86400}.freeze
37
15
 
@@ -51,16 +29,5 @@ class TestCase < ::Test::Unit::TestCase
51
29
  "#{Dir.pwd}/public"
52
30
  end
53
31
 
54
- def enter_rails_env
55
- Object.send(:const_set, :Rails, ::RailsEnvironmentStub) unless defined?(::Rails)
56
- end
57
-
58
- def exit_rails_env
59
- Object.send(:remove_const, :Rails)
60
- end
61
-
62
- def in_rails_env?
63
- return defined?(::Rails)
64
- end
65
32
 
66
33
  end
metadata CHANGED
@@ -1,16 +1,85 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rack-zippy
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.0.1
5
- prerelease:
4
+ version: 4.0.0
6
5
  platform: ruby
7
6
  authors:
8
7
  - Eliot Sykes
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2015-05-19 00:00:00.000000000 Z
13
- dependencies: []
11
+ date: 2015-10-20 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: actionpack
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 4.2.4
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 4.2.4
27
+ - !ruby/object:Gem::Dependency
28
+ name: minitest
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: 5.8.1
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: 5.8.1
41
+ - !ruby/object:Gem::Dependency
42
+ name: guard-test
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: 2.0.6
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: 2.0.6
55
+ - !ruby/object:Gem::Dependency
56
+ name: rack-test
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: 0.6.3
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: 0.6.3
69
+ - !ruby/object:Gem::Dependency
70
+ name: rake
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
14
83
  description: Rack middleware for serving static gzipped assets generated by the Rails
15
84
  asset pipeline
16
85
  email:
@@ -19,7 +88,7 @@ executables: []
19
88
  extensions: []
20
89
  extra_rdoc_files: []
21
90
  files:
22
- - .gitignore
91
+ - ".gitignore"
23
92
  - CHANGELOG.md
24
93
  - Gemfile
25
94
  - Guardfile
@@ -27,74 +96,71 @@ files:
27
96
  - README.md
28
97
  - Rakefile
29
98
  - lib/rack-zippy.rb
30
- - lib/rack-zippy/asset_compiler.rb
31
99
  - lib/rack-zippy/configuration.rb
32
- - lib/rack-zippy/serveable_file.rb
100
+ - lib/rack-zippy/railtie.rb
33
101
  - lib/rack-zippy/version.rb
34
102
  - rack-zippy.gemspec
35
103
  - test/asset_server_test.rb
36
104
  - test/configuration_test.rb
37
- - test/null_asset_compiler_test.rb
38
105
  - test/public/assets/application.css
39
106
  - test/public/assets/application.css.gz
40
107
  - test/public/assets/application.js
41
108
  - test/public/assets/application.js.gz
42
109
  - test/public/assets/blog/logos/logo1.png
43
110
  - test/public/assets/favicon.ico
111
+ - test/public/assets/loading.GiF
44
112
  - test/public/assets/rails.png
45
113
  - test/public/favicon.ico
46
114
  - test/public/foo/bar.html
47
115
  - test/public/foo/index.html
48
116
  - test/public/index.html
117
+ - test/public/report.csv
49
118
  - test/public/robots.txt
50
119
  - test/public/thanks.html
51
- - test/rails_asset_compiler_test.rb
52
- - test/serveable_file_test.rb
120
+ - test/railtie_test.rb
53
121
  - test/test_helper.rb
54
- - video-player.png
55
122
  homepage: https://github.com/eliotsykes/rack-zippy
56
123
  licenses:
57
124
  - MIT
125
+ metadata: {}
58
126
  post_install_message:
59
127
  rdoc_options: []
60
128
  require_paths:
61
129
  - lib
62
130
  required_ruby_version: !ruby/object:Gem::Requirement
63
- none: false
64
131
  requirements:
65
- - - ! '>='
132
+ - - ">="
66
133
  - !ruby/object:Gem::Version
67
134
  version: '0'
68
135
  required_rubygems_version: !ruby/object:Gem::Requirement
69
- none: false
70
136
  requirements:
71
- - - ! '>='
137
+ - - ">="
72
138
  - !ruby/object:Gem::Version
73
139
  version: '0'
74
140
  requirements: []
75
141
  rubyforge_project:
76
- rubygems_version: 1.8.23.2
142
+ rubygems_version: 2.4.5.1
77
143
  signing_key:
78
- specification_version: 3
144
+ specification_version: 4
79
145
  summary: Rack middleware for serving static gzipped assets generated by the Rails
80
146
  asset pipeline
81
147
  test_files:
82
148
  - test/asset_server_test.rb
83
149
  - test/configuration_test.rb
84
- - test/null_asset_compiler_test.rb
85
150
  - test/public/assets/application.css
86
151
  - test/public/assets/application.css.gz
87
152
  - test/public/assets/application.js
88
153
  - test/public/assets/application.js.gz
89
154
  - test/public/assets/blog/logos/logo1.png
90
155
  - test/public/assets/favicon.ico
156
+ - test/public/assets/loading.GiF
91
157
  - test/public/assets/rails.png
92
158
  - test/public/favicon.ico
93
159
  - test/public/foo/bar.html
94
160
  - test/public/foo/index.html
95
161
  - test/public/index.html
162
+ - test/public/report.csv
96
163
  - test/public/robots.txt
97
164
  - test/public/thanks.html
98
- - test/rails_asset_compiler_test.rb
99
- - test/serveable_file_test.rb
165
+ - test/railtie_test.rb
100
166
  - test/test_helper.rb
@@ -1,39 +0,0 @@
1
- module Rack
2
- module Zippy
3
-
4
- class NullAssetCompiler
5
- def compiles?(path_info)
6
- return false
7
- end
8
- end
9
-
10
- class RailsAssetCompiler
11
-
12
- def initialize
13
- # config.assets.compile is normally false in production, and true in dev+test envs.
14
- # compile == true => active pipeline
15
- # compile == false => disabled pipeline
16
- @active = ::Rails.configuration.assets.compile
17
- end
18
-
19
- def compiles?(path_info)
20
- return active? && on_pipeline_path?(path_info)
21
- end
22
-
23
- private
24
-
25
- def on_pipeline_path?(path_info)
26
- path_info =~ PRECOMPILED_ASSETS_SUBDIR_REGEX
27
- end
28
-
29
- def active?
30
- return @active
31
- end
32
-
33
- def self.rails_env?
34
- return defined?(::Rails.version)
35
- end
36
- end
37
-
38
- end
39
- end
@@ -1,138 +0,0 @@
1
- module Rack
2
- module Zippy
3
- class ServeableFile
4
-
5
- attr_reader :path, :full_path_info
6
-
7
- def initialize(options)
8
- raise ArgumentError.new(':has_encoding_variants option must be given') unless options.has_key?(:has_encoding_variants)
9
-
10
- @path = options[:path]
11
- @full_path_info = options[:full_path_info]
12
- @has_encoding_variants = options[:has_encoding_variants]
13
- @is_gzipped = options[:is_gzipped]
14
- @max_age_fallback = options[:max_age_fallback] || SECONDS_IN[:day]
15
- end
16
-
17
- def headers
18
- headers = { 'Content-Type' => Rack::Mime.mime_type(::File.extname(full_path_info)) }
19
- headers.merge! cache_headers
20
-
21
- headers['Vary'] = 'Accept-Encoding' if encoding_variants?
22
- headers['Content-Encoding'] = 'gzip' if gzipped?
23
-
24
- headers['Content-Length'] = ::File.size(path).to_s
25
- return headers
26
- end
27
-
28
- def cache_headers
29
- case full_path_info
30
- when PRECOMPILED_ASSETS_SUBDIR_REGEX
31
- lifetime_in_secs = SECONDS_IN[:year]
32
- last_modified = CACHE_FRIENDLY_LAST_MODIFIED
33
- when '/favicon.ico'
34
- lifetime_in_secs = SECONDS_IN[:month]
35
- last_modified = CACHE_FRIENDLY_LAST_MODIFIED
36
- else
37
- lifetime_in_secs = @max_age_fallback
38
- end
39
-
40
- headers = { 'Cache-Control' => "public, max-age=#{lifetime_in_secs}" }
41
- headers['Last-Modified'] = last_modified if last_modified
42
-
43
- return headers
44
- end
45
-
46
- def response_body
47
- [::File.read(path)]
48
- end
49
-
50
- def self.find_first(options)
51
- asset_compiler = options[:asset_compiler]
52
- path_info = options[:path_info].chomp('/')
53
-
54
- return nil if asset_compiler.compiles?(path_info)
55
-
56
- asset_root = options[:asset_root]
57
-
58
- candidate_path_infos = []
59
- if !path_info.empty?
60
- candidate_path_infos << path_info
61
- candidate_path_infos << "#{path_info}#{DEFAULT_STATIC_EXTENSION}"
62
- end
63
- candidate_path_infos << "#{path_info}/index#{DEFAULT_STATIC_EXTENSION}"
64
-
65
- file_path = nil
66
-
67
- full_path_info = candidate_path_infos.find do |candidate_path_info|
68
- file_path = ::File.join(asset_root, candidate_path_info)
69
- readable_file?(file_path)
70
- end
71
-
72
- return nil if full_path_info.nil? || !has_static_extension?(full_path_info)
73
-
74
- include_gzipped = options[:include_gzipped]
75
-
76
- gzipped_file_path = "#{file_path}.gz"
77
- gzipped_file_present = readable_file?(gzipped_file_path)
78
-
79
- has_encoding_variants = gzipped_file_present
80
-
81
- init_options = {
82
- :path => file_path,
83
- :full_path_info => full_path_info,
84
- :has_encoding_variants => has_encoding_variants,
85
- :max_age_fallback => options[:max_age_fallback]
86
- }
87
-
88
- if include_gzipped && gzipped_file_present
89
- init_options[:path] = gzipped_file_path
90
- init_options[:is_gzipped] = true
91
- end
92
-
93
- return ServeableFile.new(init_options)
94
- end
95
-
96
- def self.has_static_extension?(path)
97
- Rack::Zippy.static_extensions.include? ::File.extname(path).slice(1..-1).to_s.downcase
98
- end
99
-
100
- def encoding_variants?
101
- return @has_encoding_variants
102
- end
103
-
104
- def gzipped?
105
- return @is_gzipped
106
- end
107
-
108
- def ==(other)
109
- return false if other.nil?
110
- return true if self.equal?(other)
111
- return self.class == other.class &&
112
- self.gzipped? == other.gzipped? &&
113
- self.encoding_variants? == other.encoding_variants? &&
114
- self.path == other.path &&
115
- self.full_path_info == other.full_path_info
116
- end
117
- alias_method :eql?, :==
118
-
119
- private
120
-
121
- # Old last-modified headers encourage caching via browser heuristics. Use it for year-long cached assets.
122
- CACHE_FRIENDLY_LAST_MODIFIED = 'Mon, 10 Jan 2005 10:00:00 GMT'
123
-
124
- SECONDS_IN = {
125
- :day => 24*60*60,
126
- :month => 31*(24*60*60),
127
- :year => 365*(24*60*60)
128
- }.freeze
129
-
130
- DEFAULT_STATIC_EXTENSION = '.html'.freeze
131
-
132
- def self.readable_file?(file_path)
133
- return ::File.file?(file_path) && ::File.readable?(file_path)
134
- end
135
-
136
- end
137
- end
138
- end