#1411 ✓resolved

Enum doesn't play nicely with validations

Reported by siplux | September 14th, 2010 @ 09:47 PM | in 1.1

    require 'dm-core'
    require 'dm-types'
    require 'dm-migrations'
    require 'dm-validations'
    require 'test/unit'
    require 'shoulda'

    class Event
      include DataMapper::Resource
      property :id,         Serial 
      belongs_to :recurrence, :required => false

    class Recurrence
      include DataMapper::Resource
      property :id,         Serial 
      property :frequency,  Enum["day","month"]
      has 1, :event, :required => false

    DataMapper.setup(:default, 'sqlite3::memory:')

    class TestDmEvents < Test::Unit::TestCase

      context "An Event" do
        should "should be valid and saved with the recurrence" do
          event            = Event.new
          event.recurrence = Recurrence.new(:frequency =>"day")
          assert_not_nil Event.first # Fails


If you run the above code you'll see that the event is never saved.

Disabling autovalidations will allow it to be saved

    property :frequency,  Enum["day","month"], :auto_validation => false # Skip validations for dm-core bug workaround

If you output the value in validates_within, it shows that it has been typecast to 1 by the time it checks to see whether it is one of the
acceptable values, thus failing validation.

Comments and changes to this ticket

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 »

Referenced by