rails_twirp 0.6.0 → 0.7.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/rails_twirp/route_set.rb +2 -2
- data/lib/rails_twirp/testing/integration_test.rb +26 -3
- data/lib/rails_twirp/version.rb +1 -1
- data/test/ping_controller_test.rb +10 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0ed88410115867b689de324aeaf99b91ba473d3aa573915d9bec5de1142b7986
|
4
|
+
data.tar.gz: dadc45ad3c6ed38f6791e8a45573127c69297772a7b0ae4861a2867dadf26d09
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 976f3755035c22c65db62aa4b82e8019bf816e5e30cec968e19c5345630aa1b7c6d51d38439e267fde4d9696ce05667c5a2ed2566953bbe87a175ac2ea9df93f
|
7
|
+
data.tar.gz: f3c1460d7cd0ae988e8aabbb516afd1983b975e8aee872f295eb3017061a51500667ee1ecbd226f2260c03f179ad94560227710fc98095e0e60749288271d406
|
@@ -50,12 +50,12 @@ module RailsTwirp
|
|
50
50
|
method_name = rpc_info[:ruby_method]
|
51
51
|
|
52
52
|
# Stolen from Rails in ActionDispatch::Request#controller_class_for
|
53
|
-
controller_name = mapping.controller.underscore
|
54
|
-
const_name = controller_name.camelize << "Controller"
|
55
53
|
action_name = mapping.action
|
56
54
|
response_class = rpc_info[:output_class]
|
57
55
|
|
58
56
|
handler.define_method(method_name) do |req, env|
|
57
|
+
controller_name = mapping.controller.underscore
|
58
|
+
const_name = controller_name.camelize << "Controller"
|
59
59
|
controller_class = ::ActiveSupport::Dependencies.constantize(const_name)
|
60
60
|
controller_class.dispatch(action_name, req, response_class, env)
|
61
61
|
end
|
@@ -2,21 +2,40 @@ require "twirp/encoding"
|
|
2
2
|
|
3
3
|
module RailsTwirp
|
4
4
|
class IntegrationTest < ActiveSupport::TestCase
|
5
|
+
DEFAULT_HOST = "www.example.com"
|
5
6
|
Response = Struct.new(:status, :body, :headers)
|
6
7
|
|
7
8
|
attr_reader :response, :request, :controller
|
8
9
|
attr_writer :mount_path
|
10
|
+
alias :mount_path! :mount_path=
|
9
11
|
|
10
12
|
def initialize(name)
|
11
13
|
super
|
12
14
|
reset!
|
13
15
|
@before_rpc = []
|
14
|
-
|
16
|
+
end
|
17
|
+
|
18
|
+
def host
|
19
|
+
@host || DEFAULT_HOST
|
20
|
+
end
|
21
|
+
attr_writer :host
|
22
|
+
alias :host! :host=
|
23
|
+
|
24
|
+
def https?
|
25
|
+
@https
|
26
|
+
end
|
27
|
+
|
28
|
+
def https!(value = true)
|
29
|
+
@https = value
|
15
30
|
end
|
16
31
|
|
17
32
|
def reset!
|
18
33
|
@request = nil
|
19
34
|
@response = nil
|
35
|
+
@host = nil
|
36
|
+
@host = nil
|
37
|
+
@https = false
|
38
|
+
@mount_path = "/twirp"
|
20
39
|
end
|
21
40
|
|
22
41
|
def before_rpc(&block)
|
@@ -47,9 +66,13 @@ module RailsTwirp
|
|
47
66
|
def build_rack_env(service, rpc, request, headers)
|
48
67
|
env = {
|
49
68
|
"CONTENT_TYPE" => request_content_type,
|
50
|
-
"
|
69
|
+
"HTTPS" => https? ? "on" : "off",
|
70
|
+
"HTTP_HOST" => host,
|
51
71
|
"PATH_INFO" => "#{@mount_path}/#{service.service_full_name}/#{rpc}",
|
52
|
-
"REQUEST_METHOD" => "POST"
|
72
|
+
"REQUEST_METHOD" => "POST",
|
73
|
+
"SERVER_NAME" => host,
|
74
|
+
"SERVER_PORT" => https? ? "443" : "80",
|
75
|
+
"rack.url_scheme" => https? ? "https" : "http"
|
53
76
|
}
|
54
77
|
if headers.present?
|
55
78
|
http_request = ActionDispatch::Request.new(env)
|
data/lib/rails_twirp/version.rb
CHANGED
@@ -11,7 +11,16 @@ class PingControllerTest < RailsTwirp::IntegrationTest
|
|
11
11
|
req = RPC::DummyAPI::PingRequest.new(name: "Bouke")
|
12
12
|
rpc RPC::DummyAPI::DummyService, "PingRender", req
|
13
13
|
refute_instance_of Twirp::Error, response
|
14
|
-
assert_equal "http://
|
14
|
+
assert_equal "http://www.example.com/twirp BoukeBouke", response.double_name
|
15
|
+
end
|
16
|
+
|
17
|
+
test "you can ping render with host and https" do
|
18
|
+
host! "localhost"
|
19
|
+
https!
|
20
|
+
req = RPC::DummyAPI::PingRequest.new(name: "Bouke")
|
21
|
+
rpc RPC::DummyAPI::DummyService, "PingRender", req
|
22
|
+
refute_instance_of Twirp::Error, response
|
23
|
+
assert_equal "https://localhost/twirp BoukeBouke", response.double_name
|
15
24
|
end
|
16
25
|
|
17
26
|
test "you can ping template" do
|