Skip to content

Commit

Permalink
fix bug for auto_accounts (#3457)
Browse files Browse the repository at this point in the history
Cast account list to scalars here to account for dynamic accounts.
  • Loading branch information
johrstrom authored Mar 26, 2024
1 parent 6888727 commit 9c951ad
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
35 changes: 35 additions & 0 deletions apps/dashboard/test/lib/smart_attributes/auto_accounts_test.rb
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 9c951ad

Please sign in to comment.