agouti 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2d220334119fa85a7b2ddc377869b628032dc0e6
4
- data.tar.gz: f8237d926836a2490b283c9074fc75233c64c6cd
3
+ metadata.gz: 01b7db6614008d1aff38366c1a91557afb6fd75e
4
+ data.tar.gz: 0ccc48a55e09512ccddad67e3d74800dbeb971a7
5
5
  SHA512:
6
- metadata.gz: 2119a404d3ff535dd01354e9abde09a4eda59bf485574929a53d3985d287d9ea2a8c7f41230166207608505fcb0718450ca61ff7b9fe08e1b144a36d9060e506
7
- data.tar.gz: 144a9805e7ad6eec204a70691d63e23f1ddece6ea4dbda038965e7a277ee113a5378768d3fcd33715e1fb2723a2a532fa926ce96f9dcc648402823d7dcb3f7e5
6
+ metadata.gz: 864cb988390b4f297e19c9ef0fe694c6d887323e7f582e33ac92e9a257408f2c8bc12690224823968e925271c82e359ce5429488e418bfc68cd4fcc000c79c5e
7
+ data.tar.gz: de652806d32533f7dfdc32e4416214d6eb4bea9aaa6ba5a965e328c653a1910210c2a1c1dc16dc311556432f2d1e9aa1161b89fc241e7a0caf8a604e47dffdf4
@@ -7,3 +7,7 @@
7
7
  ## 0.0.2
8
8
 
9
9
  * Refactoring, add tests and code documentation.
10
+
11
+ ## 0.0.3
12
+
13
+ * Fix issues
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- agouti (0.0.2)
4
+ agouti (0.0.3)
5
5
  rack (~> 1.5)
6
6
 
7
7
  GEM
@@ -48,7 +48,7 @@ module Agouti
48
48
  set_limit(env)
49
49
 
50
50
  if enabled?(env)
51
- unless headers['Content-Type'] == 'text/html'
51
+ unless headers['Content-Type'] && headers['Content-Type'].include?('text/html')
52
52
  return [204, {}, []]
53
53
  end
54
54
 
@@ -71,27 +71,34 @@ module Agouti
71
71
  end
72
72
 
73
73
  def enabled? env
74
- get_http_header(env, ENABLE_HEADER) && get_http_header(env, ENABLE_HEADER) == 1
74
+ get_http_header(env, ENABLE_HEADER).to_i == 1
75
75
  end
76
76
 
77
77
  def set_limit env
78
78
  @limit = (get_http_header(env, LIMIT_HEADER)) ? get_http_header(env, LIMIT_HEADER).to_i : DEFAULT_LIMIT
79
79
  end
80
80
 
81
- def valid_enable_header? env
82
- header = get_http_header(env, ENABLE_HEADER)
81
+ def valid? env
82
+ valid_enable_header?(env) && valid_limit_header?(env)
83
+ end
83
84
 
84
- (0..1).include?(header) || header.nil?
85
+ def parseable?(header)
86
+ (header =~ /^[0-9]+$/) == 0
85
87
  end
86
88
 
87
- def valid_limit_header? env
88
- header = get_http_header(env, LIMIT_HEADER)
89
+ # Defines two methods: valid_enable_header? and valid_limit_header?
90
+ ['enable', 'limit'].each do |action|
91
+ define_method("valid_#{action}_header?") do |env|
92
+ header = get_http_header(env, self.class.const_get("#{action.upcase}_HEADER"))
89
93
 
90
- (header.kind_of?(Integer) && header > 0) || header.nil?
91
- end
94
+ return true if header.nil?
92
95
 
93
- def valid? env
94
- valid_enable_header?(env) && valid_limit_header?(env)
96
+ if parseable?(header)
97
+ header.to_i >= 0
98
+ else
99
+ false
100
+ end
101
+ end
95
102
  end
96
103
 
97
104
  # Public: class responsible for truncating the gzip stream to a given number of bytes.
@@ -1,3 +1,3 @@
1
1
  module Agouti
2
- VERSION = '0.0.2'
2
+ VERSION = '0.0.3'
3
3
  end
@@ -11,8 +11,8 @@ describe Agouti::Rack::PackageLimiter do
11
11
  context 'when header X-Agouti-Enable is set' do
12
12
 
13
13
  context 'when header X-Agouti-Enable is set with 1' do
14
- let(:headers) { { 'X-Agouti-Enable' => 1 } }
15
- let(:env) { { 'HTTP_X_AGOUTI_ENABLE' => 1 } }
14
+ let(:headers) { { 'X-Agouti-Enable' => '1' } }
15
+ let(:env) { { 'HTTP_X_AGOUTI_ENABLE' => '1' } }
16
16
 
17
17
  context 'when the request response is not an html' do
18
18
  it 'returns status code 204' do
@@ -37,8 +37,8 @@ describe Agouti::Rack::PackageLimiter do
37
37
 
38
38
  context 'when header X-Agouti-Limit is set with a valid number of bytes' do
39
39
  it 'returns gzipped data with given number of bytes' do
40
- headers.merge!('X-Agouti-Limit' => 10, 'Content-Type' => 'text/html')
41
- env.merge!('HTTP_X_AGOUTI_LIMIT' => 10)
40
+ headers.merge!('X-Agouti-Limit' => '10', 'Content-Type' => 'text/html')
41
+ env.merge!('HTTP_X_AGOUTI_LIMIT' => '10')
42
42
 
43
43
  response_status, response_headers, response_body = subject
44
44
 
@@ -61,8 +61,8 @@ describe Agouti::Rack::PackageLimiter do
61
61
  end
62
62
 
63
63
  context 'when header X-Agouti-Enable is set with 0' do
64
- let(:headers) { { 'X-Agouti-Enable' => 0 } }
65
- let(:env) { { 'HTTP_X_AGOUTI_ENABLE' => 0 } }
64
+ let(:headers) { { 'X-Agouti-Enable' => '0' } }
65
+ let(:env) { { 'HTTP_X_AGOUTI_ENABLE' => '0' } }
66
66
 
67
67
  it 'does nothing' do
68
68
  expect(subject). to match_array([200, headers, []])
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: agouti
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
  - dwayhs
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-09-02 00:00:00.000000000 Z
11
+ date: 2014-09-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rack