File: offline_spec.rb

package info (click to toggle)
ruby-rack-attack 6.7.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 380 kB
  • sloc: ruby: 2,626; makefile: 4
file content (92 lines) | stat: -rw-r--r-- 2,131 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
# frozen_string_literal: true

require 'active_support/cache'
require_relative '../spec_helper'

OfflineExamples = Minitest::SharedExamples.new do
  it 'should write' do
    @cache.write('cache-test-key', 'foobar', 1)
  end

  it 'should read' do
    @cache.read('cache-test-key')
  end

  it 'should count' do
    @cache.count('cache-test-key', 1)
  end

  it 'should delete' do
    @cache.delete('cache-test-key')
  end
end

if defined?(::ActiveSupport::Cache::RedisStore)
  describe 'when Redis is offline' do
    include OfflineExamples

    before do
      @cache = Rack::Attack::Cache.new
      # Use presumably unused port for Redis client
      @cache.store = ActiveSupport::Cache::RedisStore.new(host: '127.0.0.1', port: 3333)
    end
  end
end

if defined?(Redis) && defined?(ActiveSupport::Cache::RedisCacheStore) && Redis::VERSION >= '4'
  describe 'when Redis is offline' do
    include OfflineExamples

    before do
      @cache = Rack::Attack::Cache.new
      # Use presumably unused port for Redis client
      @cache.store = ActiveSupport::Cache::RedisCacheStore.new(host: '127.0.0.1', port: 3333)
    end
  end
end

if defined?(::Dalli)
  describe 'when Memcached is offline' do
    include OfflineExamples

    before do
      Dalli.logger.level = Logger::FATAL

      @cache = Rack::Attack::Cache.new
      @cache.store = Dalli::Client.new('127.0.0.1:22122')
    end

    after do
      Dalli.logger.level = Logger::INFO
    end
  end
end

if defined?(::Dalli) && defined?(::ActiveSupport::Cache::MemCacheStore)
  describe 'when Memcached is offline' do
    include OfflineExamples

    before do
      Dalli.logger.level = Logger::FATAL

      @cache = Rack::Attack::Cache.new
      @cache.store = ActiveSupport::Cache::MemCacheStore.new('127.0.0.1:22122')
    end

    after do
      Dalli.logger.level = Logger::INFO
    end
  end
end

if defined?(Redis)
  describe 'when Redis is offline' do
    include OfflineExamples

    before do
      @cache = Rack::Attack::Cache.new
      # Use presumably unused port for Redis client
      @cache.store = Redis.new(host: '127.0.0.1', port: 3333)
    end
  end
end