Skip to content

Commit

Permalink
Fix specs
Browse files Browse the repository at this point in the history
  • Loading branch information
iagopiimenta committed Jul 23, 2017
1 parent 5fd12d3 commit 7b0a710
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 3 deletions.
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
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
2 changes: 1 addition & 1 deletion spec/schema_dumper_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ 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

if ActiveRecord.version >= Gem::Version.new('5.1')
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}/)
Expand Down

0 comments on commit 7b0a710

Please sign in to comment.