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

Support numeric path components as hash keys when embedded matching

    • Type: Icon: Improvement Improvement
    • Resolution: Fixed
    • Priority: Icon: Major - P3 Major - P3
    • 7.2.2
    • Affects Version/s: 7.2.1
    • Component/s: Query
    • None
    • Minor Change

      extract_attribute() fails to correctly handle cases with a numeric hash key. When the current code finds a numeric hash key, but sees that 'src' is NOT an array, it returns that the field does not exist.

      This PR adds a test case that fails for the old code, and then passes with the new code.

      PR: https://github.com/mongodb/mongoid/pull/4964

      Test Output (Old Code)

       

      1) Matcher.extract_attribute traversal.yml numeric hash key matching the split position has the expected exists flag
           Failure/Error: actual[0].should == expected_exists
           
             expected: true
                  got: false (using ==)
             Diff:
             @@ -1 +1 @@
             -true
             +false
             
           # ./spec/mongoid/matcher/extract_attribute_spec.rb:33:in `block (6 levels) in <top (required)>'
      
                                                                                                                                                                                      
        2) Matcher.extract_attribute traversal.yml numeric hash key matching the split position has the expected value
           Failure/Error: actual[1].should == expected_value
           
             expected: true
                  got: nil (using ==)
           # ./spec/mongoid/matcher/extract_attribute_spec.rb:37:in `block (6 levels) in <top (required)>'
      
      XYZ examples, 2 failures
      

      Test Output (New Code)

      XYZ examples, 0 failures

       

            Assignee:
            oleg.pudeyev@mongodb.com Oleg Pudeyev (Inactive)
            Reporter:
            dalton.black@braze.com Dalton Black
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: