Commit 2949cd43 by Andrew W. Lee

Merge branch 'release/3.0.3'

parents 111640d0 a3793cdc
template: |
## What's Changed
$CHANGES
name: CI
on:
pull_request:
branches:
- '*'
push:
branches:
- '*'
jobs:
test:
runs-on: ubuntu-latest
strategy:
matrix:
ruby:
- 2.3.x
- 2.4.x
- 2.6.x
steps:
- name: Checkout
uses: actions/checkout@v1
- name: Setup Ruby
uses: actions/setup-ruby@v1
with:
ruby-version: ${{ matrix.ruby }}
- name: Bundle
run: |
gem update --system
gem update bundler
bundle install --jobs 4 --retry 3
- name: Test
run: bundle exec rubocop && bundle exec rspec
name: Release
on:
push:
tags:
- 'release/v*'
jobs:
release:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v1
- name: Setup Ruby
uses: actions/setup-ruby@v1
with:
ruby-version: 2.6.x
- name: Bundle
run: |
gem update --system
gem update bundler
bundle install --jobs 4 --retry 3
- name: Publish to GPR
run: |
mkdir -p $HOME/.gem
touch $HOME/.gem/credentials
chmod 0600 $HOME/.gem/credentials
printf -- "---\n:github: Bearer ${GEM_HOST_API_KEY}\n" > $HOME/.gem/credentials
gem build *.gemspec
gem push --KEY github --host https://rubygems.pkg.github.com/${OWNER} *.gem
env:
GEM_HOST_API_KEY: ${{ secrets.GPR_AUTH_TOKEN }}
OWNER: ctran
...@@ -3,12 +3,9 @@ language: ruby ...@@ -3,12 +3,9 @@ language: ruby
rvm: rvm:
- 2.2.10 - 2.2.10
- 2.3.8 - 2.3.8
- 2.4.6 - 2.4.7
- 2.5.5 - 2.5.6
- 2.6.0 - 2.6.4
- 2.6.1
- 2.6.2
- 2.6.3
- ruby-head - ruby-head
matrix: matrix:
......
== 3.0.3
* Use a less error-prone way of specifying gem files (#662)
* Update rake requirement from >= 10.4, < 13.0 to >= 10.4, < 14.0 (#659)
* Bump nokogiri from 1.6.6.2 to 1.10.4 in /spec/integration/rails_4.2.0 (#655)
* Defaults annotate models to true (#671)
* Bump loofah from 2.3.0 to 2.3.1 in /spec/integration/rails_4.2.0 (#681)
== 3.0.2
* Fixes `LoadError` due to gemspec not referencing `parser.rb`, issue #657 (#660)
* Changes `--additional_file_patterns` to use dashes `--additional-file-patterns` for consistency (#649)
* Refactor: moving constants into `constants.rb` (#653)
== 3.0.1
* Skipped as an official release, used the 3.0.1 patch for setting up Github Actions (#619)
== 3.0.0
* Added `--models` CLI option fixing issue #563 (#647)
* Added `--additional_file_patterns` option for additional file patterns (#633) (#636) (#637)
* Refactored CLI parser (#646)
* Fixed BigDecimal.new deprecation warning (#634)
* Fixed annotations for columns with long data types (#622)
* Made methods private in AnnotateRoutes (#598)
See https://github.com/ctran/annotate_models/releases/tag/v3.0.0
== 2.7.5 == 2.7.5
See https://github.com/ctran/annotate_models/releases/tag/v2.7.5 See https://github.com/ctran/annotate_models/releases/tag/v2.7.5
......
...@@ -3,10 +3,10 @@ ...@@ -3,10 +3,10 @@
{<img src="https://badge.fury.io/rb/annotate.svg" alt="Gem Version" />}[http://badge.fury.io/rb/annotate] {<img src="https://badge.fury.io/rb/annotate.svg" alt="Gem Version" />}[http://badge.fury.io/rb/annotate]
{<img src="https://img.shields.io/gem/dt/annotate.svg?style=flat" />}[https://rubygems.org/gems/annotate] {<img src="https://img.shields.io/gem/dt/annotate.svg?style=flat" />}[https://rubygems.org/gems/annotate]
{<img src="https://travis-ci.org/ctran/annotate_models.svg?branch=develop" />}[https://travis-ci.org/ctran/annotate_models] {<img src="https://travis-ci.org/ctran/annotate_models.svg?branch=develop" />}[https://travis-ci.org/ctran/annotate_models]
{<img src="https://github.com/ctran/annotate_models/workflows/CI/badge.svg" />}[https://github.com/ctran/annotate_models/actions?workflow=CI]
{<img src="https://coveralls.io/repos/ctran/annotate_models/badge.svg?branch=develop" />}[https://coveralls.io/r/ctran/annotate_models?branch=develop] {<img src="https://coveralls.io/repos/ctran/annotate_models/badge.svg?branch=develop" />}[https://coveralls.io/r/ctran/annotate_models?branch=develop]
{<img src="https://codeclimate.com/github/ctran/annotate_models/badges/gpa.svg" />}[https://codeclimate.com/github/ctran/annotate_models] {<img src="https://codeclimate.com/github/ctran/annotate_models/badges/gpa.svg" />}[https://codeclimate.com/github/ctran/annotate_models]
{<img src="http://inch-ci.org/github/ctran/annotate_models.svg?branch=develop" alt="Inline docs" />}[http://inch-ci.org/github/ctran/annotate_models] {<img src="http://inch-ci.org/github/ctran/annotate_models.svg?branch=develop" alt="Inline docs" />}[http://inch-ci.org/github/ctran/annotate_models]
{<img src="https://gemnasium.com/ctran/annotate_models.png" />}[https://gemnasium.com/ctran/annotate_models]
Add a comment summarizing the current schema to the top or bottom of each of Add a comment summarizing the current schema to the top or bottom of each of
your... your...
...@@ -90,11 +90,11 @@ To annotate all your models, tests, fixtures, and factories: ...@@ -90,11 +90,11 @@ To annotate all your models, tests, fixtures, and factories:
To annotate just your models, tests, and factories: To annotate just your models, tests, and factories:
annotate --exclude fixtures annotate --models --exclude fixtures
To annotate just your models: To annotate just your models:
annotate --exclude tests,fixtures,factories,serializers annotate --models
To annotate routes.rb: To annotate routes.rb:
...@@ -164,6 +164,7 @@ you can do so with a simple environment variable, instead of editing the ...@@ -164,6 +164,7 @@ you can do so with a simple environment variable, instead of editing the
== Options == Options
Usage: annotate [options] [model_file]* Usage: annotate [options] [model_file]*
--additional_file_patterns Additional file paths or globs to annotate, separated by commas (e.g. `/foo/bar/%model_name%/*.rb,/baz/%model_name%.rb`)
-d, --delete Remove annotations from all model files or the routes.rb file -d, --delete Remove annotations from all model files or the routes.rb file
-p [before|top|after|bottom], Place the annotations at the top (before) or the bottom (after) of the model/test/fixture/factory/route/serializer file(s) -p [before|top|after|bottom], Place the annotations at the top (before) or the bottom (after) of the model/test/fixture/factory/route/serializer file(s)
--position --position
...@@ -184,6 +185,7 @@ you can do so with a simple environment variable, instead of editing the ...@@ -184,6 +185,7 @@ you can do so with a simple environment variable, instead of editing the
--wo, --wrapper-open STR Annotation wrapper opening. --wo, --wrapper-open STR Annotation wrapper opening.
--wc, --wrapper-close STR Annotation wrapper closing --wc, --wrapper-close STR Annotation wrapper closing
-r, --routes Annotate routes.rb with the output of 'rake routes' -r, --routes Annotate routes.rb with the output of 'rake routes'
--models Annotate ActiveRecord models
-a, --active-admin Annotate active_admin models -a, --active-admin Annotate active_admin models
-v, --version Show the current version of this gem -v, --version Show the current version of this gem
-m, --show-migration Include the migration version number in the annotation -m, --show-migration Include the migration version number in the annotation
...@@ -206,16 +208,35 @@ you can do so with a simple environment variable, instead of editing the ...@@ -206,16 +208,35 @@ you can do so with a simple environment variable, instead of editing the
--frozen Do not allow to change annotations. Exits non-zero if there are going to be changes to files. --frozen Do not allow to change annotations. Exits non-zero if there are going to be changes to files.
--timestamp Include timestamp in (routes) annotation --timestamp Include timestamp in (routes) annotation
--trace If unable to annotate a file, print the full stack trace, not just the exception message. --trace If unable to annotate a file, print the full stack trace, not just the exception message.
-I, --ignore-columns REGEX don't annotate columns that match a given REGEX (i.e., `annotate -I '^(id|updated_at|created_at)'` -I, --ignore-columns REGEX don't annotate columns that match a given REGEX (e.g. `annotate -I '^(id|updated_at|created_at)'`)
--ignore-routes REGEX don't annotate routes that match a given REGEX (i.e., `annotate -I '(mobile|resque|pghero)'` --ignore-routes REGEX don't annotate routes that match a given REGEX (e.g. `annotate -I '(mobile|resque|pghero)'`)_
--hide-limit-column-types VALUES --hide-limit-column-types VALUES
don't show limit for given column types, separated by commas (i.e., `integer,boolean,text`) don't show limit for given column types, separated by commas (e.g. `integer,boolean,text`)
--hide-default-column-types VALUES --hide-default-column-types VALUES
don't show default for given column types, separated by commas (i.e., `json,jsonb,hstore`) don't show default for given column types, separated by commas (e.g. `json,jsonb,hstore`)
--ignore-unknown-models don't display warnings for bad model files --ignore-unknown-models don't display warnings for bad model files
--with-comment include database comments in model annotations --with-comment include database comments in model annotations
=== Option: +additional_file_patterns+
CLI: +--additional_file_patterns+<br>
Ruby: +:additional_file_patterns+
Provide additional paths for the gem to annotate. These paths can include globs.
It is recommended to use absolute paths. Here are some examples:
- <code>/app/lib/decorates/%MODEL_NAME%/&ast;.rb</code>
- <code>/app/lib/forms/%PLURALIZED_MODEL_NAME%/&ast;&ast;/&ast;.rb</code>
- <code>/app/lib/forms/%TABLE_NAME%/&ast;.rb</code>
The appropriate model will be inferred using the <code>%*%</code> syntax, annotating any matching files.
It works with existing filename resolutions (options for which can be found in the +resolve_filename+ method of
+annotate_models.rb+).
When using in a Rails config, you can use the following:
<code>File.join(Rails.application.root, 'app/lib/forms/%PLURALIZED_MODEL_NAME%/**/*.rb')</code>
== Sorting == Sorting
......
...@@ -14,35 +14,16 @@ Gem::Specification.new do |s| ...@@ -14,35 +14,16 @@ Gem::Specification.new do |s|
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 = [ s.files = `git ls-files -z LICENSE.txt *.rdoc *.gemspec bin lib`.split("\x0")
'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/annotate_models_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.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.'
s.specification_version = 4 if s.respond_to? :specification_version s.specification_version = 4 if s.respond_to? :specification_version
s.add_runtime_dependency(%q<rake>, ['>= 10.4', '< 13.0']) s.add_runtime_dependency(%q<rake>, '>= 10.4', '< 14.0')
s.add_runtime_dependency(%q<activerecord>, ['>= 3.2', '< 7.0']) s.add_runtime_dependency(%q<activerecord>, ['>= 3.2', '< 7.0'])
s.metadata = { "github_repo" => "ssh://github.com/ctran/annotate_models" }
end end
...@@ -14,203 +14,19 @@ end ...@@ -14,203 +14,19 @@ end
here = File.expand_path(File.dirname __FILE__) here = File.expand_path(File.dirname __FILE__)
$LOAD_PATH << "#{here}/../lib" $LOAD_PATH << "#{here}/../lib"
require 'optparse'
require 'annotate' require 'annotate'
Annotate.bootstrap_rake require 'annotate/parser'
has_set_position = {}
target_action = :do_annotations
positions = %w(before top after bottom)
OptionParser.new do |opts|
opts.banner = 'Usage: annotate [options] [model_file]*'
opts.on('-d', '--delete', 'Remove annotations from all model files or the routes.rb file') do
target_action = :remove_annotations
end
opts.on('-p', '--position [before|top|after|bottom]', positions,
'Place the annotations at the top (before) or the bottom (after) of the model/test/fixture/factory/route/serializer file(s)') do |p|
ENV['position'] = p
%w(position_in_class position_in_factory position_in_fixture position_in_test position_in_routes position_in_serializer).each do |key|
ENV[key] = p unless has_set_position[key]
end
end
opts.on('--pc', '--position-in-class [before|top|after|bottom]', positions,
'Place the annotations at the top (before) or the bottom (after) of the model file') do |p|
ENV['position_in_class'] = p
has_set_position['position_in_class'] = true
end
opts.on('--pf', '--position-in-factory [before|top|after|bottom]', positions,
'Place the annotations at the top (before) or the bottom (after) of any factory files') do |p|
ENV['position_in_factory'] = p
has_set_position['position_in_factory'] = true
end
opts.on('--px', '--position-in-fixture [before|top|after|bottom]', positions,
'Place the annotations at the top (before) or the bottom (after) of any fixture files') do |p|
ENV['position_in_fixture'] = p
has_set_position['position_in_fixture'] = true
end
opts.on('--pt', '--position-in-test [before|top|after|bottom]', positions,
'Place the annotations at the top (before) or the bottom (after) of any test files') do |p|
ENV['position_in_test'] = p
has_set_position['position_in_test'] = true
end
opts.on('--pr', '--position-in-routes [before|top|after|bottom]', positions,
'Place the annotations at the top (before) or the bottom (after) of the routes.rb file') do |p|
ENV['position_in_routes'] = p
has_set_position['position_in_routes'] = true
end
opts.on('--ps', '--position-in-serializer [before|top|after|bottom]', positions,
'Place the annotations at the top (before) or the bottom (after) of the serializer files') do |p|
ENV['position_in_serializer'] = p
has_set_position['position_in_serializer'] = true
end
opts.on('--w', '--wrapper STR', 'Wrap annotation with the text passed as parameter.',
'If --w option is used, the same text will be used as opening and closing') do |p|
ENV['wrapper'] = p
end
opts.on('--wo', '--wrapper-open STR', 'Annotation wrapper opening.') do |p|
ENV['wrapper_open'] = p
end
opts.on('--wc', '--wrapper-close STR', 'Annotation wrapper closing') do |p|
ENV['wrapper_close'] = p
end
opts.on('-r', '--routes', "Annotate routes.rb with the output of 'rake routes'") do
ENV['routes'] = 'true'
end
opts.on('-a', '--active-admin', 'Annotate active_admin models') do
ENV['active_admin'] = 'true'
end
opts.on('-v', '--version', 'Show the current version of this gem') do
puts "annotate v#{Annotate.version}"; exit
end
opts.on('-m', '--show-migration', 'Include the migration version number in the annotation') do
ENV['include_version'] = 'yes'
end
opts.on('-k', '--show-foreign-keys',
"List the table's foreign key constraints in the annotation") do
ENV['show_foreign_keys'] = 'yes'
end
opts.on('--ck', Annotate.bootstrap_rake
'--complete-foreign-keys', 'Complete foreign key names in the annotation') do
ENV['show_foreign_keys'] = 'yes'
ENV['show_complete_foreign_keys'] = 'yes'
end
opts.on('-i', '--show-indexes',
"List the table's database indexes in the annotation") do
ENV['show_indexes'] = 'yes'
end
opts.on('-s', '--simple-indexes',
"Concat the column's related indexes in the annotation") do
ENV['simple_indexes'] = 'yes'
end
opts.on('--model-dir dir',
"Annotate model files stored in dir rather than app/models, separate multiple dirs with commas") do |dir|
ENV['model_dir'] = dir
end
opts.on('--root-dir dir',
"Annotate files stored within root dir projects, separate multiple dirs with commas") do |dir|
ENV['root_dir'] = dir
end
opts.on('--ignore-model-subdirects',
"Ignore subdirectories of the models directory") do |dir|
ENV['ignore_model_sub_dir'] = 'yes'
end
opts.on('--sort',
"Sort columns alphabetically, rather than in creation order") do |dir|
ENV['sort'] = 'yes'
end
opts.on('--classified-sort',
"Sort columns alphabetically, but first goes id, then the rest columns, then the timestamp columns and then the association columns") do |dir|
ENV['classified_sort'] = 'yes'
end
opts.on('-R', '--require path',
"Additional file to require before loading models, may be used multiple times") do |path|
if !ENV['require'].blank?
ENV['require'] = ENV['require'] + ",#{path}"
else
ENV['require'] = path
end
end
opts.on('-e', '--exclude [tests,fixtures,factories,serializers]', Array, "Do not annotate fixtures, test files, factories, and/or serializers") do |exclusions|
exclusions ||= %w(tests fixtures factories)
exclusions.each { |exclusion| ENV["exclude_#{exclusion}"] = 'yes' }
end
opts.on('-f', '--format [bare|rdoc|markdown]', %w(bare rdoc markdown), 'Render Schema Infomation as plain/RDoc/Markdown') do |fmt|
ENV["format_#{fmt}"] = 'yes'
end
opts.on('--force', 'Force new annotations even if there are no changes.') do |force|
ENV['force'] = 'yes'
end
opts.on('--frozen', 'Do not allow to change annotations. Exits non-zero if there are going to be changes to files.') do
ENV['frozen'] = 'yes'
end
opts.on('--timestamp', 'Include timestamp in (routes) annotation') do
ENV['timestamp'] = 'true'
end
opts.on('--trace', 'If unable to annotate a file, print the full stack trace, not just the exception message.') do |value|
ENV['trace'] = 'yes'
end
opts.on('-I', '--ignore-columns REGEX', "don't annotate columns that match a given REGEX (i.e., `annotate -I '^(id|updated_at|created_at)'`") do |regex|
ENV['ignore_columns'] = regex
end
opts.on('--ignore-routes REGEX', "don't annotate routes that match a given REGEX (i.e., `annotate -I '(mobile|resque|pghero)'`") do |regex|
ENV['ignore_routes'] = regex
end
opts.on('--hide-limit-column-types VALUES', "don't show limit for given column types, separated by commas (i.e., `integer,boolean,text`)") do |values|
ENV['hide_limit_column_types'] = "#{values}"
end
opts.on('--hide-default-column-types VALUES', "don't show default for given column types, separated by commas (i.e., `json,jsonb,hstore`)") do |values|
ENV['hide_default_column_types'] = "#{values}"
end
opts.on('--ignore-unknown-models', "don't display warnings for bad model files") do |values| options_result = Annotate::Parser.parse(ARGV)
ENV['ignore_unknown_models'] = 'true'
end
opts.on('--with-comment', "include database comments in model annotations") do |values| exit if options_result[:exit]
ENV['with_comment'] = 'true'
end
end.parse!
options = Annotate.setup_options( options = Annotate.setup_options(
is_rake: ENV['is_rake'] && !ENV['is_rake'].empty? is_rake: ENV['is_rake'] && !ENV['is_rake'].empty?
) )
Annotate.eager_load(options) if Annotate.include_models? Annotate.eager_load(options) if Annotate.include_models?
AnnotateModels.send(target_action, options) if Annotate.include_models? AnnotateModels.send(options_result[:target_action], options) if Annotate.include_models?
AnnotateRoutes.send(target_action, options) if Annotate.include_routes? AnnotateRoutes.send(options_result[:target_action], options) if Annotate.include_routes?
machine:
ruby:
version: 2.2.6
test:
override:
- bundle exec rubocop && bundle exec rspec
...@@ -4,6 +4,7 @@ $LOAD_PATH.unshift(File.dirname(__FILE__)) ...@@ -4,6 +4,7 @@ $LOAD_PATH.unshift(File.dirname(__FILE__))
require 'annotate/version' require 'annotate/version'
require 'annotate/annotate_models' require 'annotate/annotate_models'
require 'annotate/annotate_routes' require 'annotate/annotate_routes'
require 'annotate/constants'
begin begin
# ActiveSupport 3.x... # ActiveSupport 3.x...
...@@ -16,8 +17,6 @@ rescue StandardError ...@@ -16,8 +17,6 @@ rescue StandardError
end end
module Annotate module Annotate
TRUE_RE = /^(true|t|yes|y|1)$/i
## ##
# The set of available options to customize the behavior of Annotate. # The set of available options to customize the behavior of Annotate.
# #
...@@ -36,8 +35,8 @@ module Annotate ...@@ -36,8 +35,8 @@ module Annotate
:exclude_sti_subclasses, :ignore_unknown_models, :with_comment :exclude_sti_subclasses, :ignore_unknown_models, :with_comment
].freeze ].freeze
OTHER_OPTIONS = [ OTHER_OPTIONS = [
:ignore_columns, :skip_on_db_migrate, :wrapper_open, :wrapper_close, :additional_file_patterns, :ignore_columns, :skip_on_db_migrate, :wrapper_open, :wrapper_close,
:wrapper, :routes, :hide_limit_column_types, :hide_default_column_types, :wrapper, :routes, :models, :hide_limit_column_types, :hide_default_column_types,
:ignore_routes, :active_admin :ignore_routes, :active_admin
].freeze ].freeze
PATH_OPTIONS = [ PATH_OPTIONS = [
...@@ -88,6 +87,7 @@ module Annotate ...@@ -88,6 +87,7 @@ module Annotate
options[key] = !ENV[key.to_s].blank? ? ENV[key.to_s].split(',') : [] options[key] = !ENV[key.to_s].blank? ? ENV[key.to_s].split(',') : []
end end
options[:additional_file_patterns] ||= []
options[:model_dir] = ['app/models'] if options[:model_dir].empty? options[:model_dir] = ['app/models'] if options[:model_dir].empty?
options[:wrapper_open] ||= options[:wrapper] options[:wrapper_open] ||= options[:wrapper]
...@@ -106,15 +106,15 @@ module Annotate ...@@ -106,15 +106,15 @@ module Annotate
end end
def self.skip_on_migration? def self.skip_on_migration?
ENV['ANNOTATE_SKIP_ON_DB_MIGRATE'] =~ TRUE_RE || ENV['skip_on_db_migrate'] =~ TRUE_RE ENV['ANNOTATE_SKIP_ON_DB_MIGRATE'] =~ Constants::TRUE_RE || ENV['skip_on_db_migrate'] =~ Constants::TRUE_RE
end end
def self.include_routes? def self.include_routes?
ENV['routes'] =~ TRUE_RE ENV['routes'] =~ Constants::TRUE_RE
end end
def self.include_models? def self.include_models?
ENV['routes'] !~ TRUE_RE ENV['models'] =~ Constants::TRUE_RE
end end
def self.loaded_tasks=(val) def self.loaded_tasks=(val)
...@@ -198,7 +198,7 @@ module Annotate ...@@ -198,7 +198,7 @@ module Annotate
def self.true?(val) def self.true?(val)
return false if val.blank? return false if val.blank?
return false unless val =~ TRUE_RE return false unless val =~ Constants::TRUE_RE
true true
end end
end end
...@@ -2,9 +2,9 @@ ...@@ -2,9 +2,9 @@
require 'bigdecimal' require 'bigdecimal'
module AnnotateModels require 'annotate/constants'
TRUE_RE = /^(true|t|yes|y|1)$/i
module AnnotateModels
# Annotate Models plugin use this header # Annotate Models plugin use this header
COMPAT_PREFIX = '== Schema Info'.freeze COMPAT_PREFIX = '== Schema Info'.freeze
COMPAT_PREFIX_MD = '## Schema Info'.freeze COMPAT_PREFIX_MD = '## Schema Info'.freeze
...@@ -159,13 +159,15 @@ module AnnotateModels ...@@ -159,13 +159,15 @@ module AnnotateModels
] ]
end end
def files_by_pattern(root_directory, pattern_type) def files_by_pattern(root_directory, pattern_type, options)
case pattern_type case pattern_type
when 'test' then test_files(root_directory) when 'test' then test_files(root_directory)
when 'fixture' then fixture_files(root_directory) when 'fixture' then fixture_files(root_directory)
when 'scaffold' then scaffold_files(root_directory) when 'scaffold' then scaffold_files(root_directory)
when 'factory' then factory_files(root_directory) when 'factory' then factory_files(root_directory)
when 'serializer' then serialize_files(root_directory) when 'serializer' then serialize_files(root_directory)
when 'additional_file_patterns'
[options[:additional_file_patterns] || []].flatten
when 'controller' when 'controller'
[File.join(root_directory, CONTROLLER_DIR, "%PLURALIZED_MODEL_NAME%_controller.rb")] [File.join(root_directory, CONTROLLER_DIR, "%PLURALIZED_MODEL_NAME%_controller.rb")]
when 'admin' when 'admin'
...@@ -177,14 +179,20 @@ module AnnotateModels ...@@ -177,14 +179,20 @@ module AnnotateModels
end end
end end
def get_patterns(pattern_types = []) def get_patterns(options, pattern_types = [])
current_patterns = [] current_patterns = []
root_dir.each do |root_directory| root_dir.each do |root_directory|
Array(pattern_types).each do |pattern_type| Array(pattern_types).each do |pattern_type|
current_patterns += files_by_pattern(root_directory, pattern_type) patterns = files_by_pattern(root_directory, pattern_type, options)
current_patterns += if pattern_type.to_sym == :additional_file_patterns
patterns
else
patterns.map { |p| p.sub(/^[\/]*/, '') }
end end
end end
current_patterns.map { |p| p.sub(/^[\/]*/, '') } end
current_patterns
end end
# Simple quoting for the default column value # Simple quoting for the default column value
...@@ -581,8 +589,9 @@ module AnnotateModels ...@@ -581,8 +589,9 @@ module AnnotateModels
end end
def matched_types(options) def matched_types(options)
types = MATCHED_TYPES types = MATCHED_TYPES.dup
types << 'admin' if options[:active_admin] =~ TRUE_RE && !types.include?('admin') types << 'admin' if options[:active_admin] =~ Annotate::Constants::TRUE_RE && !types.include?('admin')
types << 'additional_file_patterns' if options[:additional_file_patterns].present?
types types
end end
...@@ -634,8 +643,11 @@ module AnnotateModels ...@@ -634,8 +643,11 @@ module AnnotateModels
end end
next if options[exclusion_key] next if options[exclusion_key]
get_patterns(key)
get_patterns(options, key)
.map { |f| resolve_filename(f, model_name, table_name) } .map { |f| resolve_filename(f, model_name, table_name) }
.map { |f| expand_glob_into_files(f) }
.flatten
.each do |f| .each do |f|
if annotate_one_file(f, info, position_key, options_with_position(options, position_key)) if annotate_one_file(f, info, position_key, options_with_position(options, position_key))
annotated << f annotated << f
...@@ -793,6 +805,10 @@ module AnnotateModels ...@@ -793,6 +805,10 @@ module AnnotateModels
end end
end end
def expand_glob_into_files(glob)
Dir.glob(glob)
end
def annotate_model_file(annotated, file, header, options) def annotate_model_file(annotated, file, header, options)
begin begin
return false if /#{SKIP_ANNOTATION_PREFIX}.*/ =~ (File.exist?(file) ? File.read(file) : '') return false if /#{SKIP_ANNOTATION_PREFIX}.*/ =~ (File.exist?(file) ? File.read(file) : '')
...@@ -830,7 +846,7 @@ module AnnotateModels ...@@ -830,7 +846,7 @@ module AnnotateModels
model_file_name = file model_file_name = file
deannotated_klass = true if remove_annotation_of_file(model_file_name, options) deannotated_klass = true if remove_annotation_of_file(model_file_name, options)
get_patterns(matched_types(options)) get_patterns(options, matched_types(options))
.map { |f| resolve_filename(f, model_name, table_name) } .map { |f| resolve_filename(f, model_name, table_name) }
.each do |f| .each do |f|
if File.exist?(f) if File.exist?(f)
......
...@@ -10,7 +10,7 @@ ...@@ -10,7 +10,7 @@
# Yes, it's simple but I'm thick and often need a reminder of what my routes # Yes, it's simple but I'm thick and often need a reminder of what my routes
# mean. # mean.
# #
# Running this task will replace any exising route comment generated by the # Running this task will replace any existing route comment generated by the
# task. Best to back up your routes file before running: # task. Best to back up your routes file before running:
# #
# Author: # Author:
......
module Annotate
module Constants
TRUE_RE = /^(true|t|yes|y|1)$/i.freeze
end
end
require 'optparse'
module Annotate
# Class for handling command line arguments
class Parser # rubocop:disable Metrics/ClassLength
def self.parse(args, env = {})
new(args, env).parse
end
attr_reader :args, :options, :env
ANNOTATION_POSITIONS = %w[before top after bottom].freeze
FILE_TYPE_POSITIONS = %w[position_in_class position_in_factory position_in_fixture position_in_test position_in_routes position_in_serializer].freeze
EXCLUSION_LIST = %w[tests fixtures factories serializers].freeze
FORMAT_TYPES = %w[bare rdoc markdown].freeze
def initialize(args, env)
@args = args
@options = default_options
@env = env
end
def parse
# To split up because right now this method parses and commits
parser.parse!(args)
commit
options
end
private
def commit
env.each_pair do |key, value|
ENV[key] = value
end
end
def parser
OptionParser.new do |option_parser|
add_options_to_parser(option_parser)
end
end
def add_options_to_parser(option_parser) # rubocop:disable Metrics/MethodLength
has_set_position = {}
positions = ANNOTATION_POSITIONS
option_parser.banner = 'Usage: annotate [options] [model_file]*'
option_parser.on('--additional-file-patterns path1,path2,path3', Array, "Additional file paths or globs to annotate, separated by commas (e.g. `/foo/bar/%model_name%/*.rb,/baz/%model_name%.rb`)") do |additional_file_patterns|
ENV['additional_file_patterns'] = additional_file_patterns
end
option_parser.on('-d', '--delete', 'Remove annotations from all model files or the routes.rb file') do
@options[:target_action] = :remove_annotations
end
option_parser.on('-p', '--position [before|top|after|bottom]', positions,
'Place the annotations at the top (before) or the bottom (after) of the model/test/fixture/factory/route/serializer file(s)') do |p|
env['position'] = p
FILE_TYPE_POSITIONS.each do |key|
env[key] = p unless has_set_position[key]
end
end
option_parser.on('--pc', '--position-in-class [before|top|after|bottom]', positions,
'Place the annotations at the top (before) or the bottom (after) of the model file') do |p|
env['position_in_class'] = p
has_set_position['position_in_class'] = true
end
option_parser.on('--pf', '--position-in-factory [before|top|after|bottom]', positions,
'Place the annotations at the top (before) or the bottom (after) of any factory files') do |p|
env['position_in_factory'] = p
has_set_position['position_in_factory'] = true
end
option_parser.on('--px', '--position-in-fixture [before|top|after|bottom]', positions,
'Place the annotations at the top (before) or the bottom (after) of any fixture files') do |p|
env['position_in_fixture'] = p
has_set_position['position_in_fixture'] = true
end
option_parser.on('--pt', '--position-in-test [before|top|after|bottom]', positions,
'Place the annotations at the top (before) or the bottom (after) of any test files') do |p|
env['position_in_test'] = p
has_set_position['position_in_test'] = true
end
option_parser.on('--pr', '--position-in-routes [before|top|after|bottom]', positions,
'Place the annotations at the top (before) or the bottom (after) of the routes.rb file') do |p|
env['position_in_routes'] = p
has_set_position['position_in_routes'] = true
end
option_parser.on('--ps', '--position-in-serializer [before|top|after|bottom]', positions,
'Place the annotations at the top (before) or the bottom (after) of the serializer files') do |p|
env['position_in_serializer'] = p
has_set_position['position_in_serializer'] = true
end
option_parser.on('--w', '--wrapper STR', 'Wrap annotation with the text passed as parameter.',
'If --w option is used, the same text will be used as opening and closing') do |p|
env['wrapper'] = p
end
option_parser.on('--wo', '--wrapper-open STR', 'Annotation wrapper opening.') do |p|
env['wrapper_open'] = p
end
option_parser.on('--wc', '--wrapper-close STR', 'Annotation wrapper closing') do |p|
env['wrapper_close'] = p
end
option_parser.on('-r', '--routes', "Annotate routes.rb with the output of 'rake routes'") do
env['routes'] = 'true'
end
option_parser.on('--models', "Annotate ActiveRecord models") do
env['models'] = 'true'
end
option_parser.on('-a', '--active-admin', 'Annotate active_admin models') do
env['active_admin'] = 'true'
end
option_parser.on('-v', '--version', 'Show the current version of this gem') do
puts "annotate v#{Annotate.version}"
@options[:exit] = true
end
option_parser.on('-m', '--show-migration', 'Include the migration version number in the annotation') do
env['include_version'] = 'yes'
end
option_parser.on('-k', '--show-foreign-keys',
"List the table's foreign key constraints in the annotation") do
env['show_foreign_keys'] = 'yes'
end
option_parser.on('--ck',
'--complete-foreign-keys', 'Complete foreign key names in the annotation') do
env['show_foreign_keys'] = 'yes'
env['show_complete_foreign_keys'] = 'yes'
end
option_parser.on('-i', '--show-indexes',
"List the table's database indexes in the annotation") do
env['show_indexes'] = 'yes'
end
option_parser.on('-s', '--simple-indexes',
"Concat the column's related indexes in the annotation") do
env['simple_indexes'] = 'yes'
end
option_parser.on('--model-dir dir',
"Annotate model files stored in dir rather than app/models, separate multiple dirs with commas") do |dir|
env['model_dir'] = dir
end
option_parser.on('--root-dir dir',
"Annotate files stored within root dir projects, separate multiple dirs with commas") do |dir|
env['root_dir'] = dir
end
option_parser.on('--ignore-model-subdirects',
"Ignore subdirectories of the models directory") do |_dir|
env['ignore_model_sub_dir'] = 'yes'
end
option_parser.on('--sort',
"Sort columns alphabetically, rather than in creation order") do |_dir|
env['sort'] = 'yes'
end
option_parser.on('--classified-sort',
"Sort columns alphabetically, but first goes id, then the rest columns, then the timestamp columns and then the association columns") do |_dir|
env['classified_sort'] = 'yes'
end
option_parser.on('-R', '--require path',
"Additional file to require before loading models, may be used multiple times") do |path|
env['require'] = if !env['require'].blank?
env['require'] + ",#{path}"
else
path
end
end
option_parser.on('-e', '--exclude [tests,fixtures,factories,serializers]', Array, "Do not annotate fixtures, test files, factories, and/or serializers") do |exclusions|
exclusions ||= EXCLUSION_LIST
exclusions.each { |exclusion| env["exclude_#{exclusion}"] = 'yes' }
end
option_parser.on('-f', '--format [bare|rdoc|markdown]', FORMAT_TYPES, 'Render Schema Infomation as plain/RDoc/Markdown') do |fmt|
env["format_#{fmt}"] = 'yes'
end
option_parser.on('--force', 'Force new annotations even if there are no changes.') do |_force|
env['force'] = 'yes'
end
option_parser.on('--frozen', 'Do not allow to change annotations. Exits non-zero if there are going to be changes to files.') do
env['frozen'] = 'yes'
end
option_parser.on('--timestamp', 'Include timestamp in (routes) annotation') do
env['timestamp'] = 'true'
end
option_parser.on('--trace', 'If unable to annotate a file, print the full stack trace, not just the exception message.') do |_value|
env['trace'] = 'yes'
end
option_parser.on('-I', '--ignore-columns REGEX', "don't annotate columns that match a given REGEX (i.e., `annotate -I '^(id|updated_at|created_at)'`") do |regex|
env['ignore_columns'] = regex
end
option_parser.on('--ignore-routes REGEX', "don't annotate routes that match a given REGEX (i.e., `annotate -I '(mobile|resque|pghero)'`") do |regex|
env['ignore_routes'] = regex
end
option_parser.on('--hide-limit-column-types VALUES', "don't show limit for given column types, separated by commas (i.e., `integer,boolean,text`)") do |values|
env['hide_limit_column_types'] = values.to_s
end
option_parser.on('--hide-default-column-types VALUES', "don't show default for given column types, separated by commas (i.e., `json,jsonb,hstore`)") do |values|
env['hide_default_column_types'] = values.to_s
end
option_parser.on('--ignore-unknown-models', "don't display warnings for bad model files") do |_values|
env['ignore_unknown_models'] = 'true'
end
option_parser.on('--with-comment', "include database comments in model annotations") do |_values|
env['with_comment'] = 'true'
end
end
def default_options
{
target_action: :do_annotations,
exit: false
}
end
end
end
module Annotate module Annotate
def self.version def self.version
'2.7.5' '3.0.3'
end end
end end
...@@ -7,7 +7,9 @@ if Rails.env.development? ...@@ -7,7 +7,9 @@ if Rails.env.development?
# You can override any of these by setting an environment variable of the # You can override any of these by setting an environment variable of the
# same name. # same name.
Annotate.set_defaults( Annotate.set_defaults(
'additional_file_patterns' => [],
'routes' => 'false', 'routes' => 'false',
'models' => 'true',
'position_in_routes' => 'before', 'position_in_routes' => 'before',
'position_in_class' => 'before', 'position_in_class' => 'before',
'position_in_test' => 'before', 'position_in_test' => 'before',
......
...@@ -12,6 +12,7 @@ task annotate_models: :environment do ...@@ -12,6 +12,7 @@ task annotate_models: :environment do
options = {is_rake: true} options = {is_rake: true}
ENV['position'] = options[:position] = Annotate.fallback(ENV['position'], 'before') ENV['position'] = options[:position] = Annotate.fallback(ENV['position'], 'before')
options[:additional_file_patterns] = ENV['additional_file_patterns'] ? ENV['additional_file_patterns'].split(',') : []
options[:position_in_class] = Annotate.fallback(ENV['position_in_class'], ENV['position']) options[:position_in_class] = Annotate.fallback(ENV['position_in_class'], ENV['position'])
options[:position_in_fixture] = Annotate.fallback(ENV['position_in_fixture'], ENV['position']) options[:position_in_fixture] = Annotate.fallback(ENV['position_in_fixture'], ENV['position'])
options[:position_in_factory] = Annotate.fallback(ENV['position_in_factory'], ENV['position']) options[:position_in_factory] = Annotate.fallback(ENV['position_in_factory'], ENV['position'])
......
require File.dirname(__FILE__) + '/spec_helper.rb'
describe Annotate do
it 'should have a version' do
expect(Annotate.version).to be_instance_of(String)
end
end
...@@ -2,8 +2,8 @@ PATH ...@@ -2,8 +2,8 @@ PATH
remote: ../../.. remote: ../../..
specs: specs:
annotate (2.6.6) annotate (2.6.6)
activerecord (>= 3.2, <= 4.3) activerecord (>= 3.2, < 7.0)
rake (~> 10.4) rake (>= 10.4, < 14.0)
GEM GEM
remote: https://rubygems.org/ remote: https://rubygems.org/
...@@ -44,7 +44,7 @@ GEM ...@@ -44,7 +44,7 @@ GEM
thread_safe (~> 0.3, >= 0.3.4) thread_safe (~> 0.3, >= 0.3.4)
tzinfo (~> 1.1) tzinfo (~> 1.1)
arel (6.0.0) arel (6.0.0)
builder (3.2.2) builder (3.2.3)
coffee-rails (4.1.0) coffee-rails (4.1.0)
coffee-script (>= 2.2.0) coffee-script (>= 2.2.0)
railties (>= 4.0.0, < 5.0) railties (>= 4.0.0, < 5.0)
...@@ -52,12 +52,15 @@ GEM ...@@ -52,12 +52,15 @@ GEM
coffee-script-source coffee-script-source
execjs execjs
coffee-script-source (1.9.1) coffee-script-source (1.9.1)
concurrent-ruby (1.1.5)
crass (1.0.5)
erubis (2.7.0) erubis (2.7.0)
execjs (2.4.0) execjs (2.4.0)
globalid (0.3.3) globalid (0.3.3)
activesupport (>= 4.1.0) activesupport (>= 4.1.0)
hike (1.2.3) hike (1.2.3)
i18n (0.7.0) i18n (0.9.5)
concurrent-ruby (~> 1.0)
jbuilder (2.2.11) jbuilder (2.2.11)
activesupport (>= 3.0.0, < 5) activesupport (>= 3.0.0, < 5)
multi_json (~> 1.2) multi_json (~> 1.2)
...@@ -65,18 +68,19 @@ GEM ...@@ -65,18 +68,19 @@ GEM
rails-dom-testing (~> 1.0) rails-dom-testing (~> 1.0)
railties (>= 4.2.0) railties (>= 4.2.0)
thor (>= 0.14, < 2.0) thor (>= 0.14, < 2.0)
json (1.8.2) json (1.8.6)
loofah (2.0.1) loofah (2.3.1)
crass (~> 1.0.2)
nokogiri (>= 1.5.9) nokogiri (>= 1.5.9)
mail (2.6.3) mail (2.6.3)
mime-types (>= 1.16, < 3) mime-types (>= 1.16, < 3)
mime-types (2.4.3) mime-types (2.4.3)
mini_portile (0.6.2) mini_portile2 (2.4.0)
minitest (5.5.1) minitest (5.12.2)
multi_json (1.11.0) multi_json (1.11.0)
nokogiri (1.6.6.2) nokogiri (1.10.5)
mini_portile (~> 0.6.0) mini_portile2 (~> 2.4.0)
rack (1.6.0) rack (1.6.11)
rack-test (0.6.3) rack-test (0.6.3)
rack (>= 1.0) rack (>= 1.0)
rails (4.2.0) rails (4.2.0)
...@@ -92,12 +96,12 @@ GEM ...@@ -92,12 +96,12 @@ GEM
sprockets-rails sprockets-rails
rails-deprecated_sanitizer (1.0.3) rails-deprecated_sanitizer (1.0.3)
activesupport (>= 4.2.0.alpha) activesupport (>= 4.2.0.alpha)
rails-dom-testing (1.0.5) rails-dom-testing (1.0.9)
activesupport (>= 4.2.0.beta, < 5.0) activesupport (>= 4.2.0, < 5.0)
nokogiri (~> 1.6.0) nokogiri (~> 1.6)
rails-deprecated_sanitizer (>= 1.0.1) rails-deprecated_sanitizer (>= 1.0.1)
rails-html-sanitizer (1.0.1) rails-html-sanitizer (1.2.0)
loofah (~> 2.0) loofah (~> 2.2, >= 2.2.2)
rails-observers (0.1.2) rails-observers (0.1.2)
activemodel (~> 4.0) activemodel (~> 4.0)
railties (4.2.0) railties (4.2.0)
...@@ -130,11 +134,11 @@ GEM ...@@ -130,11 +134,11 @@ GEM
sprockets (>= 2.8, < 4.0) sprockets (>= 2.8, < 4.0)
sqlite3 (1.3.10) sqlite3 (1.3.10)
thor (0.19.1) thor (0.19.1)
thread_safe (0.3.4) thread_safe (0.3.6)
tilt (1.4.1) tilt (1.4.1)
turbolinks (2.5.3) turbolinks (2.5.3)
coffee-rails coffee-rails
tzinfo (1.2.2) tzinfo (1.2.5)
thread_safe (~> 0.1) thread_safe (~> 0.1)
uglifier (2.7.1) uglifier (2.7.1)
execjs (>= 0.3.0) execjs (>= 0.3.0)
......
# encoding: utf-8 # encoding: utf-8
require File.dirname(__FILE__) + '/../spec_helper.rb' require_relative '../../spec_helper'
require 'annotate/annotate_models' require 'annotate/annotate_models'
require 'annotate/active_record_patch' require 'annotate/active_record_patch'
require 'active_support/core_ext/string' require 'active_support/core_ext/string'
...@@ -70,8 +70,8 @@ describe AnnotateModels do # rubocop:disable Metrics/BlockLength ...@@ -70,8 +70,8 @@ describe AnnotateModels do # rubocop:disable Metrics/BlockLength
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('1.2'))).to eql('1.2') }
it { expect(AnnotateModels.quote([BigDecimal.new('1.2')])).to eql(['1.2']) } it { expect(AnnotateModels.quote([BigDecimal('1.2')])).to eql(['1.2']) }
describe '#parse_options' do describe '#parse_options' do
let(:options) do let(:options) do
...@@ -780,6 +780,69 @@ EOS ...@@ -780,6 +780,69 @@ EOS
end end
end end
describe '#files_by_pattern' do
subject { AnnotateModels.files_by_pattern(root_directory, pattern_type, options) }
context 'when pattern_type=additional_file_patterns' do
let(:pattern_type) { 'additional_file_patterns' }
let(:root_directory) { nil }
context 'with additional_file_patterns' do
let(:additional_file_patterns) do
[
'%PLURALIZED_MODEL_NAME%/**/*.rb',
'%PLURALIZED_MODEL_NAME%/*_form'
]
end
let(:options) { { additional_file_patterns: additional_file_patterns } }
it do
expect(subject).to eq(additional_file_patterns)
end
end
context 'without additional_file_patterns' do
let(:options) { {} }
it do
expect(subject).to eq([])
end
end
end
end
describe '#get_patterns' do
subject { AnnotateModels.get_patterns(options, pattern_type) }
context 'when pattern_type=additional_file_patterns' do
let(:pattern_type) { 'additional_file_patterns' }
context 'with additional_file_patterns' do
let(:additional_file_patterns) do
[
'/%PLURALIZED_MODEL_NAME%/**/*.rb',
'/bar/%PLURALIZED_MODEL_NAME%/*_form'
]
end
let(:options) { { additional_file_patterns: additional_file_patterns } }
it do
expect(subject).to eq(additional_file_patterns)
end
end
context 'without additional_file_patterns' do
let(:options) { {} }
it do
expect(subject).to eq([])
end
end
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)
...@@ -1505,6 +1568,24 @@ end ...@@ -1505,6 +1568,24 @@ end
expect(filename). to eq 'test/unit/example_model_test.rb' expect(filename). to eq 'test/unit/example_model_test.rb'
end end
it 'should return the additional glob' do
filename_template = '/foo/bar/%MODEL_NAME%/testing.rb'
model_name = 'example_model'
table_name = 'example_models'
filename = AnnotateModels.resolve_filename(filename_template, model_name, table_name)
expect(filename). to eq '/foo/bar/example_model/testing.rb'
end
it 'should return the additional glob' do
filename_template = '/foo/bar/%PLURALIZED_MODEL_NAME%/testing.rb'
model_name = 'example_model'
table_name = 'example_models'
filename = AnnotateModels.resolve_filename(filename_template, model_name, table_name)
expect(filename). to eq '/foo/bar/example_models/testing.rb'
end
it 'should return the fixture path for a model' do it 'should return the fixture path for a model' do
filename_template = 'test/fixtures/%TABLE_NAME%.yml' filename_template = 'test/fixtures/%TABLE_NAME%.yml'
model_name = 'example_model' model_name = 'example_model'
...@@ -1523,6 +1604,7 @@ end ...@@ -1523,6 +1604,7 @@ 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')
...@@ -1737,7 +1819,7 @@ end ...@@ -1737,7 +1819,7 @@ end
end end
expect(error_output).to include("Unable to annotate #{@model_dir}/user.rb: oops") expect(error_output).to include("Unable to annotate #{@model_dir}/user.rb: oops")
expect(error_output).to include('/spec/annotate/annotate_models_spec.rb:') expect(error_output).to include('/spec/lib/annotate/annotate_models_spec.rb:')
end end
end end
......
require File.dirname(__FILE__) + '/../spec_helper.rb' require_relative '../../spec_helper'
require 'annotate/annotate_routes' require 'annotate/annotate_routes'
describe AnnotateRoutes do describe AnnotateRoutes do
......
require_relative '../spec_helper'
describe Annotate do
describe '.version' do
it 'has version' do
expect(Annotate.version).to be_instance_of(String)
end
end
describe '.skip_on_migration?' do
it "checks ENV for 'ANNOTATE_SKIP_ON_DB_MIGRATE' or 'skip_on_db_migrate'" do
expect(ENV).to receive(:[]).twice
described_class.skip_on_migration?
end
end
describe '.include_routes?' do
it "checks ENV with 'routes'" do
expect(ENV).to receive(:[]).with('routes')
described_class.include_routes?
end
end
describe '.include_models?' do
it "checks ENV with 'models'" do
expect(ENV).to receive(:[]).with('models')
described_class.include_models?
end
end
end
require_relative '../spec_helper' require_relative '../../spec_helper'
describe 'ActiveRecord migration rake task hooks' do describe 'ActiveRecord migration rake task hooks' do
before do before do
......
...@@ -28,6 +28,7 @@ require 'active_support/core_ext/object/blank' ...@@ -28,6 +28,7 @@ require 'active_support/core_ext/object/blank'
require 'active_support/core_ext/class/subclasses' require 'active_support/core_ext/class/subclasses'
require 'active_support/core_ext/string/inflections' require 'active_support/core_ext/string/inflections'
require 'annotate' require 'annotate'
require 'annotate/parser'
require 'byebug' require 'byebug'
module Annotate module Annotate
......
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