Skip to content

Commit

Permalink
Merge pull request cookpad#11 from winebarrel/support_ar61
Browse files Browse the repository at this point in the history
Support ActiveRecord 6.1
  • Loading branch information
winebarrel committed Dec 30, 2020
2 parents f860521 + f4bfa66 commit edb61f4
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 5 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,12 @@ jobs:
- gemfiles/ar51.gemfile
- gemfiles/ar52.gemfile
- gemfiles/ar60.gemfile
- gemfiles/ar61.gemfile
exclude:
- ruby: 2.4
gemfile: gemfiles/ar60.gemfile
- ruby: 2.4
gemfile: gemfiles/ar61.gemfile

steps:
- uses: actions/checkout@v2
Expand Down
4 changes: 4 additions & 0 deletions Appraisals
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,7 @@ end
appraise 'ar60' do
gem 'activerecord', '~> 6.0.0'
end

appraise 'ar61' do
gem 'activerecord', '~> 6.1.0'
end
7 changes: 7 additions & 0 deletions gemfiles/ar61.gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# This file was generated by Appraisal

source "https://rubygems.org"

gem "activerecord", "~> 6.1.0"

gemspec path: "../"
6 changes: 3 additions & 3 deletions spec/migration_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
schema.sub!(', using: :btree', '') # for Active Record 5.0

expect(schema).to match_ruby erbh(<<-ERB)
create_table "geoms", force: :cascade, options: #{MysqlHelper::TABLE_OPTIONS.inspect} do |t|
create_table "geoms", force: :cascade <%= MysqlHelper::TABLE_OPTIONS ? %s!, options: "#{MysqlHelper::TABLE_OPTIONS}"! : '' %> do |t|
t.geometry "location", null: false
t.string "name"
t.index ["location"], name: "idx_location", type: :spatial <%= ActiveRecord.gem_version >= Gem::Version.new('5.2') ? ', length: 32' : '' %>
Expand All @@ -36,7 +36,7 @@
end

expect(@mysql_helper.dump).to match_ruby erbh(<<~ERB)
create_table "geoms", force: :cascade, options: #{MysqlHelper::TABLE_OPTIONS.inspect} do |t|
create_table "geoms", force: :cascade <%= MysqlHelper::TABLE_OPTIONS ? %s!, options: "#{MysqlHelper::TABLE_OPTIONS}"! : '' %> do |t|
t.geometry "location", null: false
t.index ["location"], name: "idx_location", type: :spatial <%= ActiveRecord.gem_version >= Gem::Version.new('5.2') ? ', length: 32' : '' %>
end
Expand All @@ -48,7 +48,7 @@
ActiveRecord::Migration.add_index :geoms, 'location', name: 'idx_location', type: :spatial

expect(@mysql_helper.dump).to match_ruby erbh(<<~ERB)
create_table "geoms", force: :cascade, options: #{MysqlHelper::TABLE_OPTIONS.inspect} do |t|
create_table "geoms", force: :cascade <%= MysqlHelper::TABLE_OPTIONS ? %s!, options: "#{MysqlHelper::TABLE_OPTIONS}"! : '' %> do |t|
t.geometry "location", null: false
t.index ["location"], name: "idx_location", type: :spatial <%= ActiveRecord.gem_version >= Gem::Version.new('5.2') ? ', length: 32' : '' %>
end
Expand Down
13 changes: 11 additions & 2 deletions spec/mysql_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,13 @@ class MysqlHelper
MYSQL_USER = ENV['ARMG_TEST_MYSQL_USER'] || 'root'
MYSQL_DB = ENV['ARMG_TEST_MYSQL_DB'] || 'armg_test'
MYSQL_ENGINE = ENV['ARMG_TEST_MYSQL_ENGINE'] || 'MyISAM'
TABLE_OPTIONS = "ENGINE=#{MYSQL_ENGINE} DEFAULT CHARSET=utf8"
TABLE_OPTIONS = if ActiveRecord.gem_version < Gem::Version.new('6.1.0')
"ENGINE=#{MYSQL_ENGINE} DEFAULT CHARSET=utf8"
elsif MYSQL_ENGINE == 'InnoDB'
nil
else
"ENGINE=#{MYSQL_ENGINE}"
end

def initialize
@mysql = Mysql2::Client.new(
Expand All @@ -23,7 +29,10 @@ def dump
buf = StringIO.new
ActiveRecord::SchemaDumper.dump(ActiveRecord::Base.connection, buf)
buf = buf.string.sub(/\A.*\bActiveRecord::Schema\.define\(version: \d+\) do/m, '').sub(/end\s*\z/, '')
buf.lines.map { |l| l.sub(/\A /, '') }.join.strip
schema = buf.lines.map { |l| l.sub(/\A /, '') }.join.strip

# NOTE: Fix for ActiveRecord 6.1
schema.gsub(', charset: "latin1"', '')
end

def create_table
Expand Down

0 comments on commit edb61f4

Please sign in to comment.