berater 0.2.0 → 0.6.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,26 +0,0 @@
1
- module Berater
2
- class BaseLimiter
3
-
4
- attr_reader :key, :options
5
-
6
- def redis
7
- options[:redis] || Berater.redis
8
- end
9
-
10
- def limit
11
- raise NotImplementedError
12
- end
13
-
14
- protected
15
-
16
- def initialize(key, **opts)
17
- @key = key
18
- @options = opts
19
- end
20
-
21
- def cache_key(key)
22
- "#{self.class}:#{key}"
23
- end
24
-
25
- end
26
- end
@@ -1,39 +0,0 @@
1
- describe Berater::Lock do
2
- it_behaves_like 'a lock', Berater.new(:key, :concurrency, 3)
3
-
4
- let(:limiter) { Berater.new(:key, :concurrency, 3) }
5
-
6
- describe '#expired?' do
7
- let!(:lock) { limiter.limit }
8
-
9
- context 'when timeout is not set' do
10
- it { expect(limiter.timeout).to eq 0 }
11
-
12
- it 'never expires' do
13
- expect(lock.locked?).to be true
14
- expect(lock.expired?).to be false
15
-
16
- Timecop.travel(1_000)
17
-
18
- expect(lock.locked?).to be true
19
- expect(lock.expired?).to be false
20
- end
21
- end
22
-
23
- context 'when timeout is set and exceeded' do
24
- before { Timecop.travel(1) }
25
-
26
- let(:limiter) { Berater.new(:key, :concurrency, 3, timeout: 1) }
27
-
28
- it 'expires' do
29
- expect(lock.expired?).to be true
30
- expect(lock.locked?).to be false
31
- end
32
-
33
- it 'fails to release' do
34
- expect { lock.release }.to raise_error(RuntimeError, /expired/)
35
- end
36
- end
37
- end
38
-
39
- end
@@ -1,20 +0,0 @@
1
- describe Berater::Lock do
2
- it_behaves_like 'a lock', Berater.new(:key, :rate, 3, :second)
3
-
4
- let(:limiter) { Berater.new(:key, :rate, 3, :second) }
5
-
6
- describe '#expired?' do
7
- let!(:lock) { limiter.limit }
8
-
9
- it 'never expires' do
10
- expect(lock.locked?).to be true
11
- expect(lock.expired?).to be false
12
-
13
- Timecop.travel(1_000)
14
-
15
- expect(lock.locked?).to be true
16
- expect(lock.expired?).to be false
17
- end
18
- end
19
-
20
- end