Enum doesn't play nicely with validations
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 end class Recurrence include DataMapper::Resource property :id, Serial property :frequency, Enum["day","month"] has 1, :event, :required => false end DataMapper.setup(:default, 'sqlite3::memory:') DataMapper.auto_migrate! 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") event.save assert_not_nil Event.first # Fails end end end
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.