Skip to content

Commit fd3ddbc

Browse files
committed
Merge branch 'main' into v4
2 parents 38ab10f + 7538b59 commit fd3ddbc

8 files changed

Lines changed: 125 additions & 12 deletions

File tree

.tool-versions

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
ruby 3.4.1
1+
ruby 3.4.2

Gemfile.lock

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ GEM
8888
bundler
8989
rake
9090
thor (>= 0.14.0)
91-
ast (2.4.2)
91+
ast (2.4.3)
9292
base64 (0.2.0)
9393
benchmark (0.4.0)
9494
benchmark-ips (2.14.0)
@@ -168,7 +168,6 @@ GEM
168168
matrix (0.4.2)
169169
method_source (1.1.0)
170170
mini_mime (1.1.5)
171-
mini_portile2 (2.8.8)
172171
minitest (5.25.5)
173172
net-imap (0.5.6)
174173
date
@@ -180,8 +179,21 @@ GEM
180179
net-smtp (0.5.1)
181180
net-protocol
182181
nio4r (2.7.4)
183-
nokogiri (1.18.3)
184-
mini_portile2 (~> 2.8.2)
182+
nokogiri (1.18.5-aarch64-linux-gnu)
183+
racc (~> 1.4)
184+
nokogiri (1.18.5-aarch64-linux-musl)
185+
racc (~> 1.4)
186+
nokogiri (1.18.5-arm-linux-gnu)
187+
racc (~> 1.4)
188+
nokogiri (1.18.5-arm-linux-musl)
189+
racc (~> 1.4)
190+
nokogiri (1.18.5-arm64-darwin)
191+
racc (~> 1.4)
192+
nokogiri (1.18.5-x86_64-darwin)
193+
racc (~> 1.4)
194+
nokogiri (1.18.5-x86_64-linux-gnu)
195+
racc (~> 1.4)
196+
nokogiri (1.18.5-x86_64-linux-musl)
185197
racc (~> 1.4)
186198
parallel (1.26.3)
187199
parser (3.3.7.1)
@@ -279,7 +291,7 @@ GEM
279291
rubocop-ast (>= 1.38.0, < 2.0)
280292
ruby-progressbar (~> 1.7)
281293
unicode-display_width (>= 2.4.0, < 4.0)
282-
rubocop-ast (1.38.1)
294+
rubocop-ast (1.40.0)
283295
parser (>= 3.3.1.0)
284296
rubocop-md (2.0.0)
285297
lint_roller (~> 1.1)
@@ -362,7 +374,14 @@ GEM
362374
zeitwerk (2.7.2)
363375

364376
PLATFORMS
365-
ruby
377+
aarch64-linux-gnu
378+
aarch64-linux-musl
379+
arm-linux-gnu
380+
arm-linux-musl
381+
arm64-darwin
382+
x86_64-darwin
383+
x86_64-linux-gnu
384+
x86_64-linux-musl
366385

367386
DEPENDENCIES
368387
allocation_stats
@@ -397,7 +416,7 @@ DEPENDENCIES
397416
yard-activesupport-concern (< 1)
398417

399418
RUBY VERSION
400-
ruby 3.4.1p0
419+
ruby 3.4.2p28
401420

402421
BUNDLED WITH
403-
2.5.3
422+
2.6.2

docs/CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,14 @@ nav_order: 5
7272

7373
*Tiago Menegaz*, *Joel Hawksley*
7474

75+
* Add unused mechanism for inheriting config from parent modules to enable future engine-local configuration.
76+
77+
*Simon Fish*
78+
79+
* Improve handling of malformed component edge case when mocking components in tests.
80+
81+
*Martin Meyerhoff*, *Joel Hawksley*
82+
7583
* Add Content Harmony & Learn To Be to list of companies using ViewComponent.
7684

7785
*Kane Jamison*

docs/Gemfile.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ GEM
218218
gemoji (>= 3, < 5)
219219
html-pipeline (~> 2.2)
220220
jekyll (>= 3.0, < 5.0)
221-
json (2.10.1)
221+
json (2.10.2)
222222
kramdown (2.4.0)
223223
rexml
224224
kramdown-parser-gfm (1.1.0)

lib/view_component/base.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@ class << self
2626
#
2727
# @return [ActiveSupport::OrderedOptions]
2828
def config
29+
module_parents.each do |m|
30+
config = m.try(:config).try(:view_component)
31+
return config if config
32+
end
2933
ViewComponent::Config.current
3034
end
3135
end

