Fix NoMethodError bug when params[:_rucaptha] is nil.

This commit is contained in:
Jason Lee 2016-04-25 10:09:35 +08:00
parent be7d72feb0
commit e5ff2b9e77
5 changed files with 21 additions and 3 deletions

View File

@ -1,3 +1,8 @@
0.4.2
-----
- Fix NoMethodError bug when params[:_rucaptha] is nil.
0.4.1 0.4.1
----- -----

View File

@ -1,7 +1,7 @@
PATH PATH
remote: . remote: .
specs: specs:
rucaptcha (0.4.1) rucaptcha (0.4.2)
posix-spawn (>= 0.3.0) posix-spawn (>= 0.3.0)
GEM GEM

View File

@ -15,7 +15,7 @@ module RuCaptcha
def verify_rucaptcha?(resource = nil) def verify_rucaptcha?(resource = nil)
rucaptcha_at = session[:_rucaptcha_at].to_i rucaptcha_at = session[:_rucaptcha_at].to_i
captcha = params[:_rucaptcha].downcase.strip captcha = (params[:_rucaptcha] || '').downcase.strip
# Captcha chars in Session expire in 2 minutes # Captcha chars in Session expire in 2 minutes
valid = false valid = false

View File

@ -1,3 +1,3 @@
module RuCaptcha module RuCaptcha
VERSION = '0.4.1' VERSION = '0.4.2'
end end

View File

@ -22,6 +22,19 @@ describe RuCaptcha do
end end
describe '.verify_rucaptcha?' do describe '.verify_rucaptcha?' do
context 'Nil of param' do
it 'should work when params[:_rucaptcha] is nil' do
simple.params[:_rucaptcha] = nil
expect(simple.verify_rucaptcha?).to eq(false)
end
it 'should work when session[:_rucaptcha] is nil' do
simple.session[:_rucaptcha] = nil
simple.params[:_rucaptcha] = 'Abcd'
expect(simple.verify_rucaptcha?).to eq(false)
end
end
context 'Correct chars in params' do context 'Correct chars in params' do
it 'should work' do it 'should work' do
simple.session[:_rucaptcha_at] = Time.now.to_i simple.session[:_rucaptcha_at] = Time.now.to_i