huacnlee / rucaptcha

Captcha Gem for Rails, which generates captcha image by Rust.
https://huacnlee.github.io/rucaptcha
MIT License
695 stars 133 forks source link

修复 verify_rucaptcha? 方法在过期时间验证失败后不向 resource 中添加 error 信息 #22

Closed flypiggy closed 8 years ago

flypiggy commented 8 years ago

校验验证码过期时间失败后, 方法会直接 return. 后面的向 resource 中添加 error 的代码不会执行到.

flypiggy commented 8 years ago

这种情况下测试是无法通过的

def send_verify_code
  user = current_user || User.new(user_create_params)
  if verify_rucaptcha?(user) && user.valid?
    send_register_code
  else
    render json: { errors: user.errors.full_messages }, status: :not_acceptable
  end
end
context 'verify captcha failed' do
  it 'should return error' do
    get 'send_verify_code', user: { email: 'test@geekpark.net' }
    expect(response).to have_http_status(:not_acceptable)
    expect(JSON.parse(response.body)['errors']).to include('Captcha invalid!')
  end
end
flypiggy commented 8 years ago

updated