Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PATH
remote: .
specs:
janus-ar (8.0.0)
janus-ar (8.0.1)
activerecord (>= 8.0, < 9.0)

GEM
Expand Down
5 changes: 5 additions & 0 deletions lib/janus-ar/adapter_extensions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,11 @@ def reconnect!(...)
super
end

def discard!(...)
replica_connection.discard!(...)
super
end

def disconnect!(...)
replica_connection.disconnect!(...)
super
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,12 @@
end
end

describe 'Connection lifecycle' do
let(:replica_adapter_class) { ActiveRecord::ConnectionAdapters::Mysql2Adapter }

it_behaves_like 'an adapter forwarding lifecycle calls'
end

describe 'Integration tests' do
let(:table_name) { 'table_name_mysql2' }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,12 @@
end
end

describe 'Connection lifecycle' do
let(:replica_adapter_class) { ActiveRecord::ConnectionAdapters::TrilogyAdapter }

it_behaves_like 'an adapter forwarding lifecycle calls'
end

describe 'Integration tests' do
let(:table_name) { 'table_name_trilogy' }

Expand Down
17 changes: 17 additions & 0 deletions spec/shared_examples/an_adapter_forwarding_lifecycle_calls.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# frozen_string_literal: true

RSpec.shared_examples 'an adapter forwarding lifecycle calls' do
let(:replica_connection) { instance_double(replica_adapter_class) }

before do
allow(subject).to receive(:replica_connection).and_return(replica_connection)
end

it 'forwards discard! to the replica connection' do
allow(replica_connection).to receive(:discard!)

subject.discard!

expect(replica_connection).to have_received(:discard!)
end
end
1 change: 1 addition & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
ActiveRecord::ConnectionAdapters.register("janus_mysql2", "ActiveRecord::ConnectionAdapters::JanusMysql2Adapter")

require './spec/shared_examples/a_mysql_like_server.rb'
require './spec/shared_examples/an_adapter_forwarding_lifecycle_calls.rb'

class QueryLogger
def initialize
Expand Down
Loading