Skip to content

Commit

Permalink
Merge pull request #255 from github/254/test_helpers
Browse files Browse the repository at this point in the history
re-introduce ActionView::Component::TestHelpers
  • Loading branch information
joelhawksley authored Mar 9, 2020
2 parents bb7070a + 2e52bd4 commit 5c848bc
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 15 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# master

* Re-introduce ActionView::Component::TestHelpers

*Joel Hawksley*

* Bypass monkey patch on Rails 6.1 builds.

*Joel Hawksley*
Expand Down
3 changes: 2 additions & 1 deletion lib/action_view/component/test_case.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

module ActionView
module Component
class TestCase < ViewComponent::TestCase
class TestCase
include ActionView::Component::TestHelpers
end
end
end
17 changes: 17 additions & 0 deletions lib/action_view/component/test_helpers.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# frozen_string_literal: true

module ActionView
module Component
module TestHelpers
include ViewComponent::TestHelpers

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
end
end
end
1 change: 1 addition & 0 deletions lib/view_component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ module Component
autoload :Base
autoload :Preview
autoload :TestCase
autoload :TestHelpers
end
end

Expand Down
8 changes: 0 additions & 8 deletions lib/view_component/test_helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,6 @@ def request
@request ||= ActionDispatch::TestRequest.create
end

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

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

Expand Down
6 changes: 6 additions & 0 deletions test/view_component/action_view_component_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,10 @@ def test_to_component_class

assert_selector("span", text: "The Awesome post component!")
end

def test_render_inline_with_old_helper
render_component(ActionViewComponent.new)

assert_selector("div", text: "hello,world!")
end
end
6 changes: 0 additions & 6 deletions test/view_component/view_component_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,6 @@ def test_render_inline
assert_selector("div", text: "hello,world!")
end

def test_render_inline_with_old_helper
render_component(MyComponent.new)

assert_selector("div", text: "hello,world!")
end

def test_renders_content_from_block
render_inline(WrapperComponent.new) do
"content"
Expand Down

0 comments on commit 5c848bc

Please sign in to comment.