Commit b26650d0 by Guillermo Guerrero Ibarra Committed by Cuong Tran

Fixed some offenses (#423)

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