Commit 5ffd8707 authored by Jasper Maes's avatar Jasper Maes

Rails 5 fix NoMethodError: undefined method 'message' for nil:NilClass in host_spec.rb

parent 5a2d9d67
---
title: 'Rails 5 fix NoMethodError: undefined method ''message'' for nil:NilClass in
host_spec.rb'
merge_request: 6589
author: Jasper Maes
type: fixed
......@@ -12,6 +12,24 @@ describe Gitlab::Database::LoadBalancing::Host, :postgresql do
.and_return(ActiveRecord::Base.connection_pool)
end
def raise_and_wrap(wrapper, original)
raise original
rescue original.class
raise wrapper.new('boom')
end
def wrapped_exception(wrapper, original)
if Gitlab.rails5?
begin
raise_and_wrap(wrapper, original.new)
rescue wrapper => error
error
end
else
wrapper.new('boom', original.new)
end
end
describe '#connection' do
it 'returns a connection from the pool' do
expect(host.pool).to receive(:connection)
......@@ -95,11 +113,11 @@ describe Gitlab::Database::LoadBalancing::Host, :postgresql do
context 'when the replica is not online' do
it 'returns false when ActionView::Template::Error is raised' do
error = StandardError.new
wrapped_error = wrapped_exception(ActionView::Template::Error, StandardError)
allow(host)
.to receive(:check_replica_status?)
.and_raise(ActionView::Template::Error.new('boom', error))
.and_raise(wrapped_error)
expect(host).not_to be_online
end
......@@ -274,9 +292,11 @@ describe Gitlab::Database::LoadBalancing::Host, :postgresql do
end
it 'returns nil when the database connection fails' do
wrapped_error = wrapped_exception(ActionView::Template::Error, StandardError)
allow(host)
.to receive(:connection)
.and_raise(ActionView::Template::Error.new('boom', StandardError.new))
.and_raise(wrapped_error)
expect(host.replication_lag_size).to be_nil
end
......@@ -311,9 +331,11 @@ describe Gitlab::Database::LoadBalancing::Host, :postgresql do
end
it 'returns false when the connection fails' do
wrapped_error = wrapped_exception(ActionView::Template::Error, StandardError)
allow(host)
.to receive(:connection)
.and_raise(ActionView::Template::Error.new('boom', StandardError.new))
.and_raise(wrapped_error)
expect(host.caught_up?('foo')).to eq(false)
end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment