From 175368c2c965bc33c374f249ae5909f4c70f6af8 Mon Sep 17 00:00:00 2001 From: ydakuka <yauheni.dakuka@gmail.com> Date: Thu, 27 Jul 2017 00:54:25 +0300 Subject: [PATCH] specify rails version --- .../geocoder/maxmind/geolite_city_generator.rb | 2 ++ .../geocoder/maxmind/geolite_country_generator.rb | 2 ++ .../maxmind/templates/migration/geolite_city.rb | 2 +- .../templates/migration/geolite_country.rb | 2 +- lib/generators/geocoder/migration_version.rb | 15 +++++++++++++++ test/db/migrate/001_create_test_schema.rb | 7 ++++++- 6 files changed, 27 insertions(+), 3 deletions(-) create mode 100644 lib/generators/geocoder/migration_version.rb diff --git a/lib/generators/geocoder/maxmind/geolite_city_generator.rb b/lib/generators/geocoder/maxmind/geolite_city_generator.rb index 2743957a..98589755 100644 --- a/lib/generators/geocoder/maxmind/geolite_city_generator.rb +++ b/lib/generators/geocoder/maxmind/geolite_city_generator.rb @@ -1,10 +1,12 @@ require 'rails/generators/migration' +require 'generators/geocoder/migration_version' module Geocoder module Generators module Maxmind class GeoliteCityGenerator < Rails::Generators::Base include Rails::Generators::Migration + include Generators::MigrationVersion source_root File.expand_path('../templates', __FILE__) diff --git a/lib/generators/geocoder/maxmind/geolite_country_generator.rb b/lib/generators/geocoder/maxmind/geolite_country_generator.rb index c9e4bc95..6aa07f71 100644 --- a/lib/generators/geocoder/maxmind/geolite_country_generator.rb +++ b/lib/generators/geocoder/maxmind/geolite_country_generator.rb @@ -1,10 +1,12 @@ require 'rails/generators/migration' +require 'generators/geocoder/migration_version' module Geocoder module Generators module Maxmind class GeoliteCountryGenerator < Rails::Generators::Base include Rails::Generators::Migration + include Generators::MigrationVersion source_root File.expand_path('../templates', __FILE__) diff --git a/lib/generators/geocoder/maxmind/templates/migration/geolite_city.rb b/lib/generators/geocoder/maxmind/templates/migration/geolite_city.rb index bf875206..b4068e04 100644 --- a/lib/generators/geocoder/maxmind/templates/migration/geolite_city.rb +++ b/lib/generators/geocoder/maxmind/templates/migration/geolite_city.rb @@ -1,4 +1,4 @@ -class GeocoderMaxmindGeoliteCity < ActiveRecord::Migration +class GeocoderMaxmindGeoliteCity < ActiveRecord::Migration<%= migration_version %> def self.up create_table :maxmind_geolite_city_blocks, id: false do |t| t.column :start_ip_num, :bigint, null: false diff --git a/lib/generators/geocoder/maxmind/templates/migration/geolite_country.rb b/lib/generators/geocoder/maxmind/templates/migration/geolite_country.rb index 5b3e1bf3..e7dc982a 100644 --- a/lib/generators/geocoder/maxmind/templates/migration/geolite_country.rb +++ b/lib/generators/geocoder/maxmind/templates/migration/geolite_country.rb @@ -1,4 +1,4 @@ -class GeocoderMaxmindGeoliteCountry < ActiveRecord::Migration +class GeocoderMaxmindGeoliteCountry < ActiveRecord::Migration<%= migration_version %> def self.up create_table :maxmind_geolite_country, id: false do |t| t.column :start_ip, :string diff --git a/lib/generators/geocoder/migration_version.rb b/lib/generators/geocoder/migration_version.rb new file mode 100644 index 00000000..71711eb4 --- /dev/null +++ b/lib/generators/geocoder/migration_version.rb @@ -0,0 +1,15 @@ +module Geocoder + module Generators + module MigrationVersion + def rails_5? + Rails::VERSION::MAJOR == 5 + end + + def migration_version + if rails_5? + "[#{Rails::VERSION::MAJOR}.#{Rails::VERSION::MINOR}]" + end + end + end + end +end diff --git a/test/db/migrate/001_create_test_schema.rb b/test/db/migrate/001_create_test_schema.rb index aca50cff..649f99b8 100644 --- a/test/db/migrate/001_create_test_schema.rb +++ b/test/db/migrate/001_create_test_schema.rb @@ -1,5 +1,10 @@ # CreateTestSchema creates the tables used in test_helper.rb -class CreateTestSchema < ActiveRecord::Migration + +superclass = ActiveRecord::Migration +# TODO: Inherit from the 5.0 Migration class directly when we drop support for Rails 4. +superclass = ActiveRecord::Migration[5.0] if superclass.respond_to?(:[]) + +class CreateTestSchema < superclass def self.up [ :places, -- GitLab