ncbo / goo

Graph Oriented Objects (GOO) for Ruby. A RDF/SPARQL based ORM.
http://ncbo.github.io/goo/
Other
15 stars 6 forks source link

Feature: implement new validators #139

Closed syphax-bouazzouni closed 1 year ago

syphax-bouazzouni commented 1 year ago

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 to 10.

Then we can reference it as a validator for an attribute, like so attribute :age, enforce: [:equal_to_10], this will enforce the attribute age to be 10 (as implemented in the method equal_to_10)

p1 distinct_of p2 enforce: A p1 B ^ A p2 C -> B <> C
p1 superior_equla_to p2 enforce: A p1 B ^ A p2 C -> C <= B
mdorf commented 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?

mdorf commented 1 year ago

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.

mdorf commented 1 year ago

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).

mdorf commented 1 year ago

@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.

syphax-bouazzouni commented 1 year ago

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