前提・実現したいこと
diviseでログイン機能を実装し、ユーザー登録時に入力したメールアドレスにメールを送信し、ユーザー認証をする機能を実装しました。
ブラウザ上ではメールが正しく送られ、ユーザー登録ができているのですが、フィーチャスペックでのテストを走らせるとエラーが出ます。
発生している問題・エラーメッセージ
Failure/Error: <p><%= link_to 'Confirm my account', confirmation_url(@resource, confirmation_token: @token) %></p> ActionView::Template::Error: Missing host to link to! Please provide the :host parameter, set default_url_options[:host], or set :only_path to true
該当のソースコード
spec/features/sign_up_spec.rb require 'rails_helper' feature 'Sign up' do scenario "ユーザー登録を行い、ログインするとユーザーの個別ページに遷移する" do visit root_path expect(page).to have_http_status :ok click_link "さっそく登録!" fill_in "メールアドレス", with: 'foo@example.com' fill_in "ユーザーネーム", with: 'sasa' fill_in "パスワード", with: 'test' fill_in "確認用パスワード", with: 'test' click_on 'ユーザー登録' expect(page).to have_content "本人確認用のメールを送信しました。メール内のリンクからアカウントを有効化させてください。" end end
ユーザー登録画面 <h2>ユーザー登録</h2> <%= form_for(resource, as: resource_name, url: registration_path(resource_name)) do |f| %> <%= render "devise/shared/error_messages", resource: resource %> <div class="field"> <%= f.label :email %><br /> <%= f.email_field :email, autofocus: true, autocomplete: "email" %> </div> <div class="field"> <%= f.label :username %><br /> <%= f.text_field :username, class: "form-control" %> </div> <div class="field"> <%= f.label :password %> <% if @minimum_password_length %> <em>(<%= @minimum_password_length %>文字以上)</em> <% end %><br /> <%= f.password_field :password, autocomplete: "new-password" %> </div> <div class="field"> <%= f.label :password_confirmation %><br /> <%= f.password_field :password_confirmation, autocomplete: "new-password" %> </div> <div class="actions"> <%= f.submit "ユーザー登録" %> </div> <% end %> <%= render "devise/shared/links" %>
試したこと
configのhostのリンクはもともと記載してあります。
config.action_mailer.default_url_options = { host: 'localhost:3001' }
どなたか対応策を宜しくお願い致します。。
あなたの回答
tips
プレビュー