view_component 4.3.0 → 4.4.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7cc3bb1d940451beebb05d7424ae9fe3124ddbfd2acc21e407c0b3c4964c7570
4
- data.tar.gz: 2db13b63611d87477814e3567e2aca332879a50e1a500ecc560b8a9d0537c411
3
+ metadata.gz: c3a3df2973d8a5830f14e1ec81396eb006e254a6d0092022686279231edc7fa1
4
+ data.tar.gz: 7633b908531c74612dab36a40f5d56efd2cb4e89cd89a7d476446cc758172673
5
5
  SHA512:
6
- metadata.gz: 8dd9367ebb7c528a5a89d0a76d1294a0fa0276eed80b8c819d338c82d86c131386851903fb3fe0c1be43416980ebf9cb4ca405599f4e58f73084b1d5aee8fa8d
7
- data.tar.gz: 4cca85cd44103692aed7039a7c0b044d78adbff6bbc0e5d99be0fe72590dae160047cf34ce731ec079141cf2ed22485d32898ce5917ec225e637951151c9d544
6
+ metadata.gz: c4e3496a4dd6acd8568d81ea39f69fd960e5dfc1297c008bbb83b3b946ca7f311093dee3cf129c0df77427394ba60e45407c6542e6132d6493b3748b11a483f2
7
+ data.tar.gz: 71edfce3f459946670adf0f7c96eefdb4e811d1a2a9ca613fbfd40697526d5bdf3ed204855171ebd3e2291e17b0a10bcbc0d6ea08d40515a0d2b370a454f9005
data/docs/CHANGELOG.md CHANGED
@@ -10,6 +10,16 @@ nav_order: 6
10
10
 
11
11
  ## main
12
12
 
13
+ ## 4.4.0
14
+
15
+ * Fix segfaults when Ruby coverage is enabled.
16
+
17
+ *George Holborn*, *Joel Hawksley*
18
+
19
+ * Add `protocol` parameter to `with_request_url` test helper to enable testing with HTTPS protocol.
20
+
21
+ *Joel Hawksley*
22
+
13
23
  ## 4.3.0
14
24
 
15
25
  * Fix load order issues for 3rd-party template handlers.
@@ -30,8 +30,10 @@ module ViewComponent
30
30
  # annotation line from compiled source instead.
31
31
  lineno =
32
32
  if Rails::VERSION::MAJOR >= 8 && Rails::VERSION::MINOR > 0 && details.handler == :erb
33
- if coverage_running? && ActionView::Base.annotate_rendered_view_with_filenames
34
- @strip_annotation_line = true
33
+ if coverage_running?
34
+ # Can't use negative lineno with coverage (causes segfault on Linux).
35
+ # Strip annotation line if enabled to preserve correct line numbers.
36
+ @strip_annotation_line = ActionView::Base.annotate_rendered_view_with_filenames
35
37
  0
36
38
  else
37
39
  -1
@@ -63,7 +65,7 @@ module ViewComponent
63
65
  result = super
64
66
  # Strip the annotation line to maintain correct line numbers when coverage
65
67
  # is running (avoids segfault from negative lineno)
66
- result = result.sub(/\A[^\n]*\n/, "") if @strip_annotation_line
68
+ result = result.partition(";").last if @strip_annotation_line
67
69
  result
68
70
  end
69
71
  end
@@ -196,10 +196,19 @@ module ViewComponent
196
196
  # end
197
197
  # ```
198
198
  #
199
+ # To specify a protocol, pass the protocol param:
200
+ #
201
+ # ```ruby
202
+ # with_request_url("/users/42", protocol: :https) do
203
+ # render_inline(MyComponent.new)
204
+ # end
205
+ # ```
206
+ #
199
207
  # @param full_path [String] The path to set for the current request.
200
208
  # @param host [String] The host to set for the current request.
201
209
  # @param method [String] The request method to set for the current request.
202
- def with_request_url(full_path, host: nil, method: nil)
210
+ # @param protocol [Symbol] The protocol to set for the current request (e.g., `:http` or `:https`).
211
+ def with_request_url(full_path, host: nil, method: nil, protocol: nil)
203
212
  old_request_host = vc_test_request.host
204
213
  old_request_method = vc_test_request.request_method
205
214
  old_request_path_info = vc_test_request.path_info
@@ -207,6 +216,7 @@ module ViewComponent
207
216
  old_request_query_parameters = vc_test_request.query_parameters
208
217
  old_request_query_string = vc_test_request.query_string
209
218
  old_request_format = vc_test_request.format.symbol
219
+ old_request_scheme = vc_test_request.scheme
210
220
  old_controller = defined?(@vc_test_controller) && @vc_test_controller
211
221
 
212
222
  path, query = full_path.split("?", 2)
@@ -214,6 +224,7 @@ module ViewComponent
214
224
  vc_test_request.instance_variable_set(:@original_fullpath, full_path)
215
225
  vc_test_request.host = host if host
216
226
  vc_test_request.request_method = method if method
227
+ vc_test_request.set_header(Rack::RACK_URL_SCHEME, protocol.to_s) if protocol
217
228
  vc_test_request.path_info = path
218
229
  vc_test_request.path_parameters = Rails.application.routes.recognize_path_with_request(vc_test_request, path, {})
219
230
  vc_test_request.set_header("action_dispatch.request.query_parameters",
@@ -223,6 +234,7 @@ module ViewComponent
223
234
  ensure
224
235
  vc_test_request.host = old_request_host
225
236
  vc_test_request.request_method = old_request_method
237
+ vc_test_request.set_header(Rack::RACK_URL_SCHEME, old_request_scheme)
226
238
  vc_test_request.path_info = old_request_path_info
227
239
  vc_test_request.path_parameters = old_request_path_parameters
228
240
  vc_test_request.set_header("action_dispatch.request.query_parameters", old_request_query_parameters)
@@ -3,7 +3,7 @@
3
3
  module ViewComponent
4
4
  module VERSION
5
5
  MAJOR = 4
6
- MINOR = 3
6
+ MINOR = 4
7
7
  PATCH = 0
8
8
  PRE = nil
9
9
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: view_component
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.3.0
4
+ version: 4.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - ViewComponent Team