view_component 2.26.1 → 2.27.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 071c4caebc8e0dd567d8850adff146e65f6c8c1fe600b866f072d9bfa94bbc46
4
- data.tar.gz: 64df3c2eb8d27431da23a2c628de6c9c00d7988130494d37319f4a01d653fd9c
3
+ metadata.gz: 47f112ee86431b25865a4793374e8838a1e80966d91150d4b182b38c598a9631
4
+ data.tar.gz: 97673827cb5a971d8c769b9566c87055d28af37fa04b06b6e90c5098b64c9388
5
5
  SHA512:
6
- metadata.gz: 69bc43697d70dfb9b96280f47b80c06d1020fd180c01cbc6ae8c8416c3e1b97ffc6587d00741fa81743ae482a316e653790db5af2584c16baf3839a58b809195
7
- data.tar.gz: 636d5d91edb07cb90f44e3fc21e7ee63c3c115d1f5fbf7666619205b628761028c4963c65b30a181f27fbbd0bf9539cab0ec3271a48b4d747d7a705528218f11
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
- template "component_preview.rb", File.join("test/components/previews", class_path, "#{file_name}_component_preview.rb")
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
@@ -193,8 +193,9 @@ module ViewComponent
193
193
  end
194
194
 
195
195
  # The controller used for testing components.
196
- # Defaults to ApplicationController. This should be set early
197
- # in the initialization process and should be set to a string.
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.new.tap { |c| c.request = request }.extend(Rails.application.routes.url_helpers)
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
@@ -3,8 +3,8 @@
3
3
  module ViewComponent
4
4
  module VERSION
5
5
  MAJOR = 2
6
- MINOR = 26
7
- PATCH = 1
6
+ MINOR = 27
7
+ PATCH = 0
8
8
 
9
9
  STRING = [MAJOR, MINOR, PATCH].join(".")
10
10
  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.26.1
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-02-23 00:00:00.000000000 Z
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.0.3
273
+ rubygems_version: 3.1.2
274
274
  signing_key:
275
275
  specification_version: 4
276
276
  summary: View components for Rails