Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
24 changes: 24 additions & 0 deletions test/sandbox/test/collection_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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
Loading