Ruby on Rails | Screencasts | Download | Documentation | Weblog | Community | Source

Ticket #544 (closed enhancement: fixed)

Opened 4 years ago

Last modified 1 year ago

validation when saving serialized data

Reported by: anonymous Assigned to: David
Priority: normal Milestone: 1.1
Component: ActiveRecord Version: 1.1.0 RC1
Severity: normal Keywords: serialization serialize validation
Cc: bitsweat

Description

Assume I have the following model.

class Person < ActiveRecord::Base
  serialize :lucky_numbers, Array
  validates_uniqueness_of :name
end

I can do the following

Person.create({"name" => "pete", "lucky_numbers" => "1"})

But then when I try to do this

b = Person.find_first("name = 'pete'")
b.lucky_numbers

I get a SerializationTypeMismatch Error. It would be nice for this error to be caught when creating the record, rather than when retrieving it.

Attachments

ticket_544_test.rb (0.6 kB) - added by josh on 02/15/07 12:30:57.

Change History

03/09/05 18:18:48 changed by nzkoz

  • severity changed from normal to enhancement.
  • milestone set to 1.x.

I'm setting the milestone for this ticket to 1.x, this means that the earliest it will be fixed is after the 1.0 release. If you think this should be fixed earlier, please email the developers list to discuss it.

07/07/06 21:39:37 changed by bitsweat

  • status changed from new to closed.
  • resolution set to wontfix.

Please reopen with a failing test case if this is still an issue.

12/09/06 21:58:57 changed by rarepleasures

  • status changed from closed to reopened.
  • version changed from 0.9.4.1 to 1.1.0 RC1.
  • resolution deleted.

I have a similar issue with serialize and validates_uniqueness_of

class Person < ActiveRecord::Base

serialize :lucky_numbers, Array validates_uniqueness_of :lucky_numbers

end

fails to validates the uniqueness of the array. This problem occurs eve if you don't specify serialize implicitly and the value you are evaluating is an Array in nature.

01/25/07 09:56:54 changed by bitsweat

  • status changed from reopened to closed.
  • resolution set to untested.

02/15/07 03:49:32 changed by josh

  • cc set to bitsweat.

In Rails 1.2, the issue seems to be resolved.

Person.create({"name" => "pete", "lucky_numbers" => "1"})
ActiveRecord::SerializationTypeMismatch: lucky_numbers was supposed to be a Array, but was a Fixnum

Resolution should be set to fixed.

02/15/07 05:52:18 changed by bitsweat

A test case will prove it either way so this can be resolved.

02/15/07 12:30:57 changed by josh

  • attachment ticket_544_test.rb added.

02/15/07 12:32:19 changed by josh

Check that (ticket_544_test.rb) one file test case, its so agile.

05/06/07 21:08:56 changed by josh

  • status changed from closed to reopened.
  • resolution deleted.

05/06/07 21:09:00 changed by josh

  • status changed from reopened to closed.
  • resolution set to fixed.