Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make with_comment_column work with Annotate.set_defaults #999

3 changes: 2 additions & 1 deletion lib/generators/annotate/templates/auto_annotate_models.rake
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
32 changes: 32 additions & 0 deletions spec/lib/tasks/annotate_models_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
require_relative '../../spec_helper'

describe 'Annotate annotate_models rake task and Annotate.set_defaults' do # rubocop:disable RSpec/DescribeClass
Adeynack marked this conversation as resolved.
Show resolved Hide resolved
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 have_received(: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
Loading