Rails Engine + Mongoid:找不到名为“默认"的会话的配置 [英] Rails Engine + Mongoid: No configuration could be found for a session named 'default'

查看:91
本文介绍了Rails Engine + Mongoid:找不到名为“默认"的会话的配置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个Rails Mountable App,并添加了"mongoid"和"rspec" gem.如果现在尝试运行规格,则会出现以下错误:

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.

当我将Mongoid.load!(Rails.root.join("config", "mongoid.yml"))行添加到spec_helper.rb时,一切正常.

When I add the Mongoid.load!(Rails.root.join("config", "mongoid.yml")) line to spec_helper.rb everything works normal.

为什么会这样?如何获得不需要调用load函数的普通Rails应用程序中的功能?

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

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'

推荐答案

您可能在spec_helper.rb文件中错过了require 'rails/mongoid'.

you probably missed require 'rails/mongoid' in your spec_helper.rb file.

这里有人遇到了相同的问题 https://github.com/mongoid/mongoid/issues/2894#issuecomment-14903927

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.

这篇关于Rails Engine + Mongoid:找不到名为“默认"的会话的配置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