How to test strong params with Rspec?

后端 未结 4 1255
夕颜
夕颜 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:05

    I personally use shoulda-matcher from thoughtbot.

    With something like:

    it do
      should permit(:first_name, :last_name, :email, :password).
        for(:update, params: params)
    end
    

提交回复
热议问题