Commit 124d1c09 by Adam Gaynor Committed by Cuong Tran

Do not check if an index includes another column if the name is a String,…

Do not check if an index includes another column if the name is a String, instead of an Array. (#442) * Do not check if an index includes another column if the name is a String, instead of an Array. * Fix Rubocop test conditions.
parent 625e0d0d
...@@ -103,7 +103,7 @@ Lint/UselessAccessModifier: ...@@ -103,7 +103,7 @@ Lint/UselessAccessModifier:
# Offense count: 17 # Offense count: 17
Metrics/AbcSize: Metrics/AbcSize:
Max: 144 Max: 146
# Offense count: 3 # Offense count: 3
# Configuration parameters: CountComments. # Configuration parameters: CountComments.
...@@ -116,7 +116,7 @@ Metrics/BlockNesting: ...@@ -116,7 +116,7 @@ Metrics/BlockNesting:
# Offense count: 8 # Offense count: 8
Metrics/CyclomaticComplexity: Metrics/CyclomaticComplexity:
Max: 36 Max: 37
# Offense count: 350 # Offense count: 350
# Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns. # Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns.
...@@ -127,7 +127,7 @@ Metrics/LineLength: ...@@ -127,7 +127,7 @@ Metrics/LineLength:
# Offense count: 24 # Offense count: 24
# Configuration parameters: CountComments. # Configuration parameters: CountComments.
Metrics/MethodLength: Metrics/MethodLength:
Max: 70 Max: 71
# Offense count: 1 # Offense count: 1
# Configuration parameters: CountComments. # Configuration parameters: CountComments.
...@@ -136,7 +136,7 @@ Metrics/ModuleLength: ...@@ -136,7 +136,7 @@ Metrics/ModuleLength:
# Offense count: 7 # Offense count: 7
Metrics/PerceivedComplexity: Metrics/PerceivedComplexity:
Max: 41 Max: 42
# Offense count: 1 # Offense count: 1
Style/AccessorMethodName: Style/AccessorMethodName:
......
...@@ -259,6 +259,7 @@ module AnnotateModels ...@@ -259,6 +259,7 @@ module AnnotateModels
indices = retrieve_indexes_from_table(klass) indices = retrieve_indexes_from_table(klass)
if indices = indices.select { |ind| ind.columns.include? col.name } if indices = indices.select { |ind| ind.columns.include? col.name }
indices.sort_by(&:name).each do |ind| indices.sort_by(&:name).each do |ind|
next if ind.columns.is_a?(String)
ind = ind.columns.reject! { |i| i == col.name } ind = ind.columns.reject! { |i| i == col.name }
attrs << (ind.empty? ? "indexed" : "indexed => [#{ind.join(", ")}]") attrs << (ind.empty? ? "indexed" : "indexed => [#{ind.join(", ")}]")
end end
......
...@@ -303,6 +303,25 @@ EOS ...@@ -303,6 +303,25 @@ EOS
EOS EOS
end end
it 'should get simple indexes keys if one is in string form' do
klass = mock_class(:users,
:id,
[
mock_column("id", :integer),
mock_column("name", :string)
], [mock_index('index_rails_02e851e3b7', ['id']),
mock_index('index_rails_02e851e3b8', 'LOWER(name)')])
expect(AnnotateModels.get_schema_info(klass, 'Schema Info', simple_indexes: true)).to eql(<<-EOS)
# Schema Info
#
# Table name: users
#
# id :integer not null, primary key, indexed
# name :string not null
#
EOS
end
it 'should not crash getting indexes keys' do it 'should not crash getting indexes keys' do
klass = mock_class(:users, klass = mock_class(:users,
:id, :id,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment