diff --git a/Gemfile.lock b/Gemfile.lock index 6f2565291..cf2e08ec6 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,7 +1,7 @@ PATH remote: . specs: - view_component (3.24.0) + view_component (3.25.0) activesupport (>= 5.2.0, < 8.2) concurrent-ruby (~> 1) method_source (~> 1.0) diff --git a/test/sandbox/test/collection_test.rb b/test/sandbox/test/collection_test.rb index 7d1b56d1c..01ab43f48 100644 --- a/test/sandbox/test/collection_test.rb +++ b/test/sandbox/test/collection_test.rb @@ -22,6 +22,20 @@ def call end end + # Renders a plain partial, which routes through `ViewComponent::Base#render` + # and so depends on `__vc_original_view_context` being set. + class PartialRenderingComponent < ViewComponent::Base + with_collection_parameter :item + + def initialize(item: nil) + @item = item + end + + def call + render partial: "integration_examples/test_partial" + end + end + def setup @products = [Product.new(name: "Radio clock"), Product.new(name: "Mints")] @collection = ProductComponent.with_collection(@products, notice: "secondhand") @@ -46,5 +60,15 @@ def test_supports_collection_with_spacer_component render_inline(ProductComponent.with_collection(@products, spacer_component: SpacerComponent.new)) assert_selector("hr", count: 1) end + + # A collection rendered from a plain view (rather than from inside another + # component) never has `set_original_view_context` called on it, so its own + # `__vc_original_view_context` is nil. That nil must not be forwarded to the + # child components, or rendering a partial from one raises NoMethodError. + def test_supports_components_that_render_partials + render_inline(PartialRenderingComponent.with_collection([1, 2])) + + assert_text("hello,partial world!", count: 2) + end end end