Fix test case

This commit is contained in:
Jason Lee 2016-10-29 11:06:10 +08:00
parent d0d6718e15
commit 58ab0adb75
7 changed files with 17 additions and 8 deletions

View File

@ -1,6 +1,8 @@
language: ruby language: ruby
rvm: rvm:
- 2.2.3 - 2.2.3
services:
- memcached
addons: addons:
apt: apt:
packages: packages:

View File

@ -6,3 +6,4 @@ gem 'rake'
gem 'rails' gem 'rails'
gem 'rspec' gem 'rspec'
gem 'mini_magick' gem 'mini_magick'
gem 'dalli'

View File

@ -46,6 +46,7 @@ GEM
builder (3.2.2) builder (3.2.2)
concurrent-ruby (1.0.2) concurrent-ruby (1.0.2)
concurrent-ruby (1.0.2-java) concurrent-ruby (1.0.2-java)
dalli (2.7.6)
diff-lcs (1.2.5) diff-lcs (1.2.5)
erubis (2.7.0) erubis (2.7.0)
globalid (0.3.6) globalid (0.3.6)
@ -125,6 +126,7 @@ PLATFORMS
ruby ruby
DEPENDENCIES DEPENDENCIES
dalli
mini_magick mini_magick
rails rails
rake rake

View File

@ -20,7 +20,11 @@ module RuCaptcha
@config.cache_limit = 100 @config.cache_limit = 100
@config.expires_in = 2.minutes @config.expires_in = 2.minutes
@config.style = :colorful @config.style = :colorful
if Rails.application
@config.cache_store = Rails.application.config.cache_store @config.cache_store = Rails.application.config.cache_store
else
@config.cache_store = :null_store
end
@config @config
end end

View File

@ -31,7 +31,6 @@ module RuCaptcha
end end
# Make sure not expire # Make sure not expire
puts "-------------- #{store_info.inspect}"
if (Time.now.to_i - store_info[:time]) > RuCaptcha.config.expires_in if (Time.now.to_i - store_info[:time]) > RuCaptcha.config.expires_in
return add_rucaptcha_validation_error return add_rucaptcha_validation_error
end end

View File

@ -19,11 +19,11 @@ describe RuCaptcha do
end end
def custom_session def custom_session
Rails.cache.read(self.rucaptcha_sesion_key_key) RuCaptcha.cache.read(self.rucaptcha_sesion_key_key)
end end
def clean_custom_session def clean_custom_session
Rails.cache.delete(self.rucaptcha_sesion_key_key) RuCaptcha.cache.delete(self.rucaptcha_sesion_key_key)
end end
end end
@ -59,7 +59,7 @@ describe RuCaptcha do
context 'Correct chars in params' do context 'Correct chars in params' do
it 'should work' 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, time: Time.now.to_i,
code: 'abcd' code: 'abcd'
}) })
@ -67,7 +67,7 @@ describe RuCaptcha do
expect(simple.verify_rucaptcha?).to eq(true) expect(simple.verify_rucaptcha?).to eq(true)
expect(simple.custom_session).to eq nil 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, time: Time.now.to_i,
code: 'abcd' code: 'abcd'
}) })
@ -78,7 +78,7 @@ describe RuCaptcha do
describe 'Incorrect chars' do describe 'Incorrect chars' do
it 'should work' 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, time: Time.now.to_i - 60,
code: 'abcd' code: 'abcd'
}) })
@ -90,7 +90,7 @@ describe RuCaptcha do
describe 'Expires Session key' do describe 'Expires Session key' do
it 'should work' 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, time: Time.now.to_i - 121,
code: 'abcd' code: 'abcd'
}) })

View File

@ -24,4 +24,5 @@ RuCaptcha.configure do
self.len = 2 self.len = 2
self.font_size = 48 self.font_size = 48
self.implode = 0.111 self.implode = 0.111
self.cache_store = :mem_cache_store
end end