diff --git a/.travis.yml b/.travis.yml index 28cca25..2754218 100644 --- a/.travis.yml +++ b/.travis.yml @@ -7,6 +7,9 @@ sudo: false rvm: - 2.3.1 gemfile: +- gemfiles/activerecord-4.2/Gemfile.mysql2 +- gemfiles/activerecord-4.2/Gemfile.postgresql +- gemfiles/activerecord-4.2/Gemfile.sqlite3 - gemfiles/activerecord-5.0/Gemfile.mysql2 - gemfiles/activerecord-5.0/Gemfile.postgresql - gemfiles/activerecord-5.0/Gemfile.sqlite3 diff --git a/README.md b/README.md index c7907c4..6ab22ab 100644 --- a/README.md +++ b/README.md @@ -106,6 +106,7 @@ schema_plus_indexes is tested on +* ruby **2.3.1** with activerecord **4.2**, using **mysql2**, **sqlite3** or **postgresql** * ruby **2.3.1** with activerecord **5.0**, using **mysql2**, **sqlite3** or **postgresql** diff --git a/gemfiles/activerecord-4.2/Gemfile.base b/gemfiles/activerecord-4.2/Gemfile.base new file mode 100644 index 0000000..ad6a424 --- /dev/null +++ b/gemfiles/activerecord-4.2/Gemfile.base @@ -0,0 +1,3 @@ +eval File.read File.expand_path('../../Gemfile.base', __FILE__) + +gem "activerecord", "~> 4.2.6" diff --git a/gemfiles/activerecord-4.2/Gemfile.mysql2 b/gemfiles/activerecord-4.2/Gemfile.mysql2 new file mode 100644 index 0000000..9ce0bb5 --- /dev/null +++ b/gemfiles/activerecord-4.2/Gemfile.mysql2 @@ -0,0 +1,10 @@ +require "pathname" +eval(Pathname.new(__FILE__).dirname.join("Gemfile.base").read, binding) + +platform :ruby do + gem "mysql2", '>= 0.3.18', '< 0.5' +end + +platform :jruby do + gem 'activerecord-jdbcmysql-adapter' +end diff --git a/gemfiles/activerecord-4.2/Gemfile.postgresql b/gemfiles/activerecord-4.2/Gemfile.postgresql new file mode 100644 index 0000000..2c00e63 --- /dev/null +++ b/gemfiles/activerecord-4.2/Gemfile.postgresql @@ -0,0 +1,10 @@ +require "pathname" +eval(Pathname.new(__FILE__).dirname.join("Gemfile.base").read, binding) + +platform :ruby do + gem "pg" +end + +platform :jruby do + gem 'activerecord-jdbcpostgresql-adapter' +end \ No newline at end of file diff --git a/gemfiles/activerecord-4.2/Gemfile.sqlite3 b/gemfiles/activerecord-4.2/Gemfile.sqlite3 new file mode 100644 index 0000000..a116d6d --- /dev/null +++ b/gemfiles/activerecord-4.2/Gemfile.sqlite3 @@ -0,0 +1,10 @@ +require "pathname" +eval(Pathname.new(__FILE__).dirname.join("Gemfile.base").read, binding) + +platform :ruby do + gem "sqlite3" +end + +platform :jruby do + gem 'activerecord-jdbcsqlite3-adapter', '>=1.3.0.beta2' +end \ No newline at end of file diff --git a/gemfiles/activerecord-5.0/Gemfile.base b/gemfiles/activerecord-5.0/Gemfile.base index b583c0f..b18bf66 100644 --- a/gemfiles/activerecord-5.0/Gemfile.base +++ b/gemfiles/activerecord-5.0/Gemfile.base @@ -1,3 +1,3 @@ eval File.read File.expand_path('../../Gemfile.base', __FILE__) -gem "activerecord", ">= 5.0.0.beta1", "< 5.1" +gem "activerecord", "~> 5.0.0" diff --git a/schema_dev.yml b/schema_dev.yml index 7eb9313..c91b050 100644 --- a/schema_dev.yml +++ b/schema_dev.yml @@ -1,6 +1,7 @@ ruby: - 2.3.1 activerecord: + - 4.2 - 5.0 db: - mysql2 diff --git a/schema_plus_indexes.gemspec b/schema_plus_indexes.gemspec index ff2e16f..1488d20 100644 --- a/schema_plus_indexes.gemspec +++ b/schema_plus_indexes.gemspec @@ -17,8 +17,8 @@ Gem::Specification.new do |gem| gem.test_files = gem.files.grep(%r{^(test|spec|features)/}) gem.require_paths = ["lib"] - gem.add_dependency "activerecord", "~> 5.0" - gem.add_dependency "schema_plus_core", "~> 2.0" + gem.add_dependency "activerecord", ">= 4.2", "< 5.1" + gem.add_dependency "schema_plus_core" gem.add_dependency "its-it", "~> 1.2" gem.add_development_dependency "bundler", "~> 1.7" diff --git a/spec/command_recorder_spec.rb b/spec/command_recorder_spec.rb index e6ba6a9..ff49c74 100644 --- a/spec/command_recorder_spec.rb +++ b/spec/command_recorder_spec.rb @@ -37,7 +37,9 @@ def before(env) end it "does not fail when reverting" do - migration = Class.new ::ActiveRecord::Migration[5.0] do + migration = ::ActiveRecord::Migration + migration = migration[5.0] if migration.respond_to? :[] # without [], will be rails 4.2 migration + migration = Class.new migration do define_method(:change) { change_table("comments") do |t| t.integer :column diff --git a/spec/index_spec.rb b/spec/index_spec.rb index 33ebe76..1c82b18 100644 --- a/spec/index_spec.rb +++ b/spec/index_spec.rb @@ -8,7 +8,7 @@ describe "add_index" do before(:each) do - connection.tables.each do |table| connection.drop_table table, cascade: true end + each_table connection do |table| connection.drop_table table, cascade: true end define_schema(:auto_create => false) do create_table :users, :force => true do |t| @@ -80,7 +80,7 @@ def index_for(column_names) describe "remove_index" do before(:each) do - connection.tables.each do |table| connection.drop_table table, cascade: true end + each_table connection do |table| connection.drop_table table, cascade: true end define_schema(:auto_create => false) do create_table :users, :force => true do |t| t.string :login diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 43aa2f5..6b59bfc 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -24,9 +24,17 @@ end end +# shim to handle connection.tables deprecation in favor of +# connection.data_sources +def each_table(connection) + (connection.try :data_sources || connection.tables).each do |table| + yield table + end +end + def define_schema(config={}, &block) ActiveRecord::Schema.define do - connection.tables.each do |table| + each_table(connection) do |table| drop_table table, :force => :cascade end instance_eval &block