Skip to content

Commit

Permalink
Make with_comment_column work with Annotate.set_defaults (#999)
Browse files Browse the repository at this point in the history
  • Loading branch information
Adeynack committed Nov 30, 2023
1 parent e60a666 commit 5d01c41
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/generators/annotate/templates/auto_annotate_models.rake
Expand Up @@ -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

Expand Down
1 change: 1 addition & 0 deletions lib/tasks/annotate_models.rake
Expand Up @@ -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)
Expand Down
36 changes: 36 additions & 0 deletions spec/lib/tasks/annotate_models_spec.rb
@@ -0,0 +1,36 @@
require_relative '../../spec_helper'

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')
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] }

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

0 comments on commit 5d01c41

Please sign in to comment.