From b6cedd093047fc277272d6aa6ce0db1b07442b87 Mon Sep 17 00:00:00 2001 From: Travis Ravert Date: Thu, 16 Feb 2023 09:35:33 -0500 Subject: [PATCH] Add test and logic to set default icon (#2583) --- apps/dashboard/app/models/project.rb | 4 ++++ apps/dashboard/test/models/projects_test.rb | 20 ++++++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/apps/dashboard/app/models/project.rb b/apps/dashboard/app/models/project.rb index 30f7bb8fbe..35c143c2e6 100644 --- a/apps/dashboard/app/models/project.rb +++ b/apps/dashboard/app/models/project.rb @@ -100,12 +100,16 @@ def manifest_path def valid_form_inputs?(attributes) icon_pattern = %r{\Afa[bsrl]://[\w-]+\z} name_pattern = /\A[\w-]+\z/ + if !attributes[:icon].nil? && !attributes[:icon].match?(icon_pattern) errors.add(:icon, :invalid_format, message: 'Icon format invalid or missing') false elsif !attributes[:name].match?(name_pattern) errors.add(:name, :invalid_format, message: 'Name format invalid') false + elsif attributes[:icon].nil? + attributes[:icon] = 'fas://cog' + true else true end diff --git a/apps/dashboard/test/models/projects_test.rb b/apps/dashboard/test/models/projects_test.rb index 3909524ca0..363de07676 100644 --- a/apps/dashboard/test/models/projects_test.rb +++ b/apps/dashboard/test/models/projects_test.rb @@ -141,4 +141,24 @@ class ProjectsTest < ActiveSupport::TestCase assert_equal expected_manifest_yml, File.read(project.manifest_path.to_s) end end + + test 'icon defaults to fas://cog' do + Dir.mktmpdir do |tmp| + project_path = Pathname.new(tmp) + OodAppkit.stubs(:dataroot).returns(project_path) + attrs = { name: 'test-project', description: 'test description' } + + project = Project.new(attrs) + project.save(attrs) + + manifest_yml = <<~HEREDOC + --- + name: test-project + description: test description + icon: fas://cog + HEREDOC + + assert_equal manifest_yml, File.read(project.manifest_path.to_s) + end + end end