diff --git a/app/models/ml/model_version.rb b/app/models/ml/model_version.rb index a5f45d542120593e161de4c569aa4a998b4e83ee..c32df611611197c8f8b2408a7395b1bfca7218be 100644 --- a/app/models/ml/model_version.rb +++ b/app/models/ml/model_version.rb @@ -7,6 +7,7 @@ class ModelVersion < ApplicationRecord include SemanticVersionable semver_method :semver + validate_semver validates :project, :model, presence: true @@ -63,6 +64,11 @@ def by_project_id_name_and_version(project_id, name, version) end end + def version=(value) + self.semver = value + super(value) + end + private def valid_model? diff --git a/spec/models/ml/model_version_spec.rb b/spec/models/ml/model_version_spec.rb index 6f5e250688d3e79e676c7cd6118268c56bcdd226..dc8b771c02cbef6a274c4cbc513d85a0ff5307d6 100644 --- a/spec/models/ml/model_version_spec.rb +++ b/spec/models/ml/model_version_spec.rb @@ -47,12 +47,13 @@ describe 'version' do where(:ctx, :version) do - 'version is blank' | '' - 'version is not valid package version' | '!!()()' - 'version is too large' | ('a' * 256) + 'can\'t be blank' | '' + 'is invalid' | '!!()()' + 'is too long (maximum is 255 characters)' | ('a' * 256) + 'must follow semantic version' | '1' end with_them do - it { expect(errors).to include(:version) } + it { expect(errors.messages.values.flatten).to include(ctx) } end context 'when version is not unique in project+name' do @@ -272,7 +273,7 @@ end context 'when parsing semver components' do - let(:model_version) { build(:ml_model_versions, model: model1, semver: semver, project: base_project) } + let(:model_version) { build(:ml_model_versions, model: model1, version: semver, project: base_project) } where(:semver, :valid, :major, :minor, :patch, :prerelease) do '1' | false | nil | nil | nil | nil