Skip to content

Commit 281a9bb

Browse files
author
Vivek Bisen
committed
fix tests
1 parent d152dd6 commit 281a9bb

File tree

6 files changed

+60
-19
lines changed

6 files changed

+60
-19
lines changed

.pryrc

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
if defined?(PryByebug)
2+
Pry.commands.alias_command 'c', 'continue'
3+
Pry.commands.alias_command 's', 'step'
4+
Pry.commands.alias_command 'n', 'next'
5+
Pry.commands.alias_command 'f', 'finish'
6+
Pry.commands.alias_command 'w', 'pry-backtrace'
7+
8+
Pry::Commands.command(/^$/, 'repeat last command') do
9+
pry_instance.run_command Pry.history.to_a.last
10+
end
11+
end

departure.gemspec

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,6 @@ Gem::Specification.new do |spec|
3030
spec.add_development_dependency 'rake', '~> 10.0'
3131
spec.add_development_dependency 'rspec', '~> 3.4', '>= 3.4.0'
3232
spec.add_development_dependency 'rspec-its', '~> 1.2'
33-
spec.add_development_dependency 'byebug', '~> 8.2', '>= 8.2.1'
33+
spec.add_development_dependency 'pry-byebug'
3434
spec.add_development_dependency 'climate_control', '~> 0.0.3'
3535
end

lib/active_record/connection_adapters/percona_adapter.rb

+5-2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,10 @@ module ConnectionHandling
99
# Establishes a connection to the database that's used by all Active
1010
# Record objects.
1111
def percona_connection(config)
12-
config[:username] = 'root' if config[:username].nil?
12+
if config[:username].nil?
13+
config = config.dup if config.frozen?
14+
config[:username] = 'root'
15+
end
1316
mysql2_connection = mysql2_connection(config)
1417

1518
connection_details = Departure::ConnectionDetails.new(config)
@@ -75,7 +78,7 @@ def initialize(connection, _logger, connection_options, _config)
7578
end
7679

7780
def write_query?(sql) # :nodoc:
78-
!build_read_query_regexp(
81+
!ActiveRecord::ConnectionAdapters::AbstractAdapter.build_read_query_regexp(
7982
:desc, :describe, :set, :show, :use
8083
).match?(sql)
8184
end

spec/active_record/connection_adapters/percona_adapter_spec.rb

+31-9
Original file line numberDiff line numberDiff line change
@@ -101,24 +101,46 @@
101101
describe '#add_index' do
102102
let(:table_name) { :foo }
103103
let(:column_name) { :bar_id }
104-
let(:options) { {} }
105-
let(:sql) { 'ADD index_type INDEX `index_name` (`bar_id`)' }
104+
let(:index_name) { 'index_name' }
105+
let(:options) { {type: 'index_type'} }
106+
let(:index_type) { options[:type].upcase }
107+
let(:sql) { 'ADD index_type INDEX `index_name` (bar_id)' }
108+
let(:index_options) do
109+
if ActiveRecord::VERSION::STRING >= '6.1'
110+
[
111+
ActiveRecord::ConnectionAdapters::IndexDefinition.new(
112+
table_name,
113+
index_name,
114+
nil,
115+
[column_name],
116+
**options
117+
),
118+
nil,
119+
false
120+
]
121+
else
122+
[index_name, index_type, "#{column_name}"]
123+
end
124+
end
125+
126+
let(:expected_sql) do
127+
if ActiveRecord::VERSION::STRING >= '6.1'
128+
"CREATE INDEX_TYPE INDEX `#{index_name}` ON `#{table_name}` (`#{column_name}`)"
129+
else
130+
"ALTER TABLE `#{table_name}` ADD #{index_type} INDEX `#{index_name}` (#{column_name})"
131+
end
132+
end
106133

107134
before do
108135
allow(adapter).to(
109136
receive(:add_index_options)
110137
.with(table_name, column_name, options)
111-
.and_return(['index_name', 'index_type', "`#{column_name}`"])
138+
.and_return(index_options)
112139
)
113140
end
114141

115142
it 'passes the built SQL to #execute' do
116-
expect(adapter).to(
117-
receive(:execute)
118-
.with(
119-
"ALTER TABLE `#{table_name}` ADD index_type INDEX `index_name` (`bar_id`)"
120-
)
121-
)
143+
expect(adapter).to receive(:execute).with(expected_sql)
122144
adapter.add_index(table_name, column_name, options)
123145
end
124146
end

spec/integration_spec.rb

+11-6
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,14 @@ class Comment < ActiveRecord::Base; end
99
end
1010

1111
let(:direction) { :up }
12+
let(:pool) { ActiveRecord::Base.connection_pool }
13+
let(:spec_config) do
14+
if ActiveRecord::VERSION::STRING >= '6.1'
15+
pool.connection.instance_variable_get(:@config)
16+
else
17+
pool.spec.config
18+
end
19+
end
1220

1321
it 'has a version number' do
1422
expect(Departure::VERSION).not_to be nil
@@ -51,8 +59,7 @@ class Comment < ActiveRecord::Base; end
5159

5260
it 'reconnects to the database using PerconaAdapter' do
5361
ActiveRecord::Migrator.new(direction, migration_fixtures, ActiveRecord::SchemaMigration, 1).migrate
54-
expect(ActiveRecord::Base.connection_pool.spec.config[:adapter])
55-
.to eq('percona')
62+
expect(spec_config[:adapter]).to eq('percona')
5663
end
5764

5865
context 'when a username is provided' do
@@ -68,8 +75,7 @@ class Comment < ActiveRecord::Base; end
6875

6976
it 'uses the provided username' do
7077
ActiveRecord::Migrator.new(direction, migration_fixtures, ActiveRecord::SchemaMigration, 1).migrate
71-
expect(ActiveRecord::Base.connection_pool.spec.config[:username])
72-
.to eq('root')
78+
expect(spec_config[:username]).to eq('root')
7379
end
7480
end
7581

@@ -85,8 +91,7 @@ class Comment < ActiveRecord::Base; end
8591

8692
it 'uses root' do
8793
ActiveRecord::Migrator.new(direction, migration_fixtures, ActiveRecord::SchemaMigration, 1).migrate
88-
expect(ActiveRecord::Base.connection_pool.spec.config[:username])
89-
.to eq('root')
94+
expect(spec_config[:username]).to eq('root')
9095
end
9196
end
9297

spec/lhm/column_with_sql_spec.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
require 'spec_helper'
22

33
describe Lhm::ColumnWithSql do
4-
let(:name) { :some_field_name }
4+
let(:name) { "some_field_name" }
55
let(:column) { described_class.new(name, definition) }
66

77
describe '#attributes' do

0 commit comments

Comments
 (0)