Skip to content

Commit 5d01c41

Browse files
authored
Make with_comment_column work with Annotate.set_defaults (ctran#999)
1 parent e60a666 commit 5d01c41

File tree

3 files changed

+39
-1
lines changed

3 files changed

+39
-1
lines changed

lib/generators/annotate/templates/auto_annotate_models.rake

+2-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,8 @@ if Rails.env.development?
5252
'trace' => 'false',
5353
'wrapper_open' => nil,
5454
'wrapper_close' => nil,
55-
'with_comment' => 'true'
55+
'with_comment' => 'true',
56+
'with_comment_column' => 'false'
5657
)
5758
end
5859

lib/tasks/annotate_models.rake

+1
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ task annotate_models: :environment do
5252
options[:hide_limit_column_types] = Annotate::Helpers.fallback(ENV['hide_limit_column_types'], '')
5353
options[:hide_default_column_types] = Annotate::Helpers.fallback(ENV['hide_default_column_types'], '')
5454
options[:with_comment] = Annotate::Helpers.true?(ENV['with_comment'])
55+
options[:with_comment_column] = Annotate::Helpers.true?(ENV['with_comment_column'])
5556
options[:ignore_unknown_models] = Annotate::Helpers.true?(ENV.fetch('ignore_unknown_models', 'false'))
5657

5758
AnnotateModels.do_annotations(options)
+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
require_relative '../../spec_helper'
2+
3+
describe 'Annotate annotate_models rake task and Annotate.set_defaults' do # rubocop:disable RSpec/DescribeClass
4+
before do
5+
Rake.application = Rake::Application.new
6+
Rake::Task.define_task('environment')
7+
Rake.load_rakefile('tasks/annotate_models.rake')
8+
end
9+
10+
after do
11+
Annotate.instance_variable_set('@has_set_defaults', false)
12+
end
13+
14+
let(:annotate_models_argument) do
15+
argument = nil
16+
allow(AnnotateModels).to receive(:do_annotations) { |arg| argument = arg }
17+
Rake::Task['annotate_models'].invoke
18+
argument
19+
end
20+
21+
describe 'with_comment_column' do
22+
subject { annotate_models_argument[:with_comment_column] }
23+
24+
after { ENV.delete('with_comment_column') }
25+
26+
context 'when Annotate.set_defaults is not called (defaults)' do
27+
it { is_expected.to be_falsey }
28+
end
29+
30+
context 'when Annotate.set_defaults sets it to "true"' do
31+
before { Annotate.set_defaults('with_comment_column' => 'true') }
32+
33+
it { is_expected.to be_truthy }
34+
end
35+
end
36+
end

0 commit comments

Comments
 (0)