view_component 3.0.0.rc3 → 3.0.0.rc5
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of view_component might be problematic. Click here for more details.
- checksums.yaml +4 -4
- data/app/controllers/view_components_system_test_controller.rb +5 -3
- data/docs/CHANGELOG.md +22 -0
- data/lib/view_component/capture_compatibility.rb +2 -0
- data/lib/view_component/compiler.rb +1 -2
- data/lib/view_component/system_test_helpers.rb +1 -1
- data/lib/view_component/test_helpers.rb +29 -18
- data/lib/view_component/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3746041e156447e727a9974ad435795bd08333c13f6004ba5a03f629764d301d
|
4
|
+
data.tar.gz: 47e3d85474b5cb69fbc12abb48a59a85776f14475508ff55f40f672f393bd309
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cc5edccc814c845eb63ce951e621365ec9ec3013363b32b0bc5f05db8a0fb15ea26688eae22f54fcc17bbc477c5e93350cd0b3fbf3af9bd1e27f1f3f9e53cbec
|
7
|
+
data.tar.gz: d87a2ee301acf5b4e67ec159bc3433ce2d46da343de5da26af975314b862b4befbfdd247a0046239b99bb322e26b4062625073424ba0fd7e54a1e973a2d56ebd
|
@@ -1,11 +1,13 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
class ViewComponentsSystemTestController < ActionController::Base # :nodoc:
|
4
|
-
TEMP_DIR = FileUtils.mkdir_p("./tmp/view_components/").first
|
5
|
-
|
6
4
|
before_action :validate_test_env
|
7
5
|
before_action :validate_file_path
|
8
6
|
|
7
|
+
def self.temp_dir
|
8
|
+
@_tmpdir ||= FileUtils.mkdir_p("./tmp/view_components/").first
|
9
|
+
end
|
10
|
+
|
9
11
|
def system_test_entrypoint
|
10
12
|
render file: @path
|
11
13
|
end
|
@@ -19,7 +21,7 @@ class ViewComponentsSystemTestController < ActionController::Base # :nodoc:
|
|
19
21
|
# Ensure that the file path is valid and doesn't target files outside
|
20
22
|
# the expected directory (e.g. via a path traversal or symlink attack)
|
21
23
|
def validate_file_path
|
22
|
-
base_path = ::File.realpath(
|
24
|
+
base_path = ::File.realpath(self.class.temp_dir)
|
23
25
|
@path = ::File.realpath(params.permit(:file)[:file], base_path)
|
24
26
|
unless @path.start_with?(base_path)
|
25
27
|
raise ArgumentError, "Invalid file path"
|
data/docs/CHANGELOG.md
CHANGED
@@ -10,6 +10,28 @@ nav_order: 5
|
|
10
10
|
|
11
11
|
## main
|
12
12
|
|
13
|
+
## v3.0.0.rc5
|
14
|
+
|
15
|
+
* Fix bug where `mkdir_p` failed due to incorrect permissions.
|
16
|
+
|
17
|
+
*Joel Hawksley*
|
18
|
+
|
19
|
+
* Check for inline `erb_template` calls when deciding whether or not to compile a component's superclass.
|
20
|
+
|
21
|
+
*Justin Kenyon*
|
22
|
+
|
23
|
+
* Protect against `SystemStackError` if `CaptureCompatibility` module is included more than once.
|
24
|
+
|
25
|
+
*Cameron Dutro*
|
26
|
+
|
27
|
+
## v3.0.0.rc4
|
28
|
+
|
29
|
+
Run into an issue with this release candidate? [Let us know](https://github.com/ViewComponent/view_component/issues/1629).
|
30
|
+
|
31
|
+
* Add `TestHelpers#vc_test_request`.
|
32
|
+
|
33
|
+
*Joel Hawksley*
|
34
|
+
|
13
35
|
## v3.0.0.rc3
|
14
36
|
|
15
37
|
Run into an issue with this release candidate? [Let us know](https://github.com/ViewComponent/view_component/issues/1629).
|
@@ -17,6 +17,8 @@ module ViewComponent
|
|
17
17
|
# the `capture` logic to the ViewComponent that created the block.
|
18
18
|
module CaptureCompatibility
|
19
19
|
def self.included(base)
|
20
|
+
return if base < InstanceMethods
|
21
|
+
|
20
22
|
base.class_eval do
|
21
23
|
alias_method :original_capture, :capture
|
22
24
|
end
|
@@ -285,8 +285,7 @@ module ViewComponent
|
|
285
285
|
end
|
286
286
|
|
287
287
|
def should_compile_superclass?
|
288
|
-
development? &&
|
289
|
-
templates.empty? &&
|
288
|
+
development? && templates.empty? && !has_inline_template? &&
|
290
289
|
!(
|
291
290
|
component_class.instance_methods(false).include?(:call) ||
|
292
291
|
component_class.private_instance_methods(false).include?(:call)
|
@@ -12,7 +12,7 @@ module ViewComponent
|
|
12
12
|
def with_rendered_component_path(fragment, layout: false, &block)
|
13
13
|
file = Tempfile.new(
|
14
14
|
["rendered_#{fragment.class.name}", ".html"],
|
15
|
-
ViewComponentsSystemTestController
|
15
|
+
ViewComponentsSystemTestController.temp_dir
|
16
16
|
)
|
17
17
|
begin
|
18
18
|
file.write(vc_test_controller.render_to_string(html: fragment.to_html.html_safe, layout: layout))
|
@@ -157,23 +157,23 @@ module ViewComponent
|
|
157
157
|
#
|
158
158
|
# @param path [String] The path to set for the current request.
|
159
159
|
def with_request_url(path)
|
160
|
-
old_request_path_info =
|
161
|
-
old_request_path_parameters =
|
162
|
-
old_request_query_parameters =
|
163
|
-
old_request_query_string =
|
160
|
+
old_request_path_info = vc_test_request.path_info
|
161
|
+
old_request_path_parameters = vc_test_request.path_parameters
|
162
|
+
old_request_query_parameters = vc_test_request.query_parameters
|
163
|
+
old_request_query_string = vc_test_request.query_string
|
164
164
|
old_controller = defined?(@vc_test_controller) && @vc_test_controller
|
165
165
|
|
166
166
|
path, query = path.split("?", 2)
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
167
|
+
vc_test_request.path_info = path
|
168
|
+
vc_test_request.path_parameters = Rails.application.routes.recognize_path_with_request(vc_test_request, path, {})
|
169
|
+
vc_test_request.set_header("action_dispatch.request.query_parameters", Rack::Utils.parse_nested_query(query))
|
170
|
+
vc_test_request.set_header(Rack::QUERY_STRING, query)
|
171
171
|
yield
|
172
172
|
ensure
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
173
|
+
vc_test_request.path_info = old_request_path_info
|
174
|
+
vc_test_request.path_parameters = old_request_path_parameters
|
175
|
+
vc_test_request.set_header("action_dispatch.request.query_parameters", old_request_query_parameters)
|
176
|
+
vc_test_request.set_header(Rack::QUERY_STRING, old_request_query_string)
|
177
177
|
@vc_test_controller = old_controller
|
178
178
|
end
|
179
179
|
|
@@ -192,11 +192,19 @@ module ViewComponent
|
|
192
192
|
@vc_test_controller ||= __vc_test_helpers_build_controller(Base.test_controller.constantize)
|
193
193
|
end
|
194
194
|
|
195
|
-
#
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
195
|
+
# Access the request used by `render_inline`:
|
196
|
+
#
|
197
|
+
# ```ruby
|
198
|
+
# test "component does not render in Firefox" do
|
199
|
+
# request.env["HTTP_USER_AGENT"] = "Mozilla/5.0"
|
200
|
+
# render_inline(NoFirefoxComponent.new)
|
201
|
+
# refute_component_rendered
|
202
|
+
# end
|
203
|
+
# ```
|
204
|
+
#
|
205
|
+
# @return [ActionDispatch::TestRequest]
|
206
|
+
def vc_test_request
|
207
|
+
@vc_test_request ||=
|
200
208
|
begin
|
201
209
|
out = ActionDispatch::TestRequest.create
|
202
210
|
out.session = ActionController::TestSession.new
|
@@ -204,8 +212,11 @@ module ViewComponent
|
|
204
212
|
end
|
205
213
|
end
|
206
214
|
|
215
|
+
# Note: We prefix private methods here to prevent collisions in consumer's tests.
|
216
|
+
private
|
217
|
+
|
207
218
|
def __vc_test_helpers_build_controller(klass)
|
208
|
-
klass.new.tap { |c| c.request =
|
219
|
+
klass.new.tap { |c| c.request = vc_test_request }.extend(Rails.application.routes.url_helpers)
|
209
220
|
end
|
210
221
|
|
211
222
|
def __vc_test_helpers_preview_class
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: view_component
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.0.0.
|
4
|
+
version: 3.0.0.rc5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- ViewComponent Team
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-03-
|
11
|
+
date: 2023-03-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|