apipie-rails 0.5.18 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,398 @@
1
+ {
2
+ "cells": [
3
+ {
4
+ "cell_type": "markdown",
5
+ "metadata": {},
6
+ "source": [
7
+ "## Release of apipie-rails gem\n",
8
+ "\n",
9
+ "### Requirements\n",
10
+ "- push access to https://github.com/Apipie/apipie-rails\n",
11
+ "- push access to rubygems.org for apipie-rails\n",
12
+ "- sudo yum install python-slugify asciidoc\n",
13
+ "- ensure neither the `git push` or `gem push` don't require interractive auth. If you can't use api key or ssh key to auth skip these steps and run them form the shell manually\n",
14
+ "- ensure all checks have passed on the branch you're about to release\n",
15
+ "\n",
16
+ "### Release process\n",
17
+ "- Follow the steps with `<Shift>+<Enter>` or `<Ctrl>+<Enter>,<Down>`\n",
18
+ "- If anything fails, fix it and re-run the step if applicable\n",
19
+ "\n",
20
+ "### Release settings"
21
+ ]
22
+ },
23
+ {
24
+ "cell_type": "code",
25
+ "execution_count": null,
26
+ "metadata": {},
27
+ "outputs": [],
28
+ "source": [
29
+ "%autosave 0"
30
+ ]
31
+ },
32
+ {
33
+ "cell_type": "code",
34
+ "execution_count": null,
35
+ "metadata": {},
36
+ "outputs": [],
37
+ "source": [
38
+ "%cd .."
39
+ ]
40
+ },
41
+ {
42
+ "cell_type": "markdown",
43
+ "metadata": {},
44
+ "source": [
45
+ "### Update the following notebook settings"
46
+ ]
47
+ },
48
+ {
49
+ "cell_type": "code",
50
+ "execution_count": null,
51
+ "metadata": {},
52
+ "outputs": [],
53
+ "source": [
54
+ "NEW_VERSION = '0.5.20'\n",
55
+ "LAST_VERSION = '0.5.19'\n",
56
+ "GIT_REMOTE_UPSTREAM = 'origin'\n",
57
+ "STABLE_RELEASE = False\n",
58
+ "WORK_BRANCH = 'stable' if STABLE_RELEASE else 'master'\n",
59
+ "# Array of strings, e.g. [\"21cbsc214g3\", \"21casc214g3\"]\n",
60
+ "CHERRY_PICKS = []\n",
61
+ "GEMFILE='Gemfile.rails61'"
62
+ ]
63
+ },
64
+ {
65
+ "cell_type": "markdown",
66
+ "metadata": {},
67
+ "source": [
68
+ "### Ensure the repo is up to date"
69
+ ]
70
+ },
71
+ {
72
+ "cell_type": "code",
73
+ "execution_count": null,
74
+ "metadata": {},
75
+ "outputs": [],
76
+ "source": [
77
+ "! git checkout {WORK_BRANCH}"
78
+ ]
79
+ },
80
+ {
81
+ "cell_type": "code",
82
+ "execution_count": null,
83
+ "metadata": {},
84
+ "outputs": [],
85
+ "source": [
86
+ "! git fetch {GIT_REMOTE_UPSTREAM}"
87
+ ]
88
+ },
89
+ {
90
+ "cell_type": "code",
91
+ "execution_count": null,
92
+ "metadata": {},
93
+ "outputs": [],
94
+ "source": [
95
+ "! git rebase {GIT_REMOTE_UPSTREAM}/{WORK_BRANCH}"
96
+ ]
97
+ },
98
+ {
99
+ "cell_type": "markdown",
100
+ "metadata": {},
101
+ "source": [
102
+ "### Cherry picks for stable release"
103
+ ]
104
+ },
105
+ {
106
+ "cell_type": "code",
107
+ "execution_count": null,
108
+ "metadata": {},
109
+ "outputs": [],
110
+ "source": [
111
+ "if STABLE_RELEASE:\n",
112
+ " for cp in CHERRY_PICKS:\n",
113
+ " ! git cherry-pick -x {cp}"
114
+ ]
115
+ },
116
+ {
117
+ "cell_type": "markdown",
118
+ "metadata": {},
119
+ "source": [
120
+ "### Run tests localy if your setup allows, otherwise ensure the HEAD is green"
121
+ ]
122
+ },
123
+ {
124
+ "cell_type": "code",
125
+ "execution_count": null,
126
+ "metadata": {},
127
+ "outputs": [],
128
+ "source": [
129
+ "! BUNDLE_GEMFILE=gemfiles/{GEMFILE} bundle update"
130
+ ]
131
+ },
132
+ {
133
+ "cell_type": "code",
134
+ "execution_count": null,
135
+ "metadata": {
136
+ "scrolled": true
137
+ },
138
+ "outputs": [],
139
+ "source": [
140
+ "! BUNDLE_GEMFILE=gemfiles/{GEMFILE} bundle exec rspec"
141
+ ]
142
+ },
143
+ {
144
+ "cell_type": "markdown",
145
+ "metadata": {},
146
+ "source": [
147
+ "### Update release related stuff"
148
+ ]
149
+ },
150
+ {
151
+ "cell_type": "code",
152
+ "execution_count": null,
153
+ "metadata": {},
154
+ "outputs": [],
155
+ "source": [
156
+ "! sed -i 's/VERSION = .*/VERSION = \"{NEW_VERSION}\"/' lib/apipie/version.rb"
157
+ ]
158
+ },
159
+ {
160
+ "cell_type": "code",
161
+ "execution_count": null,
162
+ "metadata": {},
163
+ "outputs": [],
164
+ "source": [
165
+ "# Parse git changelog\n",
166
+ "from IPython.display import Markdown as md\n",
167
+ "from subprocess import check_output\n",
168
+ "from shlex import split\n",
169
+ "import re\n",
170
+ "\n",
171
+ "def format_log_entry(entry):\n",
172
+ " author = re.search(r'author:(.*)', entry).group(1)\n",
173
+ " entry = re.sub(r'author:(.*)', '', entry)\n",
174
+ " entry = re.sub(r'([fF]ixes|[rR]efs)[^-]*-\\s*(.*)', r'\\2', entry)\n",
175
+ " entry = '* ' + entry.capitalize()\n",
176
+ " entry = re.sub(r'\\(#([0-9]+)\\)', r'[#\\1](https://github.com/Apipie/apipie-rails/pull/\\1)', entry)\n",
177
+ " entry = entry + f'({author})'\n",
178
+ " return entry\n",
179
+ "\n",
180
+ "def skip(entry):\n",
181
+ " if re.match(r'Merge pull', entry) or \\\n",
182
+ " re.match(r'^i18n', entry) or \\\n",
183
+ " re.match(r'^Bump to version', entry):\n",
184
+ " return True\n",
185
+ " else:\n",
186
+ " return False \n",
187
+ "git_log_cmd = 'git log --pretty=format:\"%%s author:%%an\" v%s..HEAD' % LAST_VERSION\n",
188
+ "log = check_output(split(git_log_cmd)).decode('utf8').split('\\n')\n",
189
+ "change_log = [format_log_entry(e) for e in log if not skip(e)]\n",
190
+ "md('\\n'.join(change_log))\n"
191
+ ]
192
+ },
193
+ {
194
+ "cell_type": "code",
195
+ "execution_count": null,
196
+ "metadata": {},
197
+ "outputs": [],
198
+ "source": [
199
+ "# Write release notes\n",
200
+ "from datetime import datetime\n",
201
+ "import fileinput\n",
202
+ "import sys\n",
203
+ "\n",
204
+ "fh = fileinput.input('CHANGELOG.md', inplace=True) \n",
205
+ "for line in fh: \n",
206
+ " print(line.rstrip())\n",
207
+ " if re.match(r'========', line):\n",
208
+ " print('## [v%s](https://github.com/Apipie/apipie-rails/tree/v%s) (%s)' % (NEW_VERSION, NEW_VERSION, datetime.today().strftime('%Y-%m-%d')))\n",
209
+ " print('[Full Changelog](https://github.com/Apipie/apipie-rails/compare/v%s...v%s)' % (LAST_VERSION, NEW_VERSION))\n",
210
+ " for entry in change_log:\n",
211
+ " print(entry)\n",
212
+ " print('')\n",
213
+ "fh.close() "
214
+ ]
215
+ },
216
+ {
217
+ "cell_type": "markdown",
218
+ "metadata": {},
219
+ "source": [
220
+ "#### Manual step: Update deps in the gemspec if neccessary"
221
+ ]
222
+ },
223
+ {
224
+ "cell_type": "markdown",
225
+ "metadata": {},
226
+ "source": [
227
+ "### Check what is going to be commited"
228
+ ]
229
+ },
230
+ {
231
+ "cell_type": "code",
232
+ "execution_count": null,
233
+ "metadata": {
234
+ "scrolled": false
235
+ },
236
+ "outputs": [],
237
+ "source": [
238
+ "! git add -u\n",
239
+ "! git status"
240
+ ]
241
+ },
242
+ {
243
+ "cell_type": "code",
244
+ "execution_count": null,
245
+ "metadata": {
246
+ "scrolled": true
247
+ },
248
+ "outputs": [],
249
+ "source": [
250
+ "! git diff --cached"
251
+ ]
252
+ },
253
+ {
254
+ "cell_type": "markdown",
255
+ "metadata": {},
256
+ "source": [
257
+ "### Commit changes"
258
+ ]
259
+ },
260
+ {
261
+ "cell_type": "code",
262
+ "execution_count": null,
263
+ "metadata": {
264
+ "scrolled": true
265
+ },
266
+ "outputs": [],
267
+ "source": [
268
+ "! git commit -m \"Bump to {NEW_VERSION}\""
269
+ ]
270
+ },
271
+ {
272
+ "cell_type": "markdown",
273
+ "metadata": {},
274
+ "source": [
275
+ "### Tag new version"
276
+ ]
277
+ },
278
+ {
279
+ "cell_type": "code",
280
+ "execution_count": null,
281
+ "metadata": {},
282
+ "outputs": [],
283
+ "source": [
284
+ "! git tag {NEW_VERSION}"
285
+ ]
286
+ },
287
+ {
288
+ "cell_type": "markdown",
289
+ "metadata": {},
290
+ "source": [
291
+ "### Build the gem"
292
+ ]
293
+ },
294
+ {
295
+ "cell_type": "code",
296
+ "execution_count": null,
297
+ "metadata": {},
298
+ "outputs": [],
299
+ "source": [
300
+ "! BUNDLE_GEMFILE=gemfiles/{GEMFILE} bundle exec rake build"
301
+ ]
302
+ },
303
+ {
304
+ "cell_type": "code",
305
+ "execution_count": null,
306
+ "metadata": {},
307
+ "outputs": [],
308
+ "source": [
309
+ "! gem push pkg/apipie-rails-{NEW_VERSION}.gem"
310
+ ]
311
+ },
312
+ {
313
+ "cell_type": "markdown",
314
+ "metadata": {},
315
+ "source": [
316
+ "### PUSH the changes upstream If everything is correct"
317
+ ]
318
+ },
319
+ {
320
+ "cell_type": "code",
321
+ "execution_count": null,
322
+ "metadata": {},
323
+ "outputs": [],
324
+ "source": [
325
+ "! git push {GIT_REMOTE_UPSTREAM} {WORK_BRANCH}"
326
+ ]
327
+ },
328
+ {
329
+ "cell_type": "code",
330
+ "execution_count": null,
331
+ "metadata": {},
332
+ "outputs": [],
333
+ "source": [
334
+ "! git push --tags {GIT_REMOTE_UPSTREAM} {WORK_BRANCH}"
335
+ ]
336
+ },
337
+ {
338
+ "cell_type": "markdown",
339
+ "metadata": {},
340
+ "source": [
341
+ "#### Now the new release is in upstream repo"
342
+ ]
343
+ },
344
+ {
345
+ "cell_type": "markdown",
346
+ "metadata": {},
347
+ "source": [
348
+ "### Some manual steps follow to improve the UX\n",
349
+ "\n",
350
+ "#### New relase on GitHub\n",
351
+ "\n",
352
+ "Copy the following changelog lines to the description in form on link below\n",
353
+ "The release title is the new version."
354
+ ]
355
+ },
356
+ {
357
+ "cell_type": "code",
358
+ "execution_count": null,
359
+ "metadata": {},
360
+ "outputs": [],
361
+ "source": [
362
+ "print('\\n')\n",
363
+ "print('\\n'.join(change_log))\n",
364
+ "print('\\n\\nhttps://github.com/Apipie/apipie-rails/releases/new?tag=%s' % NEW_VERSION)"
365
+ ]
366
+ },
367
+ {
368
+ "cell_type": "markdown",
369
+ "metadata": {},
370
+ "source": [
371
+ "## Congratulations\n",
372
+ "\n",
373
+ "Release is public now."
374
+ ]
375
+ }
376
+ ],
377
+ "metadata": {
378
+ "kernelspec": {
379
+ "display_name": "Python 3",
380
+ "language": "python",
381
+ "name": "python3"
382
+ },
383
+ "language_info": {
384
+ "codemirror_mode": {
385
+ "name": "ipython",
386
+ "version": 3
387
+ },
388
+ "file_extension": ".py",
389
+ "mimetype": "text/x-python",
390
+ "name": "python",
391
+ "nbconvert_exporter": "python",
392
+ "pygments_lexer": "ipython3",
393
+ "version": "3.6.8"
394
+ }
395
+ },
396
+ "nbformat": 4,
397
+ "nbformat_minor": 2
398
+ }
@@ -47,6 +47,31 @@ describe Apipie::ApipiesController do
47
47
 
