`Mongoid.purge!` and `Mongoid.truncate` ignore global persistence context overrides

XMLWordPrintableJSON

    • Type: Bug
    • Resolution: Fixed
    • Priority: Critical - P2
    • 7.3.0
    • Affects Version/s: None
    • Component/s: Persistence
    • None
    • None
    • Minor Change
    • None
    • None
    • None
    • None
    • None
    • None

      When I useĀ `Mongoid.purge!` and `Mongoid.truncate` I would expect the method to use the `Mongoid.override_database`
      Example

      require 'mongoid'
      
      Mongoid.connect_to 'bugs'
      
      class Something
        include Mongoid::Document
      
        field :doesnt_matter, type: String, default: ''
      end
      
      
      puts "----Testing purge!----"
      Something.create!(doesnt_matter: 'test-purge')
      puts "  Expect: 1, Actual: #{Something.count}"
      Mongoid.purge!
      puts "  Expect: 0, Actual: #{Something.count}"
      
      puts "----Testing truncate!----"
      Something.create!(doesnt_matter: 'test-truncate')
      puts "  Expect: 1, Actual: #{Something.count}"
      Mongoid.truncate!
      puts "  Expect: 0, Actual: #{Something.count}"
      
      Mongoid.override_database('bugs_1')
      
      puts "----Testing purge! with override db----"
      Something.create!(doesnt_matter: 'test-purge-ov')
      puts "  Expect: 1, Actual: #{Something.count}"
      Mongoid.purge!
      puts "  Expect: 0, Actual: #{Something.count}"
      
      puts "----Testing truncate! with override db----"
      Something.create!(doesnt_matter: 'test-truncate-ov')
      puts "  Expect: 1, Actual: #{Something.count}"
      Mongoid.truncate!
      puts "  Expect: 0, Actual: #{Something.count}"
      

              Assignee:
              Dmitry Rybakov
              Reporter:
              Jonathon Gardner
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

                Created:
                Updated:
                Resolved: