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

Default scoping in embedded documents

    XMLWordPrintable

    Details

    • Type: Task
    • Status: Closed
    • Resolution: Done
    • Affects Version/s: None
    • Fix Version/s: 2.4.10
    • Component/s: None
    • Labels:

      Description

      Hi,

      I create an embedded document and change the attributes, so that the default scope doesn't match any more. Then the test without reloading fails. The same works the other way round, too.
      I found this issue while looking through the sample code from apneadiving for MONGOID-1918.

       
      require 'spec_helper'
       
      describe "default scoping on embedded documents" do
       
        let(:person) do
          Person.create 
        end
       
        before do
          person.appointments.create
        end
       
        context "when changing the default scope attribute" do
        
          before do
            a = person.appointments.first
            a.active = false
            a.save
          end
       
          context "when reloading" do
            
            it "hides the document" do
              person.reload.appointments.should eq([])
              # PASS
            end
          end
       
          context "when not reloading" do
            
            it "hides the document" do
              person.appointments.should eq([])
              # FAIL
            end
          end
        end
      end
      

      I already looked at the code, but couldn't find the place to fix this issue.

        Attachments

          Activity

            People

            • Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: