Commit 7fe837cc authored by Thong Kuah's avatar Thong Kuah

Switch ActsOnTaggable model's DB connection to ci database

We need to do two things:

1. Override the LB connection (which is based off the base class's LB)
1. Override the connection_specification_name for other Rails connection
methods that LB does not handle such as retrieve_connection
parent c9eb99bd
......@@ -9,3 +9,9 @@ ActsAsTaggableOn.tags_counter = false
# validate that counter cache is disabled
raise "Counter cache is not disabled" if
ActsAsTaggableOn::Tagging.reflections["tag"].options[:counter_cache]
# Redirects retrieve_connection to use Ci::ApplicationRecord's connection
[::ActsAsTaggableOn::Tag, ::ActsAsTaggableOn::Tagging].each do |model|
model.connection_specification_name = Ci::ApplicationRecord.connection_specification_name
model.singleton_class.delegate :connection, :sticking, to: '::Ci::ApplicationRecord'
end
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe ActsAsTaggableOn::Tag do
it 'has the same connection as Ci::ApplicationRecord' do
query = 'select current_database()'
expect(described_class.connection.execute(query).first).to eq(Ci::ApplicationRecord.connection.execute(query).first)
expect(described_class.retrieve_connection.execute(query).first).to eq(Ci::ApplicationRecord.retrieve_connection.execute(query).first)
end
it 'has the same sticking as Ci::ApplicationRecord' do
expect(described_class.sticking).to eq(Ci::ApplicationRecord.sticking)
end
end
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe ActsAsTaggableOn::Tagging do
it 'has the same connection as Ci::ApplicationRecord' do
query = 'select current_database()'
expect(described_class.connection.execute(query).first).to eq(Ci::ApplicationRecord.connection.execute(query).first)
expect(described_class.retrieve_connection.execute(query).first).to eq(Ci::ApplicationRecord.retrieve_connection.execute(query).first)
end
it 'has the same sticking as Ci::ApplicationRecord' do
expect(described_class.sticking).to eq(Ci::ApplicationRecord.sticking)
end
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