agouti 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,3 +1,3 @@
1
1
  module Agouti
2
- VERSION = "0.0.1"
2
+ VERSION = '0.0.2'
3
3
  end
@@ -0,0 +1,91 @@
1
+ require 'spec_helper'
2
+
3
+ describe Agouti::Rack::PackageLimiter do
4
+
5
+ let(:app) { ->(env) { [200, headers, []] } }
6
+
7
+ describe '#call' do
8
+
9
+ subject { described_class.new(app).call(env) }
10
+
11
+ context 'when header X-Agouti-Enable is set' do
12
+
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 } }
16
+
17
+ context 'when the request response is not an html' do
18
+ it 'returns status code 204' do
19
+ expect(subject). to match_array([204, {}, []])
20
+ end
21
+ end
22
+
23
+ context 'when header X-Agouti-Limit is not set' do
24
+ it 'returns gzipped data truncated at 14000 bytes' do
25
+ headers.merge!('Content-Type' => 'text/html')
26
+
27
+ response_status, response_headers, response_body = subject
28
+
29
+ expect(response_status).to eq(200)
30
+ expect(response_headers).to include(headers.merge!('Content-Encoding' => 'gzip'))
31
+ expect(response_body).to be_a(Agouti::Rack::PackageLimiter::GzipTruncatedStream)
32
+ expect(response_body.instance_variable_get(:@byte_limit)).to eq(14000)
33
+ end
34
+ end
35
+
36
+ context 'when header X-Agouti-Limit is set' do
37
+
38
+ context 'when header X-Agouti-Limit is set with a valid number of bytes' do
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)
42
+
43
+ response_status, response_headers, response_body = subject
44
+
45
+ expect(response_status).to eq(200)
46
+ expect(response_headers).to include(headers.merge!('Content-Encoding' => 'gzip'))
47
+ expect(response_body).to be_a(Agouti::Rack::PackageLimiter::GzipTruncatedStream)
48
+ expect(response_body.instance_variable_get(:@byte_limit)).to eq(10)
49
+ end
50
+ end
51
+
52
+ context 'when header X-Agouti-Limit is set with an invalid value' do
53
+ let(:headers) { { 'X-Agouti-Limit' => 'foobar' } }
54
+ let(:env) { { 'HTTP_X_AGOUTI_LIMIT' => 'foobar' } }
55
+
56
+ it 'raises invalid header exception' do
57
+ expect { subject }.to raise_exception(Agouti::Rack::PackageLimiter::InvalidHeaderException)
58
+ end
59
+ end
60
+ end
61
+ end
62
+
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 } }
66
+
67
+ it 'does nothing' do
68
+ expect(subject). to match_array([200, headers, []])
69
+ end
70
+ end
71
+
72
+ context 'when header X-Agouti-Enable is set with an invalid value' do
73
+ let(:headers) { { 'X-Agouti-Enable' => 'foobar' } }
74
+ let(:env) { { 'HTTP_X_AGOUTI_ENABLE' => 'foobar' } }
75
+
76
+ it 'raises invalid header exception' do
77
+ expect { subject }.to raise_exception(Agouti::Rack::PackageLimiter::InvalidHeaderException)
78
+ end
79
+ end
80
+ end
81
+
82
+ context 'when header X-Agouti-Enable is not set' do
83
+ let(:headers) { { } }
84
+ let(:env) { { } }
85
+
86
+ it 'does nothing' do
87
+ expect(subject). to match_array([200, headers, []])
88
+ end
89
+ end
90
+ end
91
+ end
@@ -0,0 +1,7 @@
1
+ require 'bundler/setup'
2
+ Bundler.setup
3
+
4
+ require 'agouti'
5
+
6
+ RSpec.configure do |config|
7
+ end
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.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - dwayhs
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-08-27 00:00:00.000000000 Z
11
+ date: 2014-09-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rack
@@ -52,6 +52,62 @@ dependencies:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
54
  version: '10.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: pry
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'
83
+ - !ruby/object:Gem::Dependency
84
+ name: pry-nav
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: yard-tomdoc
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
55
111
  description: ''
56
112
  email:
57
113
  - danielwayhs@gmail.com
@@ -60,15 +116,41 @@ extensions: []
60
116
  extra_rdoc_files: []
61
117
  files:
62
118
  - ".gitignore"
119
+ - ".rspec"
120
+ - ".travis.yml"
121
+ - CHANGELOG.md
63
122
  - Gemfile
123
+ - Gemfile.lock
64
124
  - LICENSE.txt
65
125
  - README.md
66
126
  - Rakefile
67
127
  - agouti.gemspec
128
+ - doc/Agouti.html
129
+ - doc/Agouti/Rack.html
130
+ - doc/Agouti/Rack/PackageLimiter.html
131
+ - doc/Agouti/Rack/PackageLimiter/GzipTruncatedStream.html
132
+ - doc/Agouti/Rack/PackageLimiter/InvalidHeaderException.html
133
+ - doc/Agouti/Railtie.html
134
+ - doc/_index.html
135
+ - doc/class_list.html
136
+ - doc/css/common.css
137
+ - doc/css/full_list.css
138
+ - doc/css/style.css
139
+ - doc/file.README.html
140
+ - doc/file_list.html
141
+ - doc/frames.html
142
+ - doc/index.html
143
+ - doc/js/app.js
144
+ - doc/js/full_list.js
145
+ - doc/js/jquery.js
146
+ - doc/method_list.html
147
+ - doc/top-level-namespace.html
68
148
  - lib/agouti.rb
69
149
  - lib/agouti/rack/package_limiter.rb
70
150
  - lib/agouti/railtie.rb
71
151
  - lib/agouti/version.rb
152
+ - spec/rack/package_limiter_spec.rb
153
+ - spec/spec_helper.rb
72
154
  homepage: ''
73
155
  licenses:
74
156
  - MIT
@@ -93,4 +175,7 @@ rubygems_version: 2.2.2
93
175
  signing_key:
94
176
  specification_version: 4
95
177
  summary: Gem for testing above the fold render on the first tcp round trip.
96
- test_files: []
178
+ test_files:
179
+ - spec/rack/package_limiter_spec.rb
180
+ - spec/spec_helper.rb
181
+ has_rdoc: