diff --git a/app/helpers/turbo/frames_helper.rb b/app/helpers/turbo/frames_helper.rb
index f52875b3..a6c16f51 100644
--- a/app/helpers/turbo/frames_helper.rb
+++ b/app/helpers/turbo/frames_helper.rb
@@ -35,8 +35,13 @@ 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
def turbo_frame_tag(*ids, src: nil, target: nil, **attributes, &block)
- id = ids.first.respond_to?(:to_key) ? ActionView::RecordIdentifier.dom_id(*ids) : ids.join('_')
+ 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?
tag.turbo_frame(**attributes.merge(id: id, src: src, target: target).compact, &block)
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)