#793 ✓not-applicable

Integers slip through autovalidation of length

Reported by bodhi | January 29th, 2009 @ 11:28 PM | in 0.10.0

given a class:

class Widget
  include DataMapper::Resource
  property :short_property, String, :length => 10

A fixture like:

Widget.fixture {{
  :short_property => /\w+/.gen

Will occasionally generate a value for short_property longer than 10 characters, thus causing intermittent problems in specs. It was quite painful for me to track down the reason why my specs would only fail occasionally.

It can be solved by:


But you need to realise that there is a length set on the property, and carry that length over to the fixture. If not making the regexp automatically generate valid values, how about a warning when a long value is generated?

Comments and changes to this ticket

  • Dan Kubb (dkubb)

    Dan Kubb (dkubb) February 1st, 2009 @ 02:53 PM

    • Assigned user set to “Michael Klishin (antares)”
  • Michael Klishin (antares)

    Michael Klishin (antares) February 2nd, 2009 @ 10:57 AM

    • Title changed from “sweatshop sometimes generates invalid data” to “Integers slip through autovalidation of length”

    Sweatshop uses public API (notably, Resource#create) so the problem is probably with auto validations, and more specifically, the way number value of :length is treated.

  • Michael Klishin (antares)

    Michael Klishin (antares) March 25th, 2009 @ 03:15 PM

    • Tag changed from dm-sweatshop to dm-validations
    • Milestone set to 0.10.0
    • State changed from “unconfirmed” to “not-applicable”

    After reviewing this, this is a side effect of inferred validations. In 0.10 it will be possible (in fact, already on next branch) to use a block to disable inferred validations:

    without_auto_validations do
      property :short_property, String
    dm-sweatship and randexp are generic libraries that only use DM models API, but the problem with overly long string is in fact a real failed validations that was inferred for string property from :length option.

Please Sign in or create a free account to add a new ticket.

With your very own profile, you can contribute to projects, track your activity, watch tickets, receive and update tickets through your email and much more.

New-ticket Create new ticket

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

People watching this ticket