LoginSignup
0
0

More than 1 year has passed since last update.

【Rspec】リファラをheaderに設定してリダイレクトするケースを作成する。

Last updated at Posted at 2022-09-07

メモとして残します。

controllerにredirect_to :backと記載されているactionに対してのactionケースを確認する場合、
リファラが設定されていないと、リダイレクト先を確認するケースでエラーとなる。
そのため、以下でリファラの設定方法を記述します。

■やり方

リクエストヘッダにHTTP_REFERERをキーにリファラとなるURLを設定。

RSpec.describe 'put /hoge_save', type: :request do
  let(:headers){ { 'HTTP_REFERER' => referer } }
  let!(:referer){ "/hoge_prev" }

  it 'リファラにリダイレクトすること' do
    put '/hoge_save', {'params'=>'hoge'}, headers
    expect(response).to redirect_to referer
  end
end

以上

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