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

Feature: extend slice acronym validator to not accept underscore #176

Merged
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
35 changes: 18 additions & 17 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
GIT
remote: https://github.com/ncbo/goo.git
revision: 911d71aefe433314d11398445e3856fca503b9c1
revision: 83425ba6c05d051d86c6f5775540727ce4238443
branch: develop
specs:
goo (0.0.2)
Expand Down Expand Up @@ -53,11 +53,12 @@ GEM
launchy (~> 2.1)
mail (~> 2.7)
eventmachine (1.2.7)
faraday (2.7.10)
faraday (2.7.11)
base64
faraday-net_http (>= 2.0, < 3.1)
ruby2_keywords (>= 0.0.4)
faraday-net_http (3.0.2)
ffi (1.15.5)
ffi (1.16.3)
hashie (5.0.0)
htmlentities (4.3.4)
http-accept (1.7.0)
Expand All @@ -82,7 +83,7 @@ GEM
method_source (1.0.0)
mime-types (3.5.1)
mime-types-data (~> 3.2015)
mime-types-data (3.2023.0808)
mime-types-data (3.2023.1003)
mini_mime (1.1.5)
minitest (4.7.5)
minitest-reporters (0.14.24)
Expand All @@ -92,21 +93,21 @@ GEM
powerbar
multi_json (1.15.0)
net-http-persistent (2.9.4)
net-imap (0.3.7)
net-imap (0.4.2)
date
net-protocol
net-pop (0.1.2)
net-protocol
net-protocol (0.2.1)
timeout
net-smtp (0.3.3)
net-smtp (0.4.0)
net-protocol
netrc (0.11.0)
oj (3.16.1)
omni_logger (0.1.4)
logger
parallel (1.23.0)
parser (3.2.2.3)
parser (3.2.2.4)
ast (~> 2.4.1)
racc
pony (1.13.1)
Expand All @@ -125,11 +126,11 @@ GEM
rake (10.5.0)
rdf (1.0.8)
addressable (>= 2.2)
redis (5.0.7)
redis-client (>= 0.9.0)
redis-client (0.17.0)
redis (5.0.8)
redis-client (>= 0.17.0)
redis-client (0.18.0)
connection_pool
regexp_parser (2.8.1)
regexp_parser (2.8.2)
rest-client (2.1.0)
http-accept (>= 1.7.0, < 2.0)
http-cookie (>= 1.0.2, < 2.0)
Expand All @@ -139,19 +140,18 @@ GEM
rsolr (2.5.0)
builder (>= 2.1.2)
faraday (>= 0.9, < 3, != 2.0.0)
rubocop (1.56.2)
base64 (~> 0.1.1)
rubocop (1.57.2)
json (~> 2.3)
language_server-protocol (>= 3.17.0)
parallel (~> 1.10)
parser (>= 3.2.2.3)
parser (>= 3.2.2.4)
rainbow (>= 2.2.2, < 4.0)
regexp_parser (>= 1.8, < 3.0)
rexml (>= 3.2.5, < 4.0)
rubocop-ast (>= 1.28.1, < 2.0)
ruby-progressbar (~> 1.7)
unicode-display_width (>= 2.4.0, < 3.0)
rubocop-ast (1.29.0)
rubocop-ast (1.30.0)
parser (>= 3.2.1.0)
ruby-progressbar (1.13.0)
ruby2_keywords (0.0.5)
Expand All @@ -176,11 +176,12 @@ GEM
unf (0.1.4)
unf_ext
unf_ext (0.0.8.2)
unicode-display_width (2.4.2)
unicode-display_width (2.5.0)
uuid (2.3.9)
macaddr (~> 1.0)

PLATFORMS
aarch64-linux
arm64-darwin-22
x86_64-darwin-18
x86_64-darwin-21
Expand Down Expand Up @@ -215,4 +216,4 @@ DEPENDENCIES
thin

BUNDLED WITH
2.3.15
2.4.12
25 changes: 19 additions & 6 deletions lib/ontologies_linked_data/models/slice.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,25 @@ class Slice < LinkedData::Models::Base

def self.validate_acronym(inst, attr)
inst.bring(attr) if inst.bring?(attr)
value = inst.send(attr)
acronym_regex = /\A[-_a-z]+\Z/
if (acronym_regex.match value).nil?
return [:acronym_value_validator,"The acronym value #{value} is invalid"]
acronym = inst.send(attr)

return [] if acronym.nil?

errors = []

if acronym.match(/\A[^a-z^A-Z]{1}/)
errors << [:start_with_letter, "`acronym` must start with a letter"]
end

if acronym.match(/[^-0-9a-zA-Z]/)
errors << [:special_characters, "`acronym` must only contain the folowing characters: -, letters, and numbers"]
end

if acronym.match(/.{17,}/)
errors << [:length, "`acronym` must be sixteen characters or less"]
end
return [:acronym_value_validator, nil]

return errors.flatten
end

def self.synchronize_groups_to_slices
Expand All @@ -31,7 +44,7 @@ def self.synchronize_groups_to_slices
slice.save if slice.valid?
else
slice = self.new({
acronym: g.acronym.downcase.gsub(" ", "_"),
acronym: g.acronym.downcase.gsub(" ", "-"),
name: g.name,
description: g.description,
ontologies: g.ontologies
Expand Down
23 changes: 22 additions & 1 deletion test/models/test_slice.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def test_slice_lifecycle
s = LinkedData::Models::Slice.new({
:name => "Test Slice",
:description => "This is a test slice",
:acronym => "test_slice",
:acronym => "test-slice",
:ontologies => @@onts[3..-1]
})

Expand All @@ -70,6 +70,27 @@ def test_synchronization
assert slices.map {|s| s.acronym}.include?(@@group_acronym)
end

def test_slice_acronym_validity
s = LinkedData::Models::Slice.new({
:name => "Test Slice",
:description => "This is a test slice",
:acronym => "test_slice",
:ontologies => @@onts[3..-1]
})

refute s.valid?

s = LinkedData::Models::Slice.new({
:name => "Test Slice",
:description => "This is a test slice",
:acronym => "test-slice",
:ontologies => @@onts[3..-1]
})

assert s.valid?

end

private

def self._create_group
Expand Down
Loading