rack-favicon_all 0.0.2 → 0.0.3

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8bb434520514b27f2cf284c181c6a16ad8a9670c
4
- data.tar.gz: 86a6805293218268995cbb7a2aadfd7ffed0c379
3
+ metadata.gz: 513049bb88c601dcee1c68ff16d3b1ab7969185d
4
+ data.tar.gz: 79488265fa69bced0a432ddd5fe6be0cc8d5681d
5
5
  SHA512:
6
- metadata.gz: 80b440fc6e131f08e0c52c1edb12fbb1373b8b1918d812264e26aae8e85b663e296b7e6f61ab5d90173c18b4fe5e655fd766eb459a5182633219bc72a2e90645
7
- data.tar.gz: 9fe7cc16293a2bad41f76983d90ee6f3e8caae56fa17934def8ac40d6eab4dad08d0cf5f9f7626c9e3a7215feb50d2794975a03ebf159f11b623efcfdbb4873b
6
+ metadata.gz: 16918a625a26d1279736878ed692af66a81a555194c1da65ade2486432629789482ab0ac23b103204b463c75f029d9b1af515c5f219f1dfed95815ab86578cf1
7
+ data.tar.gz: 8def4ee4848ce5b4cb9fcaa71d9de35871f27c8f64f66d9545bbb9e500b753dd91d0b242612c6fcfbf1d5d450fa2f335070228984d892d36fef01e6e526d8bd3
data/Gemfile CHANGED
@@ -14,5 +14,6 @@ group :test do
14
14
  gem 'rspec'
15
15
  gem 'simplecov', require: false
16
16
  gem 'simplecov-rcov', require: false
17
+ gem 'timecop'
17
18
  end
18
19
 
@@ -1,5 +1,5 @@
1
1
  module Rack
2
2
  class FaviconAll
3
- VERSION = "0.0.2"
3
+ VERSION = "0.0.3"
4
4
  end
5
5
  end
@@ -29,21 +29,25 @@ module Rack
29
29
  def initialize(app, options = {})
30
30
  @app = app
31
31
  @favicon_path = options[:favicon_path]
32
- @image = Magick::Image.read(@favicon_path).first unless @favicon_path.nil?
32
+ if !@favicon_path.nil? && ::File.exist?(@favicon_path)
33
+ @image = Magick::Image.read(@favicon_path).first
34
+ end
33
35
  end
34
36
 
35
37
  def call(env)
36
- status, headers, body = @app.call(env)
37
- return [status, headers, body] if @image.nil?
38
+ return @app.call(env) if @image.nil?
38
39
 
39
40
  favicon_info = FAVICON.find { |f| env['PATH_INFO'] =~ f[:path] }
40
-
41
- return [status, headers, body] if favicon_info.nil?
41
+ return @app.call(env) if favicon_info.nil?
42
42
 
43
43
  body = genarate_favicon(favicon_info)
44
- headers["Content-Length"] = body.bytesize.to_s
45
- headers["Content-Type"] = favicon_info[:mime_type] || "imgae/png"
46
- [status, headers, [body]]
44
+ headers = {
45
+ "Content-Length" => body.bytesize.to_s,
46
+ "Content-Type" => favicon_info[:mime_type] || "imgae/png",
47
+ "Last-Modified" => Time.now.httpdate
48
+ }
49
+
50
+ [200, headers, [body]]
47
51
  end
48
52
 
49
53
  private
Binary file
@@ -17,5 +17,30 @@ describe Rack::FaviconAll do
17
17
  end
18
18
  end
19
19
 
20
+ context 'return valid favicon' do
21
+ before { Timecop.freeze(Time.now) }
22
+ subject do
23
+ Rack::Lint.new(Rack::FaviconAll.new(app, favicon_path: File.expand_path('images/icon.png', __dir__)))
24
+ end
25
+ it do
26
+ response = Rack::MockRequest.new(subject).get('/favicon.ico')
27
+ expect(response.successful?).to be_truthy
28
+ expect(response.headers["Content-Type"]).to eq "image/x-icon"
29
+ expect(response.headers["Last-Modified"]).to eq Time.now.httpdate
30
+ end
31
+ after { Timecop.return }
32
+ end
33
+
34
+ context 'invalid favicon_path' do
35
+ subject do
36
+ Rack::Lint.new(Rack::FaviconAll.new(app, favicon_path: File.expand_path('images/hoge', __dir__)))
37
+ end
38
+ it do
39
+ response = Rack::MockRequest.new(subject).get('/favicon.ico')
40
+ expect(response.successful?).to be_truthy
41
+ expect(response.body).to eq 'Hello, World!'
42
+ end
43
+ end
44
+
20
45
  end
21
46
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rack-favicon_all
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - SpringMT
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-01-10 00:00:00.000000000 Z
11
+ date: 2015-01-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rmagick
@@ -70,6 +70,7 @@ files:
70
70
  - lib/rack/favicon_all.rb
71
71
  - lib/rack/favicon_all/version.rb
72
72
  - rack-favicon_all.gemspec
73
+ - spec/images/icon.png
73
74
  - spec/rack-favicon_all_spec.rb
74
75
  - spec/spec_helper.rb
75
76
  homepage: https://github.com/SpringMT/rack-favicon_all
@@ -97,6 +98,7 @@ signing_key:
97
98
  specification_version: 4
98
99
  summary: Generate favicons for IE, FF, Chrome, Safari!
99
100
  test_files:
101
+ - spec/images/icon.png
100
102
  - spec/rack-favicon_all_spec.rb
101
103
  - spec/spec_helper.rb
102
104
  has_rdoc: