From 6477d22a52bc5be7b48dc3a12310907e054aa95c Mon Sep 17 00:00:00 2001 From: Maarten Claes Date: Sat, 31 Mar 2018 00:12:12 +0200 Subject: [PATCH 01/14] Remove .ruby-version file --- .ruby-version | 1 - 1 file changed, 1 deletion(-) delete mode 100644 .ruby-version diff --git a/.ruby-version b/.ruby-version deleted file mode 100644 index eca07e4..0000000 --- a/.ruby-version +++ /dev/null @@ -1 +0,0 @@ -2.1.2 From c70b85b67afe35a620ec1020f244aba3f3b8a66f Mon Sep 17 00:00:00 2001 From: Maarten Claes Date: Sun, 1 Apr 2018 14:38:07 +0200 Subject: [PATCH 02/14] gemspec: Allow a newer versions of RSpec (3.7 in this case) --- native_enum.gemspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/native_enum.gemspec b/native_enum.gemspec index 073155c..2da0bda 100644 --- a/native_enum.gemspec +++ b/native_enum.gemspec @@ -20,7 +20,7 @@ Gem::Specification.new do |s| s.add_development_dependency "bundler" s.add_development_dependency "mysql2", "~> 0.3.11" s.add_development_dependency "sqlite3", "~>1.3.4" - s.add_development_dependency "rspec", "~> 3.1.0" + s.add_development_dependency "rspec", "~> 3" s.files = `git ls-files`.split("\n") s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n") From 6524e77ac2587732103ff5cf6aa115aa2de71755 Mon Sep 17 00:00:00 2001 From: Maarten Claes Date: Sun, 1 Apr 2018 14:39:52 +0200 Subject: [PATCH 03/14] Stop supporting rails < 4.1 The specs for this version were failing with the following exception: Mysql2::Error: All parts of a PRIMARY KEY must be NOT NULL; if you need NULL in a key, use UNIQUE instead: CREATE TABLE `balloons` ( `id` int(11) DEFAULT NULL auto_increment PRIMARY KEY, `color` enum('red','gold') DEFAULT 'gold' NOT NULL, `size` enum('small','medium','large') ) ENGINE=InnoDB --- spec/Gemfile.rails_3_0 | 4 ---- spec/Gemfile.rails_3_1 | 4 ---- spec/Gemfile.rails_3_2 | 4 ---- spec/Gemfile.rails_4_0 | 4 ---- 4 files changed, 16 deletions(-) delete mode 100644 spec/Gemfile.rails_3_0 delete mode 100644 spec/Gemfile.rails_3_1 delete mode 100644 spec/Gemfile.rails_3_2 delete mode 100644 spec/Gemfile.rails_4_0 diff --git a/spec/Gemfile.rails_3_0 b/spec/Gemfile.rails_3_0 deleted file mode 100644 index c9e9c74..0000000 --- a/spec/Gemfile.rails_3_0 +++ /dev/null @@ -1,4 +0,0 @@ -source "http://rubygems.org" -gemspec :path => ".." -gem "mysql2", "~> 0.2.0" -gem "activerecord", "~> 3.0.20" diff --git a/spec/Gemfile.rails_3_1 b/spec/Gemfile.rails_3_1 deleted file mode 100644 index 2b262f2..0000000 --- a/spec/Gemfile.rails_3_1 +++ /dev/null @@ -1,4 +0,0 @@ -source "http://rubygems.org" -gemspec :path => ".." -gem "mysql2", "~> 0.3.11" -gem "activerecord", "~> 3.1.12" diff --git a/spec/Gemfile.rails_3_2 b/spec/Gemfile.rails_3_2 deleted file mode 100644 index 496dfbc..0000000 --- a/spec/Gemfile.rails_3_2 +++ /dev/null @@ -1,4 +0,0 @@ -source "http://rubygems.org" -gemspec :path => ".." -gem "mysql2", "~> 0.3.11" -gem "activerecord", "~> 3.2.13" diff --git a/spec/Gemfile.rails_4_0 b/spec/Gemfile.rails_4_0 deleted file mode 100644 index eba9d40..0000000 --- a/spec/Gemfile.rails_4_0 +++ /dev/null @@ -1,4 +0,0 @@ -source "http://rubygems.org" -gemspec :path => ".." -gem "mysql2", "~> 0.3.11" -gem "activerecord", "~> 4.0.0", "< 4.1.0" From fce8ccfbfb5463f5395d29c3f48c880e56902a4a Mon Sep 17 00:00:00 2001 From: Maarten Claes Date: Sat, 31 Mar 2018 15:18:44 +0200 Subject: [PATCH 04/14] Specs: Use `verbose = false` instead of overriding `$stdout` Same effect, but limited to ActiveRecord's logging only --- spec/spec_helper.rb | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index af44df1..4243d7f 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -6,15 +6,8 @@ def db end def load_schema filename - # silence verbose schema loading - original_stdout = $stdout - $stdout = StringIO.new - root = File.expand_path(File.dirname(__FILE__)) load root + "/schema/#{filename}.rb" - -ensure - $stdout = original_stdout end def dumped_schema @@ -43,6 +36,8 @@ def column_props table, column ActiveRecord::Base.configurations = db_config ActiveRecord::Base.establish_connection db.to_sym +# Silence AR's logging (e.g. when loading the schema) +ActiveRecord::Migration.verbose = false RSpec.configure do |c| c.filter_run_excluding :db_support => ! db_config[db]["supports_enums"] end From 6a62e782eb8b768b9241ee7d44d1e5f8e5a6153b Mon Sep 17 00:00:00 2001 From: Maarten Claes Date: Sat, 31 Mar 2018 15:37:25 +0200 Subject: [PATCH 05/14] Disable RSpec's global monkey patching and scope helpers under module Instead of defining all helper methods on Object --- spec/enum_spec.rb | 2 +- spec/set_spec.rb | 2 +- spec/spec_helper.rb | 92 +++++++++++++++++++++++++++++++-------------- 3 files changed, 65 insertions(+), 31 deletions(-) diff --git a/spec/enum_spec.rb b/spec/enum_spec.rb index 9b31998..bf78e06 100644 --- a/spec/enum_spec.rb +++ b/spec/enum_spec.rb @@ -1,6 +1,6 @@ require 'spec_helper' -describe "ENUM datatype" do +RSpec.describe "ENUM datatype" do describe "schema dump", :db_support => true do before { load_schema "enum_old" } diff --git a/spec/set_spec.rb b/spec/set_spec.rb index 5279bb2..e3aad86 100644 --- a/spec/set_spec.rb +++ b/spec/set_spec.rb @@ -1,6 +1,6 @@ require 'spec_helper' -describe "SET datatype" do +RSpec.describe "SET datatype" do describe "schema dump", :db_support => true do before { load_schema "set_old" } diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 4243d7f..59409a2 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,43 +1,77 @@ require 'rspec' require 'yaml' -def db - ENV["DB"] || "mysql" -end +module DBConfig + class << self + def db + ENV["DB"] || "mysql" + end -def load_schema filename - root = File.expand_path(File.dirname(__FILE__)) - load root + "/schema/#{filename}.rb" -end + def all_configs + @all_configs ||= YAML::load(IO.read("spec/database.yml")) + end -def dumped_schema - stream = StringIO.new - ActiveRecord::SchemaDumper.ignore_tables = [] - ActiveRecord::SchemaDumper.dump(ActiveRecord::Base.connection, stream) - stream.string.lines.select {|l| /^\s*#/.match(l).nil? }.join + def current + all_configs[db] + end + end end -def column_props table, column - case db - when "mysql" - result = ActiveRecord::Base.connection.select_one "SHOW FIELDS FROM #{table} WHERE Field='#{column}'" - { :type => result["Type"], :default => result["Default"], :null => ( result["Null"] == "YES" ) } - when "sqlite" - result = ActiveRecord::Base.connection.select_value "SELECT sql FROM sqlite_master WHERE type='table' AND name='#{table}'" - matches = /"#{column}" ([^[:space:]]+) (?:DEFAULT '([^[:space:]]+)')?( NOT NULL)?,/.match result - { :type => matches[1], :default => matches[2], :null => matches[3].nil? } +module DatabaseHelpers + def load_schema(filename) + root = File.expand_path(File.dirname(__FILE__)) + load root + "/schema/#{filename}.rb" + end + + def dumped_schema + stream = StringIO.new + ActiveRecord::SchemaDumper.ignore_tables = [] + ActiveRecord::SchemaDumper.dump(ActiveRecord::Base.connection, stream) + stream.string.lines.select {|l| /^\s*#/.match(l).nil? }.join + end + + def column_props(table, column) + case DBConfig.db + when "mysql" + result = ActiveRecord::Base.connection.select_one( + "SHOW FIELDS FROM #{table} WHERE Field='#{column}'" + ) + { + :type => result["Type"], + :default => result["Default"], + :null => ( result["Null"] == "YES" ) + } + when "sqlite" + result = ActiveRecord::Base.connection.select_value "SELECT sql FROM sqlite_master WHERE type='table' AND name='#{table}'" + matches = /"#{column}" ([^[:space:]]+) (?:DEFAULT '([^[:space:]]+)')?( NOT NULL)?,/.match result + { :type => matches[1], :default => matches[2], :null => matches[3].nil? } + end end -end -db_config = YAML::load(IO.read("spec/database.yml")) + def db_config + DBConfig.db_config + end -require db_config[db]["adapter"] + def db + DBConfig.db + end +end + +require DBConfig.current["adapter"] require 'native_enum' -ActiveRecord::Base.configurations = db_config -ActiveRecord::Base.establish_connection db.to_sym -# Silence AR's logging (e.g. when loading the schema) -ActiveRecord::Migration.verbose = false RSpec.configure do |c| - c.filter_run_excluding :db_support => ! db_config[db]["supports_enums"] + c.disable_monkey_patching! + c.expose_dsl_globally = false + + c.include DatabaseHelpers + c.filter_run_excluding db_support: !DBConfig.current["supports_enums"] + c.before :suite do + db_config = DBConfig.all_configs + db = DBConfig.db + ActiveRecord::Base.configurations = db_config + ActiveRecord::Base.establish_connection db.to_sym + # Silence AR's logging (e.g. when loading the schema) + ActiveRecord::Migration.verbose = false + end end From ae5d083fd33d9a15668ec52ddc7e8f51aa0b98be Mon Sep 17 00:00:00 2001 From: Maarten Claes Date: Sun, 1 Apr 2018 14:55:06 +0200 Subject: [PATCH 06/14] Use ActiveRecord::Rake::DatabaseTasks for the rake tasks This makes it easier to create/drop the databases. See: https://github.com/rails/rails/blob/v5.0.7/activerecord/lib/active_record/tasks/database_tasks.rb --- Rakefile | 29 ++++++++++++++++++++++++++--- 1 file changed, 26 insertions(+), 3 deletions(-) diff --git a/Rakefile b/Rakefile index de63a9d..7f4a511 100644 --- a/Rakefile +++ b/Rakefile @@ -9,13 +9,36 @@ require 'rake' desc 'Default: run all unit tests.' task :default => :"spec:all" +require 'active_record' + +# For more info on DatabaseTasks, see: +# https://github.com/rails/rails/blob/v5.0.7/activerecord/lib/active_record/tasks/database_tasks.rb namespace :db do + task :load_config do + db_configs = YAML.load_file('spec/database.yml') + ActiveRecord::Tasks::DatabaseTasks.tap do |db_tasks| + ActiveRecord::Base.configurations = db_configs + db_tasks.database_configuration = db_configs + db_tasks.db_dir = 'db' + db_tasks.root = File.dirname(__FILE__) + end + end + desc 'Prepare the databases.' - task :prepare do + task prepare: :load_config do unless File.exist? DB_CONFIG - cp "#{config_file}.tmpl", DB_CONFIG + cp "#{DB_CONFIG}.tmpl", DB_CONFIG end - #TODO would be nice to create the DBs here + + ActiveRecord::Tasks::DatabaseTasks.tap do |db_tasks| + db_tasks.create_current('mysql') + db_tasks.create_current('sqlite') + end + end + + desc "Drop all databases created for testing" + task drop_all: :load_config do + ActiveRecord::Tasks::DatabaseTasks.drop_all end end From fbab68ff4c9a456c35f51c7c3f3196fbf393a410 Mon Sep 17 00:00:00 2001 From: Maarten Claes Date: Sat, 31 Mar 2018 15:39:06 +0200 Subject: [PATCH 07/14] Travis CI: Test with newer ruby versions and drop 1.9.3 --- .travis.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index f14f8cc..513e9f3 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,9 +1,11 @@ language: ruby rvm: - - 1.9.3 - "2.0" - "2.1" - "2.2" + - "2.3" + - "2.4" + - "2.5" before_script: - "mysql -e 'create database native_enum_test;' >/dev/null" - "cp spec/{.travis.,}database.yml" From 877c2302648c6e044e6d65f1e1eba2b7a6d8dc7c Mon Sep 17 00:00:00 2001 From: Maarten Claes Date: Sun, 1 Apr 2018 15:26:38 +0200 Subject: [PATCH 08/14] Travis CI: Setup database via rake --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 513e9f3..84b9a00 100644 --- a/.travis.yml +++ b/.travis.yml @@ -7,7 +7,7 @@ rvm: - "2.4" - "2.5" before_script: - - "mysql -e 'create database native_enum_test;' >/dev/null" - "cp spec/{.travis.,}database.yml" + - "bundle exec rake db:prepare" script: bundle exec rake spec:rails_all sudo: false From 664aff35ffb50130e3a84e9be04e0334b71dcbe2 Mon Sep 17 00:00:00 2001 From: Maarten Claes Date: Sun, 1 Apr 2018 15:39:47 +0200 Subject: [PATCH 09/14] Allow 2.5 to fail until Travis CI bug is fixed For more info see: * https://github.com/travis-ci/travis-ci/issues/8978 * https://github.com/travis-ci/travis-ci/issues/8969 --- .travis.yml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/.travis.yml b/.travis.yml index 84b9a00..2637cc6 100644 --- a/.travis.yml +++ b/.travis.yml @@ -6,6 +6,12 @@ rvm: - "2.3" - "2.4" - "2.5" +matrix: + allow_failures: + # Allow 2.5 to fail until Travis CI bug is fixed. See: + # * https://github.com/travis-ci/travis-ci/issues/8978 + # * https://github.com/travis-ci/travis-ci/issues/8969 + - rvm: "2.5" before_script: - "cp spec/{.travis.,}database.yml" - "bundle exec rake db:prepare" From 7ec7787a05d945ceee3cfb47c09d156a1256cd33 Mon Sep 17 00:00:00 2001 From: Maarten Claes Date: Sat, 31 Mar 2018 00:12:12 +0200 Subject: [PATCH 10/14] Support Rails 5.1 --- lib/connection_adapters/mysql2.rb | 38 +++++++++++++++++---- lib/connection_adapters/sqlite3.rb | 17 ++++++--- lib/native_enum/activerecord_enum_post42.rb | 7 +++- spec/Gemfile.rails_5_0 | 4 +++ spec/Gemfile.rails_5_1 | 4 +++ 5 files changed, 58 insertions(+), 12 deletions(-) create mode 100644 spec/Gemfile.rails_5_0 create mode 100644 spec/Gemfile.rails_5_1 diff --git a/lib/connection_adapters/mysql2.rb b/lib/connection_adapters/mysql2.rb index c690836..f32cb81 100644 --- a/lib/connection_adapters/mysql2.rb +++ b/lib/connection_adapters/mysql2.rb @@ -2,26 +2,50 @@ module ActiveRecord module ConnectionAdapters - existing_class = defined?( Mysql2Adapter ) ? Mysql2Adapter : AbstractMysqlAdapter + existing_class = defined?(Mysql2Adapter) ? Mysql2Adapter : AbstractMysqlAdapter existing_class.class_eval do def native_database_types_with_enum - native_database_types_without_enum.merge( :enum => { :name => "enum" }, :set => { :name => "set" } ) + native_database_types_without_enum.merge({ + :enum => { :name => "enum" }, + :set => { :name => "set" } + }) end alias_method :native_database_types_without_enum, :native_database_types alias_method :native_database_types, :native_database_types_with_enum - def type_to_sql_with_enum type, limit=nil, *args - if type.to_s == "enum" || type.to_s == "set" - "#{type}(#{quoted_comma_list limit})" - else - type_to_sql_without_enum type, limit, *args + + + if ActiveRecord::VERSION::MAJOR >= 5 && ActiveRecord::VERSION::MINOR >= 1 + def type_to_sql_with_enum(type, limit: nil, **args) + if type.to_s == "enum" || type.to_s == "set" + list = limit + if limit.is_a?(Hash) + list = limit[:limit] + end + "#{type}(#{quoted_comma_list(list)})" + else + type_to_sql_without_enum(type, limit: limit, **args) + end + end + else + def type_to_sql_with_enum(type, limit=nil, *args) + if type.to_s == "enum" || type.to_s == "set" + list = limit + if limit.is_a?(Hash) + list = limit[:limit] + end + "#{type}(#{quoted_comma_list(list)})" + else + type_to_sql_without_enum(type, limit, *args) + end end end alias_method :type_to_sql_without_enum, :type_to_sql alias_method :type_to_sql, :type_to_sql_with_enum private + def quoted_comma_list list list.to_a.map{|n| "'#{n}'"}.join(",") end diff --git a/lib/connection_adapters/sqlite3.rb b/lib/connection_adapters/sqlite3.rb index a0c9bb3..02f2c13 100644 --- a/lib/connection_adapters/sqlite3.rb +++ b/lib/connection_adapters/sqlite3.rb @@ -3,11 +3,20 @@ module ActiveRecord module ConnectionAdapters class SQLite3Adapter < (defined?(SQLiteAdapter) ? SQLiteAdapter : AbstractAdapter) - def type_to_sql_with_enum type, limit=nil, *args - if type.to_s == "enum" || type.to_s == "set" - type, limit = :string, nil + if ActiveRecord::VERSION::MAJOR >= 5 && ActiveRecord::VERSION::MINOR >= 1 + def type_to_sql_with_enum(type, limit: nil, **args) + if type.to_s == "enum" || type.to_s == "set" + type, limit = :string, nil + end + type_to_sql_without_enum(type, limit: limit, **args) + end + else + def type_to_sql_with_enum(type, limit=nil, *args) + if type.to_s == "enum" || type.to_s == "set" + type, limit = :string, nil + end + type_to_sql_without_enum(type, limit, *args) end - type_to_sql_without_enum type, limit, *args end alias_method :type_to_sql_without_enum, :type_to_sql alias_method :type_to_sql, :type_to_sql_with_enum diff --git a/lib/native_enum/activerecord_enum_post42.rb b/lib/native_enum/activerecord_enum_post42.rb index 51bb24c..0a29889 100644 --- a/lib/native_enum/activerecord_enum_post42.rb +++ b/lib/native_enum/activerecord_enum_post42.rb @@ -55,9 +55,14 @@ def initialize(options = {}) @limit = options[:limit] end - def type_cast_from_database(value) + # Deserialize value from the database + # + # See: https://github.com/rails/rails/blob/v5.0.7/activemodel/lib/active_model/type/value.rb#L15-L23 + def deserialize(value) value.split(",") end + # deserialize used to be called type_cast_from_database before v5 + alias_method :type_cast_from_database, :deserialize end end end diff --git a/spec/Gemfile.rails_5_0 b/spec/Gemfile.rails_5_0 new file mode 100644 index 0000000..355ac97 --- /dev/null +++ b/spec/Gemfile.rails_5_0 @@ -0,0 +1,4 @@ +source "http://rubygems.org" +gemspec :path => ".." +gem "mysql2", "~> 0.3" +gem "activerecord", "~> 5.0.0" diff --git a/spec/Gemfile.rails_5_1 b/spec/Gemfile.rails_5_1 new file mode 100644 index 0000000..b271466 --- /dev/null +++ b/spec/Gemfile.rails_5_1 @@ -0,0 +1,4 @@ +source "http://rubygems.org" +gemspec :path => ".." +gem "mysql2", "~> 0.3" +gem "activerecord", "~> 5.1.0" From 0fa8c46fc3fd3c29cefd36a26d39bfae42e4436a Mon Sep 17 00:00:00 2001 From: Maarten Claes Date: Sun, 1 Apr 2018 15:35:57 +0200 Subject: [PATCH 11/14] Added CHANGELOG.md file --- CHANGELOG.md | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 CHANGELOG.md diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..41fe2b4 --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,9 @@ +# Unreleased + +* [Support Rails 5.1](https://github.com/iangreenleaf/native_enum/pull/13) +* Drop support for Ruby 1.9.3 +* Drop support for Rails < 4.1.0 + +# 1.0.0 + +* First version From 66e0a9bf53d6977ba7f30d13dd1f267796b6c4bf Mon Sep 17 00:00:00 2001 From: Maarten Claes Date: Sun, 1 Apr 2018 16:49:48 +0200 Subject: [PATCH 12/14] Use Appraisal to test different AR versions + update build matrix * https://github.com/thoughtbot/appraisal * https://docs.travis-ci.com/user/customizing-the-build/#Build-Matrix --- .gitignore | 1 + .travis.yml | 10 +++++++++- Appraisals | 15 +++++++++++++++ Rakefile | 15 +-------------- gemfiles/activerecord_4.1.gemfile | 7 +++++++ gemfiles/activerecord_4.2.gemfile | 7 +++++++ gemfiles/activerecord_5.0.gemfile | 7 +++++++ gemfiles/activerecord_5.1.gemfile | 7 +++++++ native_enum.gemspec | 1 + spec/Gemfile.rails_4_1 | 4 ---- spec/Gemfile.rails_4_2 | 4 ---- spec/Gemfile.rails_5_0 | 4 ---- spec/Gemfile.rails_5_1 | 4 ---- 13 files changed, 55 insertions(+), 31 deletions(-) create mode 100644 Appraisals create mode 100644 gemfiles/activerecord_4.1.gemfile create mode 100644 gemfiles/activerecord_4.2.gemfile create mode 100644 gemfiles/activerecord_5.0.gemfile create mode 100644 gemfiles/activerecord_5.1.gemfile delete mode 100644 spec/Gemfile.rails_4_1 delete mode 100644 spec/Gemfile.rails_4_2 delete mode 100644 spec/Gemfile.rails_5_0 delete mode 100644 spec/Gemfile.rails_5_1 diff --git a/.gitignore b/.gitignore index d4e4ca8..4dd951d 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,7 @@ *.gem .bundle Gemfile*.lock +gemfiles/*.lock pkg/* spec/database.yml spec/vendor diff --git a/.travis.yml b/.travis.yml index 2637cc6..beee440 100644 --- a/.travis.yml +++ b/.travis.yml @@ -12,8 +12,16 @@ matrix: # * https://github.com/travis-ci/travis-ci/issues/8978 # * https://github.com/travis-ci/travis-ci/issues/8969 - rvm: "2.5" + gemfiles: + - gemfiles/activerecord_4.1.gemfile + - gemfiles/activerecord_4.2.gemfile + - gemfiles/activerecord_5.0.gemfile + - gemfiles/activerecord_5.1.gemfile + env: + - DB=mysql + - DB=sqlite before_script: - "cp spec/{.travis.,}database.yml" - "bundle exec rake db:prepare" -script: bundle exec rake spec:rails_all +script: bundle exec rake spec sudo: false diff --git a/Appraisals b/Appraisals new file mode 100644 index 0000000..87714cc --- /dev/null +++ b/Appraisals @@ -0,0 +1,15 @@ +appraise "activerecord-4.1" do + gem "activerecord", "~> 4.1.0" +end + +appraise "activerecord-4.2" do + gem "activerecord", "~> 4.2.0" +end + +appraise "activerecord-5.0" do + gem "activerecord", "~> 5.0.0" +end + +appraise "activerecord-5.1" do + gem "activerecord", "~> 5.1.0" +end diff --git a/Rakefile b/Rakefile index 7f4a511..2c809b2 100644 --- a/Rakefile +++ b/Rakefile @@ -53,23 +53,10 @@ desc 'Run the test suite for all DBs.' namespace :spec do task :all do db_config = YAML::load(IO.read(DB_CONFIG)) - db_config.each do |db,config| + db_config.each do |db, config| ENV["DB"] = db Rake::Task["spec"].reenable Rake::Task["spec"].invoke end end - - desc 'Run the test suite for all supported versions of rails and all DBs' - task :rails_all do - STDOUT.sync = true - versions = Dir.glob(GEMFILES) - versions.each do |gemfile| - puts "Running specs for Gemfile: #{gemfile}" - Bundler.with_clean_env do - sh "bundle install --gemfile '#{gemfile}' --path 'vendor/#{File.extname(gemfile).slice(1..-1)}'" - sh "BUNDLE_GEMFILE='#{gemfile}' bundle exec rake spec:all" - end - end - end end diff --git a/gemfiles/activerecord_4.1.gemfile b/gemfiles/activerecord_4.1.gemfile new file mode 100644 index 0000000..28ca322 --- /dev/null +++ b/gemfiles/activerecord_4.1.gemfile @@ -0,0 +1,7 @@ +# This file was generated by Appraisal + +source "http://rubygems.org" + +gem "activerecord", "~> 4.1.0" + +gemspec path: "../" diff --git a/gemfiles/activerecord_4.2.gemfile b/gemfiles/activerecord_4.2.gemfile new file mode 100644 index 0000000..00e2842 --- /dev/null +++ b/gemfiles/activerecord_4.2.gemfile @@ -0,0 +1,7 @@ +# This file was generated by Appraisal + +source "http://rubygems.org" + +gem "activerecord", "~> 4.2.0" + +gemspec path: "../" diff --git a/gemfiles/activerecord_5.0.gemfile b/gemfiles/activerecord_5.0.gemfile new file mode 100644 index 0000000..5284cb8 --- /dev/null +++ b/gemfiles/activerecord_5.0.gemfile @@ -0,0 +1,7 @@ +# This file was generated by Appraisal + +source "http://rubygems.org" + +gem "activerecord", "~> 5.0.0" + +gemspec path: "../" diff --git a/gemfiles/activerecord_5.1.gemfile b/gemfiles/activerecord_5.1.gemfile new file mode 100644 index 0000000..ace0cad --- /dev/null +++ b/gemfiles/activerecord_5.1.gemfile @@ -0,0 +1,7 @@ +# This file was generated by Appraisal + +source "http://rubygems.org" + +gem "activerecord", "~> 5.1.0" + +gemspec path: "../" diff --git a/native_enum.gemspec b/native_enum.gemspec index 2da0bda..ea49451 100644 --- a/native_enum.gemspec +++ b/native_enum.gemspec @@ -21,6 +21,7 @@ Gem::Specification.new do |s| s.add_development_dependency "mysql2", "~> 0.3.11" s.add_development_dependency "sqlite3", "~>1.3.4" s.add_development_dependency "rspec", "~> 3" + s.add_development_dependency "appraisal" s.files = `git ls-files`.split("\n") s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n") diff --git a/spec/Gemfile.rails_4_1 b/spec/Gemfile.rails_4_1 deleted file mode 100644 index f46721b..0000000 --- a/spec/Gemfile.rails_4_1 +++ /dev/null @@ -1,4 +0,0 @@ -source "http://rubygems.org" -gemspec :path => ".." -gem "mysql2", "~> 0.3.11" -gem "activerecord", "~> 4.1.0" diff --git a/spec/Gemfile.rails_4_2 b/spec/Gemfile.rails_4_2 deleted file mode 100644 index d864604..0000000 --- a/spec/Gemfile.rails_4_2 +++ /dev/null @@ -1,4 +0,0 @@ -source "http://rubygems.org" -gemspec :path => ".." -gem "mysql2", "~> 0.3.11" -gem "activerecord", "~> 4.2.0" diff --git a/spec/Gemfile.rails_5_0 b/spec/Gemfile.rails_5_0 deleted file mode 100644 index 355ac97..0000000 --- a/spec/Gemfile.rails_5_0 +++ /dev/null @@ -1,4 +0,0 @@ -source "http://rubygems.org" -gemspec :path => ".." -gem "mysql2", "~> 0.3" -gem "activerecord", "~> 5.0.0" diff --git a/spec/Gemfile.rails_5_1 b/spec/Gemfile.rails_5_1 deleted file mode 100644 index b271466..0000000 --- a/spec/Gemfile.rails_5_1 +++ /dev/null @@ -1,4 +0,0 @@ -source "http://rubygems.org" -gemspec :path => ".." -gem "mysql2", "~> 0.3" -gem "activerecord", "~> 5.1.0" From a9151d87527d1e18c4a1df07e730c361ebc66e86 Mon Sep 17 00:00:00 2001 From: Maarten Claes Date: Sun, 1 Apr 2018 16:52:27 +0200 Subject: [PATCH 13/14] Travis CI: Exclude unsupported ruby versions for Rails 5 --- .travis.yml | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/.travis.yml b/.travis.yml index beee440..ec3af6d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -6,20 +6,29 @@ rvm: - "2.3" - "2.4" - "2.5" +gemfile: + - gemfiles/activerecord_4.1.gemfile + - gemfiles/activerecord_4.2.gemfile + - gemfiles/activerecord_5.0.gemfile + - gemfiles/activerecord_5.1.gemfile +env: + - DB=mysql + - DB=sqlite matrix: allow_failures: # Allow 2.5 to fail until Travis CI bug is fixed. See: # * https://github.com/travis-ci/travis-ci/issues/8978 # * https://github.com/travis-ci/travis-ci/issues/8969 - rvm: "2.5" - gemfiles: - - gemfiles/activerecord_4.1.gemfile - - gemfiles/activerecord_4.2.gemfile - - gemfiles/activerecord_5.0.gemfile - - gemfiles/activerecord_5.1.gemfile - env: - - DB=mysql - - DB=sqlite + exclude: + - rvm: "2.0" + gemfile: gemfiles/activerecord_5.0.gemfile + - rvm: "2.0" + gemfile: gemfiles/activerecord_5.1.gemfile + - rvm: "2.1" + gemfile: gemfiles/activerecord_5.0.gemfile + - rvm: "2.1" + gemfile: gemfiles/activerecord_5.1.gemfile before_script: - "cp spec/{.travis.,}database.yml" - "bundle exec rake db:prepare" From 4d643b3d459021d02224fd41aa52a1cd7abe73cd Mon Sep 17 00:00:00 2001 From: Christian-Manuel Butzke Date: Thu, 12 Jul 2018 16:15:56 +0900 Subject: [PATCH 14/14] [FIX] rails db:create failed with ArgumentError: wrong number of arguments (given 0, expected 1) --- lib/native_enum/activerecord_enum_post42.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/native_enum/activerecord_enum_post42.rb b/lib/native_enum/activerecord_enum_post42.rb index 0a29889..6e54bed 100644 --- a/lib/native_enum/activerecord_enum_post42.rb +++ b/lib/native_enum/activerecord_enum_post42.rb @@ -3,7 +3,7 @@ module ConnectionAdapters if defined?(AbstractMysqlAdapter) class AbstractMysqlAdapter protected - def initialize_type_map_with_enum(m) + def initialize_type_map_with_enum(m = type_map) initialize_without_enum(m) register_enum_type(m, %r(^enum)i) register_set_type(m, %r(^set)i)