Uploaded image for project: 'Mongoid'
  1. Mongoid
  2. MONGOID-3045

validates_uniqueness_of fails with a Date field

    • Type: Icon: Task Task
    • Resolution: Done
    • 3.1.5
    • Affects Version/s: None
    • Component/s: None
    • None

      Using validates_uniqueness_of on a Date field results in an undefined method 'bson_dump' error. This worked fine in Mongoid 2.4, but after upgrading to Mongoid 3.1.3, raises an error. A test case is outlined below.

      Minimal working model:

      class TestModel
      	include Mongoid::Document
      
      	field :date, type: Date
      end
      

      Create one in a rails console:

      > t = TestModel.new
      => #<TestModel _id: 5195692f4364202f03000001, date: nil>
      > t.date = Date.today
      => Thu, 16 May 2013
      > t.save
      => true
      

      Add in a validation on the date field:

      class TestModel
      	include Mongoid::Document
      
      	field :date, type: Date
      
      	validates_uniqueness_of :date
      end
      

      Same test in rails console now fails to save:

      > t = TestModel.new
      => #<TestModel _id: 5195692f4364202f03000001, date: nil>
      > t.date = Date.today
      => Thu, 16 May 2013
      > t.save
      NoMethodError: undefined method `__bson_dump__' for Thu, 16 May 2013:Date
      from .../ruby-1.9.3-p392@perfect-audience/gems/moped-1.4.5/lib/moped/bson/extensions/hash.rb:15:in `block in __bson_dump__'
      

            Assignee:
            Unassigned Unassigned
            Reporter:
            mchail mchail
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved: