Does not annotate factories after DB migration
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.
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.
Yeah, I now usually do rake db:migrate && bundle exec annotate to get things annotated properly.
is someone working on this?
This is happening with serializers as well. I have to run rails db:migrate && annotate to get everything annotated correctly.
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.
The root cause seems to be that we have a couple of different ways of handling blank values for this option.
# setup_options
options[:root_dir] = [''] if options[:root_dir].empty?
# annotate_models
options[:root_dir] = ENV['root_dir'] ? ENV['root_dir'].split(',') : ['']
# remove_annotation
options[:root_dir] = ENV['root_dir']
# 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.
Is this fixed? can you please update this @lime
#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.