I've created a Rails Mountable App and added 'mongoid' and 'rspec' gem's. If I try to run my specs now I get the following error:
Mongoid::Errors::NoSessionConfig:
Problem:
No configuration could be found for a session named 'default'.
Summary:
When attempting to create the new session, Mongoid could not find a session configuration for the name: 'default'. This is necessary in order to know the host, port, and options needed to connect.
Resolution:
Double check your mongoid.yml to make sure under the sessions key that a configuration exists for 'default'. If you have set the configuration programatically, ensure that 'default' exists in the configuration hash.
When I add the Mongoid.load!(Rails.root.join("config", "mongoid.yml"))
line to spec_helper.rb
everything works normal.
Why is that and how can I get the functionality like in a normal Rails app where I don't need to call the load function?
mongoid.yml
development:
sessions:
default:
database: dummy_development
hosts:
- localhost:27017
options:
options:
test:
sessions:
default:
database: dummy_test
hosts:
- localhost:27017
options:
consistency: :strong
max_retries: 1
retry_interval: 0
Versions:
gem 'rails', '~> 3.2.12'
gem 'mongoid', '~> 3.1'
gem 'rspec-rails', '~> 2.13'
This worked for me on my machine
1: Add this to your config/application.rb
2: And change your mongoid.yml from for example (Only for mongoid version < 5):
This
To:
I've found this working - notice there is no "sessions", only "clients"
And restart the server after making changes to mongoid.yml
you probably missed
require 'rails/mongoid'
in your spec_helper.rb file.Had someone having the same issue in here https://github.com/mongoid/mongoid/issues/2894#issuecomment-14903927
Try adding that require, that should fix it.
This is probably because of two simultaneous conditions: ( there is no production section in mongoid.yml ) AND ( Heroku treats Rails applications as production by default ).
Fixing either one shall suffice.
1. There is no production section in mongoid.yml
Add production section to mongoid.yml, as explained at Heroku , e.g.
2. Heroku treats rails applications as production by default
Set Heroku environment to development, or a add a new environment which would be specific to Heroku, as explained at Heroku, e.g.