Module: ActionView::Component::TestHelpers

Defined in:
lib/action_view/component/test_helpers.rb

Instance Method Summary collapse

Instance Method Details

#controllerObject



10
11
12
# File 'lib/action_view/component/test_helpers.rb', line 10

def controller
  @controller ||= ApplicationController.new.tap { |c| c.request = request }
end

#render_component(component, **args, &block) ⇒ Object



18
19
20
21
22
23
24
# File 'lib/action_view/component/test_helpers.rb', line 18

def render_component(component, **args, &block)
  ActiveSupport::Deprecation.warn(
    "`render_component` has been deprecated in favor of `render_inline`, and will be removed in v2.0.0."
  )

  render_inline(component, args, &block)
end

#render_inline(component, **args, &block) ⇒ Object



6
7
8
# File 'lib/action_view/component/test_helpers.rb', line 6

def render_inline(component, **args, &block)
  Nokogiri::HTML(controller.view_context.render(component, args, &block)).css("body > *")
end

#requestObject



14
15
16
# File 'lib/action_view/component/test_helpers.rb', line 14

def request
  @request ||= ActionDispatch::TestRequest.create
end

#with_variant(variant) ⇒ Object



26
27
28
29
30
31
32
# File 'lib/action_view/component/test_helpers.rb', line 26

def with_variant(variant)
  old_variants = controller.view_context.lookup_context.variants

  controller.view_context.lookup_context.variants = variant
  yield
  controller.view_context.lookup_context.variants = old_variants
end