rails_twirp 0.12.0 → 0.13.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (80) hide show
  1. checksums.yaml +4 -4
  2. data/.standard.yml +0 -1
  3. data/CHANGELOG.md +9 -0
  4. data/Gemfile +1 -1
  5. data/lib/rails_twirp/base.rb +12 -6
  6. data/lib/rails_twirp/engine.rb +5 -1
  7. data/lib/rails_twirp/metal.rb +26 -0
  8. data/lib/rails_twirp/version.rb +1 -1
  9. data/rails_twirp.gemspec +2 -3
  10. metadata +10 -146
  11. data/.github/workflows/test.yml +0 -21
  12. data/bin/test +0 -5
  13. data/lib/rails_twirp/testing/integration_test.rb +0 -106
  14. data/test/dummy/Rakefile +0 -6
  15. data/test/dummy/app/assets/config/manifest.js +0 -2
  16. data/test/dummy/app/assets/images/.keep +0 -0
  17. data/test/dummy/app/assets/stylesheets/application.css +0 -15
  18. data/test/dummy/app/channels/application_cable/channel.rb +0 -4
  19. data/test/dummy/app/channels/application_cable/connection.rb +0 -4
  20. data/test/dummy/app/controllers/application_controller.rb +0 -2
  21. data/test/dummy/app/controllers/application_twirp_controller.rb +0 -7
  22. data/test/dummy/app/controllers/concerns/.keep +0 -0
  23. data/test/dummy/app/controllers/dummy_controller.rb +0 -5
  24. data/test/dummy/app/controllers/pings_controller.rb +0 -40
  25. data/test/dummy/app/controllers/testmod/nested/other_controller.rb +0 -10
  26. data/test/dummy/app/helpers/application_helper.rb +0 -2
  27. data/test/dummy/app/helpers/random_helper.rb +0 -5
  28. data/test/dummy/app/javascript/packs/application.js +0 -15
  29. data/test/dummy/app/jobs/application_job.rb +0 -7
  30. data/test/dummy/app/mailers/application_mailer.rb +0 -4
  31. data/test/dummy/app/models/application_record.rb +0 -3
  32. data/test/dummy/app/models/concerns/.keep +0 -0
  33. data/test/dummy/app/views/dummy/rpc_name_check.pb.pbbuilder +0 -1
  34. data/test/dummy/app/views/layouts/application.html.erb +0 -15
  35. data/test/dummy/app/views/layouts/mailer.html.erb +0 -13
  36. data/test/dummy/app/views/layouts/mailer.text.erb +0 -1
  37. data/test/dummy/app/views/pings/ping_template.pb.pbbuilder +0 -1
  38. data/test/dummy/bin/generate +0 -3
  39. data/test/dummy/bin/rails +0 -4
  40. data/test/dummy/bin/rake +0 -4
  41. data/test/dummy/bin/setup +0 -33
  42. data/test/dummy/config/application.rb +0 -23
  43. data/test/dummy/config/boot.rb +0 -5
  44. data/test/dummy/config/cable.yml +0 -10
  45. data/test/dummy/config/database.yml +0 -25
  46. data/test/dummy/config/environment.rb +0 -5
  47. data/test/dummy/config/environments/development.rb +0 -76
  48. data/test/dummy/config/environments/production.rb +0 -120
  49. data/test/dummy/config/environments/test.rb +0 -59
  50. data/test/dummy/config/initializers/application_controller_renderer.rb +0 -8
  51. data/test/dummy/config/initializers/backtrace_silencers.rb +0 -8
  52. data/test/dummy/config/initializers/content_security_policy.rb +0 -28
  53. data/test/dummy/config/initializers/cookies_serializer.rb +0 -5
  54. data/test/dummy/config/initializers/filter_parameter_logging.rb +0 -6
  55. data/test/dummy/config/initializers/inflections.rb +0 -16
  56. data/test/dummy/config/initializers/mime_types.rb +0 -4
  57. data/test/dummy/config/initializers/permissions_policy.rb +0 -11
  58. data/test/dummy/config/initializers/wrap_parameters.rb +0 -14
  59. data/test/dummy/config/locales/en.yml +0 -33
  60. data/test/dummy/config/puma.rb +0 -43
  61. data/test/dummy/config/routes.rb +0 -3
  62. data/test/dummy/config/storage.yml +0 -34
  63. data/test/dummy/config/twirp/routes.rb +0 -22
  64. data/test/dummy/config.ru +0 -6
  65. data/test/dummy/lib/assets/.keep +0 -0
  66. data/test/dummy/log/.keep +0 -0
  67. data/test/dummy/proto/api.proto +0 -30
  68. data/test/dummy/proto/api_pb.rb +0 -29
  69. data/test/dummy/proto/api_twirp.rb +0 -25
  70. data/test/dummy/public/404.html +0 -67
  71. data/test/dummy/public/422.html +0 -67
  72. data/test/dummy/public/500.html +0 -66
  73. data/test/dummy/public/apple-touch-icon-precomposed.png +0 -0
  74. data/test/dummy/public/apple-touch-icon.png +0 -0
  75. data/test/dummy/public/favicon.ico +0 -0
  76. data/test/dummy_test.rb +0 -10
  77. data/test/other_controller_test.rb +0 -9
  78. data/test/ping_controller_test.rb +0 -114
  79. data/test/rails_twirp_test.rb +0 -7
  80. data/test/test_helper.rb +0 -16
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: '09e97be65f570cd7a2cecaaf0ef83d2ead287fd1fc8c556b833ae45395ee1c2b'
4
- data.tar.gz: 1b30d280c8c724747b0b71ef7996ad23fd0a8e189818156602f284677ac9c637
3
+ metadata.gz: d04982e98774e2a130671b2729dad6141905df3544c7cfa3900137a7cd553356
4
+ data.tar.gz: 650187fd3c34f30ca91885c6c1fa9b1547035a816d088e0b8c583f9ea6a0608e
5
5
  SHA512:
