view_component 2.26.1 → 2.27.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.
Potentially problematic release.
This version of view_component might be problematic. Click here for more details.
- checksums.yaml +4 -4
- data/CHANGELOG.md +10 -0
- data/lib/rails/generators/preview/component_generator.rb +5 -1
- data/lib/view_component/base.rb +3 -2
- data/lib/view_component/test_helpers.rb +15 -1
- data/lib/view_component/version.rb +2 -2
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 47f112ee86431b25865a4793374e8838a1e80966d91150d4b182b38c598a9631
|
4
|
+
data.tar.gz: 97673827cb5a971d8c769b9566c87055d28af37fa04b06b6e90c5098b64c9388
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 538a828cd9096fd400cd3b3bc8fa4f63666003221161b22f59a008f62fa5f8d8b311d7152498ff5519004bd960c61d058912fc7241e537d129d9873a4b6c0b63
|
7
|
+
data.tar.gz: 99de0a2aadb9eb873854b284e0be4f1aa2d20aa8262c5350b3473d536d6e40891d819dff74c73188b1106454a98299511b79e7c406ddebbe05dfdf8ebf69804b
|
data/CHANGELOG.md
CHANGED
@@ -2,6 +2,16 @@
|
|
2
2
|
|
3
3
|
## main
|
4
4
|
|
5
|
+
## 2.27.0
|
6
|
+
|
7
|
+
* Allow customization of the controller used in component tests.
|
8
|
+
|
9
|
+
*Alex Robbin*
|
10
|
+
|
11
|
+
* Generate preview at overridden path if one exists when using `--preview` flag.
|
12
|
+
|
13
|
+
*Nishiki Liu*
|
14
|
+
|
5
15
|
## 2.26.1
|
6
16
|
|
7
17
|
* Fix bug that raises when trying to use a collection before the component has been compiled.
|
@@ -8,7 +8,11 @@ module Preview
|
|
8
8
|
check_class_collision suffix: "ComponentPreview"
|
9
9
|
|
10
10
|
def create_preview_file
|
11
|
-
|
11
|
+
preview_paths = Rails.application.config.view_component.preview_paths
|
12
|
+
return if preview_paths.count > 1
|
13
|
+
|
14
|
+
path_prefix = preview_paths.one? ? preview_paths.first : "test/components/previews"
|
15
|
+
template "component_preview.rb", File.join(path_prefix, class_path, "#{file_name}_component_preview.rb")
|
12
16
|
end
|
13
17
|
|
14
18
|
private
|
data/lib/view_component/base.rb
CHANGED
@@ -193,8 +193,9 @@ module ViewComponent
|
|
193
193
|
end
|
194
194
|
|
195
195
|
# The controller used for testing components.
|
196
|
-
# Defaults to ApplicationController
|
197
|
-
#
|
196
|
+
# Defaults to ApplicationController, but can be configured
|
197
|
+
# on a per-test basis using `with_controller_class`.
|
198
|
+
# This should be set early in the initialization process and should be a string.
|
198
199
|
mattr_accessor :test_controller
|
199
200
|
@@test_controller = "ApplicationController"
|
200
201
|
|
@@ -35,7 +35,7 @@ module ViewComponent
|
|
35
35
|
end
|
36
36
|
|
37
37
|
def controller
|
38
|
-
@controller ||= Base.test_controller.constantize
|
38
|
+
@controller ||= build_controller(Base.test_controller.constantize)
|
39
39
|
end
|
40
40
|
|
41
41
|
def request
|
@@ -47,7 +47,21 @@ module ViewComponent
|
|
47
47
|
|
48
48
|
controller.view_context.lookup_context.variants = variant
|
49
49
|
yield
|
50
|
+
ensure
|
50
51
|
controller.view_context.lookup_context.variants = old_variants
|
51
52
|
end
|
53
|
+
|
54
|
+
def with_controller_class(klass)
|
55
|
+
old_controller = defined?(@controller) && @controller
|
56
|
+
|
57
|
+
@controller = build_controller(klass)
|
58
|
+
yield
|
59
|
+
ensure
|
60
|
+
@controller = old_controller
|
61
|
+
end
|
62
|
+
|
63
|
+
def build_controller(klass)
|
64
|
+
klass.new.tap { |c| c.request = request }.extend(Rails.application.routes.url_helpers)
|
65
|
+
end
|
52
66
|
end
|
53
67
|
end
|
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: 2.
|
4
|
+
version: 2.27.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- GitHub Open Source
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-
|
11
|
+
date: 2021-03-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -270,7 +270,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
270
270
|
- !ruby/object:Gem::Version
|
271
271
|
version: '0'
|
272
272
|
requirements: []
|
273
|
-
rubygems_version: 3.
|
273
|
+
rubygems_version: 3.1.2
|
274
274
|
signing_key:
|
275
275
|
specification_version: 4
|
276
276
|
summary: View components for Rails
|