0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Rspec(deviseあり)でユーザ登録する際、Missing・・とかいうエラーが出た時

Posted at

はじめに

みなさん、こんにちは torihaziです

今回はタイトルのことをやっていきます。

現状

現在、Rspecにおいてリクエストスペックのテストを行っています。

deviseを使って認証を行っており、ユーザ登録のテストをする際、次のエラーが出ました。

    ActionView::Template::Error:
       Missing host to link to! Please provide the :host parameter, set default_url_options[:host], or set :only_path to true

実際に使っていたコードは下記です。
deviseを使用して登録処理を行っているので、登録後認証メールが行く仕様になっています。

# frozen_string_literal: true

require 'rails_helper'

RSpec.describe 'Users', type: :request do
  describe 'POST #create' do
    context "when the parameters is valid" do

      it "request successfully" do
        user_params = FactoryBot.attributes_for(:user)
        post user_registration_path, params: {user: user_params}
        expect(response.status).to eq 302
      end

    end
  end
end

結論

congit/environments/test.rbに次の記述をします。

Rails.application.configure do
~~~
  config.action_mailer.default_url_options = { host: 'localhost', port: 3000 }
~~~
end

{ host: ***}のところは正直 hogehoge@mail.comとかでも機能します。

先ほどのエラーは送り元がわかんないから認証メール送れないよ、という内容でした。

開発環境(development.rb)や本番環境(production.rb)は

設定していたのに テスト環境だからということで忘れていました。

終わりに

以上!

まだエラーが出ているのでその解決に入ります!

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?