How to test strong params with Rspec?

后端 未结 4 1253
夕颜
夕颜 2021-02-13 15:40

What is the actual strategy to test strong params filtering in Rails controller with Rspec? (Except shoulda matchers) How to write failing test and then make it green?

4条回答
  •  感动是毒
    2021-02-13 16:09

    as like you create or update object using strong parameters,it is also similar except one thing that normal you do like this:

    post :create, book_id: @book.id

    But in strong parameter you have to do like this:

    post :create, {book_id: @book.id, comment: {user_id: 101, book_id: @book.id, description: "worth to buy"}}

    you have to pass in nested parameters.

提交回复
热议问题