[Nitro] 0.26.0 preview

Brian Bugh brian at xsi-design.com
Wed Dec 14 23:30:02 EST 2005


Hi,

I did the new validation code.  I am confused about your statement
'every time a file is loaded.'  Do you mean every time the file
containing the User classes is loaded?  Or any file?  Could you give me
a simple example that exhibits this behavior?

Validations are added to the validation group each time they are
declared.  If you re-declare a validation, like this:

  class User
    property :username
    property :password
    
    validate_unique :username
    validate_value :password
    validate_unique :username
  end

Then the username would have a duplicate validation check.  Perhaps that
is the behavior you are experiencing?

I decided to see how the 'other guys' handled validation to see if there
was a similar issue.  Ironically, it's pretty similar.  If you specify
something like validates_presence_of twice, it behaves the same way
Glue/Og does, and validates twice.

If this is determined to be a problem, one way to solve it is to declare
the validation type when creating the validation error, in order to test
for uniqueness.  However, you might have to make a special case for
validates_length since a lot of times you want to check for a min and a
max.  Arguably, you could force the user to use :range for both, but I
don't like the idea of artificial limitations.

Unless there is a bigger issue here, my suggestion is that the behavior
be documented and put under 'least surprise'.  If I declared a
validation twice, I would expect that it did that validation twice.

I have an idea about another way to handle validation, but I have not
fleshed it out enough to attempt it.  I will keep this issue in
consideration while pondering it.

Brian B.


On Wed, 2005-12-14 at 15:56 -0800, Bryan Soto wrote:
> I don't know if it's a big deal, but validation code appears to be
> added everytime a file is loaded. Given,
> 
> class User
>   property :username
>   property :password
> 
>   validate_unique :username
>   validate_value :password
> end
> 
> Everytime the file is reloaded, the validations are added to
> validations array so that they're run multiple times.
> 
> On 12/14/05, George Moschovitis < george.moschovitis at gmail.com> wrote:
>         Dear devs,
>         
>         I would like to ask you to grab the latest version from the
>         repository
>         and report any bugs, or problems. I would like to release
>         0.26.0 later
>         today or tommorow.
>         
>         thanks in advance,
>         -g.
>         
>         PS: especially test with psql and mysql.
>         
>         --
>         http://www.gmosx.com
>         http://www.navel.gr
>         http://www.nitrohq.com
>         
>         _______________________________________________
>         Nitro-general mailing list
>         Nitro-general at rubyforge.org
>         http://rubyforge.org/mailman/listinfo/nitro-general
> 
> _______________________________________________
> Nitro-general mailing list
> Nitro-general at rubyforge.org
> http://rubyforge.org/mailman/listinfo/nitro-general




More information about the Nitro-general mailing list