Skip to content

Commit

Permalink
Account for empty datefield (#3817)
Browse files Browse the repository at this point in the history
Account for date_field having an empty value and set to it today if it is empty.
  • Loading branch information
johrstrom authored Sep 23, 2024
1 parent 972a03b commit 740a484
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
2 changes: 2 additions & 0 deletions apps/dashboard/app/lib/smart_attributes/attribute_factory.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ def build(id, opts = {})
if respond_to?(build_method)
send(build_method, opts)
else
# date_field will throw an error if the value is an empty string.
opts[:value] = Date.today if opts[:widget] == 'date_field' && opts[:value].to_s.empty?
Attribute.new(id, opts)
end
end
Expand Down
27 changes: 27 additions & 0 deletions apps/dashboard/test/system/batch_connect_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1519,4 +1519,31 @@ def get_favorites
end
end
end

test 'date_fields correctly initialize when empty' do
Dir.mktmpdir do |dir|
"#{dir}/app".tap { |d| Dir.mkdir(d) }
SysRouter.stubs(:base_path).returns(Pathname.new(dir))
stub_scontrol
stub_sacctmgr
stub_git("#{dir}/app")

form = <<~HEREDOC
---
cluster:
- owens
form:
- date
attributes:
date:
widget: 'date_field'
HEREDOC

Pathname.new("#{dir}/app/").join('form.yml').write(form)
visit new_batch_connect_session_context_url('sys/app')

value = find('#batch_connect_session_context_date').value
assert_equal(Date.today.to_s, value)
end
end
end

0 comments on commit 740a484

Please sign in to comment.