grape-swagger-rails 0.3.1 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (62) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/danger.yml +19 -0
  3. data/.github/workflows/head.yml +32 -0
  4. data/.github/workflows/rubocop.yml +14 -0
  5. data/.github/workflows/test.yml +35 -0
  6. data/.rubocop.yml +7 -2
  7. data/.rubocop_todo.yml +103 -32
  8. data/CHANGELOG.md +25 -14
  9. data/Dangerfile +2 -0
  10. data/Gemfile +24 -16
  11. data/README.md +32 -2
  12. data/RELEASING.md +4 -5
  13. data/Rakefile +5 -9
  14. data/app/assets/config/grape_swagger_rails_manifest.js +2 -0
  15. data/app/controllers/grape_swagger_rails/application_controller.rb +4 -2
  16. data/app/views/grape_swagger_rails/application/index.html.erb +1 -1
  17. data/config/routes.rb +2 -0
  18. data/grape-swagger-rails.gemspec +13 -29
  19. data/lib/grape-swagger-rails/engine.rb +2 -0
  20. data/lib/grape-swagger-rails/version.rb +3 -1
  21. data/lib/grape-swagger-rails.rb +17 -14
  22. data/lib/script/rails +4 -2
  23. data/lib/tasks/swagger_ui.rake +6 -3
  24. data/spec/dummy/Rakefile +6 -3
  25. data/spec/dummy/app/api/api.rb +2 -0
  26. data/spec/dummy/app/assets/config/manifest.js +3 -0
  27. data/spec/dummy/app/assets/javascripts/application.js +0 -2
  28. data/spec/dummy/app/controllers/application_controller.rb +2 -0
  29. data/spec/dummy/app/controllers/welcome_controller.rb +3 -2
  30. data/spec/dummy/app/views/layouts/application.html.erb +1 -0
  31. data/spec/dummy/bin/rails +3 -5
  32. data/spec/dummy/bin/rake +2 -4
  33. data/spec/dummy/bin/setup +27 -0
  34. data/spec/dummy/config/application.rb +11 -10
  35. data/spec/dummy/config/boot.rb +4 -7
  36. data/spec/dummy/config/environment.rb +6 -2
  37. data/spec/dummy/config/environments/development.rb +40 -19
  38. data/spec/dummy/config/environments/production.rb +31 -31
  39. data/spec/dummy/config/environments/test.rb +30 -20
  40. data/spec/dummy/config/initializers/assets.rb +13 -0
  41. data/spec/dummy/config/initializers/filter_parameter_logging.rb +10 -0
  42. data/spec/dummy/config/initializers/inflections.rb +18 -0
  43. data/spec/dummy/config/initializers/swagger.rb +2 -0
  44. data/spec/dummy/config/routes.rb +2 -0
  45. data/spec/dummy/config.ru +6 -2
  46. data/spec/dummy/public/404.html +6 -6
  47. data/spec/dummy/public/422.html +6 -6
  48. data/spec/dummy/public/500.html +6 -6
  49. data/spec/features/grape-swagger-rails_spec.rb +5 -1
  50. data/spec/features/swagger_spec.rb +97 -35
  51. data/spec/features/welcome_spec.rb +3 -0
  52. data/spec/spec_helper.rb +4 -2
  53. data/spec/support/capybara.rb +3 -0
  54. data/spec/support/rails.rb +2 -0
  55. metadata +25 -340
  56. data/.travis.yml +0 -53
  57. data/spec/dummy/bin/bundle +0 -3
  58. data/spec/dummy/bin/spring +0 -18
  59. data/spec/dummy/config/initializers/cookies_serializer.rb +0 -1
  60. data/spec/dummy/config/initializers/session_store.rb +0 -1
  61. data/spec/dummy/vendor/assets/javascripts/.keep +0 -0
  62. data/spec/dummy/vendor/assets/stylesheets/.keep +0 -0
@@ -4,7 +4,7 @@
4
4
  <title>The page you were looking for doesn't exist (404)</title>
