Skip to content

Commit

Permalink
Add test and logic to set default icon (#2583)
Browse files Browse the repository at this point in the history
  • Loading branch information
Oglopf authored Feb 16, 2023
1 parent aae8336 commit b6cedd0
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
4 changes: 4 additions & 0 deletions apps/dashboard/app/models/project.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
20 changes: 20 additions & 0 deletions apps/dashboard/test/models/projects_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit b6cedd0

Please sign in to comment.