48
48
  assert_response :not_found
49
49
  end
50
+
51
+ it "succeeds on method details with a supported language" do
52
+ allow(Apipie.configuration).to receive(:languages).and_return(%w[en es])
53
+
54
+ get :index, :params => { :version => "2.0", :resource => "architectures", :method => "index.es" }
55
+
56
+ assert_response :success
57
+ end
58
+
59
+ it "succeeds on method details with the default language" do
60
+ allow(Apipie.configuration).to receive(:default_locale).and_return("en")
61
+ allow(Apipie.configuration).to receive(:languages).and_return([])
62
+
63
+ get :index, :params => { :version => "2.0", :resource => "architectures", :method => "index.en" }
64
+
65
+ assert_response :success
66
+ end
67
+
68
+ it "returns not_found on a method with an unsupported language" do
69
+ allow(Apipie.configuration).to receive(:languages).and_return(%w[en es])
70
+
71
+ get :index, :params => { :version => "2.0", :resource => "architectures", :method => "index.jp" }
72
+
73
+ assert_response :not_found
74
+ end
50
75
  end
51
76
 
52
77
  describe "reload_controllers" do
@@ -1,10 +1,7 @@
1
1
  require File.expand_path('../boot', __FILE__)
2
2
 
3
- require "active_model/railtie"
4
- require "active_record/railtie"
5
3
  require "action_controller/railtie"
6
4
  require "action_view/railtie"
7
- require "action_mailer/railtie"
8
5
 
9
6
  Bundler.require
10
7
  require "apipie-rails"
@@ -13,9 +13,6 @@ Dummy::Application.configure do
13
13
  config.consider_all_requests_local = true
14
14
  config.action_controller.perform_caching = false
15
15
 
16
- # Don't care if the mailer can't send
17
- config.action_mailer.raise_delivery_errors = false
18
-
19
16
  # Print deprecation notices to the Rails logger
20
17
  config.active_support.deprecation = :log
21
18
 
@@ -34,9 +34,6 @@ Dummy::Application.configure do
34
34
  # Enable serving of images, stylesheets, and javascripts from an asset server
35
35
  # config.action_controller.asset_host = "http://assets.example.com"
36
36
 
37
- # Disable delivery errors, bad email addresses will be ignored
38
- # config.action_mailer.raise_delivery_errors = false
39
-
40
37
  # Enable threaded mode
41
38
  # config.threadsafe!
42
39
 
@@ -20,11 +20,6 @@ Dummy::Application.configure do
20
20
  # Disable request forgery protection in test environment
21
21
  config.action_controller.allow_forgery_protection = false
22
22
 
23
- # Tell Action Mailer not to deliver emails to the real world.
24
- # The :test delivery method accumulates sent emails in the
25
- # ActionMailer::Base.deliveries array.
26
- config.action_mailer.delivery_method = :test
27
-
28
23
  # Use SQL instead of Active Record's schema dumper when creating the test database.
