32
23

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

URLリダイレクトのspecを書きたいとき

Last updated at Posted at 2014-09-01

単純に"old/page/url"を"new/page/url"にリダイレクトする処理のrspecを書くとき、

  get 'old/page/url'

で書くと、そんなacitonがないよ、と怒られる。

Controller specの場合、getに渡すパラメータがaction名だから。

そんなとき、Request specsの登場です。
やり方は簡単。specをspec/requestsフォルダ配下に作るだけです。

describe PcController do
  it 'redirect old/page/url to new/page/url' do
    get 'old/page/url'
    expect(response).to redirect_to('http://test.com/new/page/url')
  end
end

独り言

なるほど、spec/requests配下に置くだけで、urlをgetできるのだ。ちなみに、postもできる。
見た目では同じgetメソッドなのに、置く場所によって、actionであったり、urlであったりするのだ。

32
23
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
32
23

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?