
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
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.
Comments and changes to this ticket
-
Martin Gamsjaeger (snusnu) October 29th, 2010 @ 03:28 PM
- State changed from new to confirmed
- Milestone set to 1.1
- Milestone order changed from 196280 to 0
-
Piotr Solnica (solnic) October 31st, 2010 @ 02:34 PM
- Assigned user set to Piotr Solnica (solnic)
-
-
Piotr Solnica (solnic) November 19th, 2010 @ 01:53 PM
- Tag changed from dm-types property dm-validations, dm-types, validations to dm-types, property, validations
-
Piotr Solnica (solnic) January 16th, 2011 @ 08:17 PM
(from [3426299cfe5de84f2350b0c57d45e2a6d0af378d]) Collection should use loaded values when setting up default attributes
[#1336 state:fixed] [#1411 state:fixed] https://github.com/datamapper/dm-core/commit/3426299cfe5de84f2350b0...
-
Piotr Solnica (solnic) January 16th, 2011 @ 08:22 PM
- State changed from confirmed to resolved
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.
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
Tags
Referenced by
-
1411 Enum doesn't play nicely with validations [#1336 state:fixed] [#1411 state:fixed] https://github.c...
-
1336 custom properties in unsaved associations are reverted to dumped_value rather than loaded_value [#1336 state:fixed] [#1411 state:fixed] https://github.c...