Fix Lint/ConstantDefinitionInBlock cop (#24763)
This commit is contained in:
parent
8b636a29c6
commit
3df665fd23
9 changed files with 120 additions and 118 deletions
|
@ -3,30 +3,32 @@
|
|||
require 'rails_helper'
|
||||
|
||||
describe ConnectionPool::SharedTimedStack do
|
||||
class MiniConnection
|
||||
attr_reader :site
|
||||
subject { described_class.new(5) { |site| mini_connection_class.new(site) } }
|
||||
|
||||
def initialize(site)
|
||||
@site = site
|
||||
let(:mini_connection_class) do
|
||||
Class.new do
|
||||
attr_reader :site
|
||||
|
||||
def initialize(site)
|
||||
@site = site
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
subject { described_class.new(5) { |site| MiniConnection.new(site) } }
|
||||
|
||||
describe '#push' do
|
||||
it 'keeps the connection in the stack' do
|
||||
subject.push(MiniConnection.new('foo'))
|
||||
subject.push(mini_connection_class.new('foo'))
|
||||
expect(subject.size).to eq 1
|
||||
end
|
||||
end
|
||||
|
||||
describe '#pop' do
|
||||
it 'returns a connection' do
|
||||
expect(subject.pop('foo')).to be_a MiniConnection
|
||||
expect(subject.pop('foo')).to be_a mini_connection_class
|
||||
end
|
||||
|
||||
it 'returns the same connection that was pushed in' do
|
||||
connection = MiniConnection.new('foo')
|
||||
connection = mini_connection_class.new('foo')
|
||||
subject.push(connection)
|
||||
expect(subject.pop('foo')).to be connection
|
||||
end
|
||||
|
@ -36,8 +38,8 @@ describe ConnectionPool::SharedTimedStack do
|
|||
end
|
||||
|
||||
it 'repurposes a connection for a different site when maximum amount is reached' do
|
||||
5.times { subject.push(MiniConnection.new('foo')) }
|
||||
expect(subject.pop('bar')).to be_a MiniConnection
|
||||
5.times { subject.push(mini_connection_class.new('foo')) }
|
||||
expect(subject.pop('bar')).to be_a mini_connection_class
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -47,14 +49,14 @@ describe ConnectionPool::SharedTimedStack do
|
|||
end
|
||||
|
||||
it 'returns false when there are connections on the stack' do
|
||||
subject.push(MiniConnection.new('foo'))
|
||||
subject.push(mini_connection_class.new('foo'))
|
||||
expect(subject.empty?).to be false
|
||||
end
|
||||
end
|
||||
|
||||
describe '#size' do
|
||||
it 'returns the number of connections on the stack' do
|
||||
2.times { subject.push(MiniConnection.new('foo')) }
|
||||
2.times { subject.push(mini_connection_class.new('foo')) }
|
||||
expect(subject.size).to eq 2
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue