Skip to content
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

Add from to use_helpers to add macro like syntax #2034

Merged
merged 23 commits into from
Jun 20, 2024
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
add: kwargs tests
reeganviljoen committed May 26, 2024
commit f37e33c7e0f9b20fbce860b4f8a7c66e76701b7c
Original file line number Diff line number Diff line change
@@ -5,3 +5,7 @@
<div class='helper__args-message'>
<%= message_with_args('macro helper method') %>
</div>

<div class='helper__kwargs-message'>
<%= message_with_kwargs(name: 'macro kwargs helper method') %>
</div>
2 changes: 1 addition & 1 deletion test/sandbox/app/components/use_helpers_macro_component.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# frozen_string_literal: true

class UseHelpersMacroComponent < ViewComponent::Base
use_helpers :message, :message_with_args, from: MacroHelper
use_helpers :message, :message_with_args, :message_with_kwargs, from: MacroHelper
end
4 changes: 4 additions & 0 deletions test/sandbox/app/helpers/macro_helper.rb
Original file line number Diff line number Diff line change
@@ -8,4 +8,8 @@ def message
def message_with_args(name)
"Hello #{name}"
end

def message_with_kwargs(name:)
"Hello #{name}"
end
end
6 changes: 6 additions & 0 deletions test/sandbox/test/rendering_test.rb
Original file line number Diff line number Diff line change
@@ -1134,4 +1134,10 @@ def test_use_helper_macros_with_args

assert_selector ".helper__args-message", text: "Hello macro helper method"
end

def test_use_helper_macros_with_kwargs
render_inline(UseHelpersMacroComponent.new)

assert_selector ".helper__kwargs-message", text: "Hello macro kwargs helper method"
end
end