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..0a16988e71 100644 --- a/apps/dashboard/app/lib/smart_attributes/attributes/auto_accounts.rb +++ b/apps/dashboard/app/lib/smart_attributes/attributes/auto_accounts.rb @@ -21,12 +21,20 @@ 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) 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