rack-combobot 0.2.0 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
data/lib/rack/combobot.rb CHANGED
@@ -18,9 +18,8 @@ module Rack
18
18
  def initialize(app, options = {})
19
19
  @app = app
20
20
 
21
- root = Pathname.new(options[:root] || Dir.pwd)
22
- expires = options[:expires]
23
- @config = Rack::Combobot::Config.new(root, expires)
21
+ options[:root] = Pathname.new(options[:root] || Dir.pwd)
22
+ @config = Rack::Combobot::Config.new(options)
24
23
  end
25
24
 
26
25
  # rack request handler
@@ -55,6 +54,10 @@ module Rack
55
54
  if @config.expires
56
55
  headers['Expires'] = @config.expires.httpdate
57
56
  end
57
+
58
+ if @config.cache_control
59
+ headers['Cache-Control'] = @config.cache_control
60
+ end
58
61
 
59
62
  headers
60
63
  end
@@ -1,11 +1,12 @@
1
1
  module Rack
2
2
  class Combobot
3
3
  class Config
4
- attr_accessor :root, :expires
4
+ attr_accessor :root, :expires, :cache_control
5
5
 
6
- def initialize(root, expires = nil)
7
- @root = root
8
- @expires = expires
6
+ def initialize(options)
7
+ @root = options[:root]
8
+ @expires = options[:expires]
9
+ @cache_control = options[:cache_control]
9
10
  end
10
11
 
11
12
  end
@@ -4,7 +4,7 @@ $:.push File.expand_path("../lib", __FILE__)
4
4
 
5
5
  Gem::Specification.new do |s|
6
6
  s.name = "rack-combobot"
7
- s.version = "0.2.0"
7
+ s.version = "0.2.1"
8
8
  s.authors = ["Simon Højberg", "Christopher Meiklejohn"]
9
9
  s.email = ["r.hackr@gmail.com", "christopher.meiklejohn@gmail.com"]
10
10
  s.homepage = "https://github.com/hojberg/rack-combobot"
@@ -21,6 +21,8 @@ describe Rack::Combobot do
21
21
  # response helpers
22
22
  let(:combobot_js_response) { [200, {"Content-Type" => "text/javascript"}, ["function lorem() { return \"a\"; }\nfunction ipsum() { return \"b\"; }\n"]] }
23
23
  let(:expires_js_response) { [200, {"Content-Type" => "text/javascript", 'Expires' => 'Wed, 01 Jan 2020 00:00:00 GMT'}, ["function lorem() { return \"a\"; }\nfunction ipsum() { return \"b\"; }\n"]] }
24
+ let(:cache_control_js_response) { [200, {"Content-Type" => "text/javascript", 'Cache-Control' => 'public'}, ["function lorem() { return \"a\"; }\nfunction ipsum() { return \"b\"; }\n"]] }
25
+ let(:expires_and_cache_control_js_response) { [200, {"Content-Type" => "text/javascript", 'Expires' => 'Wed, 01 Jan 2020 00:00:00 GMT', 'Cache-Control' => 'public'}, ["function lorem() { return \"a\"; }\nfunction ipsum() { return \"b\"; }\n"]] }
24
26
  let(:combobot_css_response) { [200, {"Content-Type" => "text/css"}, [".lorem { background: blue; }\n#lipsum { border: 1px solid red }\n"]] }
25
27
  let(:combobot_404_response) { [404, {'Content-Type' => 'text/html'}, ['File not found']] }
26
28
 
@@ -57,6 +59,17 @@ describe Rack::Combobot do
57
59
  @app.call(combobot_js_request).must_equal(expires_js_response)
58
60
  end
59
61
 
62
+ it 'adds cache control headers' do
63
+ @app.config.cache_control = 'public'
64
+ @app.call(combobot_js_request).must_equal(cache_control_js_response)
65
+ end
66
+
67
+ it 'adds both expires and cache control headers' do
68
+ @app.config.expires = Time.gm(2020)
69
+ @app.config.cache_control = 'public'
70
+ @app.call(combobot_js_request).must_equal(expires_and_cache_control_js_response)
71
+ end
72
+
60
73
  it 'allows for versioning' do
61
74
  @app.call(
62
75
  combobot_js_request.merge({ 'PATH_INFO' => '/combobot/CACHEBUSTINGSHA1'})
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rack-combobot
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -10,11 +10,11 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2012-03-21 00:00:00.000000000 Z
13
+ date: 2012-03-22 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rake
17
- requirement: &2156803500 !ruby/object:Gem::Requirement
17
+ requirement: &2168961680 !ruby/object:Gem::Requirement
18
18
  none: false
19
19
  requirements:
20
20
  - - ! '>='
@@ -22,10 +22,10 @@ dependencies:
22
22
  version: '0'
23
23
  type: :runtime
24
24
  prerelease: false
25
- version_requirements: *2156803500
25
+ version_requirements: *2168961680
26
26
  - !ruby/object:Gem::Dependency
27
27
  name: rack
28
- requirement: &2156803060 !ruby/object:Gem::Requirement
28
+ requirement: &2168961240 !ruby/object:Gem::Requirement
29
29
  none: false
30
30
  requirements:
31
31
  - - ! '>='
@@ -33,10 +33,10 @@ dependencies:
33
33
  version: '0'
34
34
  type: :runtime
35
35
  prerelease: false
36
- version_requirements: *2156803060
36
+ version_requirements: *2168961240
37
37
  - !ruby/object:Gem::Dependency
38
38
  name: minitest
39
- requirement: &2156802640 !ruby/object:Gem::Requirement
39
+ requirement: &2168960820 !ruby/object:Gem::Requirement
40
40
  none: false
41
41
  requirements:
42
42
  - - ! '>='
@@ -44,10 +44,10 @@ dependencies:
44
44
  version: '0'
45
45
  type: :development
46
46
  prerelease: false
47
- version_requirements: *2156802640
47
+ version_requirements: *2168960820
48
48
  - !ruby/object:Gem::Dependency
49
49
  name: rack-test
50
- requirement: &2156802220 !ruby/object:Gem::Requirement
50
+ requirement: &2168960400 !ruby/object:Gem::Requirement
51
51
  none: false
52
52
  requirements:
53
53
  - - ! '>='
@@ -55,10 +55,10 @@ dependencies:
55
55
  version: '0'
56
56
  type: :development
57
57
  prerelease: false
58
- version_requirements: *2156802220
58
+ version_requirements: *2168960400
59
59
  - !ruby/object:Gem::Dependency
60
60
  name: guard
61
- requirement: &2156801800 !ruby/object:Gem::Requirement
61
+ requirement: &2168959980 !ruby/object:Gem::Requirement
62
62
  none: false
63
63
  requirements:
64
64
  - - ! '>='
@@ -66,10 +66,10 @@ dependencies:
66
66
  version: '0'
67
67
  type: :development
68
68
  prerelease: false
69
- version_requirements: *2156801800
69
+ version_requirements: *2168959980
70
70
  - !ruby/object:Gem::Dependency
71
71
  name: guard-minitest
72
- requirement: &2156801380 !ruby/object:Gem::Requirement
72
+ requirement: &2168959560 !ruby/object:Gem::Requirement
73
73
  none: false
74
74
  requirements:
75
75
  - - ! '>='
@@ -77,7 +77,7 @@ dependencies:
77
77
  version: '0'
78
78
  type: :development
79
79
  prerelease: false
80
- version_requirements: *2156801380
80
+ version_requirements: *2168959560
81
81
  description: combines assets to server 1 file
82
82
  email:
83
83
  - r.hackr@gmail.com