Skip to content

Commit

Permalink
better way of handling devise
Browse files Browse the repository at this point in the history
  • Loading branch information
fugufish committed Sep 12, 2023
1 parent 2fa7ada commit b7e0c99
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions lib/view_component/test_helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ def render_inline(component, **args, &block)
# @param params [Hash] Parameters to be passed to the preview.
# @return [Nokogiri::HTML]
def render_preview(name, from: __vc_test_helpers_preview_class, params: {})
previews_controller = __vc_test_helpers_build_controller(Rails.application.config.view_component.preview_controller.constantize)
previews_controller = __vc_render_preview_controller

# From what I can tell, it's not possible to overwrite all request parameters
# at once, so we set them individually here.
Expand Down Expand Up @@ -103,9 +103,9 @@ def render_preview(name, from: __vc_test_helpers_preview_class, params: {})
#
# assert_text("Hello, World!")
# ```
def render_in_view_context(*args, &block)
def render_in_view_context(*, &block)
@page = nil
@rendered_content = vc_test_controller.view_context.instance_exec(*args, &block)
@rendered_content = vc_test_controller.view_context.instance_exec(*, &block)
Nokogiri::HTML.fragment(@rendered_content)
end
ruby2_keywords(:render_in_view_context) if respond_to?(:ruby2_keywords, true)
Expand Down Expand Up @@ -225,6 +225,11 @@ def vc_test_request
end
end

def before_setup
@request = __vc_render_preview_controller.request
super
end

# Note: We prefix private methods here to prevent collisions in consumer's tests.
private

Expand All @@ -244,5 +249,9 @@ def __vc_test_helpers_preview_class
rescue NameError
raise NameError, "`render_preview` expected to find #{result}, but it does not exist."
end

def __vc_render_preview_controller
@vc_render_preview_controller ||= __vc_test_helpers_build_controller(Rails.application.config.view_component.preview_controller.constantize)
end
end
end

0 comments on commit b7e0c99

Please sign in to comment.