lib/view_component/configurable.rb

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# frozen_string_literal: true
2+
3+
module ViewComponent
4+
module Configurable
5+
extend ActiveSupport::Concern
6+
7+
included do
8+
next if respond_to?(:config) && config.respond_to?(:view_component) && config.respond_to_missing?(:test_controller)
9+
10+
include ActiveSupport::Configurable
11+
12+
configure do |config|
13+
config.view_component ||= ActiveSupport::InheritableOptions.new
14+
end
15+
end
16+
end
17+
end

test/sandbox/test/base_test.rb

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# frozen_string_literal: true
22

33
require "test_helper"
4+
require "view_component/configurable"
45

56
class ViewComponent::Base::UnitTest < Minitest::Test
67
def test_identifier
@@ -145,4 +146,54 @@ def test_no_method_error_does_not_reference_missing_helper
145146
MESSAGE
146147
assert !exception_message_regex.match?(exception.message)
147148
end
149+
150+
module TestModuleWithoutConfig
151+
class SomeComponent < ViewComponent::Base
152+
end
153+
end
154+
155+
# Config defined on top-level module as opposed to engine.
156+
module TestModuleWithConfig
157+
include ViewComponent::Configurable
158+
159+
configure do |config|
160+
config.view_component.test_controller = "AnotherController"
161+
end
162+
163+
class SomeComponent < ViewComponent::Base
164+
end
165+
end
166+
167+
module TestAlreadyConfigurableModule
168+
include ActiveSupport::Configurable
169+
include ViewComponent::Configurable
170+
171+
configure do |config|
172+
config.view_component.test_controller = "AnotherController"
173+
end
174+
175+
class SomeComponent < ViewComponent::Base
176+
end
177+
end
178+
179+
module TestAlreadyConfiguredModule
180+
include ActiveSupport::Configurable
181+
182+
configure do |config|
183+
config.view_component = ActiveSupport::InheritableOptions[test_controller: "AnotherController"]
184+
end
185+
186+
include ViewComponent::Configurable
187+
188+
class SomeComponent < ViewComponent::Base
189+
end
190+
end
191+
192+
def test_uses_module_configuration
193+
# We override this ourselves in test/sandbox/config/environments/test.rb.
194+
assert_equal "IntegrationExamplesController", TestModuleWithoutConfig::SomeComponent.test_controller
195+
assert_equal "AnotherController", TestModuleWithConfig::SomeComponent.test_controller
196+
assert_equal "AnotherController", TestAlreadyConfigurableModule::SomeComponent.test_controller
197+
assert_equal "AnotherController", TestAlreadyConfiguredModule::SomeComponent.test_controller
198+
end
148199
end

test/sandbox/test/rendering_test.rb

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,7 @@ def test_render_inline_allocations
1616
MyComponent.ensure_compiled
1717

1818
allocations = (Rails.version.to_f >= 8.0) ?
19-
{"3.5.0" => 73, "3.4.2" => 75, "3.3.7" => 76} :
20-
{"3.3.7" => 75, "3.2.7" => 74}
19+
{"3.5.0" => 73, "3.4.2" => 75, "3.3.7" => 76} : {"3.3.7" => 75, "3.2.7" => 74}
2120

2221
assert_allocations(**allocations) do
2322
render_inline(MyComponent.new)
@@ -1254,4 +1253,19 @@ def test_turbo_stream_format_custom_variant
12541253
end
12551254
end
12561255
end
1256+
1257+
# In https://github.com/ViewComponent/view_component/issues/2187,
1258+
# the Solidus test suite built mocked components by hand, resulting
1259+
# in a difficult-to-debug error. While this test case is quite narrow,
1260+
# it isolates the unintentional error masking we were doing.
1261+
def test_render_anonymous_component_without_template
1262+
location = caller(1, 1).first
1263+
mock_component = Class.new(MyComponent)
1264+
mock_component.define_singleton_method(:name) { "Foo" }
1265+
mock_component.define_singleton_method(:to_s) { "#{name} (#{location})" }
1266+
1267+
assert_nothing_raised do
1268+
render_inline(mock_component.new)
1269+
end
1270+
end
12571271
end

0 commit comments

Comments
 (0)