Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ruby-on-rails-3/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 3 设计不可侵犯的测试默认\u url\u选项_Ruby On Rails 3_Rspec_Devise Invitable - Fatal编程技术网

Ruby on rails 3 设计不可侵犯的测试默认\u url\u选项

Ruby on rails 3 设计不可侵犯的测试默认\u url\u选项,ruby-on-rails-3,rspec,devise-invitable,Ruby On Rails 3,Rspec,Devise Invitable,我正在测试这个方法 User.invite!(:email=>)new@example.com“” 与rspec的比较 但我得到了以下错误: ActionView::模板::错误: 缺少要链接到的主机!请提供:host参数,设置默认的\u url\u选项[:host],或将:only\u path设置为true 我已经在我的config/test.rb中添加了这一行 config.action_mailer.default_url_options = { :host => 'localho

我正在测试这个方法
User.invite!(:email=>)new@example.com“”

与rspec的比较 但我得到了以下错误:

ActionView::模板::错误: 缺少要链接到的主机!请提供:host参数,设置默认的\u url\u选项[:host],或将:only\u path设置为true

我已经在我的config/test.rb中添加了这一行

config.action_mailer.default_url_options = { :host => 'localhost:3001' }
before_filter :set_host_from_request

private

    def set_host_from_request
        ActionMailer::Base.default_url_options = { host: request.host_with_port }
    end
我要做什么来解决这个问题

我的rails版本:3.2.14

编辑 这是我的test.rb文件

MyApp::Application.configure do
  # Settings specified here will take precedence over those in config/application.rb

  # The test environment is used exclusively to run your application's
  # test suite. You never need to work with it otherwise. Remember that
  # your test database is "scratch space" for the test suite and is wiped
  # and recreated between test runs. Don't rely on the data there!
  config.cache_classes = true

  # Configure static asset server for tests with Cache-Control for performance
  config.serve_static_assets = true
  config.static_cache_control = "public, max-age=3600"

  # Log error messages when you accidentally call methods on nil
  config.whiny_nils = true

  # Show full error reports and disable caching
  config.consider_all_requests_local       = true
  config.action_controller.perform_caching = false

  # Raise exceptions instead of rendering exception templates
  config.action_dispatch.show_exceptions = false

  # Disable request forgery protection in test environment
  config.action_controller.allow_forgery_protection    = false

  # Tell Action Mailer not to deliver emails to the real world.
  # The :test delivery method accumulates sent emails in the
  # ActionMailer::Base.deliveries array.
  config.action_mailer.delivery_method = :test

  # Raise exception on mass assignment protection for Active Record models
  #config.active_record.mass_assignment_sanitizer = :strict

  # Print deprecation notices to the stderr
  config.active_support.deprecation = :stderr

  config.action_mailer.default_url_options = { :host => 'localhost:3001' }
end

我发现了这个解决方案,承认它有点黑客,但至少有效,如果有人找到一个更干净的解决方案,请随意评论

将此添加到我的应用程序\u controller.rb

config.action_mailer.default_url_options = { :host => 'localhost:3001' }
before_filter :set_host_from_request

private

    def set_host_from_request
        ActionMailer::Base.default_url_options = { host: request.host_with_port }
    end

你能把你的
test.rb
的样子贴出来吗?另外,您可能需要包括
config.action\u mailer\u delivery\u method