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

Break mongoid by overriding model method

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

      It's possible to override a method that Mongoid uses internally to break Mongoid

      I have a model Slot:

      <pre>class Slot
      include Mongoid::Document
      field :title, :type => String
      def empty?
      title.blank?
      end
      end
      </pre>

      I have configured my rails application to log mongodb queries into STDOUT

      One of my spec contains two lines:

      <pre> puts Slot.where(:_id => slot.id).first.id
      Slot.find(slot.id)</pre>

      line 2 raises an error Mongoid::Errors::DocumentNotFound

      STDOUT:

      <pre>MONGODB ffapi_test1['slots'].find({:_id=>BSON::ObjectId('4d99c9500b73e09e44000014')})
      4d99c9500b73e09e44000014
      MONGODB ffapi_test1['slots'].find({:_id=>BSON::ObjectId('4d99c9500b73e09e44000014')})</pre>

      I am using mongoid from master branch.

      The empty? definition is the problem here. Once removed, things come right.

            Assignee:
            durran Durran Jordan
            Reporter:
            prettynatty Andrey Kouznetsov
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved: