Skip to content

Commit 94e2dc0

Browse files
Copilotjoelhawksley
andcommitted
Change protocol parameter to use symbols instead of strings
Co-authored-by: joelhawksley <1940294+joelhawksley@users.noreply.github.com>
1 parent fe52278 commit 94e2dc0

4 files changed

Lines changed: 15 additions & 11 deletions

File tree

docs/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ nav_order: 6
1010

1111
## main
1212

13+
* Add `protocol` parameter to `with_request_url` test helper to enable testing with HTTPS protocol.
14+
15+
*Joel Hawksley*
16+
1317
## 4.3.0
1418

1519
* Fix load order issues for 3rd-party template handlers.

lib/view_component/test_helpers.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -199,15 +199,15 @@ def with_format(*formats)
199199
# To specify a protocol, pass the protocol param:
200200
#
201201
# ```ruby
202-
# with_request_url("/users/42", protocol: "https") do
202+
# with_request_url("/users/42", protocol: :https) do
203203
# render_inline(MyComponent.new)
204204
# end
205205
# ```
206206
#
207207
# @param full_path [String] The path to set for the current request.
208208
# @param host [String] The host to set for the current request.
209209
# @param method [String] The request method to set for the current request.
210-
# @param protocol [String] The protocol to set for the current request (e.g., "http" or "https").
210+
# @param protocol [Symbol] The protocol to set for the current request (e.g., `:http` or `:https`).
211211
def with_request_url(full_path, host: nil, method: nil, protocol: nil)
212212
old_request_host = vc_test_request.host
213213
old_request_method = vc_test_request.request_method
@@ -224,7 +224,7 @@ def with_request_url(full_path, host: nil, method: nil, protocol: nil)
224224
vc_test_request.instance_variable_set(:@original_fullpath, full_path)
225225
vc_test_request.host = host if host
226226
vc_test_request.request_method = method if method
227-
vc_test_request.set_header(Rack::RACK_URL_SCHEME, protocol) if protocol
227+
vc_test_request.set_header(Rack::RACK_URL_SCHEME, protocol.to_s) if protocol
228228
vc_test_request.path_info = path
229229
vc_test_request.path_parameters = Rails.application.routes.recognize_path_with_request(vc_test_request, path, {})
230230
vc_test_request.set_header("action_dispatch.request.query_parameters",

test/sandbox/test/rendering_test.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -965,17 +965,17 @@ def test_with_request_url_with_host
965965
end
966966

967967
def test_with_request_url_with_https_protocol
968-
with_request_url "/", protocol: "https" do
968+
with_request_url "/", protocol: :https do
969969
render_inline UrlForComponent.new(only_path: false)
970-
assert_text "https://www.example.com/?key=value"
970+
assert_text "https://example.com/?key=value"
971971
end
972972

973-
with_request_url "/products", protocol: "https", host: "secure.example.com" do
973+
with_request_url "/products", protocol: :https, host: "secure.example.com" do
974974
render_inline UrlForComponent.new(only_path: false)
975975
assert_text "https://secure.example.com/products?key=value"
976976
end
977977

978-
with_request_url "/products", protocol: "https" do
978+
with_request_url "/products", protocol: :https do
979979
assert_equal "https", vc_test_request.scheme
980980
assert vc_test_request.ssl?
981981
end

test/sandbox/test/test_helper_test.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,15 +51,15 @@ def test_vc_test_view_context_is_shared_reference
5151
end
5252

5353
def test_with_request_url_specifying_http_protocol
54-
with_request_url "/products", protocol: "http" do
54+
with_request_url "/products", protocol: :http do
5555
render_inline(ProtocolComponent.new)
5656
end
5757

5858
assert_selector(".protocol", text: "Protocol: http, SSL: false")
5959
end
6060

6161
def test_with_request_url_specifying_https_protocol
62-
with_request_url "/products", protocol: "https" do
62+
with_request_url "/products", protocol: :https do
6363
render_inline(ProtocolComponent.new)
6464
end
6565

@@ -70,7 +70,7 @@ def test_with_request_url_restores_original_protocol
7070
# Store original protocol
7171
original_scheme = vc_test_request.scheme
7272

73-
with_request_url "/products", protocol: "https" do
73+
with_request_url "/products", protocol: :https do
7474
assert_equal "https", vc_test_request.scheme
7575
end
7676

@@ -79,7 +79,7 @@ def test_with_request_url_restores_original_protocol
7979
end
8080

8181
def test_with_request_url_with_protocol_and_host
82-
with_request_url "/products", protocol: "https", host: "secure.example.com" do
82+
with_request_url "/products", protocol: :https, host: "secure.example.com" do
8383
render_inline(ProtocolComponent.new)
8484
end
8585

0 commit comments

Comments
 (0)