forked from freeCodeCamp/devdocs
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp_test.rb
More file actions
218 lines (182 loc) · 5.31 KB
/
app_test.rb
File metadata and controls
218 lines (182 loc) · 5.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
require 'test_helper'
require 'rack/test'
require 'app'
class AppTest < MiniTest::Spec
include Rack::Test::Methods
def app
App
end
describe "/" do
it "works" do
get '/'
assert last_response.ok?
end
it "redirects without the query string" do
get '/', foo: 'bar'
assert last_response.redirect?
assert_equal 'http://example.org/', last_response['Location']
end
it "sets default size" do
get '/'
assert_includes last_response.body, 'data-size="18rem"'
end
it "sets size from cookie" do
set_cookie('size=42')
get '/'
assert_includes last_response.body, 'data-size="42px"'
end
end
describe "/[static-page]" do
it "redirects to /#/[static-page]" do
%w(offline about news help).each do |page|
get "/#{page}"
assert last_response.redirect?
assert_equal "http://example.org/#/#{page}", last_response['Location']
end
end
end
describe "/search" do
it "redirects to /#q=" do
get '/search'
assert last_response.redirect?
assert_equal 'http://example.org/#q=', last_response['Location']
get '/search', q: 'foo'
assert last_response.redirect?
assert_equal 'http://example.org/#q=foo', last_response['Location']
end
end
describe "/manifest.appcache" do
it "works" do
get '/manifest.appcache'
assert last_response.ok?
end
it "works with cookie" do
set_cookie('docs=css/html')
get '/manifest.appcache'
assert last_response.ok?
assert_includes last_response.body, '/css/index.json'
assert_includes last_response.body, '/html/index.json'
end
it "includes has the word 'light' by default" do
get '/manifest.appcache'
assert_includes last_response.body, '# light'
refute_includes last_response.body, '# dark'
end
it "includes has the word 'dark' when the cookie is set" do
set_cookie('dark=1')
get '/manifest.appcache'
assert_includes last_response.body, '# dark'
refute_includes last_response.body, '# light'
end
it "sets default size" do
get '/manifest.appcache'
assert_includes last_response.body, '18rem'
end
it "sets size from cookie" do
set_cookie('size=42')
get '/manifest.appcache'
assert_includes last_response.body, '42px'
end
end
describe "/[doc]" do
it "works when the doc exists" do
get '/html/'
assert last_response.ok?
end
it "returns 404 when the doc doesn't exist" do
get '/foo/'
assert last_response.not_found?
end
it "redirects with trailing slash" do
get '/html'
assert last_response.redirect?
assert_equal 'http://example.org/html/', last_response['Location']
get '/html', bar: 'baz'
assert last_response.redirect?
assert_equal 'http://example.org/html/?bar=baz', last_response['Location']
end
end
describe "/[doc]-[type]" do
it "works when the doc exists" do
get '/html-foo-bar_42/'
assert last_response.ok?
end
it "returns 404 when the type is blank" do
get '/html-/'
assert last_response.not_found?
end
it "returns 404 when the type is not alpha-numeric" do
get '/html-foo:bar/'
assert last_response.not_found?
end
it "returns 404 when the doc doesn't exist" do
get '/foo-bar/'
assert last_response.not_found?
end
it "redirects with trailing slash" do
get '/html-foo'
assert last_response.redirect?
assert_equal 'http://example.org/html-foo/', last_response['Location']
get '/html-foo', bar: 'baz'
assert last_response.redirect?
assert_equal 'http://example.org/html-foo/?bar=baz', last_response['Location']
end
end
describe "/[doc+type]/[path]" do
it "works when the doc exists" do
get '/html/foo'
assert last_response.ok?
get '/html-bar/foo'
assert last_response.ok?
end
it "returns 404 when the doc doesn't exist" do
get '/foo/bar'
assert last_response.not_found?
end
it "redirects without trailing slash" do
get '/html/foo/'
assert last_response.redirect?
assert_equal 'http://example.org/html/foo', last_response['Location']
get '/html/foo/', bar: 'baz'
assert last_response.redirect?
assert_equal 'http://example.org/html/foo?bar=baz', last_response['Location']
end
end
describe "/docs.json" do
it "returns to the asset path" do
get '/docs.json'
assert last_response.redirect?
assert_equal 'http://example.org/assets/docs.json', last_response['Location']
end
end
describe "/feed" do
it "returns an atom feed" do
get '/feed'
assert last_response.ok?
assert_equal 'application/atom+xml', last_response['Content-Type']
get '/feed.atom'
assert last_response.ok?
assert_equal 'application/atom+xml', last_response['Content-Type']
end
end
describe "/s/[link]" do
it "redirects" do
%w(maxcdn shopify tw fb re).each do |link|
get "/s/#{link}"
assert last_response.redirect?
end
end
end
describe "/ping" do
it "works" do
get '/ping'
assert last_response.ok?
end
end
describe "404" do
it "works" do
get '/foo'
assert last_response.not_found?
end
end
end