diff --git a/CHANGELOG.md b/CHANGELOG.md index 98c70b4..0bd16a2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,8 @@ +0.4.2 +----- + +- Fix NoMethodError bug when params[:_rucaptha] is nil. + 0.4.1 ----- diff --git a/Gemfile.lock b/Gemfile.lock index 2d355e1..f5f7a04 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,7 +1,7 @@ PATH remote: . specs: - rucaptcha (0.4.1) + rucaptcha (0.4.2) posix-spawn (>= 0.3.0) GEM diff --git a/lib/rucaptcha/controller_helpers.rb b/lib/rucaptcha/controller_helpers.rb index 25ebd0c..78b3d6a 100644 --- a/lib/rucaptcha/controller_helpers.rb +++ b/lib/rucaptcha/controller_helpers.rb @@ -15,7 +15,7 @@ module RuCaptcha def verify_rucaptcha?(resource = nil) 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 valid = false diff --git a/lib/rucaptcha/version.rb b/lib/rucaptcha/version.rb index 42531f1..2164093 100644 --- a/lib/rucaptcha/version.rb +++ b/lib/rucaptcha/version.rb @@ -1,3 +1,3 @@ module RuCaptcha - VERSION = '0.4.1' + VERSION = '0.4.2' end diff --git a/spec/controller_helpers_spec.rb b/spec/controller_helpers_spec.rb index 1a3f2f9..f1fc08b 100644 --- a/spec/controller_helpers_spec.rb +++ b/spec/controller_helpers_spec.rb @@ -22,6 +22,19 @@ describe RuCaptcha do end 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 it 'should work' do simple.session[:_rucaptcha_at] = Time.now.to_i