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

Mongoid::Session.default.collections empty in Rails test environment

    XMLWordPrintable

    Details

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

      Description

      I'm currently using Rails 3.2.11 with Mongoid 3.0.17 (moped 1.3.2, origin 1.0.11) and when I open the Rails console in the "test" environment the Mongoid::Session.default.collections is empty. However, if I start the console in "development" the collections array is not empty.

      Here's the mongoid.yml:

      development:
      sessions:
      default:
      database: admin_dev
      hosts:

      • server-a.com:27017

      test:
      sessions:
      default:
      database: admin_test
      hosts:

      • server-a.com:27017

      I became aware of this problem when a spec failed b/c of a validation error. I noticed the collections weren't being emptied (even though I was calling Mongoid.truncate!.

      I fired up the rails console:

      rails c test
      > Mongoid::Sessions.default.collections
      => []
      > Mongoid::Threaded.sessions[:default].collections
      => []

      I can also get the collection from a model and access its session, however, that still shows no collections from it:

      > MyModel.collection.database.session.collections
      => []

      Any idea why the collections array is empty in "test" and not in "development"? I confirmed it is connected to the correct database and that data exists in the collections by doing a count on one of my models.

        Attachments

          Activity

            People

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

              Dates

              Created:
              Updated:
              Resolved: