From ca960e609b03126747bd8fe786a09d5abead4595 Mon Sep 17 00:00:00 2001 From: Mauro George Date: Wed, 10 Jun 2015 19:38:49 -0300 Subject: [PATCH] Update RDoc of permit matchers according the new behavior. In 3.0 the permit matcher require the definition of the params. [ci skip] --- .../action_controller/permit_matcher.rb | 66 +++++++++++++++---- 1 file changed, 54 insertions(+), 12 deletions(-) diff --git a/lib/shoulda/matchers/action_controller/permit_matcher.rb b/lib/shoulda/matchers/action_controller/permit_matcher.rb index 899c75c3..1a7678bb 100644 --- a/lib/shoulda/matchers/action_controller/permit_matcher.rb +++ b/lib/shoulda/matchers/action_controller/permit_matcher.rb @@ -37,17 +37,35 @@ module Shoulda # # RSpec # describe UsersController do # it do + # params = { + # user: { + # first_name: 'John', + # last_name: 'Doe', + # email: 'johndoe@example.com', + # password: 'password' + # } + # } # should permit(:first_name, :last_name, :email, :password). - # for(:create). + # for(:create, params: params). # on(:user) # end # end # # # Test::Unit # class UsersControllerTest < ActionController::TestCase - # should permit(:first_name, :last_name, :email, :password). - # for(:create). - # on(:user) + # should "(for POST #create) restrict parameters on :user to first_name, last_name, email, and password" do + # params = { + # user: { + # first_name: 'John', + # last_name: 'Doe', + # email: 'johndoe@example.com', + # password: 'password' + # } + # } + # should permit(:first_name, :last_name, :email, :password). + # for(:create, params: params). + # on(:user) + # end # end # # If your action requires query parameters in order to work, then you'll @@ -83,8 +101,17 @@ module Shoulda # end # # it do + # params = { + # id: 1, + # user: { + # first_name: 'Jon', + # last_name: 'Doe', + # email: 'jondoe@example.com', + # password: 'password' + # } + # } # should permit(:first_name, :last_name, :email, :password). - # for(:update, params: { id: 1 }). + # for(:update, params: params). # on(:user) # end # end @@ -95,9 +122,20 @@ module Shoulda # create(:user, id: 1) # end # - # should permit(:first_name, :last_name, :email, :password). - # for(:update, params: { id: 1 }). - # on(:user) + # should "(for PATCH #update) restrict parameters on :user to :first_name, :last_name, :email, and :password" do + # params = { + # id: 1, + # user: { + # first_name: 'Jon', + # last_name: 'Doe', + # email: 'jondoe@example.com', + # password: 'password' + # } + # } + # should permit(:first_name, :last_name, :email, :password). + # for(:update, params: params). + # on(:user) + # end # end # # Finally, if you have an action that isn't one of the seven resourceful @@ -136,8 +174,9 @@ module Shoulda # end # # it do + # params = { id: 1, user: { activated: true } } # should permit(:activated). - # for(:toggle, params: { id: 1 }, verb: :put). + # for(:toggle, params: params, verb: :put). # on(:user) # end # end @@ -148,9 +187,12 @@ module Shoulda # create(:user, id: 1) # end # - # should permit(:activated). - # for(:toggle, params: { id: 1 }, verb: :put). - # on(:user) + # should "(for PUT #toggle) restrict parameters on :user to :activated" do + # params = { id: 1, user: { activated: true } } + # should permit(:activated). + # for(:toggle, params: params, verb: :put). + # on(:user) + # end # end # # @return [PermitMatcher]