pt-osc 0.1.2 → 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -7,6 +7,7 @@ rvm:
7
7
  - 1.9.3
8
8
  - 2.0.0
9
9
  - 2.1.2
10
+ - 2.1
10
11
  env:
11
12
  - CODECLIMATE_REPO_TOKEN=0b58d4e91bfac6ed6e48b31606f6792598a3a59c27bded19d58ef8406c09f57c
12
13
  cache:
@@ -1,3 +1,8 @@
1
+ ## 0.1.3
2
+
3
+ - fix for loading percona config
4
+ - added test coverage for loading run_mode from config
5
+
1
6
  ## 0.1.2
2
7
 
3
8
  - report `adapter_name` as `mysql2` for compatibility with gems that check it (e.g. [mceachen/with_advisory_lock](https://github.com/mceachen/with_advisory_lock))
data/README.md CHANGED
@@ -53,6 +53,7 @@ This gem is not considered production ready. There will be bugs.
53
53
  - Ruby 1.9.3
54
54
  - Ruby 2.0.0
55
55
  - Ruby 2.1.2
56
+ - Ruby 2.1 latest
56
57
 
57
58
  Support for other versions of Ruby or ActiveRecord is unknown and not guaranteed.
58
59
 
@@ -155,8 +155,7 @@ module ActiveRecord
155
155
  end
156
156
 
157
157
  def database_config
158
- # @TODO better way to config?
159
- @connection.instance_variable_get(:@config) || ActiveRecord::Base.connection_config
158
+ @db_config ||= (@connection.instance_variable_get(:@config) || ActiveRecord::Base.connection_config).with_indifferent_access
160
159
  end
161
160
 
162
161
  def percona_config
@@ -1,5 +1,5 @@
1
1
  module Pt
2
2
  module Osc
3
- VERSION = '0.1.2'
3
+ VERSION = '0.1.3'
4
4
  end
5
5
  end
@@ -1,6 +1,26 @@
1
- test:
1
+ test: &test
2
2
  pool: 5
3
3
  host: localhost
4
4
  username: root
5
5
  database: pt_osc_test
6
6
  reconnect: true
7
+
8
+ test_print:
9
+ <<: *test
10
+ percona:
11
+ run_mode: print
12
+
13
+ test_execute:
14
+ <<: *test
15
+ percona:
16
+ run_mode: execute
17
+
18
+ test_print_string:
19
+ <<: *test
20
+ percona:
21
+ run_mode: 'print'
22
+
23
+ test_execute_string:
24
+ <<: *test
25
+ percona:
26
+ run_mode: 'execute'
@@ -12,8 +12,8 @@ require 'mocha'
12
12
 
13
13
  Rails.backtrace_cleaner.remove_silencers!
14
14
 
15
- def test_spec
16
- test_spec = YAML.load_file(Rails.root.join(*%w(.. config database.yml)))['test']
15
+ def test_spec(key = 'test')
16
+ test_spec = YAML.load_file(Rails.root.join(*%w(.. config database.yml)))[key]
17
17
  test_spec['adapter'] = 'mysql_pt_osc'
18
18
  test_spec
19
19
  end
@@ -9,10 +9,15 @@ class PtOscMigrationUnitTest < Test::Unit::TestCase
9
9
  context '#percona_command' do
10
10
  context 'connected to a pt-osc database' do
11
11
  setup do
12
+ @old_connection = @migration.instance_variable_get(:@connection)
12
13
  ActiveRecord::Base.establish_connection(test_spec)
13
14
  @migration.instance_variable_set(:@connection, ActiveRecord::Base.connection)
14
15
  end
15
16
 
17
+ teardown do
18
+ @migration.instance_variable_set(:@connection, @old_connection)
19
+ end
20
+
16
21
  should 'only include flags in PERCONA_FLAGS' do
17
22
  flag = ActiveRecord::PtOscMigration.percona_flags.first
18
23
  begin
@@ -76,6 +81,94 @@ class PtOscMigrationUnitTest < Test::Unit::TestCase
76
81
  end
77
82
  end
78
83
  end
84
+
85
+ context 'connected to a pt-osc database in print mode' do
86
+ setup do
87
+ @old_connection = @migration.instance_variable_get(:@connection)
88
+ ActiveRecord::Base.establish_connection(test_spec('test_print'))
89
+ @migration.instance_variable_set(:@connection, ActiveRecord::Base.connection)
90
+ end
91
+
92
+ teardown do
93
+ @migration.instance_variable_set(:@connection, @old_connection)
94
+ end
95
+
96
+ should 'have print as the run_mode' do
97
+ assert_equal 'print', @migration.send(:percona_config)[:run_mode]
98
+ end
99
+
100
+ should 'call print_pt_osc' do
101
+ @migration.expects(:print_pt_osc).once.returns(nil)
102
+ @migration.expects(:execute_pt_osc).never
103
+ @migration.migrate(:up)
104
+ end
105
+ end
106
+
107
+ context 'connected to a pt-osc database in print mode as string' do
108
+ setup do
109
+ @old_connection = @migration.instance_variable_get(:@connection)
110
+ ActiveRecord::Base.establish_connection(test_spec('test_print_string'))
111
+ @migration.instance_variable_set(:@connection, ActiveRecord::Base.connection)
112
+ end
113
+
114
+ teardown do
115
+ @migration.instance_variable_set(:@connection, @old_connection)
116
+ end
117
+
118
+ should 'have print as the run_mode' do
119
+ assert_equal 'print', @migration.send(:percona_config)[:run_mode]
120
+ end
121
+
122
+ should 'call print_pt_osc' do
123
+ @migration.expects(:print_pt_osc).once.returns(nil)
124
+ @migration.expects(:execute_pt_osc).never
125
+ @migration.migrate(:up)
126
+ end
127
+ end
128
+
129
+ context 'connected to a pt-osc database in execute mode' do
130
+ setup do
131
+ @old_connection = @migration.instance_variable_get(:@connection)
132
+ ActiveRecord::Base.establish_connection(test_spec('test_execute'))
133
+ @migration.instance_variable_set(:@connection, ActiveRecord::Base.connection)
134
+ end
135
+
136
+ teardown do
137
+ @migration.instance_variable_set(:@connection, @old_connection)
138
+ end
139
+
140
+ should 'have execute as the run_mode' do
141
+ assert_equal 'execute', @migration.send(:percona_config)[:run_mode]
142
+ end
143
+
144
+ should 'call execute_pt_osc' do
145
+ @migration.expects(:execute_pt_osc).once.returns(nil)
146
+ @migration.expects(:print_pt_osc).never
147
+ @migration.migrate(:up)
148
+ end
149
+ end
150
+
151
+ context 'connected to a pt-osc database in execute mode as string' do
152
+ setup do
153
+ @old_connection = @migration.instance_variable_get(:@connection)
154
+ ActiveRecord::Base.establish_connection(test_spec('test_execute_string'))
155
+ @migration.instance_variable_set(:@connection, ActiveRecord::Base.connection)
156
+ end
157
+
158
+ teardown do
159
+ @migration.instance_variable_set(:@connection, @old_connection)
160
+ end
161
+
162
+ should 'have execute as the run_mode' do
163
+ assert_equal 'execute', @migration.send(:percona_config)[:run_mode]
164
+ end
165
+
166
+ should 'call execute_pt_osc' do
167
+ @migration.expects(:execute_pt_osc).once.returns(nil)
168
+ @migration.expects(:print_pt_osc).never
169
+ @migration.migrate(:up)
170
+ end
171
+ end
79
172
  end
80
173
 
81
174
  context '#make_path_absolute' do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pt-osc
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-08-18 00:00:00.000000000 Z
12
+ date: 2014-10-05 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler
@@ -246,7 +246,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
246
246
  version: '0'
247
247
  segments:
248
248
  - 0
249
- hash: -4362070600124829883
249
+ hash: -738209304282433145
250
250
  required_rubygems_version: !ruby/object:Gem::Requirement
251
251
  none: false
252
252
  requirements:
@@ -255,7 +255,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
255
255
  version: '0'
256
256
  segments:
257
257
  - 0
258
- hash: -4362070600124829883
258
+ hash: -738209304282433145
259
259
  requirements: []
260
260
  rubyforge_project:
261
261
  rubygems_version: 1.8.23