29
24
  # This is necessary if your schema can't be completely dumped by the schema dumper,
30
25
  # like if you have constraints or database-specific column types
@@ -10,78 +10,78 @@ RSpec.describe PetsController, :type => :controller do
10
10
  end
11
11
 
12
12
  it "does not raise error when rendered output matches the described response" do
13
- response = get :return_and_validate_expected_response, {format: :json}
13
+ response = get :return_and_validate_expected_response, format: :json
14
14
  expect(response).to match_declared_responses
15
15
  end
16
16
 
17
17
  it "does not raise error when rendered output (array) matches the described response" do
18
- response = get :return_and_validate_expected_array_response, {format: :json}
18
+ response = get :return_and_validate_expected_array_response, format: :json
19
19
  expect(response).to match_declared_responses
20
20
  end
21
21
 
22
22
  it "does not raises error when rendered output includes null in the response" do
23
- response = get :return_and_validate_expected_response_with_null, {format: :json}
23
+ response = get :return_and_validate_expected_response_with_null, format: :json
24
24
  expect(response).to match_declared_responses
25
25
  end
26
26
 
27
27
  it "does not raise error when rendered output includes null (instead of an object) in the response" do
28
- response = get :return_and_validate_expected_response_with_null_object, {format: :json}
28
+ response = get :return_and_validate_expected_response_with_null_object, format: :json
29
29
  expect(response).to match_declared_responses
