annotate_models icon indicating copy to clipboard operation
annotate_models copied to clipboard

Does not annotate factories after DB migration

Open heaven opened this issue 10 years ago • 8 comments

Here's my config:

Annotate.set_defaults(
  'routes'                  => 'false',
  'position_in_routes'      => 'after',
  'position_in_class'       => 'after',
  'position_in_test'        => 'after',
  'position_in_fixture'     => 'after',
  'position_in_factory'     => 'after',
  'position_in_serializer'  => 'after',
  'show_foreign_keys'       => 'true',
  'show_indexes'            => 'true',
  'simple_indexes'          => 'false',
  'model_dir'               => 'app/models',
  'root_dir'                => '',
  'include_version'         => 'false',
  'require'                 => '',
  'exclude_tests'           => 'false',
  'exclude_fixtures'        => 'false',
  'exclude_factories'       => 'false',
  'exclude_serializers'     => 'false',
  'exclude_scaffolds'       => 'false',
  'exclude_controllers'     => 'true',
  'exclude_helpers'         => 'true',
  'ignore_model_sub_dir'    => 'false',
  'ignore_columns'          => nil,
  'ignore_unknown_models'   => 'false',
  'hide_limit_column_types' => 'integer,boolean',
  'skip_on_db_migrate'      => 'false',
  'format_bare'             => 'true',
  'format_rdoc'             => 'false',
  'format_markdown'         => 'false',
  'sort'                    => 'false',
  'force'                   => 'false',
  'trace'                   => 'false',
  'wrapper_open'            => nil,
  'wrapper_close'           => nil,
)
end

After running migration it updates annotations in models, but not in factories, then I have to run bundle exec annotate to annotate factories:

➜  clarion-core git:(master) ✗ rake db:migrate
== 20160202113832 AddMaxDailyCountToReminder: migrating =======================
-- add_column(:reminders, :max_daily_count, :integer, {:default=>1, :null=>false})
   -> 0.0498s
== 20160202113832 AddMaxDailyCountToReminder: migrated (0.0499s) ==============

Annotated (1): app/models/reminder.rb

➜  clarion-core git:(master) ✗ bundle exec annotate
Annotated (1): app/models/reminder.rb

➜  clarion-core git:(master) ✗ bundle exec annotate
Model files unchanged.

heaven avatar Feb 02 '16 11:02 heaven

This not only skips annotating factory_girl factories, but also skips rspec files (ie files in spec/models). But, one interesting thing I noticed is that the annotate executable DOES annotate all such files while the rake task does not.

vraravam avatar Jul 20 '16 03:07 vraravam

Yeah, I now usually do rake db:migrate && bundle exec annotate to get things annotated properly.

heaven avatar Jul 20 '16 03:07 heaven

is someone working on this?

Hirurg103 avatar Aug 25 '16 14:08 Hirurg103

This is happening with serializers as well. I have to run rails db:migrate && annotate to get everything annotated correctly.

ezekg avatar Nov 13 '16 06:11 ezekg

I managed to trace this to the root_dir option.

With 'root_dir' => '', factories are not annotated during migrations. If I comment out the line or change it to 'root_dir' => nil factory annotations work.

lime avatar Mar 02 '17 09:03 lime

The root cause seems to be that we have a couple of different ways of handling blank values for this option.

annotate.rb:

# setup_options
options[:root_dir] = [''] if options[:root_dir].empty?

annotate_models.rake:

# annotate_models
options[:root_dir] = ENV['root_dir'] ? ENV['root_dir'].split(',') : ['']

# remove_annotation
options[:root_dir] = ENV['root_dir']

annotate_models.rb:

# root_dir
@root_dir.is_a?(Array) ? @root_dir : [@root_dir || '']

Clearly, the intent is for the default value to be ['']. However, the check inside annotate_models.rake ends up turning '' into [].

Later, when looping through root_dir.each, the array is empty and a lot of files types are never added.

lime avatar Mar 02 '17 09:03 lime

Is this fixed? can you please update this @lime

vamsipavanmahesh avatar May 29 '17 04:05 vamsipavanmahesh

#448 has been merged, so this should be fixed on the develop branch.

However, there hasn't been a new released version in quite some time. Until then, you can use the unreleased version from github.

lime avatar May 29 '17 07:05 lime