2015-10-30 03:32:02 +00:00
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
describe RuCaptcha::Cache do
|
2016-05-25 03:08:48 +00:00
|
|
|
before(:all) do
|
|
|
|
RuCaptcha::Captcha.send(:prepend, RuCaptcha::Cache)
|
|
|
|
end
|
|
|
|
|
2015-10-30 03:32:02 +00:00
|
|
|
describe '.random_chars_with_cache' do
|
|
|
|
it 'should generate max chars by config.cache_limit' do
|
|
|
|
allow(RuCaptcha.config).to receive(:cache_limit).and_return(5)
|
|
|
|
items = []
|
2016-05-25 03:07:26 +00:00
|
|
|
100.times do
|
|
|
|
items << RuCaptcha::Captcha.random_chars
|
2015-10-30 03:32:02 +00:00
|
|
|
end
|
2016-05-25 03:07:26 +00:00
|
|
|
expect(items.uniq.length).to eq RuCaptcha.config.cache_limit
|
2015-10-30 03:32:02 +00:00
|
|
|
expect(RuCaptcha::Captcha.cached_codes).to eq items.uniq
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '.create' do
|
|
|
|
it 'should work' do
|
2016-05-25 03:07:26 +00:00
|
|
|
expect(RuCaptcha::Captcha).to receive(:create).and_return('aabb')
|
2015-10-30 03:32:02 +00:00
|
|
|
expect(RuCaptcha::Captcha.create('abcd')).to eq('aabb')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|