Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix bug for auto_accounts #3457

Merged
merged 3 commits into from
Mar 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading