revision_plate 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Rakefile +0 -1
- data/lib/revision_plate/app.rb +16 -4
- data/lib/revision_plate/middleware.rb +3 -1
- data/lib/revision_plate/version.rb +1 -1
- data/test/app_test.rb +49 -0
- data/test/middleware_test.rb +11 -5
- 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: 79c5fecbb74c1167c4ababa438d21c0d4a335de2
|
4
|
+
data.tar.gz: 2d6d2dea11eeb2cf53811677bf3c36a44ff1d234
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6b968fd20dc480ccaffec595c29739e369dff49d8545a475bd067c067a62d8d9f704ea3b603b71e2dee4449823d089a8e6abaacfc71f2c4c74d3e6a0a9698681
|
7
|
+
data.tar.gz: 909f0979af1ca2d06799d396f2e99322aa8d9bd791a50cb906f8275cae2ef11a1039532b0674184652e3a4a024dad88301a489dd7bd83d293f2ec2b2f4cb0a13
|
data/Rakefile
CHANGED
data/lib/revision_plate/app.rb
CHANGED
@@ -24,19 +24,31 @@ module RevisionPlate
|
|
24
24
|
end
|
25
25
|
end
|
26
26
|
|
27
|
+
ACCEPT_METHODS = ['GET', 'HEAD'].freeze
|
28
|
+
|
27
29
|
def call(env)
|
28
|
-
unless env['REQUEST_METHOD']
|
30
|
+
unless ACCEPT_METHODS.include?(env['REQUEST_METHOD']) && (@path ? env['PATH_INFO'] == @path : true)
|
29
31
|
return [404, {'Content-Type' => 'text/plain'}, []]
|
30
32
|
end
|
31
33
|
|
32
34
|
if @revision
|
33
35
|
if @file.exist?
|
34
|
-
|
36
|
+
status = 200
|
37
|
+
body = [@revision, ?\n]
|
35
38
|
else
|
36
|
-
|
39
|
+
status = 404
|
40
|
+
body = ["REVISION_FILE_REMOVED\n"]
|
37
41
|
end
|
38
42
|
else
|
39
|
-
|
43
|
+
status = 404
|
44
|
+
body = ["REVISION_FILE_NOT_FOUND\n"]
|
45
|
+
end
|
46
|
+
|
47
|
+
headers = {'Content-Type' => 'text/plain'}
|
48
|
+
if env['REQUEST_METHOD'] == 'HEAD'
|
49
|
+
[status, headers, []]
|
50
|
+
else
|
51
|
+
[status, headers, body]
|
40
52
|
end
|
41
53
|
end
|
42
54
|
end
|
@@ -8,8 +8,10 @@ module RevisionPlate
|
|
8
8
|
@revision_app = App.new(file, **options)
|
9
9
|
end
|
10
10
|
|
11
|
+
ACCEPT_METHODS = %w[GET HEAD].freeze
|
12
|
+
|
11
13
|
def call(env)
|
12
|
-
if env['PATH_INFO'] == @path && env['REQUEST_METHOD']
|
14
|
+
if env['PATH_INFO'] == @path && ACCEPT_METHODS.include?(env['REQUEST_METHOD'])
|
13
15
|
@revision_app.call(env)
|
14
16
|
else
|
15
17
|
@app.call(env)
|
data/test/app_test.rb
CHANGED
@@ -42,6 +42,14 @@ class AppTest < Minitest::Spec
|
|
42
42
|
assert_equal 200, response.status
|
43
43
|
assert_equal "a\n", response.body
|
44
44
|
end
|
45
|
+
|
46
|
+
describe 'HEAD request' do
|
47
|
+
it 'returns 200' do
|
48
|
+
head '/'
|
49
|
+
assert_equal 200, response.status
|
50
|
+
assert_equal '', response.body
|
51
|
+
end
|
52
|
+
end
|
45
53
|
end
|
46
54
|
|
47
55
|
describe 'without Rails' do
|
@@ -59,12 +67,19 @@ class AppTest < Minitest::Spec
|
|
59
67
|
assert_equal 200, response.status
|
60
68
|
assert_equal "a\n", response.body
|
61
69
|
|
70
|
+
head '/site/sha'
|
71
|
+
assert_equal 200, response.status
|
72
|
+
assert_equal "", response.body
|
73
|
+
|
62
74
|
post '/site/sha'
|
63
75
|
assert_equal 404, response.status
|
64
76
|
|
65
77
|
get '/site/sha/a'
|
66
78
|
assert_equal 404, response.status
|
67
79
|
|
80
|
+
head '/site/sha/a'
|
81
|
+
assert_equal 404, response.status
|
82
|
+
|
68
83
|
get '/'
|
69
84
|
assert_equal 404, response.status
|
70
85
|
end
|
@@ -90,6 +105,12 @@ class AppTest < Minitest::Spec
|
|
90
105
|
assert_equal 404, response.status
|
91
106
|
end
|
92
107
|
|
108
|
+
it 'returns 200 for HEAD request' do
|
109
|
+
head '/'
|
110
|
+
assert_equal 200, response.status
|
111
|
+
assert_equal '', response.body
|
112
|
+
end
|
113
|
+
|
93
114
|
it 'returns 404 if removed' do
|
94
115
|
app # ensure to instantiate
|
95
116
|
file.unlink
|
@@ -99,6 +120,15 @@ class AppTest < Minitest::Spec
|
|
99
120
|
assert_equal "REVISION_FILE_REMOVED\n", response.body
|
100
121
|
end
|
101
122
|
|
123
|
+
it 'returns 404 for HEAD request if removed' do
|
124
|
+
app # ensure to instantiate
|
125
|
+
file.unlink
|
126
|
+
|
127
|
+
head '/'
|
128
|
+
assert_equal 404, response.status
|
129
|
+
assert_equal '', response.body
|
130
|
+
end
|
131
|
+
|
102
132
|
it 'returns 404 if not exists' do
|
103
133
|
file.unlink
|
104
134
|
app # instantiate
|
@@ -108,6 +138,15 @@ class AppTest < Minitest::Spec
|
|
108
138
|
assert_equal "REVISION_FILE_NOT_FOUND\n", response.body
|
109
139
|
end
|
110
140
|
|
141
|
+
it 'returns 404 for HEAD request if not exists' do
|
142
|
+
file.unlink
|
143
|
+
app # instantiate
|
144
|
+
|
145
|
+
head '/'
|
146
|
+
assert_equal 404, response.status
|
147
|
+
assert_equal '', response.body
|
148
|
+
end
|
149
|
+
|
111
150
|
it 'returns 404 if created but it was not existed' do
|
112
151
|
file.unlink
|
113
152
|
app # instantiate
|
@@ -117,5 +156,15 @@ class AppTest < Minitest::Spec
|
|
117
156
|
assert_equal 404, response.status
|
118
157
|
assert_equal "REVISION_FILE_NOT_FOUND\n", response.body
|
119
158
|
end
|
159
|
+
|
160
|
+
it 'returns 404 for HEAD request if created but it was not existed' do
|
161
|
+
file.unlink
|
162
|
+
app # instantiate
|
163
|
+
File.write file.to_s, "b\n"
|
164
|
+
|
165
|
+
head '/'
|
166
|
+
assert_equal 404, response.status
|
167
|
+
assert_equal '', response.body
|
168
|
+
end
|
120
169
|
end
|
121
170
|
end
|
data/test/middleware_test.rb
CHANGED
@@ -32,6 +32,8 @@ class AppTest < Minitest::Spec
|
|
32
32
|
def call(env)
|
33
33
|
[200, {'Content-Type' => 'text/plain'}, "deadbeef"]
|
34
34
|
end
|
35
|
+
|
36
|
+
const_set(:ACCEPT_METHODS, %w[GET HEAD].freeze)
|
35
37
|
end
|
36
38
|
end
|
37
39
|
|
@@ -57,18 +59,22 @@ class AppTest < Minitest::Spec
|
|
57
59
|
|
58
60
|
it 'pass-through requests to nextapp' do
|
59
61
|
get '/'
|
60
|
-
assert_equal response.body
|
62
|
+
assert_equal 'hi', response.body
|
61
63
|
post '/'
|
62
|
-
assert_equal response.body
|
64
|
+
assert_equal 'hi', response.body
|
63
65
|
get '/site'
|
64
|
-
assert_equal response.body
|
66
|
+
assert_equal 'hi', response.body
|
65
67
|
post '/site/sha'
|
66
|
-
assert_equal response.body
|
68
|
+
assert_equal 'hi', response.body
|
67
69
|
end
|
68
70
|
|
69
71
|
it 'pass requests to RevisionPlate::App on specific path' do
|
70
72
|
get '/site/sha'
|
71
|
-
assert_equal response.body
|
73
|
+
assert_equal 'deadbeef', response.body
|
74
|
+
|
75
|
+
head '/site/sha'
|
76
|
+
assert_equal 200, response.status
|
77
|
+
assert_equal 'deadbeef', response.body
|
72
78
|
end
|
73
79
|
end
|
74
80
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: revision_plate
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Shota Fukumori (sora_h)
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-04-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|