From ab2e6415116d6264d36bad74d673c3fbf733ecc2 Mon Sep 17 00:00:00 2001 From: Adeynack Date: Fri, 28 Oct 2022 16:08:33 +0200 Subject: [PATCH 1/8] kick in CI --- lib/annotate/annotate_models.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/annotate/annotate_models.rb b/lib/annotate/annotate_models.rb index fc503839..e59b2cd5 100644 --- a/lib/annotate/annotate_models.rb +++ b/lib/annotate/annotate_models.rb @@ -142,6 +142,7 @@ def get_schema_info(klass, header, options = {}) if options[:format_markdown] info << sprintf( "# %-#{max_size + md_names_overhead}.#{max_size + md_names_overhead}s | %-#{md_type_allowance}.#{md_type_allowance}s | %s\n", 'Name', 'Type', 'Attributes' ) + info << "# #{ '-' * ( max_size + md_names_overhead ) } | #{'-' * md_type_allowance} | #{ '-' * 27 }\n" end From 2ff2fe7d3116c0daaeaca2a0e6a5a0b8d3852192 Mon Sep 17 00:00:00 2001 From: Adeynack Date: Wed, 15 Nov 2023 01:03:25 +0100 Subject: [PATCH 2/8] read with_comment_column in rake task --- lib/generators/annotate/templates/auto_annotate_models.rake | 3 ++- lib/tasks/annotate_models.rake | 1 + 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/generators/annotate/templates/auto_annotate_models.rake b/lib/generators/annotate/templates/auto_annotate_models.rake index 78b75eb5..61cdcd7a 100644 --- a/lib/generators/annotate/templates/auto_annotate_models.rake +++ b/lib/generators/annotate/templates/auto_annotate_models.rake @@ -52,7 +52,8 @@ if Rails.env.development? 'trace' => 'false', 'wrapper_open' => nil, 'wrapper_close' => nil, - 'with_comment' => 'true' + 'with_comment' => 'true', + 'with_comment_column' => 'false' ) end diff --git a/lib/tasks/annotate_models.rake b/lib/tasks/annotate_models.rake index 448fa80b..776f97ba 100644 --- a/lib/tasks/annotate_models.rake +++ b/lib/tasks/annotate_models.rake @@ -52,6 +52,7 @@ task annotate_models: :environment do options[:hide_limit_column_types] = Annotate::Helpers.fallback(ENV['hide_limit_column_types'], '') options[:hide_default_column_types] = Annotate::Helpers.fallback(ENV['hide_default_column_types'], '') options[:with_comment] = Annotate::Helpers.true?(ENV['with_comment']) + options[:with_comment_column] = Annotate::Helpers.true?(ENV['with_comment_column']) options[:ignore_unknown_models] = Annotate::Helpers.true?(ENV.fetch('ignore_unknown_models', 'false')) AnnotateModels.do_annotations(options) From 756f71cca38dce57e5dd16a76b06d54e2f20c25c Mon Sep 17 00:00:00 2001 From: Adeynack Date: Wed, 15 Nov 2023 01:05:26 +0100 Subject: [PATCH 3/8] less diff --- lib/annotate/annotate_models.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/annotate/annotate_models.rb b/lib/annotate/annotate_models.rb index d8353c37..dc2901a3 100644 --- a/lib/annotate/annotate_models.rb +++ b/lib/annotate/annotate_models.rb @@ -146,6 +146,7 @@ def get_schema_info(klass, header, options = {}) # rubocop:disable Metrics/Metho if options[:format_markdown] info << sprintf( "# %-#{max_size + md_names_overhead}.#{max_size + md_names_overhead}s | %-#{md_type_allowance}.#{md_type_allowance}s | %s\n", 'Name', 'Type', 'Attributes' ) + info << "# #{ '-' * ( max_size + md_names_overhead ) } | #{'-' * md_type_allowance} | #{ '-' * 27 }\n" end From df61c0cae78854ffe0a690ae6a6ffbf9d4cc3275 Mon Sep 17 00:00:00 2001 From: Adeynack Date: Wed, 15 Nov 2023 21:26:46 +0100 Subject: [PATCH 4/8] add annotate_models config test --- spec/lib/tasks/annotate_models_spec.rb | 30 ++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 spec/lib/tasks/annotate_models_spec.rb diff --git a/spec/lib/tasks/annotate_models_spec.rb b/spec/lib/tasks/annotate_models_spec.rb new file mode 100644 index 00000000..4da0e5e6 --- /dev/null +++ b/spec/lib/tasks/annotate_models_spec.rb @@ -0,0 +1,30 @@ +require_relative '../../spec_helper' + +describe 'annotate_models rake task and Annotate.set_defaults' do + before do + Rake.application = Rake::Application.new + Rake::Task.define_task('environment') + Rake.load_rakefile('tasks/annotate_models.rake') + end + + let(:annotate_models_argument) do + argument = nil + expect(AnnotateModels).to receive(:do_annotations) { |arg| argument = arg } + Rake::Task['annotate_models'].invoke + argument + end + + describe 'with_comment_column' do + after { ENV.delete('with_comment_column') } + subject { annotate_models_argument[:with_comment_column] } + + context 'when Annotate.set_defaults is not called (defaults)' do + it { is_expected.to be_falsey } + end + + context 'when Annotate.set_defaults sets it to "true"' do + before { Annotate.set_defaults('with_comment_column' => 'true') } + it { is_expected.to be_truthy } + end + end +end \ No newline at end of file From d9cb25cd3d02ff4e9801c4d8dadb2cb0ffbfae33 Mon Sep 17 00:00:00 2001 From: Adeynack Date: Wed, 15 Nov 2023 21:35:44 +0100 Subject: [PATCH 5/8] lint --- spec/lib/tasks/annotate_models_spec.rb | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/spec/lib/tasks/annotate_models_spec.rb b/spec/lib/tasks/annotate_models_spec.rb index 4da0e5e6..8c51826f 100644 --- a/spec/lib/tasks/annotate_models_spec.rb +++ b/spec/lib/tasks/annotate_models_spec.rb @@ -1,6 +1,6 @@ require_relative '../../spec_helper' -describe 'annotate_models rake task and Annotate.set_defaults' do +describe 'Annotate annotate_models rake task and Annotate.set_defaults' do # rubocop:disable RSpec/DescribeClass before do Rake.application = Rake::Application.new Rake::Task.define_task('environment') @@ -9,22 +9,24 @@ let(:annotate_models_argument) do argument = nil - expect(AnnotateModels).to receive(:do_annotations) { |arg| argument = arg } + expect(AnnotateModels).to have_received(:do_annotations) { |arg| argument = arg } Rake::Task['annotate_models'].invoke argument end describe 'with_comment_column' do - after { ENV.delete('with_comment_column') } subject { annotate_models_argument[:with_comment_column] } + after { ENV.delete('with_comment_column') } + context 'when Annotate.set_defaults is not called (defaults)' do it { is_expected.to be_falsey } end context 'when Annotate.set_defaults sets it to "true"' do before { Annotate.set_defaults('with_comment_column' => 'true') } + it { is_expected.to be_truthy } end end -end \ No newline at end of file +end From 5b358658cc5fdc225b4abe716654df7ea574dfcb Mon Sep 17 00:00:00 2001 From: Adeynack Date: Wed, 15 Nov 2023 21:42:48 +0100 Subject: [PATCH 6/8] fix stub --- spec/lib/tasks/annotate_models_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/lib/tasks/annotate_models_spec.rb b/spec/lib/tasks/annotate_models_spec.rb index 8c51826f..9b622f93 100644 --- a/spec/lib/tasks/annotate_models_spec.rb +++ b/spec/lib/tasks/annotate_models_spec.rb @@ -9,7 +9,7 @@ let(:annotate_models_argument) do argument = nil - expect(AnnotateModels).to have_received(:do_annotations) { |arg| argument = arg } + allow(AnnotateModels).to receive(:do_annotations) { |arg| argument = arg } Rake::Task['annotate_models'].invoke argument end From 6310406bda8d35699b75aee9350839073466f1b0 Mon Sep 17 00:00:00 2001 From: Adeynack Date: Wed, 15 Nov 2023 21:50:45 +0100 Subject: [PATCH 7/8] reset `has_set_defaults` after test --- spec/lib/tasks/annotate_models_spec.rb | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/spec/lib/tasks/annotate_models_spec.rb b/spec/lib/tasks/annotate_models_spec.rb index 9b622f93..a66e7a6f 100644 --- a/spec/lib/tasks/annotate_models_spec.rb +++ b/spec/lib/tasks/annotate_models_spec.rb @@ -7,12 +7,17 @@ Rake.load_rakefile('tasks/annotate_models.rake') end + after do + Annotate.instance_variable_set('@has_set_defaults', false) + end + let(:annotate_models_argument) do argument = nil allow(AnnotateModels).to receive(:do_annotations) { |arg| argument = arg } Rake::Task['annotate_models'].invoke argument end + describe 'with_comment_column' do subject { annotate_models_argument[:with_comment_column] } From ae62b783c98accd26024b7f21effe839d4a64711 Mon Sep 17 00:00:00 2001 From: Adeynack Date: Wed, 15 Nov 2023 21:52:24 +0100 Subject: [PATCH 8/8] lint --- spec/lib/tasks/annotate_models_spec.rb | 1 - 1 file changed, 1 deletion(-) diff --git a/spec/lib/tasks/annotate_models_spec.rb b/spec/lib/tasks/annotate_models_spec.rb index a66e7a6f..03f82391 100644 --- a/spec/lib/tasks/annotate_models_spec.rb +++ b/spec/lib/tasks/annotate_models_spec.rb @@ -17,7 +17,6 @@ Rake::Task['annotate_models'].invoke argument end - describe 'with_comment_column' do subject { annotate_models_argument[:with_comment_column] }