Skip to content

Add test showing that form helpers aren't used by View Components #1260

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
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
1 change: 1 addition & 0 deletions test/sandbox/app/components/form_component.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<%= form_tag do %><% end %>
4 changes: 4 additions & 0 deletions test/sandbox/app/components/form_component.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# frozen_string_literal: true

class FormComponent < ViewComponent::Base
end
10 changes: 10 additions & 0 deletions test/sandbox/app/helpers/form_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# frozen_string_literal: true

module FormHelper
def form_tag_html(options = {})
safe_join [
"<span>Hello, World!</span>".html_safe,
super(options),
]
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<%= render FormComponent.new %>
1 change: 1 addition & 0 deletions test/sandbox/config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,5 @@
get :render_component, to: "integration_examples#render_component"
get :controller_inline_render_component, to: "integration_examples#controller_inline_render_component"
get :controller_to_string_render_component, to: "integration_examples#controller_to_string_render_component"
get :form_helper, to: "integration_examples#form_helper"
end
9 changes: 9 additions & 0 deletions test/view_component/integration_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -583,4 +583,13 @@ def test_sets_the_compiler_mode_in_development_mode
assert_equal ViewComponent::Compiler::DEVELOPMENT_MODE, ViewComponent::Compiler.mode
end
end

def test_uses_form_helper_methods
get "/form_helper"

# The FormHelper module overrides form_tag_html to add this HTML
# fragment, so it should get included when form_tag is called
# from a ViewComponent.
assert_includes response.body, "<span>Hello, World!</span>"
end
end