Skip to content

Commit 124d1c0

Browse files
adamgaynorctran
authored andcommitted
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.
1 parent 625e0d0 commit 124d1c0

File tree

3 files changed

+24
-4
lines changed

3 files changed

+24
-4
lines changed

.rubocop_todo.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ Lint/UselessAccessModifier:
103103

104104
# Offense count: 17
105105
Metrics/AbcSize:
106-
Max: 144
106+
Max: 146
107107

108108
# Offense count: 3
109109
# Configuration parameters: CountComments.
@@ -116,7 +116,7 @@ Metrics/BlockNesting:
116116

117117
# Offense count: 8
118118
Metrics/CyclomaticComplexity:
119-
Max: 36
119+
Max: 37
120120

121121
# Offense count: 350
122122
# Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns.
@@ -127,7 +127,7 @@ Metrics/LineLength:
127127
# Offense count: 24
128128
# Configuration parameters: CountComments.
129129
Metrics/MethodLength:
130-
Max: 70
130+
Max: 71
131131

132132
# Offense count: 1
133133
# Configuration parameters: CountComments.
@@ -136,7 +136,7 @@ Metrics/ModuleLength:
136136

137137
# Offense count: 7
138138
Metrics/PerceivedComplexity:
139-
Max: 41
139+
Max: 42
140140

141141
# Offense count: 1
142142
Style/AccessorMethodName:

lib/annotate/annotate_models.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,7 @@ def get_schema_info(klass, header, options = {})
259259
indices = retrieve_indexes_from_table(klass)
260260
if indices = indices.select { |ind| ind.columns.include? col.name }
261261
indices.sort_by(&:name).each do |ind|
262+
next if ind.columns.is_a?(String)
262263
ind = ind.columns.reject! { |i| i == col.name }
263264
attrs << (ind.empty? ? "indexed" : "indexed => [#{ind.join(", ")}]")
264265
end

spec/annotate/annotate_models_spec.rb

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,25 @@ def mock_column(name, type, options = {})
303303
EOS
304304
end
305305

306+
it 'should get simple indexes keys if one is in string form' do
307+
klass = mock_class(:users,
308+
:id,
309+
[
310+
mock_column("id", :integer),
311+
mock_column("name", :string)
312+
], [mock_index('index_rails_02e851e3b7', ['id']),
313+
mock_index('index_rails_02e851e3b8', 'LOWER(name)')])
314+
expect(AnnotateModels.get_schema_info(klass, 'Schema Info', simple_indexes: true)).to eql(<<-EOS)
315+
# Schema Info
316+
#
317+
# Table name: users
318+
#
319+
# id :integer not null, primary key, indexed
320+
# name :string not null
321+
#
322+
EOS
323+
end
324+
306325
it 'should not crash getting indexes keys' do
307326
klass = mock_class(:users,
308327
:id,

0 commit comments

Comments
 (0)