Skip to content

Commit

Permalink
Merge 7b0a710 into 98a9401
Browse files Browse the repository at this point in the history
  • Loading branch information
iagopiimenta committed Jul 23, 2017
2 parents 98a9401 + 7b0a710 commit da30b45
Show file tree
Hide file tree
Showing 10 changed files with 52 additions and 4 deletions.
3 changes: 3 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ gemfile:
- gemfiles/activerecord-5.0/Gemfile.mysql2
- gemfiles/activerecord-5.0/Gemfile.postgresql
- gemfiles/activerecord-5.0/Gemfile.sqlite3
- gemfiles/activerecord-5.1/Gemfile.mysql2
- gemfiles/activerecord-5.1/Gemfile.postgresql
- gemfiles/activerecord-5.1/Gemfile.sqlite3
env: POSTGRESQL_DB_USER=postgres MYSQL_DB_USER=travis
addons:
postgresql: '9.4'
Expand Down
3 changes: 3 additions & 0 deletions gemfiles/activerecord-5.1/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", "~> 5.1.0"
10 changes: 10 additions & 0 deletions gemfiles/activerecord-5.1/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"
end

platform :jruby do
gem 'activerecord-jdbcmysql-adapter'
end
10 changes: 10 additions & 0 deletions gemfiles/activerecord-5.1/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-5.1/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
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ def ==(other)
return false unless self.name == other.name
return false unless Array.wrap(self.columns).collect(&:to_s).sort == Array.wrap(other.columns).collect(&:to_s).sort
return false unless !!self.unique == !!other.unique
return false unless Array.wrap(self.lengths).compact.sort == Array.wrap(other.lengths).compact.sort
return false if other.lengths.is_a?(Array) && Array.wrap(self.lengths).compact.sort != Array.wrap(other.lengths).compact.sort
return false if other.lengths.is_a?(Hash) && (self.lengths || {}) != other.lengths
return false unless self.where == other.where
return false unless (self.using||:btree) == (other.using||:btree)
true
Expand Down
1 change: 1 addition & 0 deletions lib/schema_plus/indexes/middleware/migration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ def around(env)
yield env
rescue => e
raise unless e.message.match(/["']([^"']+)["'].*already exists/)

name = $1
existing = env.caller.indexes(env.table_name).find{|i| i.name == name}
attempted = ::ActiveRecord::ConnectionAdapters::IndexDefinition.new(env.table_name, env.column_names, env.options.merge(:name => name))
Expand Down
2 changes: 1 addition & 1 deletion schema_plus_indexes.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ Gem::Specification.new do |gem|
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
gem.require_paths = ["lib"]

gem.add_dependency "activerecord", ">= 4.2", "< 5.1"
gem.add_dependency "activerecord", ">= 4.2", "< 5.2"
gem.add_dependency "schema_plus_core"
gem.add_dependency "its-it", "~> 1.2"

Expand Down
7 changes: 6 additions & 1 deletion spec/migration_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,12 @@ class Comment < ::ActiveRecord::Base ; end
t.string :bar, :index => { :with => :foo, :length => { :foo => 8, :bar => 12 }}
end
index = @model.indexes.first
expect(Hash[index.columns.zip(index.lengths.map(&:to_i))]).to eq({ "foo" => 8, "bar" => 12})

if ActiveRecord.version >= Gem::Version.new('5.0')
expect(index.lengths).to eq({ "foo" => 8, "bar" => 12})
else
expect(Hash[index.columns.zip(index.lengths.map(&:to_i))]).to eq({ "foo" => 8, "bar" => 12})
end
end

it "should create an index if specified explicitly" do
Expand Down
7 changes: 6 additions & 1 deletion spec/schema_dumper_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,12 @@ class ::Comment < ActiveRecord::Base ; end

it "should include index order", :mysql => :skip do
with_index Post, [:user_id, :first_comment_id, :short_id], :order => { :user_id => :asc, :first_comment_id => :desc } do
expect(dump_posts).to match(/"user_id".*:index=>{.*:with=>\["first_comment_id", "short_id"\],.*:order=>{"user_id"=>:asc, "first_comment_id"=>:desc, "short_id"=>:asc}/)

if ActiveRecord.version >= Gem::Version.new('5.0')
expect(dump_posts).to match(/"user_id".*:index=>{.*:with=>\["first_comment_id", "short_id"\],.*:order=>{:user_id=>:asc, :first_comment_id=>:desc, :short_id=>:asc}/)
else
expect(dump_posts).to match(/"user_id".*:index=>{.*:with=>\["first_comment_id", "short_id"\],.*:order=>{"user_id"=>:asc, "first_comment_id"=>:desc, "short_id"=>:asc}/)
end
end
end

Expand Down

0 comments on commit da30b45

Please sign in to comment.