Commit b26650d0 by Guillermo Guerrero Ibarra Committed by Cuong Tran

Fixed some offenses (#423)

Fixed some offenses
parent bb8cdf84
# This configuration was generated by # This configuration was generated by
# `rubocop --auto-gen-config` # `rubocop --auto-gen-config`
# on 2016-12-13 20:39:56 +0100 using RuboCop version 0.46.0. # on 2016-12-14 23:38:08 +0100 using RuboCop version 0.46.0.
# The point is for the user to remove these configuration records # The point is for the user to remove these configuration records
# one by one as the offenses are removed from the code base. # one by one as the offenses are removed from the code base.
# Note that changes in the inspected code, or installation of new # Note that changes in the inspected code, or installation of new
...@@ -21,12 +21,11 @@ Bundler/DuplicatedGem: ...@@ -21,12 +21,11 @@ Bundler/DuplicatedGem:
- 'spec/integration/rails_4.2.0/Gemfile' - 'spec/integration/rails_4.2.0/Gemfile'
- 'spec/integration/standalone/Gemfile' - 'spec/integration/standalone/Gemfile'
# Offense count: 10 # Offense count: 2
# Configuration parameters: Include. # Configuration parameters: Include.
# Include: **/Gemfile, **/gems.rb # Include: **/Gemfile, **/gems.rb
Bundler/OrderedGems: Bundler/OrderedGems:
Exclude: Exclude:
- 'Gemfile'
- 'spec/integration/rails_2.3_with_bundler/Gemfile' - 'spec/integration/rails_2.3_with_bundler/Gemfile'
- 'spec/integration/rails_3.2_with_asset_pipeline/Gemfile' - 'spec/integration/rails_3.2_with_asset_pipeline/Gemfile'
...@@ -37,11 +36,13 @@ Lint/AssignmentInCondition: ...@@ -37,11 +36,13 @@ Lint/AssignmentInCondition:
- 'lib/annotate/annotate_models.rb' - 'lib/annotate/annotate_models.rb'
- 'spec/integration/rails_2.3_with_bundler/config/boot.rb' - 'spec/integration/rails_2.3_with_bundler/config/boot.rb'
# Offense count: 1 # Offense count: 2
# Cop supports --auto-correct. # Cop supports --auto-correct.
Lint/Debugger: # Configuration parameters: AlignWith, SupportedStyles.
# SupportedStyles: either, start_of_block, start_of_line
Lint/BlockAlignment:
Exclude: Exclude:
- 'spec/integration/common_validation.rb' - 'spec/annotate/annotate_models_spec.rb'
# Offense count: 6 # Offense count: 6
# Cop supports --auto-correct. # Cop supports --auto-correct.
...@@ -130,7 +131,7 @@ Metrics/BlockNesting: ...@@ -130,7 +131,7 @@ Metrics/BlockNesting:
Metrics/CyclomaticComplexity: Metrics/CyclomaticComplexity:
Max: 36 Max: 36
# Offense count: 358 # Offense count: 347
# Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns. # Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns.
# URISchemes: http, https # URISchemes: http, https
Metrics/LineLength: Metrics/LineLength:
...@@ -150,6 +151,14 @@ Style/AccessorMethodName: ...@@ -150,6 +151,14 @@ Style/AccessorMethodName:
Exclude: Exclude:
- 'lib/annotate.rb' - 'lib/annotate.rb'
# Offense count: 1
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle, SupportedStyles, IndentationWidth.
# SupportedStyles: with_first_parameter, with_fixed_indentation
Style/AlignParameters:
Exclude:
- 'spec/annotate/annotate_models_spec.rb'
# Offense count: 2 # Offense count: 2
# Cop supports --auto-correct. # Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle, SupportedStyles. # Configuration parameters: EnforcedStyle, SupportedStyles.
...@@ -158,7 +167,7 @@ Style/BarePercentLiterals: ...@@ -158,7 +167,7 @@ Style/BarePercentLiterals:
Exclude: Exclude:
- 'spec/integration/rails_2.3_with_bundler/config/boot.rb' - 'spec/integration/rails_2.3_with_bundler/config/boot.rb'
# Offense count: 9 # Offense count: 8
# Cop supports --auto-correct. # Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle, SupportedStyles, ProceduralMethods, FunctionalMethods, IgnoredMethods. # Configuration parameters: EnforcedStyle, SupportedStyles, ProceduralMethods, FunctionalMethods, IgnoredMethods.
# SupportedStyles: line_count_based, semantic, braces_for_chaining # SupportedStyles: line_count_based, semantic, braces_for_chaining
...@@ -255,7 +264,7 @@ Style/Documentation: ...@@ -255,7 +264,7 @@ Style/Documentation:
- 'lib/generators/annotate/install_generator.rb' - 'lib/generators/annotate/install_generator.rb'
- 'lib/tasks/migrate.rake' - 'lib/tasks/migrate.rake'
# Offense count: 14 # Offense count: 11
# Cop supports --auto-correct. # Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle, SupportedStyles. # Configuration parameters: EnforcedStyle, SupportedStyles.
# SupportedStyles: leading, trailing # SupportedStyles: leading, trailing
...@@ -263,13 +272,11 @@ Style/DotPosition: ...@@ -263,13 +272,11 @@ Style/DotPosition:
Exclude: Exclude:
- 'lib/annotate/annotate_models.rb' - 'lib/annotate/annotate_models.rb'
- 'spec/integration/common_validation.rb' - 'spec/integration/common_validation.rb'
- 'spec/spec_helper.rb'
# Offense count: 3 # Offense count: 2
# Cop supports --auto-correct. # Cop supports --auto-correct.
Style/EmptyLines: Style/EmptyLines:
Exclude: Exclude:
- 'spec/annotate/annotate_models_spec.rb'
- 'spec/integration/rails_4.1.1/Gemfile' - 'spec/integration/rails_4.1.1/Gemfile'
- 'spec/integration/rails_4.2.0/Gemfile' - 'spec/integration/rails_4.2.0/Gemfile'
...@@ -279,7 +286,7 @@ Style/EmptyLinesAroundAccessModifier: ...@@ -279,7 +286,7 @@ Style/EmptyLinesAroundAccessModifier:
Exclude: Exclude:
- 'spec/integration/rails_2.3_with_bundler/config/boot.rb' - 'spec/integration/rails_2.3_with_bundler/config/boot.rb'
# Offense count: 20 # Offense count: 8
# Cop supports --auto-correct. # Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle, SupportedStyles. # Configuration parameters: EnforcedStyle, SupportedStyles.
# SupportedStyles: empty_lines, no_empty_lines # SupportedStyles: empty_lines, no_empty_lines
...@@ -288,14 +295,8 @@ Style/EmptyLinesAroundBlockBody: ...@@ -288,14 +295,8 @@ Style/EmptyLinesAroundBlockBody:
- 'bin/annotate' - 'bin/annotate'
- 'spec/annotate/annotate_models_spec.rb' - 'spec/annotate/annotate_models_spec.rb'
- 'spec/integration/rails_2.3_with_bundler/db/schema.rb' - 'spec/integration/rails_2.3_with_bundler/db/schema.rb'
- 'spec/integration/rails_3.2.2/db/schema.rb'
- 'spec/integration/rails_3.2.8/db/schema.rb'
- 'spec/integration/rails_3.2_autoloading_factory_girl/db/schema.rb'
- 'spec/integration/rails_3.2_custom_inflections/db/schema.rb'
- 'spec/integration/rails_3.2_with_asset_pipeline/db/schema.rb'
- 'spec/integration/rails_4.1.1/db/schema.rb' - 'spec/integration/rails_4.1.1/db/schema.rb'
- 'spec/integration/rails_4.2.0/db/schema.rb' - 'spec/integration/rails_4.2.0/db/schema.rb'
- 'spec/integration/standalone/db/schema.rb'
# Offense count: 25 # Offense count: 25
# Cop supports --auto-correct. # Cop supports --auto-correct.
...@@ -339,7 +340,7 @@ Style/GuardClause: ...@@ -339,7 +340,7 @@ Style/GuardClause:
- 'lib/tasks/migrate.rake' - 'lib/tasks/migrate.rake'
- 'spec/integration/rails_2.3_with_bundler/config/boot.rb' - 'spec/integration/rails_2.3_with_bundler/config/boot.rb'
# Offense count: 161 # Offense count: 76
# Cop supports --auto-correct. # Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle, SupportedStyles, UseHashRocketsWithSymbolValues, PreferHashRocketsForNonAlnumEndingSymbols. # Configuration parameters: EnforcedStyle, SupportedStyles, UseHashRocketsWithSymbolValues, PreferHashRocketsForNonAlnumEndingSymbols.
# SupportedStyles: ruby19, hash_rockets, no_mixed_keys, ruby19_no_mixed_keys # SupportedStyles: ruby19, hash_rockets, no_mixed_keys, ruby19_no_mixed_keys
...@@ -353,7 +354,7 @@ Style/IfUnlessModifier: ...@@ -353,7 +354,7 @@ Style/IfUnlessModifier:
Exclude: Exclude:
- 'lib/annotate/annotate_models.rb' - 'lib/annotate/annotate_models.rb'
# Offense count: 34 # Offense count: 32
# Cop supports --auto-correct. # Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle, SupportedStyles, IndentationWidth. # Configuration parameters: EnforcedStyle, SupportedStyles, IndentationWidth.
# SupportedStyles: special_inside_parentheses, consistent, align_brackets # SupportedStyles: special_inside_parentheses, consistent, align_brackets
...@@ -362,16 +363,15 @@ Style/IndentArray: ...@@ -362,16 +363,15 @@ Style/IndentArray:
- 'lib/annotate/annotate_models.rb' - 'lib/annotate/annotate_models.rb'
- 'lib/annotate/annotate_routes.rb' - 'lib/annotate/annotate_routes.rb'
- 'spec/annotate/annotate_models_spec.rb' - 'spec/annotate/annotate_models_spec.rb'
- 'spec/spec_helper.rb'
# Offense count: 12 # Offense count: 6
# Cop supports --auto-correct. # Cop supports --auto-correct.
# Configuration parameters: SupportedStyles, IndentationWidth. # Configuration parameters: SupportedStyles, IndentationWidth.
# SupportedStyles: special_inside_parentheses, consistent, align_braces # SupportedStyles: special_inside_parentheses, consistent, align_braces
Style/IndentHash: Style/IndentHash:
EnforcedStyle: consistent EnforcedStyle: consistent
# Offense count: 3 # Offense count: 7
# Cop supports --auto-correct. # Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle, SupportedStyles. # Configuration parameters: EnforcedStyle, SupportedStyles.
# SupportedStyles: normal, rails # SupportedStyles: normal, rails
...@@ -380,23 +380,16 @@ Style/IndentationConsistency: ...@@ -380,23 +380,16 @@ Style/IndentationConsistency:
- 'spec/annotate/annotate_models_spec.rb' - 'spec/annotate/annotate_models_spec.rb'
- 'spec/integration/rails_2.3_with_bundler/config/boot.rb' - 'spec/integration/rails_2.3_with_bundler/config/boot.rb'
# Offense count: 8 # Offense count: 4
# Cop supports --auto-correct. # Cop supports --auto-correct.
# Configuration parameters: Width. # Configuration parameters: Width.
Style/IndentationWidth: Style/IndentationWidth:
Exclude: Exclude:
- 'spec/annotate/annotate_models_spec.rb'
- 'spec/integration/rails_4.1.1/app/models/sub1/sub2/sub3/event.rb' - 'spec/integration/rails_4.1.1/app/models/sub1/sub2/sub3/event.rb'
- 'spec/integration/rails_4.1.1/app/models/task.rb' - 'spec/integration/rails_4.1.1/app/models/task.rb'
- 'spec/integration/rails_4.2.0/app/models/sub1/sub2/sub3/event.rb' - 'spec/integration/rails_4.2.0/app/models/sub1/sub2/sub3/event.rb'
- 'spec/integration/rails_4.2.0/app/models/task.rb' - 'spec/integration/rails_4.2.0/app/models/task.rb'
# Offense count: 1
# Cop supports --auto-correct.
Style/LeadingCommentSpace:
Exclude:
- 'spec/annotate/annotate_models_spec.rb'
# Offense count: 3 # Offense count: 3
# Cop supports --auto-correct. # Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle, SupportedStyles. # Configuration parameters: EnforcedStyle, SupportedStyles.
...@@ -410,17 +403,12 @@ Style/MethodMissing: ...@@ -410,17 +403,12 @@ Style/MethodMissing:
Exclude: Exclude:
- 'lib/annotate/active_record_patch.rb' - 'lib/annotate/active_record_patch.rb'
# Offense count: 2 # Offense count: 3
Style/MultilineBlockChain: Style/MultilineBlockChain:
Exclude: Exclude:
- 'Rakefile' - 'Rakefile'
- 'lib/annotate/annotate_models.rb' - 'lib/annotate/annotate_models.rb'
- 'spec/spec_helper.rb'
# Offense count: 2
# Cop supports --auto-correct.
Style/MultilineIfThen:
Exclude:
- 'annotate.gemspec'
# Offense count: 3 # Offense count: 3
# Cop supports --auto-correct. # Cop supports --auto-correct.
...@@ -430,14 +418,13 @@ Style/MultilineMethodCallBraceLayout: ...@@ -430,14 +418,13 @@ Style/MultilineMethodCallBraceLayout:
Exclude: Exclude:
- 'spec/annotate/annotate_models_spec.rb' - 'spec/annotate/annotate_models_spec.rb'
# Offense count: 6 # Offense count: 3
# Cop supports --auto-correct. # Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle, SupportedStyles, IndentationWidth. # Configuration parameters: EnforcedStyle, SupportedStyles, IndentationWidth.
# SupportedStyles: aligned, indented, indented_relative_to_receiver # SupportedStyles: aligned, indented, indented_relative_to_receiver
Style/MultilineMethodCallIndentation: Style/MultilineMethodCallIndentation:
Exclude: Exclude:
- 'lib/annotate/annotate_models.rb' - 'lib/annotate/annotate_models.rb'
- 'spec/spec_helper.rb'
# Offense count: 7 # Offense count: 7
# Cop supports --auto-correct. # Cop supports --auto-correct.
...@@ -447,18 +434,16 @@ Style/MultilineOperationIndentation: ...@@ -447,18 +434,16 @@ Style/MultilineOperationIndentation:
Exclude: Exclude:
- 'lib/annotate/annotate_models.rb' - 'lib/annotate/annotate_models.rb'
# Offense count: 16 # Offense count: 11
# Cop supports --auto-correct. # Cop supports --auto-correct.
Style/MutableConstant: Style/MutableConstant:
Exclude: Exclude:
- 'lib/annotate/annotate_models.rb' - 'lib/annotate/annotate_models.rb'
- 'lib/annotate/annotate_routes.rb' - 'lib/annotate/annotate_routes.rb'
- 'spec/annotate/annotate_routes_spec.rb'
- 'spec/integration/rails_2.3_with_bundler/config/boot.rb' - 'spec/integration/rails_2.3_with_bundler/config/boot.rb'
- 'spec/integration/rails_2.3_with_bundler/config/environment.rb' - 'spec/integration/rails_2.3_with_bundler/config/environment.rb'
- 'spec/spec_helper.rb'
# Offense count: 3 # Offense count: 2
# Cop supports --auto-correct. # Cop supports --auto-correct.
Style/NegatedIf: Style/NegatedIf:
Exclude: Exclude:
...@@ -507,14 +492,13 @@ Style/ParenthesesAroundCondition: ...@@ -507,14 +492,13 @@ Style/ParenthesesAroundCondition:
Exclude: Exclude:
- 'bin/annotate' - 'bin/annotate'
# Offense count: 8 # Offense count: 7
# Cop supports --auto-correct. # Cop supports --auto-correct.
# Configuration parameters: PreferredDelimiters. # Configuration parameters: PreferredDelimiters.
Style/PercentLiteralDelimiters: Style/PercentLiteralDelimiters:
Exclude: Exclude:
- 'annotate.gemspec' - 'annotate.gemspec'
- 'spec/integration/common_validation.rb' - 'spec/integration/common_validation.rb'
- 'spec/integration/standalone.rb'
# Offense count: 1 # Offense count: 1
# Cop supports --auto-correct. # Cop supports --auto-correct.
...@@ -542,7 +526,7 @@ Style/RedundantParentheses: ...@@ -542,7 +526,7 @@ Style/RedundantParentheses:
Exclude: Exclude:
- 'lib/annotate/annotate_models.rb' - 'lib/annotate/annotate_models.rb'
# Offense count: 25 # Offense count: 6
# Cop supports --auto-correct. # Cop supports --auto-correct.
# Configuration parameters: AllowMultipleReturnValues. # Configuration parameters: AllowMultipleReturnValues.
Style/RedundantReturn: Style/RedundantReturn:
...@@ -551,24 +535,14 @@ Style/RedundantReturn: ...@@ -551,24 +535,14 @@ Style/RedundantReturn:
- 'lib/annotate/annotate_routes.rb' - 'lib/annotate/annotate_routes.rb'
- 'spec/annotate/annotate_models_spec.rb' - 'spec/annotate/annotate_models_spec.rb'
- 'spec/integration/common_validation.rb' - 'spec/integration/common_validation.rb'
- 'spec/integration/rails_2.3_with_bundler.rb'
- 'spec/integration/rails_3.2.2.rb'
- 'spec/integration/rails_3.2.8.rb' - 'spec/integration/rails_3.2.8.rb'
- 'spec/integration/rails_3.2_autoloading_factory_girl.rb'
- 'spec/integration/rails_3.2_custom_inflections.rb'
- 'spec/integration/rails_3.2_with_asset_pipeline.rb'
- 'spec/integration/standalone.rb'
- 'spec/spec_helper.rb'
# Offense count: 8 # Offense count: 3
# Cop supports --auto-correct. # Cop supports --auto-correct.
Style/RedundantSelf: Style/RedundantSelf:
Exclude: Exclude:
- 'lib/annotate/annotate_models.rb' - 'lib/annotate/annotate_models.rb'
- 'lib/tasks/migrate.rake' - 'lib/tasks/migrate.rake'
- 'spec/integration/common_validation.rb'
- 'spec/integration/rails_3.2_autoloading_factory_girl.rb'
- 'spec/integration/standalone.rb'
# Offense count: 12 # Offense count: 12
# Cop supports --auto-correct. # Cop supports --auto-correct.
...@@ -596,13 +570,7 @@ Style/Semicolon: ...@@ -596,13 +570,7 @@ Style/Semicolon:
- 'spec/annotate/annotate_models_spec.rb' - 'spec/annotate/annotate_models_spec.rb'
- 'spec/integration/rails_2.3_with_bundler/config/initializers/unified_initializer.rb' - 'spec/integration/rails_2.3_with_bundler/config/initializers/unified_initializer.rb'
# Offense count: 1 # Offense count: 19
# Cop supports --auto-correct.
Style/SpaceAfterComma:
Exclude:
- 'lib/annotate/annotate_models.rb'
# Offense count: 23
# Cop supports --auto-correct. # Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle, SupportedStyles. # Configuration parameters: EnforcedStyle, SupportedStyles.
# SupportedStyles: space, no_space # SupportedStyles: space, no_space
...@@ -610,8 +578,6 @@ Style/SpaceAroundEqualsInParameterDefault: ...@@ -610,8 +578,6 @@ Style/SpaceAroundEqualsInParameterDefault:
Exclude: Exclude:
- 'lib/annotate/annotate_models.rb' - 'lib/annotate/annotate_models.rb'
- 'lib/annotate/annotate_routes.rb' - 'lib/annotate/annotate_routes.rb'
- 'spec/annotate/annotate_models_spec.rb'
- 'spec/annotate/annotate_routes_spec.rb'
- 'spec/integration/common_validation.rb' - 'spec/integration/common_validation.rb'
# Offense count: 16 # Offense count: 16
...@@ -630,7 +596,7 @@ Style/SpaceAroundKeyword: ...@@ -630,7 +596,7 @@ Style/SpaceAroundKeyword:
- 'spec/integration/rails_4.2.0/Gemfile' - 'spec/integration/rails_4.2.0/Gemfile'
- 'spec/integration/standalone/Gemfile' - 'spec/integration/standalone/Gemfile'
# Offense count: 19 # Offense count: 13
# Cop supports --auto-correct. # Cop supports --auto-correct.
# Configuration parameters: AllowForAlignment. # Configuration parameters: AllowForAlignment.
Style/SpaceAroundOperators: Style/SpaceAroundOperators:
...@@ -639,18 +605,15 @@ Style/SpaceAroundOperators: ...@@ -639,18 +605,15 @@ Style/SpaceAroundOperators:
- 'lib/annotate/annotate_models.rb' - 'lib/annotate/annotate_models.rb'
- 'lib/tasks/annotate_models.rake' - 'lib/tasks/annotate_models.rake'
- 'lib/tasks/annotate_routes.rake' - 'lib/tasks/annotate_routes.rake'
- 'spec/annotate/annotate_models_spec.rb'
- 'spec/integration/integration_spec.rb' - 'spec/integration/integration_spec.rb'
- 'spec/spec_helper.rb'
# Offense count: 7 # Offense count: 6
# Cop supports --auto-correct. # Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle, SupportedStyles. # Configuration parameters: EnforcedStyle, SupportedStyles.
# SupportedStyles: space, no_space # SupportedStyles: space, no_space
Style/SpaceBeforeBlockBraces: Style/SpaceBeforeBlockBraces:
Exclude: Exclude:
- 'lib/annotate/annotate_models.rb' - 'lib/annotate/annotate_models.rb'
- 'spec/annotate/annotate_models_spec.rb'
# Offense count: 1 # Offense count: 1
# Cop supports --auto-correct. # Cop supports --auto-correct.
...@@ -658,14 +621,13 @@ Style/SpaceBeforeComment: ...@@ -658,14 +621,13 @@ Style/SpaceBeforeComment:
Exclude: Exclude:
- 'lib/annotate/annotate_models.rb' - 'lib/annotate/annotate_models.rb'
# Offense count: 10 # Offense count: 9
# Cop supports --auto-correct. # Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle, SupportedStyles, EnforcedStyleForEmptyBraces, SpaceBeforeBlockParameters. # Configuration parameters: EnforcedStyle, SupportedStyles, EnforcedStyleForEmptyBraces, SpaceBeforeBlockParameters.
# SupportedStyles: space, no_space # SupportedStyles: space, no_space
Style/SpaceInsideBlockBraces: Style/SpaceInsideBlockBraces:
Exclude: Exclude:
- 'lib/annotate/annotate_models.rb' - 'lib/annotate/annotate_models.rb'
- 'spec/annotate/annotate_models_spec.rb'
# Offense count: 2 # Offense count: 2
# Cop supports --auto-correct. # Cop supports --auto-correct.
...@@ -696,17 +658,15 @@ Style/SpaceInsideStringInterpolation: ...@@ -696,17 +658,15 @@ Style/SpaceInsideStringInterpolation:
Exclude: Exclude:
- 'lib/annotate/annotate_models.rb' - 'lib/annotate/annotate_models.rb'
# Offense count: 4 # Offense count: 1
# Cop supports --auto-correct. # Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle, SupportedStyles. # Configuration parameters: EnforcedStyle, SupportedStyles.
# SupportedStyles: use_perl_names, use_english_names # SupportedStyles: use_perl_names, use_english_names
Style/SpecialGlobalVars: Style/SpecialGlobalVars:
Exclude: Exclude:
- 'bin/annotate' - 'bin/annotate'
- 'spec/integration/integration_spec.rb'
- 'spec/spec_helper.rb'
# Offense count: 426 # Offense count: 266
# Cop supports --auto-correct. # Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle, SupportedStyles, ConsistentQuotesInMultiline. # Configuration parameters: EnforcedStyle, SupportedStyles, ConsistentQuotesInMultiline.
# SupportedStyles: single_quotes, double_quotes # SupportedStyles: single_quotes, double_quotes
...@@ -736,19 +696,18 @@ Style/Tab: ...@@ -736,19 +696,18 @@ Style/Tab:
- 'spec/integration/rails_4.2.0/app/models/sub1/sub2/sub3/event.rb' - 'spec/integration/rails_4.2.0/app/models/sub1/sub2/sub3/event.rb'
- 'spec/integration/rails_4.2.0/app/models/task.rb' - 'spec/integration/rails_4.2.0/app/models/task.rb'
# Offense count: 5 # Offense count: 4
# Cop supports --auto-correct. # Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle, SupportedStyles. # Configuration parameters: EnforcedStyle, SupportedStyles.
# SupportedStyles: final_newline, final_blank_line # SupportedStyles: final_newline, final_blank_line
Style/TrailingBlankLines: Style/TrailingBlankLines:
Exclude: Exclude:
- 'Guardfile'
- 'spec/integration/rails_4.1.1/app/models/task_observer.rb' - 'spec/integration/rails_4.1.1/app/models/task_observer.rb'
- 'spec/integration/rails_4.1.1/config/initializers/cookies_serializer.rb' - 'spec/integration/rails_4.1.1/config/initializers/cookies_serializer.rb'
- 'spec/integration/rails_4.2.0/app/models/task_observer.rb' - 'spec/integration/rails_4.2.0/app/models/task_observer.rb'
- 'spec/integration/rails_4.2.0/config/initializers/cookies_serializer.rb' - 'spec/integration/rails_4.2.0/config/initializers/cookies_serializer.rb'
# Offense count: 12 # Offense count: 11
# Cop supports --auto-correct. # Cop supports --auto-correct.
# Configuration parameters: EnforcedStyleForMultiline, SupportedStyles. # Configuration parameters: EnforcedStyleForMultiline, SupportedStyles.
# SupportedStyles: comma, consistent_comma, no_comma # SupportedStyles: comma, consistent_comma, no_comma
...@@ -764,20 +723,17 @@ Style/TrailingWhitespace: ...@@ -764,20 +723,17 @@ Style/TrailingWhitespace:
Exclude: Exclude:
- 'spec/integration/rails_2.3_with_bundler/db/schema.rb' - 'spec/integration/rails_2.3_with_bundler/db/schema.rb'
# Offense count: 4 # Offense count: 3
# Cop supports --auto-correct. # Cop supports --auto-correct.
Style/UnneededInterpolation: Style/UnneededInterpolation:
Exclude: Exclude:
- 'bin/annotate' - 'bin/annotate'
- 'lib/annotate/annotate_routes.rb' - 'lib/annotate/annotate_routes.rb'
- 'spec/integration/integration_spec.rb'
# Offense count: 11 # Offense count: 9
# Cop supports --auto-correct. # Cop supports --auto-correct.
Style/UnneededPercentQ: Style/UnneededPercentQ:
Exclude: Exclude:
- 'annotate.gemspec' - 'annotate.gemspec'
- 'spec/integration/common_validation.rb' - 'spec/integration/common_validation.rb'
- 'spec/integration/rails_2.3_with_bundler/config/boot.rb' - 'spec/integration/rails_2.3_with_bundler/config/boot.rb'
- 'spec/integration/standalone.rb'
- 'spec/spec_helper.rb'
source 'https://rubygems.org' source 'https://rubygems.org'
gem 'rake', require: false
gem 'activerecord', '>= 4.2.5', require: false gem 'activerecord', '>= 4.2.5', require: false
gem 'rake', require: false
group :development do group :development do
gem 'mg', require: false
gem 'bump' gem 'bump'
gem 'mg', require: false
platforms :mri, :mingw do platforms :mri, :mingw do
gem 'yard', require: false gem 'yard', require: false
end end
...@@ -13,13 +13,16 @@ end ...@@ -13,13 +13,16 @@ end
group :development, :test do group :development, :test do
gem 'byebug' gem 'byebug'
gem 'rspec', require: false
gem 'guard-rspec', require: false gem 'guard-rspec', require: false
gem 'terminal-notifier-guard', require: false gem 'rspec', require: false
gem 'simplecov', require: false
gem 'rubocop', '~> 0.46.0', require: false unless RUBY_VERSION =~ /^1.8/ gem 'rubocop', '~> 0.46.0', require: false unless RUBY_VERSION =~ /^1.8/
gem 'coveralls' gem 'simplecov', require: false
gem 'terminal-notifier-guard', require: false
gem 'codeclimate-test-reporter' gem 'codeclimate-test-reporter'
gem 'coveralls'
gem 'ruby_dep', '1.3.1' gem 'ruby_dep', '1.3.1'
platforms :mri, :mingw do platforms :mri, :mingw do
...@@ -29,6 +32,6 @@ group :development, :test do ...@@ -29,6 +32,6 @@ group :development, :test do
end end
group :test do group :test do
gem 'wrong', require: false
gem 'files', require: false gem 'files', require: false
gem 'wrong', require: false
end end
# Note: The cmd option is now required due to the increasing number of ways # Note: The cmd option is now required due to the increasing number of ways
# rspec may be run, below are examples of the most common uses. # rspec may be run, below are examples of the most common uses.
# * bundler: 'bundle exec rspec' # * bundler: 'bundle exec rspec'
...@@ -11,16 +9,16 @@ ...@@ -11,16 +9,16 @@
guard :rspec, cmd: 'bundle exec rspec' do guard :rspec, cmd: 'bundle exec rspec' do
watch(%r{^spec/.+_spec\.rb$}) watch(%r{^spec/.+_spec\.rb$})
watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" } watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
watch('spec/spec_helper.rb') { "spec" } watch('spec/spec_helper.rb') { 'spec' }
# Rails example # Rails example
watch(%r{^app/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" } watch(%r{^app/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
watch(%r{^app/(.*)(\.erb|\.haml|\.slim)$}) { |m| "spec/#{m[1]}#{m[2]}_spec.rb" } watch(%r{^app/(.*)(\.erb|\.haml|\.slim)$}) { |m| "spec/#{m[1]}#{m[2]}_spec.rb" }
watch(%r{^app/controllers/(.+)_(controller)\.rb$}) { |m| ["spec/routing/#{m[1]}_routing_spec.rb", "spec/#{m[2]}s/#{m[1]}_#{m[2]}_spec.rb", "spec/acceptance/#{m[1]}_spec.rb"] } watch(%r{^app/controllers/(.+)_(controller)\.rb$}) { |m| ["spec/routing/#{m[1]}_routing_spec.rb", "spec/#{m[2]}s/#{m[1]}_#{m[2]}_spec.rb", "spec/acceptance/#{m[1]}_spec.rb"] }
watch(%r{^spec/support/(.+)\.rb$}) { "spec" } watch(%r{^spec/support/(.+)\.rb$}) { 'spec' }
watch('config/routes.rb') { "spec/routing" } watch('config/routes.rb') { 'spec/routing' }
watch('app/controllers/application_controller.rb') { "spec/controllers" } watch('app/controllers/application_controller.rb') { 'spec/controllers' }
watch('spec/rails_helper.rb') { "spec" } watch('spec/rails_helper.rb') { 'spec' }
# Capybara features specs # Capybara features specs
watch(%r{^app/views/(.+)/.*\.(erb|haml|slim)$}) { |m| "spec/features/#{m[1]}_spec.rb" } watch(%r{^app/views/(.+)/.*\.(erb|haml|slim)$}) { |m| "spec/features/#{m[1]}_spec.rb" }
...@@ -29,4 +27,3 @@ guard :rspec, cmd: 'bundle exec rspec' do ...@@ -29,4 +27,3 @@ guard :rspec, cmd: 'bundle exec rspec' do
watch(%r{^spec/acceptance/(.+)\.feature$}) watch(%r{^spec/acceptance/(.+)\.feature$})
watch(%r{^spec/acceptance/steps/(.+)_steps\.rb$}) { |m| Dir[File.join("**/#{m[1]}.feature")][0] || 'spec/acceptance' } watch(%r{^spec/acceptance/steps/(.+)_steps\.rb$}) { |m| Dir[File.join("**/#{m[1]}.feature")][0] || 'spec/acceptance' }
end end
...@@ -4,36 +4,36 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib) ...@@ -4,36 +4,36 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
require 'annotate/version' require 'annotate/version'
Gem::Specification.new do |s| Gem::Specification.new do |s|
s.name = "annotate" s.name = 'annotate'
s.version = Annotate.version s.version = Annotate.version
s.required_ruby_version = '>= 1.9.3' s.required_ruby_version = '>= 1.9.3'
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version= s.required_rubygems_version = Gem::Requirement.new('>= 0') if s.respond_to? :required_rubygems_version=
s.authors = ["Alex Chaffee", "Cuong Tran", "Marcos Piccinini", "Turadg Aleahmad", "Jon Frisby"] s.authors = ['Alex Chaffee', 'Cuong Tran', 'Marcos Piccinini', 'Turadg Aleahmad', 'Jon Frisby']
s.description = "Annotates Rails/ActiveRecord Models, routes, fixtures, and others based on the database schema." s.description = 'Annotates Rails/ActiveRecord Models, routes, fixtures, and others based on the database schema.'
s.email = ["alex@stinky.com", "cuong.tran@gmail.com", "x@nofxx.com", "turadg@aleahmad.net", "jon@cloudability.com"] s.email = ['alex@stinky.com', 'cuong.tran@gmail.com', 'x@nofxx.com', 'turadg@aleahmad.net', 'jon@cloudability.com']
s.executables = ["annotate"] s.executables = ['annotate']
s.extra_rdoc_files = ["README.rdoc", "CHANGELOG.rdoc", "TODO.rdoc"] s.extra_rdoc_files = ['README.rdoc', 'CHANGELOG.rdoc', 'TODO.rdoc']
s.files = ["AUTHORS.rdoc", "CHANGELOG.rdoc", "LICENSE.txt", "README.rdoc", "TODO.rdoc", "annotate.gemspec", "bin/annotate", "lib/annotate.rb", "lib/annotate/active_record_patch.rb", "lib/annotate/annotate_models.rb", "lib/annotate/annotate_routes.rb", "lib/annotate/tasks.rb", "lib/annotate/version.rb", "lib/generators/annotate/USAGE", "lib/generators/annotate/install_generator.rb", "lib/generators/annotate/templates/auto_annotate_models.rake", "lib/tasks/annotate_models.rake", "lib/tasks/annotate_routes.rake", "lib/tasks/migrate.rake"] s.files = ['AUTHORS.rdoc', 'CHANGELOG.rdoc', 'LICENSE.txt', 'README.rdoc', 'TODO.rdoc', 'annotate.gemspec', 'bin/annotate', 'lib/annotate.rb', 'lib/annotate/active_record_patch.rb', 'lib/annotate/annotate_models.rb', 'lib/annotate/annotate_routes.rb', 'lib/annotate/tasks.rb', 'lib/annotate/version.rb', 'lib/generators/annotate/USAGE', 'lib/generators/annotate/install_generator.rb', 'lib/generators/annotate/templates/auto_annotate_models.rake', 'lib/tasks/annotate_models.rake', 'lib/tasks/annotate_routes.rake', 'lib/tasks/migrate.rake']
s.homepage = "http://github.com/ctran/annotate_models" s.homepage = 'http://github.com/ctran/annotate_models'
s.licenses = ["Ruby"] s.licenses = ['Ruby']
s.require_paths = ["lib"] s.require_paths = ['lib']
s.rubyforge_project = "annotate" s.rubyforge_project = 'annotate'
s.rubygems_version = "2.1.11" s.rubygems_version = '2.1.11'
s.summary = "Annotates Rails Models, routes, fixtures, and others based on the database schema." s.summary = 'Annotates Rails Models, routes, fixtures, and others based on the database schema.'
if s.respond_to? :specification_version then if s.respond_to? :specification_version
s.specification_version = 4 s.specification_version = 4
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0')
s.add_runtime_dependency(%q<rake>, [">= 10.4", "< 12.1"]) s.add_runtime_dependency(%q<rake>, ['>= 10.4', '< 12.1'])
s.add_runtime_dependency(%q<activerecord>, [">= 3.2", "< 6.0"]) s.add_runtime_dependency(%q<activerecord>, ['>= 3.2', '< 6.0'])
else else
s.add_dependency(%q<rake>, [">= 10.4", "< 12.1"]) s.add_dependency(%q<rake>, ['>= 10.4', '< 12.1'])
s.add_dependency(%q<activerecord>, [">= 3.2", "< 6.0"]) s.add_dependency(%q<activerecord>, ['>= 3.2', '< 6.0'])
end end
else else
s.add_dependency(%q<rake>, [">= 0.8.7"]) s.add_dependency(%q<rake>, ['>= 0.8.7'])
s.add_dependency(%q<activerecord>, [">= 3.2", "< 6.0"]) s.add_dependency(%q<activerecord>, ['>= 3.2', '< 6.0'])
end end
end end
...@@ -716,7 +716,7 @@ module AnnotateModels ...@@ -716,7 +716,7 @@ module AnnotateModels
id = c id = c
elsif c.name.eql?('created_at') || c.name.eql?('updated_at') elsif c.name.eql?('created_at') || c.name.eql?('updated_at')
timestamps << c timestamps << c
elsif c.name[-3,3].eql?('_id') elsif c.name[-3, 3].eql?('_id')
associations << c associations << c
else else
rest_cols << c rest_cols << c
......
#encoding: utf-8 # encoding: utf-8
require File.dirname(__FILE__) + '/../spec_helper.rb' require File.dirname(__FILE__) + '/../spec_helper.rb'
require 'annotate/annotate_models' require 'annotate/annotate_models'
require 'annotate/active_record_patch' require 'annotate/active_record_patch'
...@@ -6,54 +6,52 @@ require 'active_support/core_ext/string' ...@@ -6,54 +6,52 @@ require 'active_support/core_ext/string'
describe AnnotateModels do describe AnnotateModels do
def mock_index(name, columns = [], unique = false) def mock_index(name, columns = [], unique = false)
double("IndexKeyDefinition", double('IndexKeyDefinition',
:name => name, name: name,
:columns => columns, columns: columns,
:unique => unique unique: unique
) )
end end
def mock_foreign_key(name, from_column, to_table, to_column = 'id', constraints = {}) def mock_foreign_key(name, from_column, to_table, to_column = 'id', constraints = {})
double("ForeignKeyDefinition", double('ForeignKeyDefinition',
:name => name, name: name,
:column => from_column, column: from_column,
:to_table => to_table, to_table: to_table,
:primary_key => to_column, primary_key: to_column,
:on_delete => constraints[:on_delete], on_delete: constraints[:on_delete],
:on_update => constraints[:on_update] on_update: constraints[:on_update]
) )
end end
def mock_connection(indexes = [], foreign_keys = []) def mock_connection(indexes = [], foreign_keys = [])
double("Conn", double('Conn',
:indexes => indexes, indexes: indexes,
:foreign_keys => foreign_keys, foreign_keys: foreign_keys,
:supports_foreign_keys? => true supports_foreign_keys?: true
) )
end end
def mock_class(table_name, primary_key, columns, indexes = [], foreign_keys = []) def mock_class(table_name, primary_key, columns, indexes = [], foreign_keys = [])
options = { options = {
:connection => mock_connection(indexes, foreign_keys), connection: mock_connection(indexes, foreign_keys),
:table_exists? => true, table_exists?: true,
:table_name => table_name, table_name: table_name,
:primary_key => primary_key, primary_key: primary_key,
:column_names => columns.map { |col| col.name.to_s }, column_names: columns.map { |col| col.name.to_s },
:columns => columns, columns: columns,
:column_defaults => Hash[columns.map { |col| column_defaults: Hash[columns.map { |col| [col.name, col.default] }],
[col.name, col.default] table_name_prefix: ''
}],
:table_name_prefix => '',
} }
double("An ActiveRecord class", options) double('An ActiveRecord class', options)
end end
def mock_column(name, type, options={}) def mock_column(name, type, options = {})
default_options = { default_options = {
:limit => nil, limit: nil,
:null => false, null: false,
:default => nil default: nil
} }
stubs = default_options.dup stubs = default_options.dup
...@@ -61,26 +59,26 @@ describe AnnotateModels do ...@@ -61,26 +59,26 @@ describe AnnotateModels do
stubs[:name] = name stubs[:name] = name
stubs[:type] = type stubs[:type] = type
double("Column", stubs) double('Column', stubs)
end end
it { expect(AnnotateModels.quote(nil)).to eql("NULL") } it { expect(AnnotateModels.quote(nil)).to eql('NULL') }
it { expect(AnnotateModels.quote(true)).to eql("TRUE") } it { expect(AnnotateModels.quote(true)).to eql('TRUE') }
it { expect(AnnotateModels.quote(false)).to eql("FALSE") } it { expect(AnnotateModels.quote(false)).to eql('FALSE') }
it { expect(AnnotateModels.quote(25)).to eql("25") } it { expect(AnnotateModels.quote(25)).to eql('25') }
it { expect(AnnotateModels.quote(25.6)).to eql("25.6") } it { expect(AnnotateModels.quote(25.6)).to eql('25.6') }
it { expect(AnnotateModels.quote(1e-20)).to eql("1.0e-20") } it { expect(AnnotateModels.quote(1e-20)).to eql('1.0e-20') }
it { expect(AnnotateModels.quote(BigDecimal.new("1.2"))).to eql("1.2") } it { expect(AnnotateModels.quote(BigDecimal.new('1.2'))).to eql('1.2') }
it { expect(AnnotateModels.quote([BigDecimal.new("1.2")])).to eql(["1.2"]) } it { expect(AnnotateModels.quote([BigDecimal.new('1.2')])).to eql(['1.2']) }
it "should get schema info with default options" do it 'should get schema info with default options' do
klass = mock_class(:users, :id, [ klass = mock_class(:users, :id, [
mock_column(:id, :integer, :limit => 8), mock_column(:id, :integer, limit: 8),
mock_column(:name, :string, :limit => 50), mock_column(:name, :string, limit: 50),
mock_column(:notes, :text, :limit => 55), mock_column(:notes, :text, limit: 55),
]) ])
expect(AnnotateModels.get_schema_info(klass, "Schema Info")).to eql(<<-EOS) expect(AnnotateModels.get_schema_info(klass, 'Schema Info')).to eql(<<-EOS)
# Schema Info # Schema Info
# #
# Table name: users # Table name: users
...@@ -92,13 +90,13 @@ describe AnnotateModels do ...@@ -92,13 +90,13 @@ describe AnnotateModels do
EOS EOS
end end
it "should get schema info even if the primary key is not set" do it 'should get schema info even if the primary key is not set' do
klass = mock_class(:users, nil, [ klass = mock_class(:users, nil, [
mock_column(:id, :integer), mock_column(:id, :integer),
mock_column(:name, :string, :limit => 50) mock_column(:name, :string, limit: 50)
]) ])
expect(AnnotateModels.get_schema_info(klass, "Schema Info")).to eql(<<-EOS) expect(AnnotateModels.get_schema_info(klass, 'Schema Info')).to eql(<<-EOS)
# Schema Info # Schema Info
# #
# Table name: users # Table name: users
...@@ -109,14 +107,14 @@ EOS ...@@ -109,14 +107,14 @@ EOS
EOS EOS
end end
it "should get schema info even if the primary key is array, if using composite_primary_keys" do it 'should get schema info even if the primary key is array, if using composite_primary_keys' do
klass = mock_class(:users, [:a_id, :b_id], [ klass = mock_class(:users, [:a_id, :b_id], [
mock_column(:a_id, :integer), mock_column(:a_id, :integer),
mock_column(:b_id, :integer), mock_column(:b_id, :integer),
mock_column(:name, :string, :limit => 50) mock_column(:name, :string, limit: 50)
]) ])
expect(AnnotateModels.get_schema_info(klass, "Schema Info")).to eql(<<-EOS) expect(AnnotateModels.get_schema_info(klass, 'Schema Info')).to eql(<<-EOS)
# Schema Info # Schema Info
# #
# Table name: users # Table name: users
...@@ -128,13 +126,13 @@ EOS ...@@ -128,13 +126,13 @@ EOS
EOS EOS
end end
it "should get schema info with enum type " do it 'should get schema info with enum type' do
klass = mock_class(:users, nil, [ klass = mock_class(:users, nil, [
mock_column(:id, :integer), mock_column(:id, :integer),
mock_column(:name, :enum, :limit => [:enum1, :enum2]) mock_column(:name, :enum, limit: [:enum1, :enum2])
]) ])
expect(AnnotateModels.get_schema_info(klass, "Schema Info")).to eql(<<-EOS) expect(AnnotateModels.get_schema_info(klass, 'Schema Info')).to eql(<<-EOS)
# Schema Info # Schema Info
# #
# Table name: users # Table name: users
...@@ -145,16 +143,16 @@ EOS ...@@ -145,16 +143,16 @@ EOS
EOS EOS
end end
it "should get schema info with unsigned" do it 'should get schema info with unsigned' do
klass = mock_class(:users, nil, [ klass = mock_class(:users, nil, [
mock_column(:id, :integer), mock_column(:id, :integer),
mock_column(:integer, :integer, :unsigned? => true), mock_column(:integer, :integer, unsigned?: true),
mock_column(:bigint, :bigint, :unsigned? => true), mock_column(:bigint, :bigint, unsigned?: true),
mock_column(:float, :float, :unsigned? => true), mock_column(:float, :float, unsigned?: true),
mock_column(:decimal, :decimal, :unsigned? => true, :precision => 10, :scale => 2), mock_column(:decimal, :decimal, unsigned?: true, :precision => 10, :scale => 2),
]) ])
expect(AnnotateModels.get_schema_info(klass, "Schema Info")).to eql(<<-EOS) expect(AnnotateModels.get_schema_info(klass, 'Schema Info')).to eql(<<-EOS)
# Schema Info # Schema Info
# #
# Table name: users # Table name: users
...@@ -168,13 +166,13 @@ EOS ...@@ -168,13 +166,13 @@ EOS
EOS EOS
end end
it "should get schema info for integer and boolean with default" do it 'should get schema info for integer and boolean with default' do
klass = mock_class(:users, :id, [ klass = mock_class(:users, :id, [
mock_column(:id, :integer), mock_column(:id, :integer),
mock_column(:size, :integer, :default => 20), mock_column(:size, :integer, default: 20),
mock_column(:flag, :boolean, :default => false) mock_column(:flag, :boolean, default: false)
]) ])
expect(AnnotateModels.get_schema_info(klass, "Schema Info")).to eql(<<-EOS) expect(AnnotateModels.get_schema_info(klass, 'Schema Info')).to eql(<<-EOS)
# Schema Info # Schema Info
# #
# Table name: users # Table name: users
...@@ -186,7 +184,7 @@ EOS ...@@ -186,7 +184,7 @@ EOS
EOS EOS
end end
it "should get foreign key info" do it 'should get foreign key info' do
klass = mock_class(:users, :id, [ klass = mock_class(:users, :id, [
mock_column(:id, :integer), mock_column(:id, :integer),
mock_column(:foreign_thing_id, :integer), mock_column(:foreign_thing_id, :integer),
...@@ -208,7 +206,7 @@ EOS ...@@ -208,7 +206,7 @@ EOS
'third_things' 'third_things'
) )
]) ])
expect(AnnotateModels.get_schema_info(klass, "Schema Info", :show_foreign_keys => true)).to eql(<<-EOS) expect(AnnotateModels.get_schema_info(klass, 'Schema Info', show_foreign_keys: true)).to eql(<<-EOS)
# Schema Info # Schema Info
# #
# Table name: users # Table name: users
...@@ -225,7 +223,7 @@ EOS ...@@ -225,7 +223,7 @@ EOS
EOS EOS
end end
it "should get foreign key info if on_delete/on_update options present" do it 'should get foreign key info if on_delete/on_update options present' do
klass = mock_class(:users, :id, [ klass = mock_class(:users, :id, [
mock_column(:id, :integer), mock_column(:id, :integer),
mock_column(:foreign_thing_id, :integer), mock_column(:foreign_thing_id, :integer),
...@@ -240,7 +238,7 @@ EOS ...@@ -240,7 +238,7 @@ EOS
on_update: 'on_update_value' on_update: 'on_update_value'
) )
]) ])
expect(AnnotateModels.get_schema_info(klass, "Schema Info", :show_foreign_keys => true)).to eql(<<-EOS) expect(AnnotateModels.get_schema_info(klass, 'Schema Info', show_foreign_keys: true)).to eql(<<-EOS)
# Schema Info # Schema Info
# #
# Table name: users # Table name: users
...@@ -255,13 +253,13 @@ EOS ...@@ -255,13 +253,13 @@ EOS
EOS EOS
end end
it "should get indexes keys" do it 'should get indexes keys' do
klass = mock_class(:users, :id, [ klass = mock_class(:users, :id, [
mock_column(:id, :integer), mock_column(:id, :integer),
mock_column(:foreign_thing_id, :integer), mock_column(:foreign_thing_id, :integer),
], [mock_index('index_rails_02e851e3b7', ['id']), ], [mock_index('index_rails_02e851e3b7', ['id']),
mock_index('index_rails_02e851e3b8', ['foreign_thing_id'])]) mock_index('index_rails_02e851e3b8', ['foreign_thing_id'])])
expect(AnnotateModels.get_schema_info(klass, "Schema Info", :show_indexes => true)).to eql(<<-EOS) expect(AnnotateModels.get_schema_info(klass, 'Schema Info', show_indexes: true)).to eql(<<-EOS)
# Schema Info # Schema Info
# #
# Table name: users # Table name: users
...@@ -277,12 +275,12 @@ EOS ...@@ -277,12 +275,12 @@ EOS
EOS EOS
end end
it "should not crash getting indexes keys" do it 'should not crash getting indexes keys' do
klass = mock_class(:users, :id, [ klass = mock_class(:users, :id, [
mock_column(:id, :integer), mock_column(:id, :integer),
mock_column(:foreign_thing_id, :integer), mock_column(:foreign_thing_id, :integer),
], []) ], [])
expect(AnnotateModels.get_schema_info(klass, "Schema Info", :show_indexes => true)).to eql(<<-EOS) expect(AnnotateModels.get_schema_info(klass, 'Schema Info', show_indexes: true)).to eql(<<-EOS)
# Schema Info # Schema Info
# #
# Table name: users # Table name: users
...@@ -293,10 +291,10 @@ EOS ...@@ -293,10 +291,10 @@ EOS
EOS EOS
end end
it "should get schema info as RDoc" do it 'should get schema info as RDoc' do
klass = mock_class(:users, :id, [ klass = mock_class(:users, :id, [
mock_column(:id, :integer), mock_column(:id, :integer),
mock_column(:name, :string, :limit => 50) mock_column(:name, :string, limit: 50)
]) ])
expect(AnnotateModels.get_schema_info(klass, AnnotateModels::PREFIX, :format_rdoc => true)).to eql(<<-EOS) expect(AnnotateModels.get_schema_info(klass, AnnotateModels::PREFIX, :format_rdoc => true)).to eql(<<-EOS)
# #{AnnotateModels::PREFIX} # #{AnnotateModels::PREFIX}
...@@ -311,24 +309,24 @@ EOS ...@@ -311,24 +309,24 @@ EOS
EOS EOS
end end
describe "#get_schema_info with custom options" do describe '#get_schema_info with custom options' do
def self.when_called_with(options = {}) def self.when_called_with(options = {})
expected = options.delete(:returns) expected = options.delete(:returns)
default_columns = [ default_columns = [
[:id, :integer, { :limit => 8 }], [:id, :integer, { limit: 8 }],
[:active, :boolean, { :limit => 1 }], [:active, :boolean, { limit: 1 }],
[:name, :string, { :limit => 50 }], [:name, :string, { limit: 50 }],
[:notes, :text, { :limit => 55 }] [:notes, :text, { limit: 55 }]
] ]
it "should work with options = #{options}" do it 'should work with options = #{options}' do
with_columns = (options.delete(:with_columns) || default_columns).map do |column| with_columns = (options.delete(:with_columns) || default_columns).map do |column|
mock_column(column[0], column[1], column[2]) mock_column(column[0], column[1], column[2])
end end
klass = mock_class(:users, :id, with_columns) klass = mock_class(:users, :id, with_columns)
schema_info = AnnotateModels.get_schema_info(klass, "Schema Info", options) schema_info = AnnotateModels.get_schema_info(klass, 'Schema Info', options)
expect(schema_info).to eql(expected) expect(schema_info).to eql(expected)
end end
end end
...@@ -425,9 +423,9 @@ EOS ...@@ -425,9 +423,9 @@ EOS
describe 'classified_sort option' do describe 'classified_sort option' do
mocked_columns_without_id = [ mocked_columns_without_id = [
[:active, :boolean, { :limit => 1 }], [:active, :boolean, { limit: 1 }],
[:name, :string, { :limit => 50 }], [:name, :string, { limit: 50 }],
[:notes, :text, { :limit => 55 }] [:notes, :text, { limit: 55 }]
] ]
when_called_with classified_sort: 'yes', with_columns: mocked_columns_without_id, returns: when_called_with classified_sort: 'yes', with_columns: mocked_columns_without_id, returns:
...@@ -444,8 +442,8 @@ EOS ...@@ -444,8 +442,8 @@ EOS
end end
end end
describe "#get_model_class" do describe '#get_model_class' do
require "tmpdir" require 'tmpdir'
module ::ActiveRecord module ::ActiveRecord
class Base class Base
...@@ -455,10 +453,10 @@ EOS ...@@ -455,10 +453,10 @@ EOS
end end
# todo: use 'files' gem instead # todo: use 'files' gem instead
def create(file, body="hi") def create(file, body = 'hi')
file_path = File.join(AnnotateModels.model_dir[0], file) file_path = File.join(AnnotateModels.model_dir[0], file)
FileUtils.mkdir_p(File.dirname(file_path)) FileUtils.mkdir_p(File.dirname(file_path))
File.open(file_path, "wb") do |f| File.open(file_path, 'wb') do |f|
f.puts(body) f.puts(body)
end end
file_path file_path
...@@ -475,7 +473,7 @@ EOS ...@@ -475,7 +473,7 @@ EOS
AnnotateModels.model_dir = Dir.mktmpdir 'annotate_models' AnnotateModels.model_dir = Dir.mktmpdir 'annotate_models'
end end
it "should work" do it 'should work' do
create 'foo.rb', <<-EOS create 'foo.rb', <<-EOS
class Foo < ActiveRecord::Base class Foo < ActiveRecord::Base
end end
...@@ -483,7 +481,7 @@ EOS ...@@ -483,7 +481,7 @@ EOS
check_class_name 'foo.rb', 'Foo' check_class_name 'foo.rb', 'Foo'
end end
it "should find models with non standard capitalization" do it 'should find models with non standard capitalization' do
create 'foo_with_capitals.rb', <<-EOS create 'foo_with_capitals.rb', <<-EOS
class FooWithCAPITALS < ActiveRecord::Base class FooWithCAPITALS < ActiveRecord::Base
end end
...@@ -491,7 +489,7 @@ EOS ...@@ -491,7 +489,7 @@ EOS
check_class_name 'foo_with_capitals.rb', 'FooWithCAPITALS' check_class_name 'foo_with_capitals.rb', 'FooWithCAPITALS'
end end
it "should find models inside modules" do it 'should find models inside modules' do
create 'bar/foo_inside_bar.rb', <<-EOS create 'bar/foo_inside_bar.rb', <<-EOS
module Bar module Bar
class FooInsideBar < ActiveRecord::Base class FooInsideBar < ActiveRecord::Base
...@@ -501,7 +499,7 @@ EOS ...@@ -501,7 +499,7 @@ EOS
check_class_name 'bar/foo_inside_bar.rb', 'Bar::FooInsideBar' check_class_name 'bar/foo_inside_bar.rb', 'Bar::FooInsideBar'
end end
it "should find AR model when duplicated by a nested model" do it 'should find AR model when duplicated by a nested model' do
create 'foo.rb', <<-EOS create 'foo.rb', <<-EOS
class Foo < ActiveRecord::Base class Foo < ActiveRecord::Base
end end
...@@ -515,7 +513,7 @@ EOS ...@@ -515,7 +513,7 @@ EOS
check_class_name 'foo.rb', 'Foo' check_class_name 'foo.rb', 'Foo'
end end
it "should find AR model nested inside a class" do it 'should find AR model nested inside a class' do
create 'voucher.rb', <<-EOS create 'voucher.rb', <<-EOS
class Voucher < ActiveRecord::Base class Voucher < ActiveRecord::Base
end end
...@@ -532,8 +530,7 @@ EOS ...@@ -532,8 +530,7 @@ EOS
check_class_name 'voucher/foo.rb', 'Voucher::Foo' check_class_name 'voucher/foo.rb', 'Voucher::Foo'
end end
it 'should not care about unknown macros' do
it "should not care about unknown macros" do
create 'foo_with_macro.rb', <<-EOS create 'foo_with_macro.rb', <<-EOS
class FooWithMacro < ActiveRecord::Base class FooWithMacro < ActiveRecord::Base
acts_as_awesome :yah acts_as_awesome :yah
...@@ -542,7 +539,7 @@ EOS ...@@ -542,7 +539,7 @@ EOS
check_class_name 'foo_with_macro.rb', 'FooWithMacro' check_class_name 'foo_with_macro.rb', 'FooWithMacro'
end end
it "should not care about known macros" do it 'should not care about known macros' do
create('foo_with_known_macro.rb', <<-EOS) create('foo_with_known_macro.rb', <<-EOS)
class FooWithKnownMacro < ActiveRecord::Base class FooWithKnownMacro < ActiveRecord::Base
has_many :yah has_many :yah
...@@ -551,7 +548,7 @@ EOS ...@@ -551,7 +548,7 @@ EOS
check_class_name 'foo_with_known_macro.rb', 'FooWithKnownMacro' check_class_name 'foo_with_known_macro.rb', 'FooWithKnownMacro'
end end
it "should work with class names with ALL CAPS segments" do it 'should work with class names with ALL CAPS segments' do
create('foo_with_capitals.rb', <<-EOS) create('foo_with_capitals.rb', <<-EOS)
class FooWithCAPITALS < ActiveRecord::Base class FooWithCAPITALS < ActiveRecord::Base
acts_as_awesome :yah acts_as_awesome :yah
...@@ -560,7 +557,7 @@ EOS ...@@ -560,7 +557,7 @@ EOS
check_class_name 'foo_with_capitals.rb', 'FooWithCAPITALS' check_class_name 'foo_with_capitals.rb', 'FooWithCAPITALS'
end end
it "should not complain of invalid multibyte char (USASCII)" do it 'should not complain of invalid multibyte char (USASCII)' do
create 'foo_with_utf8.rb', <<-EOS create 'foo_with_utf8.rb', <<-EOS
#encoding: utf-8 #encoding: utf-8
class FooWithUtf8 < ActiveRecord::Base class FooWithUtf8 < ActiveRecord::Base
...@@ -570,7 +567,7 @@ EOS ...@@ -570,7 +567,7 @@ EOS
check_class_name 'foo_with_utf8.rb', 'FooWithUtf8' check_class_name 'foo_with_utf8.rb', 'FooWithUtf8'
end end
it "should find models inside modules with non standard capitalization" do it 'should find models inside modules with non standard capitalization' do
create 'bar/foo_inside_capitals_bar.rb', <<-EOS create 'bar/foo_inside_capitals_bar.rb', <<-EOS
module BAR module BAR
class FooInsideCapitalsBAR < ActiveRecord::Base class FooInsideCapitalsBAR < ActiveRecord::Base
...@@ -580,7 +577,7 @@ EOS ...@@ -580,7 +577,7 @@ EOS
check_class_name 'bar/foo_inside_capitals_bar.rb', 'BAR::FooInsideCapitalsBAR' check_class_name 'bar/foo_inside_capitals_bar.rb', 'BAR::FooInsideCapitalsBAR'
end end
it "should find non-namespaced models inside subdirectories" do it 'should find non-namespaced models inside subdirectories' do
create 'bar/non_namespaced_foo_inside_bar.rb', <<-EOS create 'bar/non_namespaced_foo_inside_bar.rb', <<-EOS
class NonNamespacedFooInsideBar < ActiveRecord::Base class NonNamespacedFooInsideBar < ActiveRecord::Base
end end
...@@ -588,7 +585,7 @@ EOS ...@@ -588,7 +585,7 @@ EOS
check_class_name 'bar/non_namespaced_foo_inside_bar.rb', 'NonNamespacedFooInsideBar' check_class_name 'bar/non_namespaced_foo_inside_bar.rb', 'NonNamespacedFooInsideBar'
end end
it "should find non-namespaced models with non standard capitalization inside subdirectories" do it 'should find non-namespaced models with non standard capitalization inside subdirectories' do
create 'bar/non_namespaced_foo_with_capitals_inside_bar.rb', <<-EOS create 'bar/non_namespaced_foo_with_capitals_inside_bar.rb', <<-EOS
class NonNamespacedFooWithCapitalsInsideBar < ActiveRecord::Base class NonNamespacedFooWithCapitalsInsideBar < ActiveRecord::Base
end end
...@@ -596,7 +593,7 @@ EOS ...@@ -596,7 +593,7 @@ EOS
check_class_name 'bar/non_namespaced_foo_with_capitals_inside_bar.rb', 'NonNamespacedFooWithCapitalsInsideBar' check_class_name 'bar/non_namespaced_foo_with_capitals_inside_bar.rb', 'NonNamespacedFooWithCapitalsInsideBar'
end end
it "should allow known macros" do it 'should allow known macros' do
create('foo_with_known_macro.rb', <<-EOS) create('foo_with_known_macro.rb', <<-EOS)
class FooWithKnownMacro < ActiveRecord::Base class FooWithKnownMacro < ActiveRecord::Base
has_many :yah has_many :yah
...@@ -604,10 +601,10 @@ EOS ...@@ -604,10 +601,10 @@ EOS
EOS EOS
expect(capturing(:stderr) do expect(capturing(:stderr) do
check_class_name 'foo_with_known_macro.rb', 'FooWithKnownMacro' check_class_name 'foo_with_known_macro.rb', 'FooWithKnownMacro'
end).to eq("") end).to eq('')
end end
it "should not require model files twice" do it 'should not require model files twice' do
create 'loaded_class.rb', <<-EOS create 'loaded_class.rb', <<-EOS
class LoadedClass < ActiveRecord::Base class LoadedClass < ActiveRecord::Base
CONSTANT = 1 CONSTANT = 1
...@@ -619,19 +616,20 @@ EOS ...@@ -619,19 +616,20 @@ EOS
expect(capturing(:stderr) { expect(capturing(:stderr) {
check_class_name 'loaded_class.rb', 'LoadedClass' check_class_name 'loaded_class.rb', 'LoadedClass'
}).not_to include("warning: already initialized constant LoadedClass::CONSTANT") }).not_to include('warning: already initialized constant LoadedClass::CONSTANT')
end end
end end
describe "#remove_annotation_of_file" do describe '#remove_annotation_of_file' do
require "tmpdir" require 'tmpdir'
def create(file, body="hi") def create(file, body = 'hi')
path = File.join(@dir, file) path = File.join(@dir, file)
File.open(path, "w") do |f| File.open(path, 'w') do |f|
f.puts(body) f.puts(body)
end end
return path
path
end end
def content(path) def content(path)
...@@ -642,8 +640,8 @@ EOS ...@@ -642,8 +640,8 @@ EOS
@dir = Dir.mktmpdir 'annotate_models' @dir = Dir.mktmpdir 'annotate_models'
end end
it "should remove before annotate" do it 'should remove before annotate' do
path = create "before.rb", <<-EOS path = create 'before.rb', <<-EOS
# == Schema Information # == Schema Information
# #
# Table name: foo # Table name: foo
...@@ -665,8 +663,8 @@ end ...@@ -665,8 +663,8 @@ end
EOS EOS
end end
it "should remove after annotate" do it 'should remove after annotate' do
path = create "after.rb", <<-EOS path = create 'after.rb', <<-EOS
class Foo < ActiveRecord::Base class Foo < ActiveRecord::Base
end end
...@@ -689,8 +687,8 @@ end ...@@ -689,8 +687,8 @@ end
EOS EOS
end end
it "should remove opening wrapper" do it 'should remove opening wrapper' do
path = create "opening_wrapper.rb", <<-EOS path = create 'opening_wrapper.rb', <<-EOS
# wrapper # wrapper
# == Schema Information # == Schema Information
# #
...@@ -713,8 +711,8 @@ end ...@@ -713,8 +711,8 @@ end
EOS EOS
end end
it "should remove closing wrapper" do it 'should remove closing wrapper' do
path = create "closing_wrapper.rb", <<-EOS path = create 'closing_wrapper.rb', <<-EOS
class Foo < ActiveRecord::Base class Foo < ActiveRecord::Base
end end
...@@ -768,26 +766,26 @@ end ...@@ -768,26 +766,26 @@ end
expect(filename). to eq 'test/fixtures/parent/children.yml' expect(filename). to eq 'test/fixtures/parent/children.yml'
end end
end end
describe "annotating a file" do describe 'annotating a file' do
before do before do
@model_dir = Dir.mktmpdir('annotate_models') @model_dir = Dir.mktmpdir('annotate_models')
(@model_file_name, @file_content) = write_model "user.rb", <<-EOS (@model_file_name, @file_content) = write_model 'user.rb', <<-EOS
class User < ActiveRecord::Base class User < ActiveRecord::Base
end end
EOS EOS
@klass = mock_class(:users, :id, [ @klass = mock_class(:users, :id, [
mock_column(:id, :integer), mock_column(:id, :integer),
mock_column(:name, :string, :limit => 50) mock_column(:name, :string, limit: 50)
]) ])
@schema_info = AnnotateModels.get_schema_info(@klass, "== Schema Info") @schema_info = AnnotateModels.get_schema_info(@klass, '== Schema Info')
Annotate.reset_options Annotate.reset_options
end end
def write_model file_name, file_content def write_model file_name, file_content
fname = File.join(@model_dir, file_name) fname = File.join(@model_dir, file_name)
FileUtils.mkdir_p(File.dirname(fname)) FileUtils.mkdir_p(File.dirname(fname))
File.open(fname, "wb") { |f| f.write file_content } File.open(fname, 'wb') { |f| f.write file_content }
return fname, file_content return fname, file_content
end end
...@@ -816,134 +814,111 @@ end ...@@ -816,134 +814,111 @@ end
'# frozen_string_literal: true', '# frozen_string_literal: true',
'#frozen_string_literal: false', '#frozen_string_literal: false',
'# -*- frozen_string_literal : true -*-', '# -*- frozen_string_literal : true -*-',
].each{|magic_comment| yield magic_comment } ].each { |magic_comment| yield magic_comment }
end
it "should put annotation before class if :position == 'before'" do
annotate_one_file :position => "before"
expect(File.read(@model_file_name)).to eq("#{@schema_info}\n#{@file_content}")
end
it "should put annotation before class if :position => :before" do
annotate_one_file :position => :before
expect(File.read(@model_file_name)).to eq("#{@schema_info}\n#{@file_content}")
end
it "should put annotation before class if :position == 'top'" do
annotate_one_file :position => "top"
expect(File.read(@model_file_name)).to eq("#{@schema_info}\n#{@file_content}")
end end
it "should put annotation before class if :position => :top" do ['before', :before, 'top', :top].each do |position|
annotate_one_file :position => :top it "should put annotation before class if :position == #{position}" do
expect(File.read(@model_file_name)).to eq("#{@schema_info}\n#{@file_content}") annotate_one_file position: position
end expect(File.read(@model_file_name))
.to eq("#{@schema_info}\n#{@file_content}")
it "should put annotation after class if :position => 'after'" do
annotate_one_file :position => 'after'
expect(File.read(@model_file_name)).to eq("#{@file_content}\n#{@schema_info}")
end end
it "should put annotation after class if :position => :after" do
annotate_one_file :position => :after
expect(File.read(@model_file_name)).to eq("#{@file_content}\n#{@schema_info}")
end end
it "should put annotation after class if :position => 'bottom'" do ['after', :after, 'bottom', :bottom].each do |position|
annotate_one_file :position => 'bottom' it "should put annotation after class if position: #{position}" do
expect(File.read(@model_file_name)).to eq("#{@file_content}\n#{@schema_info}") annotate_one_file position: position
expect(File.read(@model_file_name))
.to eq("#{@file_content}\n#{@schema_info}")
end end
it "should put annotation after class if :position => :bottom" do
annotate_one_file :position => :bottom
expect(File.read(@model_file_name)).to eq("#{@file_content}\n#{@schema_info}")
end end
it 'should wrap annotation if wrapper is specified' do it 'should wrap annotation if wrapper is specified' do
annotate_one_file :wrapper_open => 'START', :wrapper_close => 'END' annotate_one_file wrapper_open: 'START', wrapper_close: 'END'
expect(File.read(@model_file_name)).to eq("# START\n#{@schema_info}# END\n\n#{@file_content}") expect(File.read(@model_file_name))
.to eq("# START\n#{@schema_info}# END\n\n#{@file_content}")
end end
describe "with existing annotation => :before" do describe 'with existing annotation => :before' do
before do before do
annotate_one_file :position => :before annotate_one_file position: :before
another_schema_info = AnnotateModels.get_schema_info(mock_class(:users, :id, [mock_column(:id, :integer),]), another_schema_info = AnnotateModels.get_schema_info(mock_class(:users, :id, [mock_column(:id, :integer),]),
"== Schema Info") '== Schema Info')
@schema_info = another_schema_info @schema_info = another_schema_info
end end
it "should retain current position" do it 'should retain current position' do
annotate_one_file annotate_one_file
expect(File.read(@model_file_name)).to eq("#{@schema_info}\n#{@file_content}") expect(File.read(@model_file_name)).to eq("#{@schema_info}\n#{@file_content}")
end end
it "should retain current position even when :position is changed to :after" do it 'should retain current position even when :position is changed to :after' do
annotate_one_file :position => :after annotate_one_file position: :after
expect(File.read(@model_file_name)).to eq("#{@schema_info}\n#{@file_content}") expect(File.read(@model_file_name)).to eq("#{@schema_info}\n#{@file_content}")
end end
it "should change position to :after when :force => true" do it 'should change position to :after when force: true' do
annotate_one_file :position => :after, :force => true annotate_one_file position: :after, force: true
expect(File.read(@model_file_name)).to eq("#{@file_content}\n#{@schema_info}") expect(File.read(@model_file_name)).to eq("#{@file_content}\n#{@schema_info}")
end end
end end
describe "with existing annotation => :after" do describe 'with existing annotation => :after' do
before do before do
annotate_one_file :position => :after annotate_one_file position: :after
another_schema_info = AnnotateModels.get_schema_info(mock_class(:users, :id, [mock_column(:id, :integer),]), another_schema_info = AnnotateModels.get_schema_info(mock_class(:users, :id, [mock_column(:id, :integer),]),
"== Schema Info") '== Schema Info')
@schema_info = another_schema_info @schema_info = another_schema_info
end end
it "should retain current position" do it 'should retain current position' do
annotate_one_file annotate_one_file
expect(File.read(@model_file_name)).to eq("#{@file_content}\n#{@schema_info}") expect(File.read(@model_file_name)).to eq("#{@file_content}\n#{@schema_info}")
end end
it "should retain current position even when :position is changed to :before" do it 'should retain current position even when :position is changed to :before' do
annotate_one_file :position => :before annotate_one_file position: :before
expect(File.read(@model_file_name)).to eq("#{@file_content}\n#{@schema_info}") expect(File.read(@model_file_name)).to eq("#{@file_content}\n#{@schema_info}")
end end
it "should change position to :before when :force => true" do it 'should change position to :before when force: true' do
annotate_one_file :position => :before, :force => true annotate_one_file position: :before, force: true
expect(File.read(@model_file_name)).to eq("#{@schema_info}\n#{@file_content}") expect(File.read(@model_file_name)).to eq("#{@schema_info}\n#{@file_content}")
end end
end end
it 'should skip columns with option[:ignore_columns] set' do it 'should skip columns with option[:ignore_columns] set' do
output = AnnotateModels.get_schema_info(@klass, "== Schema Info", output = AnnotateModels.get_schema_info(@klass, '== Schema Info',
:ignore_columns => '(id|updated_at|created_at)') :ignore_columns => '(id|updated_at|created_at)')
expect(output.match(/id/)).to be_nil expect(output.match(/id/)).to be_nil
end end
it "works with namespaced models (i.e. models inside modules/subdirectories)" do it 'works with namespaced models (i.e. models inside modules/subdirectories)' do
(model_file_name, file_content) = write_model "foo/user.rb", <<-EOS (model_file_name, file_content) = write_model 'foo/user.rb', <<-EOS
class Foo::User < ActiveRecord::Base class Foo::User < ActiveRecord::Base
end end
EOS EOS
klass = mock_class(:'foo_users', :id, [ klass = mock_class(:'foo_users', :id, [
mock_column(:id, :integer), mock_column(:id, :integer),
mock_column(:name, :string, :limit => 50) mock_column(:name, :string, limit: 50)
]) ])
schema_info = AnnotateModels.get_schema_info(klass, "== Schema Info") schema_info = AnnotateModels.get_schema_info(klass, '== Schema Info')
AnnotateModels.annotate_one_file(model_file_name, schema_info, :position => :before) AnnotateModels.annotate_one_file(model_file_name, schema_info, position: :before)
expect(File.read(model_file_name)).to eq("#{schema_info}\n#{file_content}") expect(File.read(model_file_name)).to eq("#{schema_info}\n#{file_content}")
end end
it "should not touch magic comments" do it 'should not touch magic comments' do
magic_comments_list_each do |magic_comment| magic_comments_list_each do |magic_comment|
write_model "user.rb", <<-EOS write_model 'user.rb', <<-EOS
#{magic_comment} #{magic_comment}
class User < ActiveRecord::Base class User < ActiveRecord::Base
end end
EOS EOS
annotate_one_file :position => :before annotate_one_file position: :before
lines= magic_comment.split("\n") lines = magic_comment.split("\n")
File.open @model_file_name do |file| File.open @model_file_name do |file|
lines.count.times do |index| lines.count.times do |index|
expect(file.readline).to eq "#{lines[index]}\n" expect(file.readline).to eq "#{lines[index]}\n"
...@@ -963,19 +938,19 @@ end ...@@ -963,19 +938,19 @@ end
EOS EOS
end end
it "displays an error message" do it 'displays an error message' do
expect(capturing(:stdout) { expect(capturing(:stdout) {
AnnotateModels.do_annotations :model_dir => @model_dir, :is_rake => true AnnotateModels.do_annotations :model_dir => @model_dir, :is_rake => true
}).to include("Unable to annotate #{@model_dir}/user.rb: oops") }).to include("Unable to annotate #{@model_dir}/user.rb: oops")
end end
it "displays the full stack trace with --trace" do it 'displays the full stack trace with --trace' do
expect(capturing(:stdout) { expect(capturing(:stdout) {
AnnotateModels.do_annotations :model_dir => @model_dir, :trace => true, :is_rake => true AnnotateModels.do_annotations :model_dir => @model_dir, :trace => true, :is_rake => true
}).to include("/spec/annotate/annotate_models_spec.rb:") }).to include("/spec/annotate/annotate_models_spec.rb:")
end end
it "omits the full stack trace without --trace" do it 'omits the full stack trace without --trace' do
expect(capturing(:stdout) { expect(capturing(:stdout) {
AnnotateModels.do_annotations :model_dir => @model_dir, :trace => false, :is_rake => true AnnotateModels.do_annotations :model_dir => @model_dir, :trace => false, :is_rake => true
}).not_to include("/spec/annotate/annotate_models_spec.rb:") }).not_to include("/spec/annotate/annotate_models_spec.rb:")
...@@ -993,19 +968,19 @@ end ...@@ -993,19 +968,19 @@ end
EOS EOS
end end
it "displays an error message" do it 'displays an error message' do
expect(capturing(:stdout) { expect(capturing(:stdout) {
AnnotateModels.remove_annotations :model_dir => @model_dir, :is_rake => true AnnotateModels.remove_annotations :model_dir => @model_dir, :is_rake => true
}).to include("Unable to deannotate #{@model_dir}/user.rb: oops") }).to include("Unable to deannotate #{@model_dir}/user.rb: oops")
end end
it "displays the full stack trace" do it 'displays the full stack trace' do
expect(capturing(:stdout) { expect(capturing(:stdout) {
AnnotateModels.remove_annotations :model_dir => @model_dir, :trace => true, :is_rake => true AnnotateModels.remove_annotations :model_dir => @model_dir, :trace => true, :is_rake => true
}).to include("/user.rb:2:in `<class:User>'") }).to include("/user.rb:2:in `<class:User>'")
end end
it "omits the full stack trace without --trace" do it 'omits the full stack trace without --trace' do
expect(capturing(:stdout) { expect(capturing(:stdout) {
AnnotateModels.remove_annotations :model_dir => @model_dir, :trace => false, :is_rake => true AnnotateModels.remove_annotations :model_dir => @model_dir, :trace => false, :is_rake => true
}).not_to include("/user.rb:2:in `<class:User>'") }).not_to include("/user.rb:2:in `<class:User>'")
......
...@@ -2,12 +2,12 @@ require File.dirname(__FILE__) + '/../spec_helper.rb' ...@@ -2,12 +2,12 @@ require File.dirname(__FILE__) + '/../spec_helper.rb'
require 'annotate/annotate_routes' require 'annotate/annotate_routes'
describe AnnotateRoutes do describe AnnotateRoutes do
ROUTE_FILE = 'config/routes.rb' ROUTE_FILE = 'config/routes.rb'.freeze
ANNOTATION_ADDED = "#{ROUTE_FILE} annotated." ANNOTATION_ADDED = "#{ROUTE_FILE} annotated.".freeze
ANNOTATION_REMOVED = "Removed annotations from #{ROUTE_FILE}." ANNOTATION_REMOVED = "Removed annotations from #{ROUTE_FILE}.".freeze
FILE_UNCHANGED = "#{ROUTE_FILE} unchanged." FILE_UNCHANGED = "#{ROUTE_FILE} unchanged.".freeze
def mock_file(stubs={}) def mock_file(stubs = {})
@mock_file ||= double(File, stubs) @mock_file ||= double(File, stubs)
end end
...@@ -82,7 +82,7 @@ describe AnnotateRoutes do ...@@ -82,7 +82,7 @@ describe AnnotateRoutes do
describe 'When adding with newer Rake versions' do describe 'When adding with newer Rake versions' do
before(:each) do before(:each) do
expect(File).to receive(:exists?).with(ROUTE_FILE).and_return(true) expect(File).to receive(:exists?).with(ROUTE_FILE).and_return(true)
expect(AnnotateRoutes).to receive(:`).with("rake routes").and_return("another good line\ngood line") expect(AnnotateRoutes).to receive(:`).with('rake routes').and_return("another good line\ngood line")
expect(File).to receive(:open).with(ROUTE_FILE, 'wb').and_yield(mock_file) expect(File).to receive(:open).with(ROUTE_FILE, 'wb').and_yield(mock_file)
expect(AnnotateRoutes).to receive(:puts).with(ANNOTATION_ADDED) expect(AnnotateRoutes).to receive(:puts).with(ANNOTATION_ADDED)
end end
...@@ -102,7 +102,7 @@ describe AnnotateRoutes do ...@@ -102,7 +102,7 @@ describe AnnotateRoutes do
it 'should add a timestamp when :timestamp is passed' do it 'should add a timestamp when :timestamp is passed' do
expect(File).to receive(:read).with(ROUTE_FILE).and_return("ActionController::Routing...\nfoo") expect(File).to receive(:read).with(ROUTE_FILE).and_return("ActionController::Routing...\nfoo")
expect(@mock_file).to receive(:puts).with(/ActionController::Routing...\nfoo\n\n# == Route Map \(Updated \d{4}-\d{2}-\d{2} \d{2}:\d{2}\)\n#\n# another good line\n# good line\n/) expect(@mock_file).to receive(:puts).with(/ActionController::Routing...\nfoo\n\n# == Route Map \(Updated \d{4}-\d{2}-\d{2} \d{2}:\d{2}\)\n#\n# another good line\n# good line\n/)
AnnotateRoutes.do_annotations :timestamp => true AnnotateRoutes.do_annotations timestamp: true
end end
end end
......
require File.dirname(__FILE__) + '/spec_helper.rb' require File.dirname(__FILE__) + '/spec_helper.rb'
describe Annotate do describe Annotate do
it "should have a version" do it 'should have a version' do
expect(Annotate.version).to be_instance_of(String) expect(Annotate.version).to be_instance_of(String)
end end
end end
...@@ -12,11 +12,9 @@ ...@@ -12,11 +12,9 @@
# It's strongly recommended to check this file into your version control system. # It's strongly recommended to check this file into your version control system.
ActiveRecord::Schema.define(:version => 20120816164927) do ActiveRecord::Schema.define(:version => 20120816164927) do
create_table "tasks", :force => true do |t| create_table "tasks", :force => true do |t|
t.string "content" t.string "content"
t.datetime "created_at", :null => false t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false t.datetime "updated_at", :null => false
end end
end end
...@@ -71,27 +71,28 @@ module Annotate ...@@ -71,27 +71,28 @@ module Annotate
module Validations module Validations
class Base class Base
def self.test_commands def self.test_commands
return Annotate::Validations::Common.test_commands Annotate::Validations::Common.test_commands
end end
def self.verify_output(output) def self.verify_output(output)
return Annotate::Validations::Common.verify_output(output) Annotate::Validations::Common.verify_output(output)
end end
def self.verify_files(test_rig) def self.verify_files(test_rig)
return Annotate::Validations::Common.verify_files({ Annotate::Validations::Common.verify_files(
:model => true, {
:test => true, model: true,
:fixture => true, test: true,
:factory => false, fixture: true,
:routes => true factory: false,
}, test_rig, self.schema_annotation, self.route_annotation, true) routes: true
}, test_rig, schema_annotation, route_annotation, true
)
end end
def self.foo def self.foo
require 'pry' require 'pry'
require 'pry-coolline' require 'pry-coolline'
binding.pry
end end
end end
end end
......
# Smoke test to assure basic functionality works on a variety of Rails versions. # Smoke test to assure basic functionality works on a variety of Rails versions.
$:.unshift(File.dirname(__FILE__)) $LOAD_PATH.unshift(File.dirname(__FILE__))
require 'spec_helper' require 'spec_helper'
require 'files' require 'files'
require 'wrong' require 'wrong'
...@@ -7,7 +7,7 @@ require 'rake' ...@@ -7,7 +7,7 @@ require 'rake'
include Files include Files
include Wrong::D include Wrong::D
BASEDIR=File.expand_path(File.join(File.dirname(__FILE__), '..', '..')) BASEDIR = File.expand_path(File.join(File.dirname(__FILE__), '..', '..'))
RVM_BIN = `which rvm`.chomp RVM_BIN = `which rvm`.chomp
USING_RVM = (RVM_BIN != '') USING_RVM = (RVM_BIN != '')
...@@ -24,13 +24,13 @@ describe "annotate inside Rails, using #{CURRENT_RUBY}" do ...@@ -24,13 +24,13 @@ describe "annotate inside Rails, using #{CURRENT_RUBY}" do
Annotate::Integration::SCENARIOS.each do |test_rig, base_dir, test_name| Annotate::Integration::SCENARIOS.each do |test_rig, base_dir, test_name|
next if(chosen_scenario && chosen_scenario != test_rig) next if(chosen_scenario && chosen_scenario != test_rig)
it "works under #{test_name}" do it "works under #{test_name}" do
if !USING_RVM unless USING_RVM
skip 'Must have RVM installed.' skip 'Must have RVM installed.'
next next
end end
# Don't proceed if the working copy is dirty! # Don't proceed if the working copy is dirty!
expect(Annotate::Integration.is_clean?(test_rig)).to eq(true) expect(Annotate::Integration.clean?(test_rig)).to eq(true)
skip 'temporarily ignored until Travis can run them' skip 'temporarily ignored until Travis can run them'
...@@ -53,7 +53,7 @@ describe "annotate inside Rails, using #{CURRENT_RUBY}" do ...@@ -53,7 +53,7 @@ describe "annotate inside Rails, using #{CURRENT_RUBY}" do
# make sure it's there so our .rvmrc will work. # make sure it's there so our .rvmrc will work.
ENV['rvm_ruby_string']=CURRENT_RUBY ENV['rvm_ruby_string']=CURRENT_RUBY
require "#{base_dir}" # Will get "#{base_dir}.rb"... require base_dir.to_s # Will get "#{base_dir}.rb"...
klass = "Annotate::Validations::#{base_dir.tr('.', '_').classify}".constantize klass = "Annotate::Validations::#{base_dir.tr('.', '_').classify}".constantize
Dir.chdir(temp_dir) do Dir.chdir(temp_dir) do
......
...@@ -4,7 +4,7 @@ module Annotate ...@@ -4,7 +4,7 @@ module Annotate
module Validations module Validations
class Rails23WithBundler < Base class Rails23WithBundler < Base
def self.schema_annotation def self.schema_annotation
return <<-RUBY <<-RUBY
# == Schema Information # == Schema Information
# #
# Table name: tasks # Table name: tasks
...@@ -18,7 +18,7 @@ RUBY ...@@ -18,7 +18,7 @@ RUBY
end end
def self.route_annotation def self.route_annotation
return <<-RUBY <<-RUBY
# == Route Map (Updated YYYY-MM-DD HH:MM) # == Route Map (Updated YYYY-MM-DD HH:MM)
# #
# tasks GET /tasks(.:format) {:controller=>"tasks", :action=>"index"} # tasks GET /tasks(.:format) {:controller=>"tasks", :action=>"index"}
......
...@@ -4,7 +4,7 @@ module Annotate ...@@ -4,7 +4,7 @@ module Annotate
module Validations module Validations
class Rails322 < Base class Rails322 < Base
def self.schema_annotation def self.schema_annotation
return <<-RUBY <<-RUBY
# == Schema Information # == Schema Information
# #
# Table name: tasks # Table name: tasks
...@@ -18,7 +18,7 @@ RUBY ...@@ -18,7 +18,7 @@ RUBY
end end
def self.route_annotation def self.route_annotation
return <<-RUBY <<-RUBY
# == Route Map (Updated YYYY-MM-DD HH:MM) # == Route Map (Updated YYYY-MM-DD HH:MM)
# #
# tasks GET /tasks(.:format) tasks#index # tasks GET /tasks(.:format) tasks#index
......
...@@ -4,7 +4,7 @@ module Annotate ...@@ -4,7 +4,7 @@ module Annotate
module Validations module Validations
class Rails32AutoloadingFactoryGirl < Base class Rails32AutoloadingFactoryGirl < Base
def self.schema_annotation def self.schema_annotation
return <<-RUBY <<-RUBY
# == Schema Information # == Schema Information
# #
# Table name: tasks # Table name: tasks
...@@ -18,7 +18,7 @@ RUBY ...@@ -18,7 +18,7 @@ RUBY
end end
def self.route_annotation def self.route_annotation
return <<-RUBY <<-RUBY
# == Route Map (Updated YYYY-MM-DD HH:MM) # == Route Map (Updated YYYY-MM-DD HH:MM)
# #
# tasks GET /tasks(.:format) tasks#index # tasks GET /tasks(.:format) tasks#index
...@@ -33,13 +33,15 @@ RUBY ...@@ -33,13 +33,15 @@ RUBY
end end
def self.verify_files(test_rig) def self.verify_files(test_rig)
return Annotate::Validations::Common.verify_files({ Annotate::Validations::Common.verify_files(
:model => true, {
:test => true, model: true,
:fixture => false, test: true,
:factory => true, fixture: false,
:routes => true factory: true,
}, test_rig, self.schema_annotation, self.route_annotation, true) routes: true
}, test_rig, schema_annotation, route_annotation, true
)
end end
end end
end end
......
...@@ -4,7 +4,7 @@ module Annotate ...@@ -4,7 +4,7 @@ module Annotate
module Validations module Validations
class Rails32CustomInflection < Base class Rails32CustomInflection < Base
def self.schema_annotation def self.schema_annotation
return <<-RUBY <<-RUBY
# == Schema Information # == Schema Information
# #
# Table name: tasks # Table name: tasks
...@@ -18,7 +18,7 @@ RUBY ...@@ -18,7 +18,7 @@ RUBY
end end
def self.route_annotation def self.route_annotation
return <<-RUBY <<-RUBY
# == Route Map (Updated YYYY-MM-DD HH:MM) # == Route Map (Updated YYYY-MM-DD HH:MM)
# #
# tasks GET /tasks(.:format) tasks#index # tasks GET /tasks(.:format) tasks#index
......
...@@ -4,7 +4,7 @@ module Annotate ...@@ -4,7 +4,7 @@ module Annotate
module Validations module Validations
class Rails32WithAssetPipeline < Base class Rails32WithAssetPipeline < Base
def self.schema_annotation def self.schema_annotation
return <<-RUBY <<-RUBY
# == Schema Information # == Schema Information
# #
# Table name: tasks # Table name: tasks
...@@ -18,7 +18,7 @@ RUBY ...@@ -18,7 +18,7 @@ RUBY
end end
def self.route_annotation def self.route_annotation
return <<-RUBY <<-RUBY
# == Route Map (Updated YYYY-MM-DD HH:MM) # == Route Map (Updated YYYY-MM-DD HH:MM)
# #
# tasks GET /tasks(.:format) tasks#index # tasks GET /tasks(.:format) tasks#index
......
...@@ -4,7 +4,7 @@ module Annotate ...@@ -4,7 +4,7 @@ module Annotate
module Validations module Validations
class Standalone < Base class Standalone < Base
def self.schema_annotation def self.schema_annotation
return <<-RUBY <<-RUBY
# == Schema Information # == Schema Information
# #
# Table name: tasks # Table name: tasks
...@@ -18,9 +18,7 @@ RUBY ...@@ -18,9 +18,7 @@ RUBY
end end
def self.test_commands def self.test_commands
return %q{ 'bin/annotate --require ./config/init.rb'
bin/annotate --require ./config/init.rb
}
end end
def self.verify_output(output) def self.verify_output(output)
...@@ -28,13 +26,15 @@ RUBY ...@@ -28,13 +26,15 @@ RUBY
end end
def self.verify_files(test_rig) def self.verify_files(test_rig)
return Annotate::Validations::Common.verify_files({ Annotate::Validations::Common.verify_files(
:model => true, {
:test => false, model: true,
:fixture => false, test: false,
:factory => false, fixture: false,
:routes => false factory: false,
}, test_rig, self.schema_annotation, nil, true) routes: false
}, test_rig, schema_annotation, nil, true
)
end end
end end
end end
......
...@@ -2,11 +2,13 @@ require 'coveralls' ...@@ -2,11 +2,13 @@ require 'coveralls'
require 'codeclimate-test-reporter' require 'codeclimate-test-reporter'
require 'simplecov' require 'simplecov'
SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter.new([ SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter.new(
[
Coveralls::SimpleCov::Formatter, Coveralls::SimpleCov::Formatter,
SimpleCov::Formatter::HTMLFormatter, SimpleCov::Formatter::HTMLFormatter,
CodeClimate::TestReporter::Formatter CodeClimate::TestReporter::Formatter
]) ]
)
SimpleCov.start SimpleCov.start
...@@ -18,8 +20,8 @@ require 'rake' ...@@ -18,8 +20,8 @@ require 'rake'
require 'rspec' require 'rspec'
require 'wrong/adapters/rspec' require 'wrong/adapters/rspec'
$:.unshift(File.join(File.dirname(__FILE__), '../lib')) $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '../lib'))
$:.unshift(File.dirname(__FILE__)) $LOAD_PATH.unshift(File.dirname(__FILE__))
require 'active_support' require 'active_support'
require 'active_support/core_ext/object/blank' require 'active_support/core_ext/object/blank'
...@@ -30,21 +32,28 @@ require 'byebug' ...@@ -30,21 +32,28 @@ require 'byebug'
module Annotate module Annotate
module Integration module Integration
ABSOLUTE_GEM_ROOT=File.expand_path('../../', __FILE__) ABSOLUTE_GEM_ROOT = File.expand_path('../../', __FILE__)
CRUFT_PATTERNS= %w(%SCENARIO%/bin/* %SCENARIO%/log/* %SCENARIO%/tmp/* %SCENARIO%/.bundle) CRUFT_PATTERNS = %w(
SCENARIO_HOME=File.join(File.dirname(__FILE__), 'integration') %SCENARIO%/bin/*
SCENARIOS=Dir.glob("#{SCENARIO_HOME}/*"). %SCENARIO%/log/*
select { |candidate| File.directory?(candidate) }. %SCENARIO%/tmp/*
map do |test_rig| %SCENARIO%/.bundle
).freeze
SCENARIO_HOME = File.join(File.dirname(__FILE__), 'integration')
SCENARIOS = Dir.glob("#{SCENARIO_HOME}/*").select do |candidate|
File.directory?(candidate)
end.map do |test_rig|
base_dir = File.basename(test_rig) base_dir = File.basename(test_rig)
[test_rig, base_dir, base_dir.titlecase] [test_rig, base_dir, base_dir.titlecase]
end end
def self.nuke_cruft(test_rig) def self.nuke_cruft(test_rig)
FileList[ FileList[
Annotate::Integration::CRUFT_PATTERNS. Annotate::Integration::CRUFT_PATTERNS.map do |pattern|
map { |pattern| pattern.sub('%SCENARIO%', test_rig) } pattern.sub('%SCENARIO%', test_rig)
end
].each do |fname| ].each do |fname|
FileUtils.rm_rf(fname) FileUtils.rm_rf(fname)
end end
...@@ -58,13 +67,13 @@ module Annotate ...@@ -58,13 +67,13 @@ module Annotate
def self.empty_gemset(test_rig) def self.empty_gemset(test_rig)
Dir.chdir(test_rig) do Dir.chdir(test_rig) do
system(%q{ system('
( (
export SKIP_BUNDLER=1 export SKIP_BUNDLER=1
source .rvmrc && source .rvmrc &&
rvm --force gemset empty rvm --force gemset empty
) 2>&1 ) 2>&1
}) ')
end end
end end
...@@ -76,8 +85,8 @@ module Annotate ...@@ -76,8 +85,8 @@ module Annotate
system("git clean -dfx #{SCENARIO_HOME}/*/") system("git clean -dfx #{SCENARIO_HOME}/*/")
end end
def self.is_clean?(test_rig) def self.clean?(test_rig)
return `git status --porcelain #{test_rig}/ | wc -l`.strip.to_i == 0 `git status --porcelain #{test_rig}/ | wc -l`.strip.to_i.zero?
end end
end end
end end
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