Skip to content

Commit

Permalink
Use correct migration class in acceptance tests
Browse files Browse the repository at this point in the history
In Rails 5.0, migration classes changed so that they were versioned:
instead of inheriting from `ActiveRecord::Migration`, you inherited from
`ActiveRecord::Migration[5.0]`. The old way wasn't removed, however --
that is, until Rails 5.1. Hence, our acceptance tests that use the old
style no longer work under the 5.1 Appraisal.
  • Loading branch information
mcmire committed Sep 28, 2017
1 parent 5fec4cd commit b310986
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 2 deletions.
2 changes: 1 addition & 1 deletion spec/acceptance/multiple_libraries_integration_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
create_rails_application

write_file 'db/migrate/1_create_users.rb', <<-FILE
class CreateUsers < ActiveRecord::Migration
class CreateUsers < #{migration_class_name}
def self.up
create_table :users do |t|
t.string :name
Expand Down
2 changes: 1 addition & 1 deletion spec/acceptance/rails_integration_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
create_rails_application

write_file 'db/migrate/1_create_users.rb', <<-FILE
class CreateUsers < ActiveRecord::Migration
class CreateUsers < #{migration_class_name}
def self.up
create_table :users do |t|
t.string :name
Expand Down
2 changes: 2 additions & 0 deletions spec/support/acceptance/helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
require_relative 'helpers/command_helpers'
require_relative 'helpers/gem_helpers'
require_relative 'helpers/n_unit_helpers'
require_relative 'helpers/rails_migration_helpers'
require_relative 'helpers/rails_version_helpers'
require_relative 'helpers/rspec_helpers'
require_relative 'helpers/ruby_version_helpers'
Expand All @@ -23,6 +24,7 @@ def self.configure_example_group(example_group)
include CommandHelpers
include GemHelpers
include NUnitHelpers
include RailsMigrationHelpers
include RailsVersionHelpers
include RspecHelpers
include RubyVersionHelpers
Expand Down
21 changes: 21 additions & 0 deletions spec/support/acceptance/helpers/rails_migration_helpers.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
require_relative 'gem_helpers'

module AcceptanceTests
module RailsMigrationHelpers
include RailsVersionHelpers

def migration_class_name
if rails_version >= 5
"ActiveRecord::Migration[#{rails_version_for_migration}]"
else
'ActiveRecord::Migration'
end
end

private

def rails_version_for_migration
rails_version.to_s.split('.')[0..1].join('.')
end
end
end

0 comments on commit b310986

Please sign in to comment.