Skip to content

Commit

Permalink
support AR 4.2 and 5.0 simultaneously
Browse files Browse the repository at this point in the history
  • Loading branch information
ronen committed Aug 24, 2016
1 parent ff0a3b6 commit 292ee5a
Show file tree
Hide file tree
Showing 12 changed files with 55 additions and 7 deletions.
3 changes: 3 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ schema_plus_indexes is tested on

<!-- SCHEMA_DEV: MATRIX - begin -->
<!-- These lines are auto-generated by schema_dev based on schema_dev.yml -->
* 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**

<!-- SCHEMA_DEV: MATRIX - end -->
Expand Down
3 changes: 3 additions & 0 deletions gemfiles/activerecord-4.2/Gemfile.base
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
eval File.read File.expand_path('../../Gemfile.base', __FILE__)

gem "activerecord", "~> 4.2.6"
10 changes: 10 additions & 0 deletions gemfiles/activerecord-4.2/Gemfile.mysql2
Original file line number Diff line number Diff line change
@@ -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
10 changes: 10 additions & 0 deletions gemfiles/activerecord-4.2/Gemfile.postgresql
Original file line number Diff line number Diff line change
@@ -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
10 changes: 10 additions & 0 deletions gemfiles/activerecord-4.2/Gemfile.sqlite3
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion gemfiles/activerecord-5.0/Gemfile.base
Original file line number Diff line number Diff line change
@@ -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"
1 change: 1 addition & 0 deletions schema_dev.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
ruby:
- 2.3.1
activerecord:
- 4.2
- 5.0
db:
- mysql2
Expand Down
4 changes: 2 additions & 2 deletions schema_plus_indexes.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
4 changes: 3 additions & 1 deletion spec/command_recorder_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions spec/index_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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|
Expand Down Expand Up @@ -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
Expand Down
10 changes: 9 additions & 1 deletion spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 292ee5a

Please sign in to comment.