From 58ab0adb750b36a449dc0a6cbba2bfd1c254a059 Mon Sep 17 00:00:00 2001 From: Jason Lee Date: Sat, 29 Oct 2016 11:06:10 +0800 Subject: [PATCH] Fix test case --- .travis.yml | 2 ++ Gemfile | 1 + Gemfile.lock | 2 ++ lib/rucaptcha.rb | 6 +++++- lib/rucaptcha/controller_helpers.rb | 1 - spec/controller_helpers_spec.rb | 12 ++++++------ spec/spec_helper.rb | 1 + 7 files changed, 17 insertions(+), 8 deletions(-) diff --git a/.travis.yml b/.travis.yml index b7c50da..bbdbe04 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,6 +1,8 @@ language: ruby rvm: - 2.2.3 +services: + - memcached addons: apt: packages: diff --git a/Gemfile b/Gemfile index 8a579c5..b30ae89 100644 --- a/Gemfile +++ b/Gemfile @@ -6,3 +6,4 @@ gem 'rake' gem 'rails' gem 'rspec' gem 'mini_magick' +gem 'dalli' \ No newline at end of file diff --git a/Gemfile.lock b/Gemfile.lock index 9fdc381..5a0f6f6 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -46,6 +46,7 @@ GEM builder (3.2.2) concurrent-ruby (1.0.2) concurrent-ruby (1.0.2-java) + dalli (2.7.6) diff-lcs (1.2.5) erubis (2.7.0) globalid (0.3.6) @@ -125,6 +126,7 @@ PLATFORMS ruby DEPENDENCIES + dalli mini_magick rails rake diff --git a/lib/rucaptcha.rb b/lib/rucaptcha.rb index 7ca293a..0c44b49 100644 --- a/lib/rucaptcha.rb +++ b/lib/rucaptcha.rb @@ -20,7 +20,11 @@ module RuCaptcha @config.cache_limit = 100 @config.expires_in = 2.minutes @config.style = :colorful - @config.cache_store = Rails.application.config.cache_store + if Rails.application + @config.cache_store = Rails.application.config.cache_store + else + @config.cache_store = :null_store + end @config end diff --git a/lib/rucaptcha/controller_helpers.rb b/lib/rucaptcha/controller_helpers.rb index 771ed95..8b00eb1 100644 --- a/lib/rucaptcha/controller_helpers.rb +++ b/lib/rucaptcha/controller_helpers.rb @@ -31,7 +31,6 @@ module RuCaptcha end # Make sure not expire - puts "-------------- #{store_info.inspect}" if (Time.now.to_i - store_info[:time]) > RuCaptcha.config.expires_in return add_rucaptcha_validation_error end diff --git a/spec/controller_helpers_spec.rb b/spec/controller_helpers_spec.rb index bddf38c..0ec6ee8 100644 --- a/spec/controller_helpers_spec.rb +++ b/spec/controller_helpers_spec.rb @@ -19,11 +19,11 @@ describe RuCaptcha do end def custom_session - Rails.cache.read(self.rucaptcha_sesion_key_key) + RuCaptcha.cache.read(self.rucaptcha_sesion_key_key) end def clean_custom_session - Rails.cache.delete(self.rucaptcha_sesion_key_key) + RuCaptcha.cache.delete(self.rucaptcha_sesion_key_key) end end @@ -59,7 +59,7 @@ describe RuCaptcha do context 'Correct chars in params' do it 'should work' do - Rails.cache.write(simple.rucaptcha_sesion_key_key, { + RuCaptcha.cache.write(simple.rucaptcha_sesion_key_key, { time: Time.now.to_i, code: 'abcd' }) @@ -67,7 +67,7 @@ describe RuCaptcha do expect(simple.verify_rucaptcha?).to eq(true) expect(simple.custom_session).to eq nil - Rails.cache.write(simple.rucaptcha_sesion_key_key, { + RuCaptcha.cache.write(simple.rucaptcha_sesion_key_key, { time: Time.now.to_i, code: 'abcd' }) @@ -78,7 +78,7 @@ describe RuCaptcha do describe 'Incorrect chars' do it 'should work' do - Rails.cache.write(simple.rucaptcha_sesion_key_key, { + RuCaptcha.cache.write(simple.rucaptcha_sesion_key_key, { time: Time.now.to_i - 60, code: 'abcd' }) @@ -90,7 +90,7 @@ describe RuCaptcha do describe 'Expires Session key' do it 'should work' do - Rails.cache.write(simple.rucaptcha_sesion_key_key, { + RuCaptcha.cache.write(simple.rucaptcha_sesion_key_key, { time: Time.now.to_i - 121, code: 'abcd' }) diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 7549506..0e13a35 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -24,4 +24,5 @@ RuCaptcha.configure do self.len = 2 self.font_size = 48 self.implode = 0.111 + self.cache_store = :mem_cache_store end