rails_twirp 0.12.0 → 0.13.1
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/.standard.yml +0 -1
- data/CHANGELOG.md +9 -0
- data/Gemfile +1 -1
- data/lib/rails_twirp/base.rb +12 -6
- data/lib/rails_twirp/engine.rb +5 -1
- data/lib/rails_twirp/metal.rb +26 -0
- data/lib/rails_twirp/version.rb +1 -1
- data/rails_twirp.gemspec +2 -3
- metadata +10 -146
- data/.github/workflows/test.yml +0 -21
- data/bin/test +0 -5
- data/lib/rails_twirp/testing/integration_test.rb +0 -106
- data/test/dummy/Rakefile +0 -6
- data/test/dummy/app/assets/config/manifest.js +0 -2
- data/test/dummy/app/assets/images/.keep +0 -0
- data/test/dummy/app/assets/stylesheets/application.css +0 -15
- data/test/dummy/app/channels/application_cable/channel.rb +0 -4
- data/test/dummy/app/channels/application_cable/connection.rb +0 -4
- data/test/dummy/app/controllers/application_controller.rb +0 -2
- data/test/dummy/app/controllers/application_twirp_controller.rb +0 -7
- data/test/dummy/app/controllers/concerns/.keep +0 -0
- data/test/dummy/app/controllers/dummy_controller.rb +0 -5
- data/test/dummy/app/controllers/pings_controller.rb +0 -40
- data/test/dummy/app/controllers/testmod/nested/other_controller.rb +0 -10
- data/test/dummy/app/helpers/application_helper.rb +0 -2
- data/test/dummy/app/helpers/random_helper.rb +0 -5
- data/test/dummy/app/javascript/packs/application.js +0 -15
- data/test/dummy/app/jobs/application_job.rb +0 -7
- data/test/dummy/app/mailers/application_mailer.rb +0 -4
- data/test/dummy/app/models/application_record.rb +0 -3
- data/test/dummy/app/models/concerns/.keep +0 -0
- data/test/dummy/app/views/dummy/rpc_name_check.pb.pbbuilder +0 -1
- data/test/dummy/app/views/layouts/application.html.erb +0 -15
- data/test/dummy/app/views/layouts/mailer.html.erb +0 -13
- data/test/dummy/app/views/layouts/mailer.text.erb +0 -1
- data/test/dummy/app/views/pings/ping_template.pb.pbbuilder +0 -1
- data/test/dummy/bin/generate +0 -3
- data/test/dummy/bin/rails +0 -4
- data/test/dummy/bin/rake +0 -4
- data/test/dummy/bin/setup +0 -33
- data/test/dummy/config/application.rb +0 -23
- data/test/dummy/config/boot.rb +0 -5
- data/test/dummy/config/cable.yml +0 -10
- data/test/dummy/config/database.yml +0 -25
- data/test/dummy/config/environment.rb +0 -5
- data/test/dummy/config/environments/development.rb +0 -76
- data/test/dummy/config/environments/production.rb +0 -120
- data/test/dummy/config/environments/test.rb +0 -59
- data/test/dummy/config/initializers/application_controller_renderer.rb +0 -8
- data/test/dummy/config/initializers/backtrace_silencers.rb +0 -8
- data/test/dummy/config/initializers/content_security_policy.rb +0 -28
- data/test/dummy/config/initializers/cookies_serializer.rb +0 -5
- data/test/dummy/config/initializers/filter_parameter_logging.rb +0 -6
- data/test/dummy/config/initializers/inflections.rb +0 -16
- data/test/dummy/config/initializers/mime_types.rb +0 -4
- data/test/dummy/config/initializers/permissions_policy.rb +0 -11
- data/test/dummy/config/initializers/wrap_parameters.rb +0 -14
- data/test/dummy/config/locales/en.yml +0 -33
- data/test/dummy/config/puma.rb +0 -43
- data/test/dummy/config/routes.rb +0 -3
- data/test/dummy/config/storage.yml +0 -34
- data/test/dummy/config/twirp/routes.rb +0 -22
- data/test/dummy/config.ru +0 -6
- data/test/dummy/lib/assets/.keep +0 -0
- data/test/dummy/log/.keep +0 -0
- data/test/dummy/proto/api.proto +0 -30
- data/test/dummy/proto/api_pb.rb +0 -29
- data/test/dummy/proto/api_twirp.rb +0 -25
- data/test/dummy/public/404.html +0 -67
- data/test/dummy/public/422.html +0 -67
- data/test/dummy/public/500.html +0 -66
- data/test/dummy/public/apple-touch-icon-precomposed.png +0 -0
- data/test/dummy/public/apple-touch-icon.png +0 -0
- data/test/dummy/public/favicon.ico +0 -0
- data/test/dummy_test.rb +0 -10
- data/test/other_controller_test.rb +0 -9
- data/test/ping_controller_test.rb +0 -114
- data/test/rails_twirp_test.rb +0 -7
- data/test/test_helper.rb +0 -16
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d04982e98774e2a130671b2729dad6141905df3544c7cfa3900137a7cd553356
|
4
|
+
data.tar.gz: 650187fd3c34f30ca91885c6c1fa9b1547035a816d088e0b8c583f9ea6a0608e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4021ee3e130f4647423177456c9ccfb5bcce728874b547f56c2ae52a78fc92a953f6e98e7dee7eb87c78adca37f4f42cd21c7761f3842f20859923a3a8b8096f
|
7
|
+
data.tar.gz: bcb8240668e0c0d59f63ad7148595fcf15142533bed252e6f55212f51a73df0f31a623ca97f675c1494712631ffb025b20f71956dbfaa71ba61d9d48e12f2512
|
data/.standard.yml
CHANGED
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,12 @@
|
|
1
|
+
### 0.13.1
|
2
|
+
* Don't include `test/` folder in a final gem distribution
|
3
|
+
* Format dummy app code with standardrb
|
4
|
+
|
5
|
+
### 0.13.0
|
6
|
+
* Adding #controller_name methods to Metal/Base controller (used for instrumentation)
|
7
|
+
* Include `ActionController::Caching` with Base controller/helpers
|
8
|
+
|
9
|
+
|
1
10
|
### 0.12.0
|
2
11
|
|
3
12
|
* Allow a custom exception handling proc to be assigned using `RailsTwirp.unhandled_exception_handler`
|
data/Gemfile
CHANGED
data/lib/rails_twirp/base.rb
CHANGED
@@ -1,10 +1,11 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require "abstract_controller/base"
|
2
4
|
require "abstract_controller/rendering"
|
3
5
|
require "action_view/rendering"
|
4
6
|
require "rails_twirp/render_pb"
|
5
7
|
require "rails_twirp/errors"
|
6
8
|
require "abstract_controller/asset_paths"
|
7
|
-
require "abstract_controller/caching"
|
8
9
|
require "abstract_controller/logger"
|
9
10
|
require "abstract_controller/callbacks"
|
10
11
|
require "action_controller/metal/helpers"
|
@@ -13,11 +14,10 @@ require "rails_twirp/url_for"
|
|
13
14
|
require "rails_twirp/implicit_render"
|
14
15
|
require "rails_twirp/instrumentation"
|
15
16
|
require "rails_twirp/exception_handling"
|
17
|
+
require "rails_twirp/metal"
|
16
18
|
|
17
19
|
module RailsTwirp
|
18
|
-
class Base <
|
19
|
-
abstract!
|
20
|
-
|
20
|
+
class Base < RailsTwirp::Metal
|
21
21
|
# The order of these includes matter.
|
22
22
|
# The rendering modules extend each other, so need to be in this order.
|
23
23
|
include AbstractController::Rendering
|
@@ -26,7 +26,6 @@ module RailsTwirp
|
|
26
26
|
include ActionController::Helpers
|
27
27
|
include UrlFor
|
28
28
|
include AbstractController::AssetPaths
|
29
|
-
include AbstractController::Caching
|
30
29
|
|
31
30
|
include ActionView::Rendering
|
32
31
|
include RenderPb
|
@@ -39,7 +38,14 @@ module RailsTwirp
|
|
39
38
|
include Instrumentation
|
40
39
|
include ExceptionHandling
|
41
40
|
|
42
|
-
|
41
|
+
##
|
42
|
+
# :attr_reader: request
|
43
|
+
#
|
44
|
+
# The ActionDispatch::Request instance for the current request.
|
45
|
+
attr_internal :request
|
46
|
+
|
47
|
+
attr_internal :env, :response_class, :rpc_name
|
48
|
+
|
43
49
|
def initialize
|
44
50
|
@_request = nil
|
45
51
|
@_env = nil
|
data/lib/rails_twirp/engine.rb
CHANGED
@@ -34,7 +34,11 @@ module RailsTwirp
|
|
34
34
|
|
35
35
|
initializer "rails_twirp.helpers" do |app|
|
36
36
|
ActiveSupport.on_load(:rails_twirp) do
|
37
|
-
# Load all the application helpers into the controller
|
37
|
+
# Load all the application helpers into the controller.
|
38
|
+
# Note that helpers need to be set up here, because apparently
|
39
|
+
# the AbstractController::Helpers module won't be able to find
|
40
|
+
# the _helpers method on a reloaded controller
|
41
|
+
include ActionController::Caching
|
38
42
|
include app.routes.mounted_helpers
|
39
43
|
extend ::AbstractController::Railties::RoutesHelpers.with(app.routes, false)
|
40
44
|
extend ::ActionController::Railties::Helpers
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RailsTwirp
|
4
|
+
# This is a simplest possible controller, providing a valid
|
5
|
+
# Rack interfacee without the additional niceties provided by RailsTwirp.
|
6
|
+
#
|
7
|
+
# Idiologially, it's similar to Rails version of ActionController::Metal
|
8
|
+
class Metal < AbstractController::Base
|
9
|
+
abstract!
|
10
|
+
|
11
|
+
# Returns the last part of the controller's name, underscored, without the ending
|
12
|
+
# <tt>Controller</tt>. For instance, PostsController returns <tt>posts</tt>.
|
13
|
+
# Namespaces are left out, so Admin::PostsController returns <tt>posts</tt> as well.
|
14
|
+
#
|
15
|
+
# ==== Returns
|
16
|
+
# * <tt>string</tt>
|
17
|
+
def self.controller_name
|
18
|
+
@controller_name ||= (name.demodulize.delete_suffix("Controller").underscore unless anonymous?)
|
19
|
+
end
|
20
|
+
|
21
|
+
# Delegates to the class's ::controller_name.
|
22
|
+
def controller_name
|
23
|
+
self.class.controller_name
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
data/lib/rails_twirp/version.rb
CHANGED
data/rails_twirp.gemspec
CHANGED
@@ -9,10 +9,9 @@ Gem::Specification.new do |spec|
|
|
9
9
|
spec.summary = "Integrate Twirp into Rails"
|
10
10
|
spec.license = "MIT"
|
11
11
|
|
12
|
-
spec.files = `git ls-files`.split("\n")
|
13
|
-
spec.test_files = `git ls-files -- test/*`.split("\n")
|
12
|
+
spec.files = `git ls-files | grep -v -E "test/*"`.split("\n")
|
14
13
|
|
15
14
|
spec.add_dependency "rails", ">= 6.1.3"
|
16
|
-
spec.add_dependency "twirp", ">= 1.
|
15
|
+
spec.add_dependency "twirp", ">= 1.9", "< 1.11"
|
17
16
|
spec.required_ruby_version = ">= 3"
|
18
17
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rails_twirp
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.13.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Bouke van der Bijl
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2023-01-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -30,20 +30,20 @@ dependencies:
|
|
30
30
|
requirements:
|
31
31
|
- - ">="
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: 1.
|
34
|
-
- - "
|
33
|
+
version: '1.9'
|
34
|
+
- - "<"
|
35
35
|
- !ruby/object:Gem::Version
|
36
|
-
version: 1.
|
36
|
+
version: '1.11'
|
37
37
|
type: :runtime
|
38
38
|
prerelease: false
|
39
39
|
version_requirements: !ruby/object:Gem::Requirement
|
40
40
|
requirements:
|
41
41
|
- - ">="
|
42
42
|
- !ruby/object:Gem::Version
|
43
|
-
version: 1.
|
44
|
-
- - "
|
43
|
+
version: '1.9'
|
44
|
+
- - "<"
|
45
45
|
- !ruby/object:Gem::Version
|
46
|
-
version: 1.
|
46
|
+
version: '1.11'
|
47
47
|
description:
|
48
48
|
email:
|
49
49
|
- bouke@cheddar.me
|
@@ -52,7 +52,6 @@ extensions: []
|
|
52
52
|
extra_rdoc_files: []
|
53
53
|
files:
|
54
54
|
- ".github/dependabot.yml"
|
55
|
-
- ".github/workflows/test.yml"
|
56
55
|
- ".gitignore"
|
57
56
|
- ".ruby-version"
|
58
57
|
- ".standard.yml"
|
@@ -61,7 +60,6 @@ files:
|
|
61
60
|
- MIT-LICENSE
|
62
61
|
- README.md
|
63
62
|
- Rakefile
|
64
|
-
- bin/test
|
65
63
|
- lib/commands/twirp/routes_command.rb
|
66
64
|
- lib/rails_twirp.rb
|
67
65
|
- lib/rails_twirp/application.rb
|
@@ -73,80 +71,13 @@ files:
|
|
73
71
|
- lib/rails_twirp/instrumentation.rb
|
74
72
|
- lib/rails_twirp/log_subscriber.rb
|
75
73
|
- lib/rails_twirp/mapper.rb
|
74
|
+
- lib/rails_twirp/metal.rb
|
76
75
|
- lib/rails_twirp/render_pb.rb
|
77
76
|
- lib/rails_twirp/rescue.rb
|
78
77
|
- lib/rails_twirp/route_set.rb
|
79
|
-
- lib/rails_twirp/testing/integration_test.rb
|
80
78
|
- lib/rails_twirp/url_for.rb
|
81
79
|
- lib/rails_twirp/version.rb
|
82
80
|
- rails_twirp.gemspec
|
83
|
-
- test/dummy/Rakefile
|
84
|
-
- test/dummy/app/assets/config/manifest.js
|
85
|
-
- test/dummy/app/assets/images/.keep
|
86
|
-
- test/dummy/app/assets/stylesheets/application.css
|
87
|
-
- test/dummy/app/channels/application_cable/channel.rb
|
88
|
-
- test/dummy/app/channels/application_cable/connection.rb
|
89
|
-
- test/dummy/app/controllers/application_controller.rb
|
90
|
-
- test/dummy/app/controllers/application_twirp_controller.rb
|
91
|
-
- test/dummy/app/controllers/concerns/.keep
|
92
|
-
- test/dummy/app/controllers/dummy_controller.rb
|
93
|
-
- test/dummy/app/controllers/pings_controller.rb
|
94
|
-
- test/dummy/app/controllers/testmod/nested/other_controller.rb
|
95
|
-
- test/dummy/app/helpers/application_helper.rb
|
96
|
-
- test/dummy/app/helpers/random_helper.rb
|
97
|
-
- test/dummy/app/javascript/packs/application.js
|
98
|
-
- test/dummy/app/jobs/application_job.rb
|
99
|
-
- test/dummy/app/mailers/application_mailer.rb
|
100
|
-
- test/dummy/app/models/application_record.rb
|
101
|
-
- test/dummy/app/models/concerns/.keep
|
102
|
-
- test/dummy/app/views/dummy/rpc_name_check.pb.pbbuilder
|
103
|
-
- test/dummy/app/views/layouts/application.html.erb
|
104
|
-
- test/dummy/app/views/layouts/mailer.html.erb
|
105
|
-
- test/dummy/app/views/layouts/mailer.text.erb
|
106
|
-
- test/dummy/app/views/pings/ping_template.pb.pbbuilder
|
107
|
-
- test/dummy/bin/generate
|
108
|
-
- test/dummy/bin/rails
|
109
|
-
- test/dummy/bin/rake
|
110
|
-
- test/dummy/bin/setup
|
111
|
-
- test/dummy/config.ru
|
112
|
-
- test/dummy/config/application.rb
|
113
|
-
- test/dummy/config/boot.rb
|
114
|
-
- test/dummy/config/cable.yml
|
115
|
-
- test/dummy/config/database.yml
|
116
|
-
- test/dummy/config/environment.rb
|
117
|
-
- test/dummy/config/environments/development.rb
|
118
|
-
- test/dummy/config/environments/production.rb
|
119
|
-
- test/dummy/config/environments/test.rb
|
120
|
-
- test/dummy/config/initializers/application_controller_renderer.rb
|
121
|
-
- test/dummy/config/initializers/backtrace_silencers.rb
|
122
|
-
- test/dummy/config/initializers/content_security_policy.rb
|
123
|
-
- test/dummy/config/initializers/cookies_serializer.rb
|
124
|
-
- test/dummy/config/initializers/filter_parameter_logging.rb
|
125
|
-
- test/dummy/config/initializers/inflections.rb
|
126
|
-
- test/dummy/config/initializers/mime_types.rb
|
127
|
-
- test/dummy/config/initializers/permissions_policy.rb
|
128
|
-
- test/dummy/config/initializers/wrap_parameters.rb
|
129
|
-
- test/dummy/config/locales/en.yml
|
130
|
-
- test/dummy/config/puma.rb
|
131
|
-
- test/dummy/config/routes.rb
|
132
|
-
- test/dummy/config/storage.yml
|
133
|
-
- test/dummy/config/twirp/routes.rb
|
134
|
-
- test/dummy/lib/assets/.keep
|
135
|
-
- test/dummy/log/.keep
|
136
|
-
- test/dummy/proto/api.proto
|
137
|
-
- test/dummy/proto/api_pb.rb
|
138
|
-
- test/dummy/proto/api_twirp.rb
|
139
|
-
- test/dummy/public/404.html
|
140
|
-
- test/dummy/public/422.html
|
141
|
-
- test/dummy/public/500.html
|
142
|
-
- test/dummy/public/apple-touch-icon-precomposed.png
|
143
|
-
- test/dummy/public/apple-touch-icon.png
|
144
|
-
- test/dummy/public/favicon.ico
|
145
|
-
- test/dummy_test.rb
|
146
|
-
- test/other_controller_test.rb
|
147
|
-
- test/ping_controller_test.rb
|
148
|
-
- test/rails_twirp_test.rb
|
149
|
-
- test/test_helper.rb
|
150
81
|
homepage: https://github.com/cheddar-me/rails-twirp
|
151
82
|
licenses:
|
152
83
|
- MIT
|
@@ -170,71 +101,4 @@ rubygems_version: 3.2.32
|
|
170
101
|
signing_key:
|
171
102
|
specification_version: 4
|
172
103
|
summary: Integrate Twirp into Rails
|
173
|
-
test_files:
|
174
|
-
- test/dummy/Rakefile
|
175
|
-
- test/dummy/app/assets/config/manifest.js
|
176
|
-
- test/dummy/app/assets/images/.keep
|
177
|
-
- test/dummy/app/assets/stylesheets/application.css
|
178
|
-
- test/dummy/app/channels/application_cable/channel.rb
|
179
|
-
- test/dummy/app/channels/application_cable/connection.rb
|
180
|
-
- test/dummy/app/controllers/application_controller.rb
|
181
|
-
- test/dummy/app/controllers/application_twirp_controller.rb
|
182
|
-
- test/dummy/app/controllers/concerns/.keep
|
183
|
-
- test/dummy/app/controllers/dummy_controller.rb
|
184
|
-
- test/dummy/app/controllers/pings_controller.rb
|
185
|
-
- test/dummy/app/controllers/testmod/nested/other_controller.rb
|
186
|
-
- test/dummy/app/helpers/application_helper.rb
|
187
|
-
- test/dummy/app/helpers/random_helper.rb
|
188
|
-
- test/dummy/app/javascript/packs/application.js
|
189
|
-
- test/dummy/app/jobs/application_job.rb
|
190
|
-
- test/dummy/app/mailers/application_mailer.rb
|
191
|
-
- test/dummy/app/models/application_record.rb
|
192
|
-
- test/dummy/app/models/concerns/.keep
|
193
|
-
- test/dummy/app/views/dummy/rpc_name_check.pb.pbbuilder
|
194
|
-
- test/dummy/app/views/layouts/application.html.erb
|
195
|
-
- test/dummy/app/views/layouts/mailer.html.erb
|
196
|
-
- test/dummy/app/views/layouts/mailer.text.erb
|
197
|
-
- test/dummy/app/views/pings/ping_template.pb.pbbuilder
|
198
|
-
- test/dummy/bin/generate
|
199
|
-
- test/dummy/bin/rails
|
200
|
-
- test/dummy/bin/rake
|
201
|
-
- test/dummy/bin/setup
|
202
|
-
- test/dummy/config.ru
|
203
|
-
- test/dummy/config/application.rb
|
204
|
-
- test/dummy/config/boot.rb
|
205
|
-
- test/dummy/config/cable.yml
|
206
|
-
- test/dummy/config/database.yml
|
207
|
-
- test/dummy/config/environment.rb
|
208
|
-
- test/dummy/config/environments/development.rb
|
209
|
-
- test/dummy/config/environments/production.rb
|
210
|
-
- test/dummy/config/environments/test.rb
|
211
|
-
- test/dummy/config/initializers/application_controller_renderer.rb
|
212
|
-
- test/dummy/config/initializers/backtrace_silencers.rb
|
213
|
-
- test/dummy/config/initializers/content_security_policy.rb
|
214
|
-
- test/dummy/config/initializers/cookies_serializer.rb
|
215
|
-
- test/dummy/config/initializers/filter_parameter_logging.rb
|
216
|
-
- test/dummy/config/initializers/inflections.rb
|
217
|
-
- test/dummy/config/initializers/mime_types.rb
|
218
|
-
- test/dummy/config/initializers/permissions_policy.rb
|
219
|
-
- test/dummy/config/initializers/wrap_parameters.rb
|
220
|
-
- test/dummy/config/locales/en.yml
|
221
|
-
- test/dummy/config/puma.rb
|
222
|
-
- test/dummy/config/routes.rb
|
223
|
-
- test/dummy/config/storage.yml
|
224
|
-
- test/dummy/config/twirp/routes.rb
|
225
|
-
- test/dummy/lib/assets/.keep
|
226
|
-
- test/dummy/log/.keep
|
227
|
-
- test/dummy/proto/api.proto
|
228
|
-
- test/dummy/proto/api_pb.rb
|
229
|
-
- test/dummy/proto/api_twirp.rb
|
230
|
-
- test/dummy/public/404.html
|
231
|
-
- test/dummy/public/422.html
|
232
|
-
- test/dummy/public/500.html
|
233
|
-
- test/dummy/public/apple-touch-icon-precomposed.png
|
234
|
-
- test/dummy/public/apple-touch-icon.png
|
235
|
-
- test/dummy/public/favicon.ico
|
236
|
-
- test/dummy_test.rb
|
237
|
-
- test/other_controller_test.rb
|
238
|
-
- test/ping_controller_test.rb
|
239
|
-
- test/rails_twirp_test.rb
|
240
|
-
- test/test_helper.rb
|
104
|
+
test_files: []
|
data/.github/workflows/test.yml
DELETED
@@ -1,21 +0,0 @@
|
|
1
|
-
name: Ruby Test
|
2
|
-
on: push
|
3
|
-
|
4
|
-
jobs:
|
5
|
-
test:
|
6
|
-
runs-on: ubuntu-latest
|
7
|
-
steps:
|
8
|
-
- name: Checkout code
|
9
|
-
uses: actions/checkout@v2
|
10
|
-
|
11
|
-
- name: Setup Ruby
|
12
|
-
uses: ruby/setup-ruby@v1
|
13
|
-
with:
|
14
|
-
ruby-version: 3.0.0
|
15
|
-
bundler-cache: true
|
16
|
-
|
17
|
-
- name: Run tests
|
18
|
-
run: bin/test
|
19
|
-
|
20
|
-
- name: Run standardrb
|
21
|
-
run: bundle exec standardrb
|
data/bin/test
DELETED
@@ -1,106 +0,0 @@
|
|
1
|
-
require "twirp/encoding"
|
2
|
-
|
3
|
-
module RailsTwirp
|
4
|
-
class IntegrationTest < ActiveSupport::TestCase
|
5
|
-
DEFAULT_HOST = "www.example.com"
|
6
|
-
Response = Struct.new(:status, :body, :headers)
|
7
|
-
|
8
|
-
attr_reader :response, :request, :controller
|
9
|
-
attr_writer :mount_path
|
10
|
-
alias_method :mount_path!, :mount_path=
|
11
|
-
|
12
|
-
def initialize(name)
|
13
|
-
super
|
14
|
-
reset!
|
15
|
-
@before_rpc = []
|
16
|
-
end
|
17
|
-
|
18
|
-
def host
|
19
|
-
@host || DEFAULT_HOST
|
20
|
-
end
|
21
|
-
attr_writer :host
|
22
|
-
alias_method :host!, :host=
|
23
|
-
|
24
|
-
def https?
|
25
|
-
@https
|
26
|
-
end
|
27
|
-
|
28
|
-
def https!(value = true)
|
29
|
-
@https = value
|
30
|
-
end
|
31
|
-
|
32
|
-
def reset!
|
33
|
-
@request = nil
|
34
|
-
@response = nil
|
35
|
-
@host = nil
|
36
|
-
@host = nil
|
37
|
-
@https = false
|
38
|
-
@mount_path = "/twirp"
|
39
|
-
end
|
40
|
-
|
41
|
-
def before_rpc(&block)
|
42
|
-
@before_rpc << block
|
43
|
-
end
|
44
|
-
|
45
|
-
def rpc(service, rpc, request, headers: nil)
|
46
|
-
@request = request
|
47
|
-
|
48
|
-
env = build_rack_env(service, rpc, request, headers)
|
49
|
-
@before_rpc.each do |hook|
|
50
|
-
hook.call(env)
|
51
|
-
end
|
52
|
-
|
53
|
-
status, headers, body = app.call(env)
|
54
|
-
@response = decode_rack_response(service, rpc, status, headers, body)
|
55
|
-
set_controller_from_rack_env(env)
|
56
|
-
|
57
|
-
@response
|
58
|
-
end
|
59
|
-
|
60
|
-
def app
|
61
|
-
RailsTwirp.test_app
|
62
|
-
end
|
63
|
-
|
64
|
-
private
|
65
|
-
|
66
|
-
def build_rack_env(service, rpc, request, headers)
|
67
|
-
env = {
|
68
|
-
"CONTENT_TYPE" => request_content_type,
|
69
|
-
"HTTPS" => https? ? "on" : "off",
|
70
|
-
"HTTP_HOST" => host,
|
71
|
-
"PATH_INFO" => "#{@mount_path}/#{service.service_full_name}/#{rpc}",
|
72
|
-
"REQUEST_METHOD" => "POST",
|
73
|
-
"SERVER_NAME" => host,
|
74
|
-
"SERVER_PORT" => https? ? "443" : "80",
|
75
|
-
"rack.url_scheme" => https? ? "https" : "http"
|
76
|
-
}
|
77
|
-
if headers.present?
|
78
|
-
http_request = ActionDispatch::Request.new(env)
|
79
|
-
http_request.headers.merge! headers
|
80
|
-
end
|
81
|
-
|
82
|
-
input_class = service.rpcs[rpc][:input_class]
|
83
|
-
env["rack.input"] = StringIO.new(Twirp::Encoding.encode(request, input_class, request_content_type))
|
84
|
-
env
|
85
|
-
end
|
86
|
-
|
87
|
-
def request_content_type
|
88
|
-
Twirp::Encoding::PROTO
|
89
|
-
end
|
90
|
-
|
91
|
-
def decode_rack_response(service, rpc, status, headers, body)
|
92
|
-
body = body.join # body is an Enumerable
|
93
|
-
|
94
|
-
if status === 200
|
95
|
-
output_class = service.rpcs[rpc][:output_class]
|
96
|
-
Twirp::Encoding.decode(body, output_class, headers["Content-Type"])
|
97
|
-
else
|
98
|
-
Twirp::Client.error_from_response(Response.new(status, body, headers))
|
99
|
-
end
|
100
|
-
end
|
101
|
-
|
102
|
-
def set_controller_from_rack_env(env)
|
103
|
-
@controller = ActionDispatch::Request.new(env).controller_instance
|
104
|
-
end
|
105
|
-
end
|
106
|
-
end
|
data/test/dummy/Rakefile
DELETED
File without changes
|
@@ -1,15 +0,0 @@
|
|
1
|
-
/*
|
2
|
-
* This is a manifest file that'll be compiled into application.css, which will include all the files
|
3
|
-
* listed below.
|
4
|
-
*
|
5
|
-
* Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
|
6
|
-
* or any plugin's vendor/assets/stylesheets directory can be referenced here using a relative path.
|
7
|
-
*
|
8
|
-
* You're free to add application-wide styles to this file and they'll appear at the bottom of the
|
9
|
-
* compiled file so the styles you add here take precedence over styles defined in any other CSS/SCSS
|
10
|
-
* files in this directory. Styles in this file should be added after the last require_* statement.
|
11
|
-
* It is generally better to create a new file per style scope.
|
12
|
-
*
|
13
|
-
*= require_tree .
|
14
|
-
*= require_self
|
15
|
-
*/
|
File without changes
|
@@ -1,40 +0,0 @@
|
|
1
|
-
class PingsController < ApplicationTwirpController
|
2
|
-
before_action :respond_error, only: :before_error
|
3
|
-
|
4
|
-
def ping
|
5
|
-
response = RPC::DummyAPI::PingResponse.new(double_name: request.name * 2)
|
6
|
-
self.response_body = response
|
7
|
-
end
|
8
|
-
|
9
|
-
def ping_render
|
10
|
-
url = rails_twirp_engine_url
|
11
|
-
response = RPC::DummyAPI::PingResponse.new(double_name: "#{url} #{helpers.does_this_work(request.name)}")
|
12
|
-
render pb: response
|
13
|
-
end
|
14
|
-
|
15
|
-
def ping_template
|
16
|
-
@double_name = request.name * 2
|
17
|
-
end
|
18
|
-
|
19
|
-
def error_response
|
20
|
-
error :unauthenticated, "You are not authenticated!!"
|
21
|
-
end
|
22
|
-
|
23
|
-
def raise_error
|
24
|
-
# This error is rescued in ApplicationTwirpController
|
25
|
-
raise ActiveRecord::RecordNotFound, "Not found"
|
26
|
-
end
|
27
|
-
|
28
|
-
def uncaught_raise
|
29
|
-
raise StandardError, "Uncaught"
|
30
|
-
end
|
31
|
-
|
32
|
-
def before_error
|
33
|
-
# This error won't be reached because of the before_action
|
34
|
-
raise NotImplementedError
|
35
|
-
end
|
36
|
-
|
37
|
-
def respond_error
|
38
|
-
error :malformed, "yOuR ReQuEsT Is mAlFoRmEd"
|
39
|
-
end
|
40
|
-
end
|
@@ -1,15 +0,0 @@
|
|
1
|
-
// This is a manifest file that'll be compiled into application.js, which will include all the files
|
2
|
-
// listed below.
|
3
|
-
//
|
4
|
-
// Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
|
5
|
-
// or any plugin's vendor/assets/javascripts directory can be referenced here using a relative path.
|
6
|
-
//
|
7
|
-
// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
|
8
|
-
// compiled file. JavaScript code in this file should be added after the last require_* statement.
|
9
|
-
//
|
10
|
-
// Read Sprockets README (https://github.com/rails/sprockets#sprockets-directives) for details
|
11
|
-
// about supported directives.
|
12
|
-
//
|
13
|
-
//= require rails-ujs
|
14
|
-
//= require activestorage
|
15
|
-
//= require_tree .
|
@@ -1,7 +0,0 @@
|
|
1
|
-
class ApplicationJob < ActiveJob::Base
|
2
|
-
# Automatically retry jobs that encountered a deadlock
|
3
|
-
# retry_on ActiveRecord::Deadlocked
|
4
|
-
|
5
|
-
# Most jobs are safe to ignore if the underlying records are no longer available
|
6
|
-
# discard_on ActiveJob::DeserializationError
|
7
|
-
end
|