30
30
  end
31
31
 
32
32
  it "raises error when a response field has the wrong type" do
33
- response = get :return_and_validate_type_mismatch, {format: :json}
33
+ response = get :return_and_validate_type_mismatch, format: :json
34
34
  expect(response).not_to match_declared_responses
35
35
  end
36
36
 
37
37
  it "raises error when a response has a missing field" do
38
- response = get :return_and_validate_missing_field, {format: :json}
38
+ response = get :return_and_validate_missing_field, format: :json
39
39
  expect(response).not_to match_declared_responses
40
40
  end
41
41
 
42
42
  it "raises error when a response has an extra property and 'swagger_allow_additional_properties_in_response' is false" do
43
- response = get :return_and_validate_extra_property, {format: :json}
43
+ response = get :return_and_validate_extra_property, format: :json
44
44
  expect(response).not_to match_declared_responses
45
45
  end
46
46
 
47
47
  it "raises error when a response has is array instead of object" do
48
48
  # note: this action returns HTTP 201, not HTTP 200!
49
- response = get :return_and_validate_unexpected_array_response, {format: :json}
49
+ response = get :return_and_validate_unexpected_array_response, format: :json
50
50
  expect(response).not_to match_declared_responses
51
51
  end
52
52
 
53
53
  it "does not raise error when a response has an extra property and 'swagger_allow_additional_properties_in_response' is true" do
54
54
  Apipie.configuration.swagger_allow_additional_properties_in_response = true
55
- response = get :return_and_validate_extra_property, {format: :json}
55
+ response = get :return_and_validate_extra_property, format: :json
56
56
  expect(response).to match_declared_responses
57
57
  end
58
58
 
