Skip to content

Commit

Permalink
Support for multiple string arguments to frame helper
Browse files Browse the repository at this point in the history
This fixes a regression in 1.5.0

Fixes #503
  • Loading branch information
jcoyne committed Oct 16, 2023
1 parent 097d8f9 commit f26b571
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
2 changes: 1 addition & 1 deletion app/helpers/turbo/frames_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ module Turbo::FramesHelper
# <%= turbo_frame_tag(Article.find(1), Comment.new) %>
# # => <turbo-frame id="article_1_new_comment"></turbo-frame>
def turbo_frame_tag(*ids, src: nil, target: nil, **attributes, &block)
id = ids.first.respond_to?(:to_key) ? ActionView::RecordIdentifier.dom_id(*ids) : ids.first
id = ids.first.respond_to?(:to_key) ? ActionView::RecordIdentifier.dom_id(*ids) : ids.join('_')
src = url_for(src) if src.present?

tag.turbo_frame(**attributes.merge(id: id, src: src, target: target).compact, &block)
Expand Down
6 changes: 5 additions & 1 deletion test/frames/frames_helper_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,16 @@ class Turbo::FramesHelperTest < ActionView::TestCase
assert_dom_equal %(<turbo-frame id="message_1"></turbo-frame>), turbo_frame_tag(record)
end

test "string frame nested withing a model frame" do
test "string frame with a model frame" do
record = Article.new(id: 1)

assert_dom_equal %(<turbo-frame id="comments_article_1"></turbo-frame>), turbo_frame_tag(record, "comments")
end

test "string frame with non-record array" do
assert_dom_equal %(<turbo-frame id="foo_1_2"></turbo-frame>), turbo_frame_tag(['foo', 1, 2])
end

test "block style" do
assert_dom_equal(%(<turbo-frame id="tray"><p>tray!</p></turbo-frame>), turbo_frame_tag("tray") { tag.p("tray!") })
end
Expand Down

0 comments on commit f26b571

Please sign in to comment.