Skip to content

Commit

Permalink
Merge b9e83c9 into 0bce503
Browse files Browse the repository at this point in the history
  • Loading branch information
alfa-jpn committed Jan 16, 2019
2 parents 0bce503 + b9e83c9 commit ea145c3
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 3 deletions.
4 changes: 4 additions & 0 deletions lib/mysql2/aurora.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,16 @@ def query(*args)
# Reconnect to database and Set `@client`
# @note If client is not connected, Connect to database.
def reconnect!
query_options = (@client&.query_options&.dup || {})

begin
@client&.close
rescue StandardError
nil
end

@client = Mysql2::Aurora::ORIGINAL_CLIENT_CLASS.new(@opts)
@client.query_options.merge!(query_options)
end

# Delegate method call to client.
Expand Down
2 changes: 1 addition & 1 deletion lib/mysql2/aurora/version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ module Aurora
# Major Version: Support `mysql2` major version.
# Minor Version: Support `mysql2` minor version.
# Tiny Version: Mysql2::Aurora version.
VERSION = '0.5.0'.freeze
VERSION = '0.5.1'.freeze
end
end
15 changes: 13 additions & 2 deletions spec/mysql2/aurora_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@

it 'Set new Mysql2::Client to #client' do
expect { subject }.to change { client.client }
expect(subject).to be_instance_of(Mysql2::Aurora::ORIGINAL_CLIENT_CLASS)
expect(client.client).to be_instance_of(Mysql2::Aurora::ORIGINAL_CLIENT_CLASS)
end

it 'Close old #client' do
Expand Down Expand Up @@ -138,7 +138,18 @@

it 'Set new Mysql2::Client to #client' do
expect { subject }.to change { client.client }.from(nil)
expect(subject).to be_instance_of(Mysql2::Aurora::ORIGINAL_CLIENT_CLASS)
expect(client.client).to be_instance_of(Mysql2::Aurora::ORIGINAL_CLIENT_CLASS)
end
end

context 'When #query_options is changed' do
before :each do
expect(client.query_options[:as]).to eq(:hash)
client.query_options[:as] = :array
end

it '#query_options are inherited' do
expect { subject }.not_to change { client.query_options[:as] }.from(:array)
end
end
end
Expand Down

0 comments on commit ea145c3

Please sign in to comment.