From 7c9ff345dc9305eb5acec57dceecfd9fe6bc58f7 Mon Sep 17 00:00:00 2001 From: Aday Bujeda Date: Wed, 4 Oct 2023 14:48:32 +0100 Subject: [PATCH 1/2] Disabled deleting auto_batch_clusters from edit script forms --- apps/dashboard/app/helpers/scripts_helper.rb | 2 +- apps/dashboard/test/helpers/scripts_helper_test.rb | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) create mode 100644 apps/dashboard/test/helpers/scripts_helper_test.rb diff --git a/apps/dashboard/app/helpers/scripts_helper.rb b/apps/dashboard/app/helpers/scripts_helper.rb index f3477522a7..63af0399db 100644 --- a/apps/dashboard/app/helpers/scripts_helper.rb +++ b/apps/dashboard/app/helpers/scripts_helper.rb @@ -62,6 +62,6 @@ def script_form_double end def script_removable_field?(id) - !['script_auto_scripts'].include?(id.to_s) + !['script_auto_scripts', 'script_auto_batch_clusters'].include?(id.to_s) end end diff --git a/apps/dashboard/test/helpers/scripts_helper_test.rb b/apps/dashboard/test/helpers/scripts_helper_test.rb new file mode 100644 index 0000000000..79674300c2 --- /dev/null +++ b/apps/dashboard/test/helpers/scripts_helper_test.rb @@ -0,0 +1,14 @@ +require 'test_helper' + +class ScriptsHelperTest < ActionView::TestCase + include ScriptsHelper + + test 'script_removable_field? should return false for expected fields' do + assert_equal true, script_removable_field?('any_field') + + non_removable_fields = ['script_auto_scripts', 'script_auto_batch_clusters'] + non_removable_fields.each do |field| + assert_equal false, script_removable_field?(field) + end + end +end From d40ae10314ab59ea1667026242829e29fde5abea Mon Sep 17 00:00:00 2001 From: Aday Bujeda Date: Wed, 4 Oct 2023 16:07:38 +0100 Subject: [PATCH 2/2] Updated to array.exclude? to avoid using negation --- apps/dashboard/app/helpers/scripts_helper.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/dashboard/app/helpers/scripts_helper.rb b/apps/dashboard/app/helpers/scripts_helper.rb index 63af0399db..92879bf762 100644 --- a/apps/dashboard/app/helpers/scripts_helper.rb +++ b/apps/dashboard/app/helpers/scripts_helper.rb @@ -62,6 +62,6 @@ def script_form_double end def script_removable_field?(id) - !['script_auto_scripts', 'script_auto_batch_clusters'].include?(id.to_s) + ['script_auto_scripts', 'script_auto_batch_clusters'].exclude?(id.to_s) end end