Skip to content

Commit

Permalink
Remove unnecessary Hash#compact call
Browse files Browse the repository at this point in the history
  • Loading branch information
marcoroth committed Aug 22, 2022
1 parent d388611 commit 325a910
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
4 changes: 2 additions & 2 deletions app/helpers/turbo/streams/action_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ def turbo_stream_action_tag(action, target: nil, targets: nil, template: nil, **
template = action.to_sym == :remove ? "" : tag.template(template.to_s.html_safe)

if target = convert_to_turbo_stream_dom_id(target)
tag.turbo_stream(template, **attributes.merge(action: action, target: target).compact)
tag.turbo_stream(template, **attributes.merge(action: action, target: target))
elsif targets = convert_to_turbo_stream_dom_id(targets, include_selector: true)
tag.turbo_stream(template, **attributes.merge(action: action, targets: targets).compact)
tag.turbo_stream(template, **attributes.merge(action: action, targets: targets))
else
raise ArgumentError, "target or targets must be supplied"
end
Expand Down
6 changes: 6 additions & 0 deletions test/streams/action_helper_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,12 @@ class Turbo::ActionHelperTest < ActionCable::Channel::TestCase
assert_equal stream, turbo_stream_action_tag("append", target: "message_1", template: "Template", hello: "world", foo: "bar")
end

test "additional nil attributes" do
stream = "<turbo-stream action=\"append\" target=\"message_1\"><template>Template</template></turbo-stream>"

assert_equal stream, turbo_stream_action_tag("append", target: "message_1", template: "Template", hello: nil, foo: nil)
end

test "additional boolean attributes" do
stream = "<turbo-stream checked=\"checked\" action=\"append\" target=\"message_1\"><template>Template</template></turbo-stream>"

Expand Down

0 comments on commit 325a910

Please sign in to comment.