Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Do not check if an index includes another column if the name is a Str…
…ing, 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.
  • Loading branch information
adamgaynor authored and ctran committed Feb 2, 2017
1 parent 625e0d0 commit 124d1c0
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 4 deletions.
8 changes: 4 additions & 4 deletions .rubocop_todo.yml
Expand Up @@ -103,7 +103,7 @@ Lint/UselessAccessModifier:

# Offense count: 17
Metrics/AbcSize:
Max: 144
Max: 146

# Offense count: 3
# Configuration parameters: CountComments.
Expand All @@ -116,7 +116,7 @@ Metrics/BlockNesting:

# Offense count: 8
Metrics/CyclomaticComplexity:
Max: 36
Max: 37

# Offense count: 350
# Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns.
Expand All @@ -127,7 +127,7 @@ Metrics/LineLength:
# Offense count: 24
# Configuration parameters: CountComments.
Metrics/MethodLength:
Max: 70
Max: 71

# Offense count: 1
# Configuration parameters: CountComments.
Expand All @@ -136,7 +136,7 @@ Metrics/ModuleLength:

# Offense count: 7
Metrics/PerceivedComplexity:
Max: 41
Max: 42

# Offense count: 1
Style/AccessorMethodName:
Expand Down
1 change: 1 addition & 0 deletions lib/annotate/annotate_models.rb
Expand Up @@ -259,6 +259,7 @@ def get_schema_info(klass, header, options = {})
indices = retrieve_indexes_from_table(klass)
if indices = indices.select { |ind| ind.columns.include? col.name }
indices.sort_by(&:name).each do |ind|
next if ind.columns.is_a?(String)
ind = ind.columns.reject! { |i| i == col.name }
attrs << (ind.empty? ? "indexed" : "indexed => [#{ind.join(", ")}]")
end
Expand Down
19 changes: 19 additions & 0 deletions spec/annotate/annotate_models_spec.rb
Expand Up @@ -303,6 +303,25 @@ def mock_column(name, type, options = {})
EOS
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
klass = mock_class(:users,
:id,
Expand Down

0 comments on commit 124d1c0

Please sign in to comment.