[Nitro] 0.26.0 preview

Bryan Soto bryan.a.soto at gmail.com
Thu Dec 15 01:06:43 EST 2005


Sorry if I wasn't clear. In debug mode, i.e. webrick, files are
automatically reloaded on change. I noticed after adding and removing a
field to test Mysql evolution that my validations had increased. Something
along the lines of:

# user.rb
class User
  property :username
  property :password

  validate_unique :username
  validate_value :password
end

User.validations.size   #  => 2

# touch user.rb

User.validations.size   #  => 4

assuming user.rb is a model class in a Nitro application. Basically, after
the touch is performed, the file is reloaded and the validations are added
anew to the already existing validations array (speculation on my part as to
your implementation) in the already existing User class.

As I said, it's not that a big a deal. A stop and restart of the webrick
server clears it up. I just happended to notice twice as many error messages
as I expected from a form. Just make sure your production apps aren't in
debug mode.

bryan

On 12/14/05, Brian Bugh <brian at xsi-design.com> wrote:
>
> 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
>
> _______________________________________________
> Nitro-general mailing list
> Nitro-general at rubyforge.org
> http://rubyforge.org/mailman/listinfo/nitro-general
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://rubyforge.org/pipermail/nitro-general/attachments/20051215/bb59f631/attachment.html 


More information about the Nitro-general mailing list