6
- metadata.gz: 858ea0680c3efd03f2f1fdc766f6097b6e0a7b19ff39974412207139cd28a432d4c620a7a4f9243b63b9f70eff1919cb5a92d0c3dc6b5cd73ba99eb1349ac870
7
- data.tar.gz: ba6311d0b7cb64755380eff9d1168d24458d5804f36acf21c7fceab2a8b0db305722353d8c5f493bf1692225f973342e3194f825d995df286802da6958631e3a
6
+ metadata.gz: 4021ee3e130f4647423177456c9ccfb5bcce728874b547f56c2ae52a78fc92a953f6e98e7dee7eb87c78adca37f4f42cd21c7761f3842f20859923a3a8b8096f
7
+ data.tar.gz: bcb8240668e0c0d59f63ad7148595fcf15142533bed252e6f55212f51a73df0f31a623ca97f675c1494712631ffb025b20f71956dbfaa71ba61d9d48e12f2512
data/.standard.yml CHANGED
@@ -1,4 +1,3 @@
1
1
  ignore:
2
- - 'test/dummy/proto/*'
3
2
  - '**/*':
4
3
  - Lint/RescueException
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
@@ -4,7 +4,7 @@ source "https://rubygems.org"
4
4
  gemspec
5
5
 
6
6
  gem "sqlite3"
7
- gem "pbbuilder", "~> 0.12.0"
7
+ gem "pbbuilder"
8
8
  gem "standard"
9
9
  gem "pry"
10
10
 
@@ -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 < AbstractController::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
- attr_internal :request, :env, :response_class, :rpc_name
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
@@ -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
@@ -1,3 +1,3 @@
1
1
  module RailsTwirp
2
- VERSION = "0.12.0"
2
+ VERSION = "0.13.1"
3
3
  end
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.7.2", "~> 1.9.0"
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.12.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: 2022-01-26 00:00:00.000000000 Z
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.7.2
34
- - - "~>"
33
+ version: '1.9'
34
+ - - "<"
35
35
  - !ruby/object:Gem::Version
36
- version: 1.9.0
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.7.2
44
- - - "~>"
43
+ version: '1.9'
44
+ - - "<"
45
45
  - !ruby/object:Gem::Version
46
- version: 1.9.0
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: []
@@ -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,5 +0,0 @@
1
- #!/usr/bin/env ruby
2
- $: << File.expand_path("../test", __dir__)
3
-
4
- require "bundler/setup"
5
- require "rails/plugin/test"
@@ -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
@@ -1,6 +0,0 @@
1
- # Add your own tasks in files placed in lib/tasks ending in .rake,
2
- # for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
3
-
4
- require_relative "config/application"
5
-
6
- Rails.application.load_tasks
@@ -1,2 +0,0 @@
1
- //= link_tree ../images
2
- //= link_directory ../stylesheets .css
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
- */
@@ -1,4 +0,0 @@
1
- module ApplicationCable
2
- class Channel < ActionCable::Channel::Base
3
- end
4
- end
@@ -1,4 +0,0 @@
1
- module ApplicationCable
2
- class Connection < ActionCable::Connection::Base
3
- end
4
- end
@@ -1,2 +0,0 @@
1
- class ApplicationController < ActionController::Base
2
- end
@@ -1,7 +0,0 @@
1
- class ApplicationTwirpController < RailsTwirp::Base
2
- rescue_from ActiveRecord::RecordNotFound, with: :handle_not_found
3
-
4
- def handle_not_found
5
- error :not_found, "Not found"
6
- end
7
- end
File without changes
@@ -1,5 +0,0 @@
1
- class DummyController < RailsTwirp::Base
2
- def rpc_name_check
3
- @rpc_name = rpc_name
4
- end
5
- end
@@ -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,10 +0,0 @@
1
- module Testmod
2
- module Nested
3
- class OtherController < ApplicationTwirpController
4
- def ping
5
- response = RPC::DummyAPI::PingResponse.new(double_name: request.name * 2)
6
- self.response_body = response
7
- end
8
- end
9
- end
10
- end
@@ -1,2 +0,0 @@
1
- module ApplicationHelper
2
- end
@@ -1,5 +0,0 @@
1
- module RandomHelper
2
- def does_this_work(n)
3
- n * 2
4
- end
5
- 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
@@ -1,4 +0,0 @@
1
- class ApplicationMailer < ActionMailer::Base
2
- default from: "from@example.com"
3
- layout "mailer"
4
- end
@@ -1,3 +0,0 @@
1
- class ApplicationRecord < ActiveRecord::Base
2
- self.abstract_class = true
3
- end