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

Review instance === implementation

    • Type: Icon: Improvement Improvement
    • Resolution: Fixed
    • Priority: Icon: Major - P3 Major - P3
    • 7.4.0
    • Affects Version/s: None
    • Component/s: None
    • Fully Compatible

      Mongoid defines === for Mongoid::Document class and its instances (two separate implementations). The existing implementation calls this operator an "equality" one. However, the post at https://dev.to/baweaver/understanding-ruby-triple-equals-2p9c suggests the === operatior is really a membership operator rather than an equality operator (which would explain why, for example, === is false for some class comparisons to itself, e.g. String === String is false but Object === Object is true).

      Given the changes already made in https://jira.mongodb.org/browse/MONGOID-5126, which applied to class-level === implementation in Mongoid, I think we should review the instance-level implementation as well and ensure both are consistent with "=== is a membership operator" idea.

      Make instance level === delegate to super when legacy behavior is off
      Review all specs in spec/mongoid/equality_spec.rb that use ===, ensure both values of the flag are tested
      Update release note for === change to show examples of different legacy behavior - already done
      Move === implementation from mongoid/document.rb to mongoid/equality.rb

            Assignee:
            neil.shweky@mongodb.com Neil Shweky (Inactive)
            Reporter:
            oleg.pudeyev@mongodb.com Oleg Pudeyev (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: