Repository: statamic-rad-pack/runway (php)

Issue:
When "Duplicate" toggle is switched off in the blueprint, the value is still copied when duplicating a record
### Description

When "Duplicate" toggle is switched off in the blueprint, the value is still copied when duplicating a record.

### Steps to reproduce

1. Create a model with a blueprint
2. In this case I create a "BelongsTo" relation field and switch "Duplicate" of
3. Create a record 
4. Duplicate the record

### Environment

Environment
Application Name: ESLHO EQA Portal
Laravel Version: 11.27.2
PHP Version: 8.2.25
Composer Version: 2.3.5
Environment: local
Debug Mode: ENABLED
URL: eslho-eqa-portal.test
Maintenance Mode: OFF
Timezone: Europe/Amsterdam
Locale: en

Cache
Config: NOT CACHED
Events: NOT CACHED
Routes: NOT CACHED
Views: CACHED

Drivers
Broadcasting: log
Cache: file
Database: mysql
Logs: stack / single
Mail: smtp
Queue: sync
Session: file

Statamic
Addons: 1
Sites: 1
Stache Watcher: Enabled
Static Caching: Disabled
Version: 5.37.0 PRO

Statamic Addons
statamic-rad-pack/runway: 7.12.0

Pull request:
[7.x] Respect "Duplicate" toggle on fields
This pull request fixes an issue with Runway's "Duplicate" action where it wasn't respecting the "Duplicate" option on fields. Now it does.

Closes #635.

Patch:
diff --git a/src/Actions/DuplicateModel.php b/src/Actions/DuplicateModel.php
index d798104..494f3fa 100644
--- a/src/Actions/DuplicateModel.php
+++ b/src/Actions/DuplicateModel.php
@@ -64,7 +64,7 @@ class DuplicateModel extends Action
 
     private function duplicateModel(Model $original, Resource $resource): Model
     {
-        $model = $original->replicate();
+        $model = $original->replicate($resource->blueprint()->fields()->all()->reject->shouldBeDuplicated()->keys()->all());
 
         if ($resource->titleField()) {
             $model->setAttribute($resource->titleField(), $original->getAttribute($resource->titleField()).' (Duplicate)');


Test patch:
diff --git a/tests/Actions/DuplicateModelTest.php b/tests/Actions/DuplicateModelTest.php
index d3c6d6d..139ead4 100644
--- a/tests/Actions/DuplicateModelTest.php
+++ b/tests/Actions/DuplicateModelTest.php
@@ -72,7 +72,7 @@ class DuplicateModelTest extends TestCase
     }
 
     #[Test]
-    public function is_not_visible_to_entry()
+    public function is_not_visible_to_an_entry()
     {
         Collection::make('posts')->save();
 
@@ -156,6 +156,29 @@ class DuplicateModelTest extends TestCase
 
         $duplicate = Post::query()->whereNot('id', $post->id)->first();
 
+        $this->assertEquals('Hello World (Duplicate)', $duplicate->title);
+        $this->assertNotNull($duplicate->start_date);
+        $this->assertFalse($duplicate->published());
+    }
+
+    #[Test]
+    public function only_duplicates_fields_where_duplication_is_enabled()
+    {
+        $blueprint = Blueprint::find('runway::post');
+        $blueprint->ensureFieldHasConfig('start_date', ['duplicate' => false]);
+
+        Blueprint::shouldReceive('find')
+            ->with('runway::post')
+            ->andReturn($blueprint);
+
+        $post = Post::factory()->create(['title' => 'Hello World', 'start_date' => now()]);
+
+        (new DuplicateModel)->run(collect([$post]), []);
+
+        $duplicate = Post::query()->whereNot('id', $post->id)->first();
+
+        $this->assertEquals('Hello World (Duplicate)', $duplicate->title);
+        $this->assertNull($duplicate->start_date);
         $this->assertFalse($duplicate->published());
     }
 }
diff --git a/tests/__fixtures__/database/factories/PostFactory.php b/tests/__fixtures__/database/factories/PostFactory.php
index a6441dd..9a0d1a2 100644
--- a/tests/__fixtures__/database/factories/PostFactory.php
+++ b/tests/__fixtures__/database/factories/PostFactory.php
@@ -28,6 +28,7 @@ class PostFactory extends Factory
             'slug' => Str::slug($title),
             'body' => implode(' ', $this->faker->paragraphs(10)),
             'author_id' => Author::factory()->create()->id,
+            'start_date' => now(),
             'published' => true,
             'mutated_value' => 'Foo',
         ];