floodgate 0.0.3 → 0.0.7
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 +4 -4
- data/lib/floodgate/version.rb +1 -1
- data/lib/floodgate.rb +16 -7
- data/spec/floodgate_spec.rb +71 -9
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: dfa3da66938d40caf0237a7ea2c66e092948332c
|
4
|
+
data.tar.gz: 00a92131edb02b28a8ed0f6d2a6858f56bdc8320
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d0665c1e13d70a8ae8e253509d366ab835fdf143736d03a4ffabfc63c02f9c260470b42a4b7d63db958bacbe8091c0107764e389245bb2f36bf1463e394fb1a7
|
7
|
+
data.tar.gz: 5385f21d8fdeb1e9fc0c11333dbc9437e214a6c1576f42592b4f2cdf9871326f71de4ba91c3e584671471a6605d6517ba21894d508bc346998fc3b82bfdfabe6
|
data/lib/floodgate/version.rb
CHANGED
data/lib/floodgate.rb
CHANGED
@@ -6,18 +6,27 @@ module Floodgate
|
|
6
6
|
@app = app
|
7
7
|
end
|
8
8
|
|
9
|
-
def filter_traffic?(env)
|
10
|
-
!env['FLOODGATE_FILTER_TRAFFIC'].nil?
|
11
|
-
end
|
12
|
-
|
13
9
|
def call(env)
|
14
|
-
return @app.call(env) unless filter_traffic?
|
10
|
+
return @app.call(env) unless filter_traffic?
|
15
11
|
|
16
|
-
if
|
17
|
-
[307, { 'Location' =>
|
12
|
+
if redirect?
|
13
|
+
[307, { 'Location' => redirect_url }, []]
|
18
14
|
else
|
19
15
|
[503, {}, ['Application Unavailable']]
|
20
16
|
end
|
21
17
|
end
|
18
|
+
|
19
|
+
def filter_traffic?
|
20
|
+
!(ENV['FLOODGATE_FILTER_TRAFFIC'].nil? || ENV['FLOODGATE_FILTER_TRAFFIC'] == '')
|
21
|
+
end
|
22
|
+
|
23
|
+
def redirect?
|
24
|
+
!(redirect_url.nil? || redirect_url == '')
|
25
|
+
end
|
26
|
+
|
27
|
+
def redirect_url
|
28
|
+
ENV['MAINTENANCE_PAGE_URL']
|
29
|
+
end
|
30
|
+
|
22
31
|
end
|
23
32
|
end
|
data/spec/floodgate_spec.rb
CHANGED
@@ -6,6 +6,16 @@ module Floodgate
|
|
6
6
|
let(:control) { described_class.new(app) }
|
7
7
|
let(:env) { Hash.new }
|
8
8
|
|
9
|
+
before do
|
10
|
+
ENV['FLOODGATE_FILTER_TRAFFIC'] = ''
|
11
|
+
ENV['MAINTENANCE_PAGE_URL'] = ''
|
12
|
+
end
|
13
|
+
|
14
|
+
after do
|
15
|
+
ENV['FLOODGATE_FILTER_TRAFFIC'] = ''
|
16
|
+
ENV['MAINTENANCE_PAGE_URL'] = ''
|
17
|
+
end
|
18
|
+
|
9
19
|
describe '#call' do
|
10
20
|
it 'sends :call to the app with the specified environment' do
|
11
21
|
expect(app).to receive(:call).with(env)
|
@@ -13,7 +23,7 @@ module Floodgate
|
|
13
23
|
end
|
14
24
|
|
15
25
|
context 'when the floodgate is closed' do
|
16
|
-
before {
|
26
|
+
before { ENV['FLOODGATE_FILTER_TRAFFIC'] = 'closed' }
|
17
27
|
|
18
28
|
let(:control) { described_class.new(app) }
|
19
29
|
|
@@ -22,8 +32,20 @@ module Floodgate
|
|
22
32
|
control.call(env)
|
23
33
|
end
|
24
34
|
|
35
|
+
context 'when no maintenance page is specified in the environment' do
|
36
|
+
before { ENV['MAINTENANCE_PAGE_URL'] = '' }
|
37
|
+
|
38
|
+
it 'responds with a status of service unavailable' do
|
39
|
+
expect(control.call(env)[0]).to eq(503)
|
40
|
+
end
|
41
|
+
|
42
|
+
it 'has an appropriate message in the response' do
|
43
|
+
expect(control.call(env)[2]).to eq(['Application Unavailable'])
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
25
47
|
context 'when a maintenance page is specified in the environment' do
|
26
|
-
before {
|
48
|
+
before { ENV['MAINTENANCE_PAGE_URL'] = 'someurl' }
|
27
49
|
|
28
50
|
it 'redirects with a temporary redirect status' do
|
29
51
|
expect(control.call(env)[0]).to eq(307)
|
@@ -33,17 +55,57 @@ module Floodgate
|
|
33
55
|
expect(control.call(env)[1]['Location']).to eq('someurl')
|
34
56
|
end
|
35
57
|
end
|
58
|
+
end
|
59
|
+
end
|
36
60
|
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
61
|
+
describe '#filter_traffic?' do
|
62
|
+
it 'returns false by default' do
|
63
|
+
expect(control.filter_traffic?).to eq(false)
|
64
|
+
end
|
41
65
|
|
42
|
-
|
43
|
-
|
44
|
-
|
66
|
+
context 'when traffic filtering is enabled in the environment' do
|
67
|
+
before { ENV['FLOODGATE_FILTER_TRAFFIC'] = 'closed' }
|
68
|
+
|
69
|
+
it 'returns true' do
|
70
|
+
expect(control.filter_traffic?).to eq(true)
|
71
|
+
end
|
72
|
+
|
73
|
+
after { ENV['FLOODGATE_FILTER_TRAFFIC'] = nil }
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
describe '#redirect?' do
|
78
|
+
it 'is false by default' do
|
79
|
+
expect(control.redirect?).to eq(false)
|
80
|
+
end
|
81
|
+
|
82
|
+
context 'when the redirect url is an empty string' do
|
83
|
+
before { control.stub(:redirect_url).and_return '' }
|
84
|
+
|
85
|
+
it 'is false' do
|
86
|
+
expect(control.redirect?).to eq(false)
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
context 'when the redirect url is a string' do
|
91
|
+
before { control.stub(:redirect_url).and_return 'someurl' }
|
92
|
+
|
93
|
+
it 'is true' do
|
94
|
+
expect(control.redirect?).to eq(true)
|
45
95
|
end
|
46
96
|
end
|
47
97
|
end
|
98
|
+
|
99
|
+
describe '#redirect_url' do
|
100
|
+
context 'when a maintenance page is specified in the environment' do
|
101
|
+
before { ENV['MAINTENANCE_PAGE_URL'] = 'someurl' }
|
102
|
+
|
103
|
+
it 'returns the maintenance page url' do
|
104
|
+
expect(control.redirect_url).to eq('someurl')
|
105
|
+
end
|
106
|
+
|
107
|
+
after { ENV['MAINTENANCE_PAGE_URL'] = '' }
|
108
|
+
end
|
109
|
+
end
|
48
110
|
end
|
49
111
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: floodgate
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mark McEahern
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2014-02-
|
12
|
+
date: 2014-02-17 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rake
|