Skip to content

Commit 50f3efa

Browse files
committed
Fix Rails 5.0 deprecation warning with Migration class usage
1 parent aa148f0 commit 50f3efa

File tree

9 files changed

+18
-11
lines changed

9 files changed

+18
-11
lines changed

gemfiles/rails_3.2.gemfile.lock

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
PATH
2-
remote: ../
2+
remote: ..
33
specs:
44
migration_tools (1.3.1)
55
activerecord (>= 3.2.6, < 5.1)
@@ -51,4 +51,4 @@ DEPENDENCIES
5151
wwtd
5252

5353
BUNDLED WITH
54-
1.12.3
54+
1.14.6

gemfiles/rails_4.2.gemfile.lock

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
PATH
2-
remote: ../
2+
remote: ..
33
specs:
44
migration_tools (1.3.1)
55
activerecord (>= 3.2.6, < 5.1)
@@ -55,4 +55,4 @@ DEPENDENCIES
5555
wwtd
5656

5757
BUNDLED WITH
58-
1.12.3
58+
1.14.6

gemfiles/rails_5.0.gemfile.lock

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
PATH
2-
remote: ../
2+
remote: ..
33
specs:
44
migration_tools (1.3.1)
55
activerecord (>= 3.2.6, < 5.1)
@@ -50,4 +50,4 @@ DEPENDENCIES
5050
wwtd
5151

5252
BUNDLED WITH
53-
1.12.5
53+
1.14.6

test/helper.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,13 @@
66
require 'active_support/all'
77
require 'migration_tools'
88

9+
MIGRATION_CLASS = if ActiveRecord::Migration.respond_to?(:[])
10+
rails_version = "#{ActiveRecord::VERSION::MAJOR}.#{ActiveRecord::VERSION::MINOR}".to_f
11+
ActiveRecord::Migration[rails_version]
12+
else
13+
ActiveRecord::Migration
14+
end
15+
916
dir = File.expand_path('../migrations', __FILE__)
1017
ActiveRecord::Migrator.migrations_paths.replace([dir])
1118
Dir.glob(File.join(dir, '*.rb')).each {|f| require f}

test/migrations/0_alpha.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
class Alpha < ActiveRecord::Migration
1+
class Alpha < MIGRATION_CLASS
22
group :before
33

44
def self.up

test/migrations/1_beta.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
class Beta < ActiveRecord::Migration
1+
class Beta < MIGRATION_CLASS
22
group :before
33

44
def self.up

test/migrations/2_delta.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
class Delta < ActiveRecord::Migration
1+
class Delta < MIGRATION_CLASS
22
group :change
33

44
def self.up

test/migrations/3_kappa.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
class Kappa < ActiveRecord::Migration
1+
class Kappa < MIGRATION_CLASS
22
def self.up
33
end
44
end

test/test_migration_tools.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ def migration_proxy(m)
4141

4242
it "runtime_checking" do
4343
begin
44-
eval("class Kappa < ActiveRecord::Migration; group 'drunk'; end")
44+
eval("class Kappa < MIGRATION_CLASS; group 'drunk'; end")
4545
fail "You should not be able to specify custom groups"
4646
rescue RuntimeError => e
4747
assert e.message.index('Invalid group "drunk" - valid groups are ["before", "during", "after", "change"]')

0 commit comments

Comments
 (0)