From eab37861302d2a25f7665c22ad825e80c3e60827 Mon Sep 17 00:00:00 2001 From: Thiago Pradi Date: Mon, 8 Jan 2024 01:03:56 -0300 Subject: [PATCH 1/4] Handle nil and empty values on turbo_frame_tag --- app/helpers/turbo/frames_helper.rb | 5 +++++ test/frames/frames_helper_test.rb | 20 ++++++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/app/helpers/turbo/frames_helper.rb b/app/helpers/turbo/frames_helper.rb index 3697f13f..653c07b0 100644 --- a/app/helpers/turbo/frames_helper.rb +++ b/app/helpers/turbo/frames_helper.rb @@ -38,7 +38,12 @@ module Turbo::FramesHelper # # <%= turbo_frame_tag(Article.find(1), Comment.new) %> # # => + # + # Raises an +ArgumentError+ if called without a frame id. + # <%= turbo_frame_tag(nil) %> # => ArgumentError: You must supply a frame id def turbo_frame_tag(*ids, src: nil, target: nil, **attributes, &block) + raise ArgumentError, "You must supply a frame id" if ids.all? { |id| id.blank? } + id = ids.first.respond_to?(:to_key) ? ActionView::RecordIdentifier.dom_id(*ids) : ids.join('_') src = url_for(src) if src.present? diff --git a/test/frames/frames_helper_test.rb b/test/frames/frames_helper_test.rb index d7531282..9e722c63 100644 --- a/test/frames/frames_helper_test.rb +++ b/test/frames/frames_helper_test.rb @@ -21,6 +21,26 @@ class Turbo::FramesHelperTest < ActionView::TestCase assert_dom_equal %(), turbo_frame_tag(record) end + test "frame with invalid argument should raise ArgumentError" do + assert_raises ArgumentError, "ArgumentError: You must supply a frame id" do + record = nil + + turbo_frame_tag(record) + end + + assert_raises ArgumentError, "ArgumentError: You must supply a frame id" do + record = [] + + turbo_frame_tag(record) + end + + assert_raises ArgumentError, "ArgumentError: You must supply a frame id" do + record = '' + + turbo_frame_tag(record) + end + end + test "string frame within a model frame" do record = Article.new(id: 1) From c05e5801b3b747e28b05654374ead88955c93040 Mon Sep 17 00:00:00 2001 From: Thiago Pradi Date: Mon, 8 Jan 2024 11:35:27 -0300 Subject: [PATCH 2/4] Update app/helpers/turbo/frames_helper.rb Co-authored-by: Sean Doyle --- app/helpers/turbo/frames_helper.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/helpers/turbo/frames_helper.rb b/app/helpers/turbo/frames_helper.rb index 653c07b0..b5aac7f1 100644 --- a/app/helpers/turbo/frames_helper.rb +++ b/app/helpers/turbo/frames_helper.rb @@ -42,7 +42,7 @@ module Turbo::FramesHelper # Raises an +ArgumentError+ if called without a frame id. # <%= turbo_frame_tag(nil) %> # => ArgumentError: You must supply a frame id def turbo_frame_tag(*ids, src: nil, target: nil, **attributes, &block) - raise ArgumentError, "You must supply a frame id" if ids.all? { |id| id.blank? } + raise ArgumentError, "You must supply a frame id" if ids.all?(&:blank?) id = ids.first.respond_to?(:to_key) ? ActionView::RecordIdentifier.dom_id(*ids) : ids.join('_') src = url_for(src) if src.present? From 8e4a85f8358687deb45e950e7468dc6fc9df5cf5 Mon Sep 17 00:00:00 2001 From: Thiago Pradi Date: Sun, 25 Feb 2024 11:31:52 -0300 Subject: [PATCH 3/4] Ops, reverting bad merge --- app/helpers/turbo/frames_helper.rb | 3 --- 1 file changed, 3 deletions(-) diff --git a/app/helpers/turbo/frames_helper.rb b/app/helpers/turbo/frames_helper.rb index 8758f304..81082043 100644 --- a/app/helpers/turbo/frames_helper.rb +++ b/app/helpers/turbo/frames_helper.rb @@ -36,9 +36,6 @@ module Turbo::FramesHelper # <%= turbo_frame_tag(Article.find(1), "comments") %> # # => # - # <%= turbo_frame_tag(Article.find(1), Comment.new) %> - # # => - # # Raises an +ArgumentError+ if called without a frame id. # <%= turbo_frame_tag(nil) %> # => ArgumentError: You must supply a frame id def turbo_frame_tag(*ids, src: nil, target: nil, **attributes, &block) From 3f68bc3208317aa30552b443ec49e969c25109c7 Mon Sep 17 00:00:00 2001 From: Thiago Pradi Date: Sun, 25 Feb 2024 11:32:24 -0300 Subject: [PATCH 4/4] Ops, reverting bad merge #2 --- app/helpers/turbo/frames_helper.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/helpers/turbo/frames_helper.rb b/app/helpers/turbo/frames_helper.rb index 81082043..a6c16f51 100644 --- a/app/helpers/turbo/frames_helper.rb +++ b/app/helpers/turbo/frames_helper.rb @@ -34,7 +34,7 @@ module Turbo::FramesHelper # # => # # <%= turbo_frame_tag(Article.find(1), "comments") %> - # # => + # # => # # Raises an +ArgumentError+ if called without a frame id. # <%= turbo_frame_tag(nil) %> # => ArgumentError: You must supply a frame id