1
1

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.

Controller Specでcookiesの値を指定して処理する。

Posted at

#環境
macOS High Sierra 10.13.6
Docker Version: 18.09.2
rails 5.2.1

#問題
RspecのController Specでcookiesの値を指定して処理をしたい。

#解決法
cookies.signed[:key] = 'value' として、その後リクエストを送ります。

_spec.rb
describe "#index" do
  let(:guest_token) { 'abcde' }
  let!(:order) do
    create(
      :order_with_line_items,
      guest_token: guest_token
    )
  end

  before do
    cookies.signed[:guest_token] = guest_token
    get :index
  end

  it "assigns the guest's current order to @order" do
    expect(assigns(:order)).to eq order
  end
end

これでうまくいきました!

1
1
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
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?