Skip to content

Commit

Permalink
Specify rails' tmp path in the Railtie
Browse files Browse the repository at this point in the history
  • Loading branch information
sauloperez committed Oct 3, 2016
1 parent 63e0b13 commit 35068ec
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 9 deletions.
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -9,3 +9,4 @@
/tmp/
.byebug_history
tags
percona_migrator_error.log
3 changes: 2 additions & 1 deletion lib/percona_migrator.rb
Expand Up @@ -16,7 +16,8 @@ class << self
attr_accessor :configuration
end

def self.config
def self.configure
self.configuration ||= Configuration.new
yield(configuration)
end
end
6 changes: 6 additions & 0 deletions lib/percona_migrator/railtie.rb
Expand Up @@ -51,5 +51,11 @@ def reconnect_with_percona
end
end
end

initializer 'percona_migrator.configure' do |app|
PerconaMigrator.configure do |config|
config.tmp_path = app.paths['tmp'].first
end
end
end
end
2 changes: 1 addition & 1 deletion lib/percona_migrator/runner.rb
Expand Up @@ -46,7 +46,7 @@ class Runner
# @param cli_generator [CliGenerator]
# @param mysql_adapter [ActiveRecord::ConnectionAdapter] it must implement
# #execute and #raw_connection
def initialize(logger, cli_generator, mysql_adapter, config = PerconaMigrator.config)
def initialize(logger, cli_generator, mysql_adapter, config = PerconaMigrator.configuration)
@logger = logger
@cli_generator = cli_generator
@mysql_adapter = mysql_adapter
Expand Down
8 changes: 4 additions & 4 deletions spec/percona_migrator/runner_spec.rb
Expand Up @@ -10,8 +10,9 @@
let(:mysql_adapter) do
instance_double(ActiveRecord::ConnectionAdapters::Mysql2Adapter)
end
let(:config) { instance_double(PerconaMigrator::Configuration, tmp_path: 'percona_migrator_error.log') }

let(:runner) { described_class.new(logger, cli_generator, mysql_adapter) }
let(:runner) { described_class.new(logger, cli_generator, mysql_adapter, config) }

describe '#query' do
end
Expand Down Expand Up @@ -47,8 +48,7 @@
end
let(:stdout) { temp_file.open }
let(:wait_thread) { instance_double(Thread, value: status) }
let(:error_log_path) { 'percona_migrator_error.log' }
let(:expected_command) { "#{command} 2> #{error_log_path}" }
let(:expected_command) { "#{command} 2> #{config.tmp_path}" }

before do
allow(Open3).to(
Expand Down Expand Up @@ -93,7 +93,7 @@
end

context 'on failure' do
let(:expected_command) { "#{command} 2> #{error_log_path}" }
let(:expected_command) { "#{command} 2> #{config.tmp_path}" }

before do
allow(Open3).to(
Expand Down
9 changes: 6 additions & 3 deletions spec/percona_migrator_spec.rb
@@ -1,8 +1,11 @@
require 'spec_helper'

describe PerconaMigrator do
describe '.config' do
subject { described_class.config }
it { is_expected.to be_a(PerconaMigrator::Configuration) }
describe '.configure' do
it 'yields the configuration object' do
expect do |b|
described_class.configure(&b)
end.to yield_with_args(kind_of(PerconaMigrator::Configuration))
end
end
end
4 changes: 4 additions & 0 deletions spec/spec_helper.rb
Expand Up @@ -32,6 +32,10 @@
RSpec.configure do |config|
ActiveRecord::Migration.verbose = false

# Needs an empty block to initialize the config with the default values
PerconaMigrator.configure do |config|
end

config.around(:each) do |example|

# Cleans up the database before each example, so the current example doesn't
Expand Down

0 comments on commit 35068ec

Please sign in to comment.