59
59
  it "does not raise error when a response has an extra field and 'additional_properties' is specified in the response" do
60
60
  Apipie.configuration.swagger_allow_additional_properties_in_response = false
61
- response = get :return_and_validate_allowed_extra_property, {format: :json}
61
+ response = get :return_and_validate_allowed_extra_property, format: :json
62
62
  expect(response).to match_declared_responses
63
63
  end
64
64
 
65
65
  it "raises error when a response sub-object has an extra field and 'additional_properties' is not specified on it, but specified on the top level of the response" do
66
66
  Apipie.configuration.swagger_allow_additional_properties_in_response = false
67
- response = get :sub_object_invalid_extra_property, {format: :json}
67
+ response = get :sub_object_invalid_extra_property, format: :json
68
68
  expect(response).not_to match_declared_responses
69
69
  end
70
70
 
71
- it "does not rais error when a response sub-object has an extra field and 'additional_properties' is specified on it" do
71
+ it "does not raise error when a response sub-object has an extra field and 'additional_properties' is specified on it" do
72
72
  Apipie.configuration.swagger_allow_additional_properties_in_response = false
73
- response = get :sub_object_allowed_extra_property, {format: :json}
73
+ response = get :sub_object_allowed_extra_property, format: :json
74
74
  expect(response).to match_declared_responses
75
75
  end
76
76
 
77
77
  describe "auto validation" do
78
78
  auto_validate_rendered_views
79
79
  it "raises exception when a response field has the wrong type and auto validation is turned on" do
80
- expect { get :return_and_validate_type_mismatch, {format: :json} }.to raise_error(Apipie::ResponseDoesNotMatchSwaggerSchema)
80
+ expect { get :return_and_validate_type_mismatch, format: :json }.to raise_error(Apipie::ResponseDoesNotMatchSwaggerSchema)
81
81
  end
82
82
 
83
83
  it "does not raise an exception when calling an undocumented method" do
84
- expect { get :undocumented_method, {format: :json} }.not_to raise_error
84
+ expect { get :undocumented_method, format: :json }.not_to raise_error
85
85
  end
86
86
 
87
87
  end
@@ -89,12 +89,12 @@ RSpec.describe PetsController, :type => :controller do
89
89
 
90
90
  describe "with array field" do
91
91
  it "no error for valid response" do
92
- response = get :returns_response_with_valid_array, {format: :json}
92
+ response = get :returns_response_with_valid_array, format: :json
93
93
  expect(response).to match_declared_responses
94
94
  end
95
95
 
96
96
  it "error if type of element in the array is wrong" do
97
- response = get :returns_response_with_invalid_array, {format: :json}
97
+ response = get :returns_response_with_invalid_array, format: :json
98
98
  expect(response).not_to match_declared_responses
99
99
  end
100
100
  end
data/spec/spec_helper.rb CHANGED
@@ -13,7 +13,13 @@ require 'test_engine'
13
13
  module Rails4Compatibility
14
14
  module Testing
15
15
  def process(*args)
16
- compatible_request(*args) { |*new_args| super(*new_args) }
16
+ compatible_request(*args) do |*new_args|
17
+ if Gem.ruby_version < Gem::Version.new('3.0.0')
18
+ super(*new_args)
19
+ else
20
+ super(new_args[0], **new_args[1])
21
+ end
22
+ end
17
23
  end
18
24
 
19
25
  def compatible_request(method, action, hash = {})
@@ -0,0 +1,15 @@
1
+ if RUBY_VERSION >= '2.6.0'
2
+ if Rails.version < '5'
3
+ # rubocop:disable Style/CommentAnnotation
4
+ class ActionController::TestResponse < ActionDispatch::TestResponse
5
+ def recycle!
6
+ # hack to avoid MonitorMixin double-initialize error:
7
+ @mon_mutex_owner_object_id = nil
8
+ @mon_mutex = nil
9
+ initialize
10
+ end
11
+ end
12
+ # rubocop:enable Style/CommentAnnotation
13
+ end
14
+ end
15
+