From 747dd474dc4d7fc523bc0ce3e79de403b405ac0a Mon Sep 17 00:00:00 2001 From: Jeff Ohrstrom Date: Tue, 26 Mar 2024 10:37:22 -0400 Subject: [PATCH 1/3] add test case for bug --- .../smart_attributes/auto_accounts_test.rb | 35 +++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 apps/dashboard/test/lib/smart_attributes/auto_accounts_test.rb diff --git a/apps/dashboard/test/lib/smart_attributes/auto_accounts_test.rb b/apps/dashboard/test/lib/smart_attributes/auto_accounts_test.rb new file mode 100644 index 0000000000..4da9397919 --- /dev/null +++ b/apps/dashboard/test/lib/smart_attributes/auto_accounts_test.rb @@ -0,0 +1,35 @@ +# frozen_string_literal: true + +require 'test_helper' +require 'smart_attributes' + +module SmartAttributes + class AutoAccountsTest < ActiveSupport::TestCase + def setup + stub_clusters + stub_user + stub_sacctmgr + end + + def dynamic_env + { + OOD_BC_DYNAMIC_JS: 'true' + } + end + + test 'correctly sets the value when previous value cannot be found' do + with_modified_env(dynamic_env) do + options = { + options: [['pzs1118', 'pzs1118', {}], ['pzs0715', 'pzs0715', {}], ['pzs0714', 'pzs0714', {}], + ['pzs1117', 'pzs1117', { 'data-option-for-cluster-ruby'=>false }], ['pas1604', 'pas1604', { 'data-option-for-cluster-ruby'=>false }]], + value: 'pzs0714', + exclude_options: ['pzs1118', 'pzs1117', 'pas1604', 'pzs0715'], + fixed: true + } + attribute = SmartAttributes::AttributeFactory.build('auto_accounts', options) + + assert_equal('pzs0714', attribute.value.to_s) + end + end + end +end From 8c47363fbbd3d3943d6d37940c53e5c29baaf3f3 Mon Sep 17 00:00:00 2001 From: Jeff Ohrstrom Date: Tue, 26 Mar 2024 10:41:05 -0400 Subject: [PATCH 2/3] cast account list to scalars --- .../lib/smart_attributes/attributes/auto_accounts.rb | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/apps/dashboard/app/lib/smart_attributes/attributes/auto_accounts.rb b/apps/dashboard/app/lib/smart_attributes/attributes/auto_accounts.rb index 4568af9fce..75d9370450 100644 --- a/apps/dashboard/app/lib/smart_attributes/attributes/auto_accounts.rb +++ b/apps/dashboard/app/lib/smart_attributes/attributes/auto_accounts.rb @@ -21,15 +21,24 @@ def self.build_auto_accounts(opts = {}) static_opts = { options: options, - value: default_value(opts, options) + value: default_value(opts, scalar_accounts(options)) }.merge(opts.without(:options, :value).to_h) Attributes::AutoAccounts.new('auto_accounts', static_opts) end + # dynamic accounts are in the form [acct, acct, {}]. so cast these + # arrays to scalar strings if applicable. + def self.scalar_accounts(account_list) + account_list.map do |account| + account.is_a?(Array) ? account.first : account + end + end + # try to find which default account value to use given # all the input options and the actual users' account list. def self.default_value(input_options, account_list) + Rails.logger.debug("input: #{input_options.inspect} & #{account_list.inspect}") input_value = input_options[:value].to_s exclude_list = input_options[:exclude_options].to_a available_accounts = account_list - exclude_list From 3377a90953180b9e91f8baa8748ddeb9bfec0e51 Mon Sep 17 00:00:00 2001 From: Jeff Ohrstrom Date: Tue, 26 Mar 2024 10:41:43 -0400 Subject: [PATCH 3/3] dont need this debug line --- .../app/lib/smart_attributes/attributes/auto_accounts.rb | 1 - 1 file changed, 1 deletion(-) diff --git a/apps/dashboard/app/lib/smart_attributes/attributes/auto_accounts.rb b/apps/dashboard/app/lib/smart_attributes/attributes/auto_accounts.rb index 75d9370450..0a16988e71 100644 --- a/apps/dashboard/app/lib/smart_attributes/attributes/auto_accounts.rb +++ b/apps/dashboard/app/lib/smart_attributes/attributes/auto_accounts.rb @@ -38,7 +38,6 @@ def self.scalar_accounts(account_list) # try to find which default account value to use given # all the input options and the actual users' account list. def self.default_value(input_options, account_list) - Rails.logger.debug("input: #{input_options.inspect} & #{account_list.inspect}") input_value = input_options[:value].to_s exclude_list = input_options[:exclude_options].to_a available_accounts = account_list - exclude_list