From 1d6a36d7be3263ea5d3e0c79546f3effc812ecd4 Mon Sep 17 00:00:00 2001 From: Thomas Cannon Date: Mon, 18 Aug 2025 08:19:04 -0400 Subject: [PATCH] `quack_like` also delegates `new_record?` * `new_record?` is the counterpart to `persisted?`, so it should be delegated as well for ease-of-use --- lib/trenchcoat.rb | 2 +- test/test_trenchcoat.rb | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/trenchcoat.rb b/lib/trenchcoat.rb index 670f8ed..7285c2a 100644 --- a/lib/trenchcoat.rb +++ b/lib/trenchcoat.rb @@ -27,7 +27,7 @@ def copy_attribute_definitions(model_class:, attributes:) end def quack_like(model_instance_attr:) - delegate :model_name, :persisted?, :id, to: model_instance_attr + delegate :model_name, :persisted?, :new_record?, :id, to: model_instance_attr end end end diff --git a/test/test_trenchcoat.rb b/test/test_trenchcoat.rb index 29fda4f..7db22c1 100644 --- a/test/test_trenchcoat.rb +++ b/test/test_trenchcoat.rb @@ -160,6 +160,7 @@ def normalize_published_at assert_equal Post.model_name, form.model_name assert_equal false, form.persisted? + assert_equal true, form.new_record? assert_nil form.id end @@ -168,6 +169,7 @@ def normalize_published_at assert_equal Post.model_name, form.model_name assert_equal false, form.persisted? + assert_equal true, form.new_record? assert_nil form.id end @@ -177,6 +179,7 @@ def normalize_published_at assert_equal Post.model_name, form.model_name assert_equal true, form.persisted? + assert_equal false, form.new_record? assert_equal post.id, form.id end end