5
5
  <meta name="viewport" content="width=device-width,initial-scale=1">
6
6
  <style>
7
- body {
7
+ .rails-default-error-page {
8
8
  background-color: #EFEFEF;
9
9
  color: #2E2F30;
10
10
  text-align: center;
@@ -12,13 +12,13 @@
12
12
  margin: 0;
13
13
  }
14
14
 
15
- div.dialog {
15
+ .rails-default-error-page div.dialog {
16
16
  width: 95%;
17
17
  max-width: 33em;
18
18
  margin: 4em auto 0;
19
19
  }
20
20
 
21
- div.dialog > div {
21
+ .rails-default-error-page div.dialog > div {
22
22
  border: 1px solid #CCC;
23
23
  border-right-color: #999;
24
24
  border-left-color: #999;
@@ -31,13 +31,13 @@
31
31
  box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
32
32
  }
33
33
 
34
- h1 {
34
+ .rails-default-error-page h1 {
35
35
  font-size: 100%;
36
36
  color: #730E15;
37
37
  line-height: 1.5em;
38
38
  }
39
39
 
40
- div.dialog > p {
40
+ .rails-default-error-page div.dialog > p {
41
41
  margin: 0 0 1em;
42
42
  padding: 1em;
43
43
  background-color: #F7F7F7;
@@ -54,7 +54,7 @@
54
54
  </style>
55
55
  </head>
56
56
 
57
- <body>
57
+ <body class="rails-default-error-page">
58
58
  <!-- This file lives in public/404.html -->
59
59
  <div class="dialog">
60
60
  <div>
@@ -4,7 +4,7 @@
4
4
  <title>The change you wanted was rejected (422)</title>
5
5
  <meta name="viewport" content="width=device-width,initial-scale=1">
6
6
  <style>
7
- body {
7
+ .rails-default-error-page {
8
8
  background-color: #EFEFEF;
9
9
  color: #2E2F30;
10
10
  text-align: center;
@@ -12,13 +12,13 @@
12
12
  margin: 0;
13
13
  }
14
14
 
15
- div.dialog {
15
+ .rails-default-error-page div.dialog {
16
16
  width: 95%;
17
17
  max-width: 33em;
18
18
  margin: 4em auto 0;
19
19
  }
20
20
 
21
- div.dialog > div {
21
+ .rails-default-error-page div.dialog > div {
22
22
  border: 1px solid #CCC;
23
23
  border-right-color: #999;
24
24
  border-left-color: #999;
@@ -31,13 +31,13 @@
31
31
  box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
32
32
  }
33
33
 
34
- h1 {
34
+ .rails-default-error-page h1 {
35
35
  font-size: 100%;
36
36
  color: #730E15;
37
37
  line-height: 1.5em;
38
38
  }
39
39
 
40
- div.dialog > p {
40
+ .rails-default-error-page div.dialog > p {
41
41
  margin: 0 0 1em;
42
42
  padding: 1em;
43
43
  background-color: #F7F7F7;
@@ -54,7 +54,7 @@
54
54
  </style>
55
55
  </head>
56
56
 
57
- <body>
57
+ <body class="rails-default-error-page">
58
58
  <!-- This file lives in public/422.html -->
59
59
  <div class="dialog">
60
60
  <div>
@@ -4,7 +4,7 @@
4
4
  <title>We're sorry, but something went wrong (500)</title>
5
5
  <meta name="viewport" content="width=device-width,initial-scale=1">
6
6
  <style>
7
- body {
7
+ .rails-default-error-page {
8
8
  background-color: #EFEFEF;
9
9
  color: #2E2F30;
10
10
  text-align: center;
@@ -12,13 +12,13 @@
12
12
  margin: 0;
13
13
  }
14
14
 
15
- div.dialog {
15
+ .rails-default-error-page div.dialog {
16
16
  width: 95%;
17
17
  max-width: 33em;
18
18
  margin: 4em auto 0;
19
19
  }
20
20
 
21
- div.dialog > div {
21
+ .rails-default-error-page div.dialog > div {
22
22
  border: 1px solid #CCC;
23
23
  border-right-color: #999;
24
24
  border-left-color: #999;
@@ -31,13 +31,13 @@
31
31
  box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
32
32
  }
33
33
 
34
- h1 {
34
+ .rails-default-error-page h1 {
35
35
  font-size: 100%;
36
36
  color: #730E15;
37
37
  line-height: 1.5em;
38
38
  }
39
39
 
40
- div.dialog > p {
40
+ .rails-default-error-page div.dialog > p {
41
41
  margin: 0 0 1em;
42
42
  padding: 1em;
43
43
  background-color: #F7F7F7;
@@ -54,7 +54,7 @@
54
54
  </style>
55
55
  </head>
56
56
 
57
- <body>
57
+ <body class="rails-default-error-page">
58
58
  <!-- This file lives in public/500.html -->
59
59
  <div class="dialog">
60
60
  <div>
@@ -1,13 +1,17 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'spec_helper'
2
4
 
3
5
  describe GrapeSwaggerRails do
4
- context '#options' do
6
+ describe '#options' do
5
7
  subject do
6
8
  GrapeSwaggerRails.options
7
9
  end
10
+
8
11
  it 'is an instance of Options' do
9
12
  expect(subject).to be_a GrapeSwaggerRails::Options
10
13
  end
14
+
11
15
  it 'defaults headers to an empty hash' do
12
16
  expect(subject.headers).to eq({})
13
17
  end
@@ -1,46 +1,62 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'spec_helper'
2
4
 
3
5
  describe 'Swagger' do
6
+ it "uses grape-swagger=#{GrapeSwagger::VERSION} grape-swagger-rails=#{GrapeSwaggerRails::VERSION}" do
7
+ expect(GrapeSwagger::VERSION).not_to be_blank
8
+ expect(GrapeSwaggerRails::VERSION).not_to be_blank
9
+ end
10
+
4
11
  context 'swaggerUi' do
5
12
  before do
6
13
  visit '/swagger'
7
14
  end
15
+
8
16
  it 'loads foos resource' do
9
17
  expect(page).to have_css 'li#resource_foos'
10
18
  end
19
+
11
20
  it 'loads Swagger UI' do
12
21
  expect(page.evaluate_script('window.swaggerUi != null')).to be true
13
22
  end
14
23
  end
15
- context '#options' do
24
+
25
+ describe '#options' do
16
26
  before do
17
27
  @options = GrapeSwaggerRails.options.dup
18
28
  end
19
29
 
30
+ after do
31
+ GrapeSwaggerRails.options = @options
32
+ end
33
+
20
34
  it 'evaluates config options correctly' do
21
35
  visit '/swagger'
22
36
  page_options = page.evaluate_script("$('html').data('swagger-options')").symbolize_keys
23
37
  expect(page_options).to eq(@options.marshal_dump)
24
38
  end
25
39
 
26
- context '#headers' do
40
+ describe '#headers' do
27
41
  before do
28
42
  GrapeSwaggerRails.options.headers['X-Test-Header'] = 'Test Value'
29
43
  GrapeSwaggerRails.options.headers['X-Another-Header'] = 'Another Value'
30
44
  visit '/swagger'
31
45
  end
46
+
32
47
  it 'adds headers' do
33
48
  headers = page.evaluate_script('swaggerUi.api.clientAuthorizations')['authz']
34
49
  expect(headers.select { |key| key.to_s.match(/^header/) }).not_to be_blank
35
50
  expect(headers.fetch('header_0', {}).fetch('name', {})).to eq GrapeSwaggerRails.options.headers.keys.first
36
- find('#endpointListTogger_headers', visible: true).click
51
+ find_by_id('endpointListTogger_headers', visible: true).click
37
52
  first('span[class="http_method"] a', visible: true).click
38
53
  click_button 'Try it out!'
39
54
  expect(page).to have_css 'span.hljs-attr', text: 'X-Test-Header'
40
55
  expect(page).to have_css 'span.hljs-string', text: 'Test Value'
41
56
  end
57
+
42
58
  it 'supports multiple headers' do
43
- find('#endpointListTogger_headers', visible: true).click
59
+ find_by_id('endpointListTogger_headers', visible: true).click
44
60
  first('span[class="http_method"] a', visible: true).click
45
61
  click_button 'Try it out!'
46
62
  expect(page).to have_css 'span.hljs-attr', text: 'X-Test-Header'
@@ -49,7 +65,8 @@ describe 'Swagger' do
49
65
  expect(page).to have_css 'span.hljs-string', text: 'Another Value'
50
66
  end
51
67
  end
52
- context '#api_key_default_value' do
68
+
69
+ describe '#api_key_default_value' do
53
70
  before do
54
71
  GrapeSwaggerRails.options.api_auth = 'bearer'
55
72
  GrapeSwaggerRails.options.api_key_name = 'Authorization'
@@ -57,6 +74,7 @@ describe 'Swagger' do
57
74
  GrapeSwaggerRails.options.api_key_default_value = 'token'
58
75
  visit '/swagger'
59
76
  end
77
+
60
78
  it 'adds an Authorization header' do
61
79
  headers = page.evaluate_script('swaggerUi.api.clientAuthorizations')['authz']
62
80
  last_header = headers.fetch("header_#{headers.length - 1}", {})
@@ -64,85 +82,107 @@ describe 'Swagger' do
64
82
  .to eq('name' => 'Authorization', 'value' => 'Bearer token')
65
83
  end
66
84
  end
67
- context '#api_auth:basic' do
85
+
86
+ describe '#api_key_placeholder' do
87
+ before do
88
+ GrapeSwaggerRails.options.api_key_placeholder = 'authorization_code'
89
+ visit '/swagger'
90
+ end
91
+
92
+ it 'adds a custom placeholder' do
93
+ expect(find_by_id('input_apiKey')['placeholder']).to eq 'authorization_code'
94
+ end
95
+ end
96
+
97
+ describe '#api_auth:basic' do
68
98
  before do
69
99
  GrapeSwaggerRails.options.api_auth = 'basic'
70
100
  GrapeSwaggerRails.options.api_key_name = 'Authorization'
71
101
  GrapeSwaggerRails.options.api_key_type = 'header'
72
102
  visit '/swagger'
73
103
  end
104
+
74
105
  it 'adds an Authorization header' do
75
106
  page.execute_script("$('#input_apiKey').val('username:password')")
76
107
  page.execute_script("$('#input_apiKey').trigger('change')")
77
- find('#endpointListTogger_headers', visible: true).click
108
+ find_by_id('endpointListTogger_headers', visible: true).click
78
109
  first('span[class="http_method"] a', visible: true).click
79
110
  click_button 'Try it out!'
80
111
  expect(page).to have_css 'span.hljs-attr', text: 'Authorization'
81
112
  expect(page).to have_css 'span.hljs-string', text: "Basic #{Base64.encode64('username:password').strip}"
82
113
  end
83
114
  end
84
- context '#api_auth:bearer' do
115
+
116
+ describe '#api_auth:bearer' do
85
117
  before do
86
118
  GrapeSwaggerRails.options.api_auth = 'bearer'
87
119
  GrapeSwaggerRails.options.api_key_name = 'Authorization'
88
120
  GrapeSwaggerRails.options.api_key_type = 'header'
89
121
  visit '/swagger'
90
122
  end
123
+
91
124
  it 'adds an Authorization header' do
92
125
  page.execute_script("$('#input_apiKey').val('token')")
93
126
  page.execute_script("$('#input_apiKey').trigger('change')")
94
- find('#endpointListTogger_headers', visible: true).click
127
+ find_by_id('endpointListTogger_headers', visible: true).click
95
128
  first('span[class="http_method"] a', visible: true).click
96
129
  click_button 'Try it out!'
97
130
  expect(page).to have_css 'span.hljs-attr', text: 'Authorization'
98
131
  expect(page).to have_css 'span.hljs-string', text: 'Bearer token'
99
132
  end
100
133
  end
101
- context '#api_auth:token and #api_key_type:header' do
134
+
135
+ describe '#api_auth:token and #api_key_type:header' do
102
136
  before do
103
137
  GrapeSwaggerRails.options.api_auth = 'token'
104
138
  GrapeSwaggerRails.options.api_key_name = 'Authorization'
105
139
  GrapeSwaggerRails.options.api_key_type = 'header'
106
140
  visit '/swagger'
107
141
  end
142
+
108
143
  it 'adds an Authorization header' do
109
144
  page.execute_script("$('#input_apiKey').val('token')")
110
145
  page.execute_script("$('#input_apiKey').trigger('change')")
111
- find('#endpointListTogger_headers', visible: true).click
146
+ find_by_id('endpointListTogger_headers', visible: true).click
112
147
  first('span[class="http_method"] a', visible: true).click
113
148
  click_button 'Try it out!'
114
149
  expect(page).to have_css 'span.hljs-attr', text: 'Authorization'
115
150
  expect(page).to have_css 'span.hljs-string', text: 'Token token'
116
151
  end
117
152
  end
118
- context '#api_auth:token' do
153
+
154
+ describe '#api_auth:token' do
119
155
  before do
120
156
  GrapeSwaggerRails.options.api_key_name = 'api_token'
121
157
  GrapeSwaggerRails.options.api_key_type = 'query'
122
158
  visit '/swagger'
123
159
  end
160
+
124
161
  it 'adds an api_token query parameter' do
125
162
  page.execute_script("$('#input_apiKey').val('dummy')")
126
163
  page.execute_script("$('#input_apiKey').trigger('change')")
127
- find('#endpointListTogger_params', visible: true).click
164
+ find_by_id('endpointListTogger_params', visible: true).click
128
165
  first('span[class="http_method"] a', visible: true).click
129
166
  click_button 'Try it out!'
130
167
  expect(page).to have_css 'span.hljs-attr', text: 'api_token'
131
168
  expect(page).to have_css 'span.hljs-string', text: 'dummy'
132
169
  end
133
170
  end
134
- context '#before_filter' do
171
+
172
+ describe '#before_filter' do
135
173
  before do
136
174
  allow(ActiveSupport::Deprecation).to receive(:warn)
137
175
  end
176
+
138
177
  it 'throws deprecation warning' do
139
178
  GrapeSwaggerRails.options.before_filter { true }
140
179
 
141
180
  expect(ActiveSupport::Deprecation).to have_received(:warn).with('This option is deprecated ' \
142
- 'and going to be removed in 1.0.0. Please use `before_action` instead')
181
+ 'and going to be removed in 1.0.0. Please use `before_action` instead')
143
182
  end
144
183
  end
145
- context '#before_action' do
184
+
185
+ describe '#before_action' do
146
186
  before do
147
187
  GrapeSwaggerRails.options.before_action do |_request|
148
188
  flash[:error] = 'Unauthorized Access'
@@ -151,139 +191,161 @@ describe 'Swagger' do
151
191
  end
152
192
  visit '/swagger'
153
193
  end
194
+
154
195
  it 'denies access' do
155
- expect(current_path).to eq '/'
196
+ expect(page).to have_current_path '/', ignore_query: true
156
197
  expect(page).to have_content 'Unauthorized Access'
157
198
  end
158
199
  end
159
- context '#app_name' do
200
+
201
+ describe '#app_name' do
160
202
  context 'set' do
161
203
  before do
162
204
  GrapeSwaggerRails.options.app_name = 'Test App'
163
205
  visit '/swagger'
164
206
  end
207
+
165
208
  it 'sets page title' do
166
209
  expect(page.title).to eq 'Test App'
167
210
  end
168
211
  end
212
+
169
213
  context 'not set' do
170
214
  before do
171
215
  visit '/swagger'
172
216
  end
217
+
173
218
  it 'defaults page title' do
174
219
  expect(page.title).to eq 'Swagger'
175
220
  end
176
221
  end
177
222
  end
178
- context '#doc_expansion' do
223
+
224
+ describe '#doc_expansion' do
179
225
  context 'set list' do
180
226
  before do
181
227
  GrapeSwaggerRails.options.doc_expansion = 'list'
182
228
  visit '/swagger'
183
229
  end
230
+
184
231
  it 'sets SwaggerUI docExpansion with list' do
185
232
  expect(page.evaluate_script('window.swaggerUi.options.docExpansion == "list"')).to be true
186
233
  end
187
234
  end
235
+
188
236
  context 'set full' do
189
237
  before do
190
238
  GrapeSwaggerRails.options.doc_expansion = 'full'
191
239
  visit '/swagger'
192
240
  end
241
+
193
242
  it 'sets SwaggerUI docExpansion with full' do
194
243
  expect(page.evaluate_script('window.swaggerUi.options.docExpansion == "full"')).to be true
195
244
  end
196
245
  end
246
+
197
247
  context 'not set' do
198
248
  before do
199
249
  visit '/swagger'
200
250
  end
251
+
201
252
  it 'defaults SwaggerUI docExpansion' do
202
253
  expect(page.evaluate_script('window.swaggerUi.options.docExpansion == "none"')).to be true
203
254
  end
204
255
  end
205
256
  end
206
- context '#supported_submit_methods' do
257
+
258
+ describe '#supported_submit_methods' do
207
259
  context 'set all operations' do
208
260
  before do
209
- GrapeSwaggerRails.options.supported_submit_methods = %w(get post put delete patch)
261
+ GrapeSwaggerRails.options.supported_submit_methods = %w[get post put delete patch]
210
262
  visit '/swagger'
211
263
  end
264
+
212
265
  it 'sets SwaggerUI supportedSubmitMethods with all operations' do
213
266
  expect(page.evaluate_script('window.swaggerUi.options.supportedSubmitMethods.length')).to eq 5
214
- find('#endpointListTogger_params', visible: true).click
267
+ find_by_id('endpointListTogger_params', visible: true).click
215
268
  first('span[class="http_method"] a', visible: true).click
216
269
  expect(page).to have_button('Try it out!', disabled: false)
217
270
  end
218
271
  end
272
+
219
273
  context 'set some operations' do
220
274
  before do
221
275
  GrapeSwaggerRails.options.supported_submit_methods = ['post']
222
276
  visit '/swagger'
223
277
  end
278
+
224
279
  it 'sets SwaggerUI supportedSubmitMethods with some operations' do
225
280
  expect(page.evaluate_script('window.swaggerUi.options.supportedSubmitMethods.length')).to eq 1
226
- find('#endpointListTogger_params', visible: true).click
281
+ find_by_id('endpointListTogger_params', visible: true).click
227
282
  first('span[class="http_method"] a', visible: true).click
228
- expect(page).not_to have_button('Try it out!')
283
+ expect(page).to have_no_button('Try it out!')
229
284
  end
230
285
  end
286
+
231
287
  context 'set nil' do
232
288
  before do
233
289
  GrapeSwaggerRails.options.supported_submit_methods = nil
234
290
  visit '/swagger'
235
291
  end
292
+
236
293
  it 'clears SwaggerUI supportedSubmitMethods' do
237
294
  expect(page.evaluate_script('window.swaggerUi.options.supportedSubmitMethods.length')).to eq 0
238
- find('#endpointListTogger_params', visible: true).click
295
+ find_by_id('endpointListTogger_params', visible: true).click
239
296
  first('span[class="http_method"] a', visible: true).click
240
- expect(page).not_to have_button('Try it out!')
297
+ expect(page).to have_no_button('Try it out!')
241
298
  end
242
299
  end
300
+
243
301
  context 'not set' do
244
302
  before do
245
303
  visit '/swagger'
246
304
  end
305
+
247
306
  it 'defaults SwaggerUI supportedSubmitMethods' do
248
307
  expect(page.evaluate_script('window.swaggerUi.options.supportedSubmitMethods.length')).to eq 5
249
- find('#endpointListTogger_params', visible: true).click
308
+ find_by_id('endpointListTogger_params', visible: true).click
250
309
  first('span[class="http_method"] a', visible: true).click
251
310
  expect(page).to have_button('Try it out!', disabled: false)
252
311
  end
253
312
  end
254
313
  end
255
- context '#validator_url' do
314
+
315
+ describe '#validator_url' do
256
316
  context 'set null' do
257
317
  before do
258
318
  GrapeSwaggerRails.options.validator_url = nil
259
319
  visit '/swagger'
260
320
  end
321
+
261
322
  it 'sets SwaggerUI validatorUrl to null' do
262
- expect(page.evaluate_script('window.swaggerUi.options.validatorUrl === null && '\
263
- 'typeof window.swaggerUi.options.validatorUrl === "object"')).to be true
323
+ expect(page.evaluate_script('window.swaggerUi.options.validatorUrl === null && ' \
324
+ 'typeof window.swaggerUi.options.validatorUrl === "object"')).to be true
264
325
  end
265
326
  end
327
+
266
328
  context 'set a url' do
267
329
  before do
268
330
  GrapeSwaggerRails.options.validator_url = 'http://www.example.com/'
269
331
  visit '/swagger'
270
332
  end
333
+
271
334
  it 'sets SwaggerUI validatorUrl to expected url' do
272
335
  expect(page.evaluate_script('window.swaggerUi.options.validatorUrl === "http://www.example.com/"')).to be true
273
336
  end
274
337
  end
338
+
275
339
  context 'not set' do
276
340
  before do
277
341
  visit '/swagger'
278
342
  end
343
+
279
344
  it 'defaults SwaggerUI validatorUrl' do
280
- expect(page.evaluate_script('window.swaggerUi.options.validatorUrl === undefined && '\
281
- 'typeof window.swaggerUi.options.validatorUrl === "undefined"')).to be true
345
+ expect(page.evaluate_script('window.swaggerUi.options.validatorUrl === undefined && ' \
346
+ 'typeof window.swaggerUi.options.validatorUrl === "undefined"')).to be true
282
347
  end
283
348
  end
284
349
  end
285
- after do
286
- GrapeSwaggerRails.options = @options
287
- end
288
350
  end
289
351
  end
@@ -1,9 +1,12 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'spec_helper'
2
4
 
3
5
  describe 'Welcome' do
4
6
  before do
5
7
  visit '/'
6
8
  end
9
+
7
10
  it 'renders a link to swagger' do
8
11
  expect(page).to have_css 'a[href="/swagger"]'
9
12
  end
data/spec/spec_helper.rb CHANGED
@@ -1,11 +1,13 @@
1
+ # frozen_string_literal: true
2
+
1
3
  ENV['RAILS_ENV'] ||= 'test'
2
4
 
3
- require File.expand_path('../dummy/config/environment.rb', __FILE__)
5
+ require File.expand_path('dummy/config/environment.rb', __dir__)
4
6
  require 'rspec/rails'
5
7
 
6
8
  Rails.backtrace_cleaner.remove_silencers!
7
9
 
8
- Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each do |f|
10
+ Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].sort.each do |f|
9
11
  require f
10
12
  end
11
13
 
@@ -1,5 +1,8 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'capybara/rspec'
2
4
  require 'capybara/rails'
3
5
 
4
6
  Capybara.default_driver = :selenium
5
7
  Capybara.server_port = 3000
8
+ Capybara.server = :webrick
@@ -1 +1,3 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'rspec/rails'