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

When a hash attribute's field is updated via [], changed? returns false

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

      When a document has a hash field, accessing it via [] and updating a property does not cause changed? to return true. I've been able to reproduce this error, but unable to discover a solution so far.

      To reproduce, place these tests in changeable_spec.rb

      The first one should pass, and the second should fail reproducing the error described above.

      context "when a subfield is changed" do
      
        let(:person) do
          Person.create(map: { name: "value" })
        end
      
        it "returns true" do
          person.map[:name] = "Another Person"
          expect(person).to be_changed
        end
      
        it "returns true if accessed via []" do
          person[:map][:name] = "The Third Person"
          expect(person).to be_changed
        end
      end
      

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

              Created:
              Updated:
              Resolved: