Skip to content

Commit 727c07d

Browse files
committed
added #setup_render test helper
1 parent 4be1914 commit 727c07d

File tree

3 files changed

+6
-2
lines changed

3 files changed

+6
-2
lines changed

lib/view_component/base.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,7 @@ def setup_render(view_context, &block)
141141
@__vc_render_in_block = block
142142

143143
@view_context.instance_variable_set(:@virtual_path, virtual_path)
144+
self
144145
end
145146

146147
def perform_render

lib/view_component/test_helpers.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,10 @@ def render_inline(component, **args, &block)
4545
fragment
4646
end
4747

48+
def setup_render(component)
49+
component.setup_render(vc_test_view_context)
50+
end
51+
4852
# Returns the view context used to render components in tests. Note that the view context
4953
# is reset after each call to `render_inline`.
5054
#

test/sandbox/test/rendering_test.rb

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1345,8 +1345,7 @@ def test_i18n_in_render_hook
13451345
end
13461346

13471347
def test_render_lifecycle_hooks
1348-
component = I18nTestComponent.new
1349-
component.setup_render(vc_test_view_context)
1348+
component = setup_render(I18nTestComponent.new)
13501349
assert_equal(component.message, I18n.t("rendering_test.i18n_test_component.message"))
13511350
end
13521351
end

0 commit comments

Comments
 (0)