Closed syphax-bouazzouni closed 1 year ago
We are getting this error when running ncbo/ontologies_linked_data unit tests:
2: from /Users/mdorf/dev/ncbo/goo/lib/goo/validators/validator.rb:94:in `empty_to_s?'
1: from /Users/mdorf/dev/ncbo/ontologies_linked_data/lib/ontologies_linked_data/models/users/user.rb:93:in `to_s'
/Users/mdorf/dev/ncbo/goo/lib/goo/base/settings/settings.rb:272:in `block in shape_attribute': Attribute `username` is not loaded for http://data.bioontology.org/users/tim. Loaded attributes: #<Set: {}>. (Goo::Base::AttributeNotLoaded)
rake aborted!
Is there another pull request inside ontologies_linked_data that we are missing?
With the new validators in place, it appears that the "username" of the User object is automatically assumed to have been loaded, which is not always the case, hence these errors. This errors out in multiple places in our test code.
These types of errors would be almost impossible to detect unit after the code is merged and deployed. We should be more diligent about submitting pull requests that are not fully self contained (or at least without having the additional dependencies clearly documented in the PR).
@syphax-bouazzouni, just wanted to check if you saw my original error report. The code errors out at:
def to_s
self.username.to_s
end
Adding this code fixes many of these errors, but not all:
def to_s
self.bring(:username) if self.bring?(:username)
self.username.to_s
end
Do you have a different fix to this? This issue prevents us from proceeding.
Hi @mdorf ,
I just did this PR, that fixed the failing test in ontologies-linked-data (https://github.com/ontoportal-lirmm/ontologies_linked_data/actions/runs/6042678133), sorry I fixed this locally but forgot to do a PR for NCBO.
A better solution (i think) would be also to update the function empty_to_s?(object)
, like so
def empty_to_s?(object)
begin
object && object.to_s&.strip.empty?
rescue
return true
end
end
Prerequisites
Context
See https://github.com/agroportal/project-management/issues/393
Changes
Now we can call, model-specific validators.
For example, if a model defines an instance method called
equal_to_10
that tests if a value is equal to10
.Then we can reference it as a validator for an attribute, like so
attribute :age, enforce: [:equal_to_10]
, this will enforce the attributeage
to be10
(as implemented in the methodequal_to_10
)distinct_of
validator (0be792585ee84614dad2ba2a4a5af697e7351f05)superior_equla_to
validator (deed329490cb74a0e725c2fefc656062d69f8b50)Add
email
validator , that enforce the string to be a valid emailAdd
symmetric
validator (5164723b2d3e6b32312d8ee874df06ad881af09e)Add
inverse_of
validator (d57a719692b70308a992e24d75d64f5ecdd6a602)