@@ -242,26 +242,38 @@ def custom_timestamp_callback
242242 end
243243
244244 context 'spinner attribute' do
245+ let ( :spinner_value ) do
246+ '32ab649161f9f6faeeb323746de1a25d'
247+ end
248+
249+ let ( :valid_params ) do
250+ { title : 'foobar' , author : 'author' , body : 'body that passes validation' }
251+ end
252+
245253 before ( :each ) do
246254 InvisibleCaptcha . spinner_enabled = true
247255 InvisibleCaptcha . secret = 'secret'
248256 session [ :invisible_captcha_timestamp ] = Time . zone . now . iso8601
249- session [ :invisible_captcha_spinner ] = '32ab649161f9f6faeeb323746de1a25d'
257+ session [ :invisible_captcha_spinner ] = spinner_value
250258
251259 # Wait for valid submission
252260 sleep InvisibleCaptcha . timestamp_threshold
253261 end
254262
255263 it 'fails with no spam, but mismatch of spinner' do
256- post :create , params : { topic : { title : 'foo' } , spinner : 'mismatch' }
264+ post :create , params : { topic : valid_params , spinner : spinner_value . reverse }
257265
258- expect ( response . body ) . to be_blank
266+ expect ( response ) . to have_http_status ( :success )
267+ expect ( flash . notice ) . to be_blank
268+ expect ( session ) . not_to have_key ( :invisible_captcha_spinner )
259269 end
260270
261271 it 'passes with no spam and spinner match' do
262- post :create , params : { topic : { title : 'foo' } , spinner : '32ab649161f9f6faeeb323746de1a25d' }
263-
264- expect ( response . body ) . to be_present
272+ post :create , params : { topic : valid_params , spinner : spinner_value }
273+
274+ expect ( response ) . to have_http_status ( :redirect )
275+ expect ( flash . notice ) . to be_present
276+ expect ( session ) . not_to have_key ( :invisible_captcha_spinner )
265277 end
266278 end
267279end
0 commit comments