From a5ce8818d29a367ac2a80eeeae649486e1158206 Mon Sep 17 00:00:00 2001 From: John Meehan Date: Tue, 5 Jul 2016 01:10:24 +0100 Subject: [PATCH 1/3] Allow rake notes to work with other directories. Additional directories can be added using SourceAnnotationExtractor::Annotation.register_directories("spec", "other_dir") Result: rake notes will now extract notes from these directories. --- railties/lib/rails/source_annotation_extractor.rb | 6 ++++++ railties/test/application/rake/notes_test.rb | 13 +++++++++++++ 2 files changed, 19 insertions(+) diff --git a/railties/lib/rails/source_annotation_extractor.rb b/railties/lib/rails/source_annotation_extractor.rb index ca195bd752559..85818fafc98d9 100644 --- a/railties/lib/rails/source_annotation_extractor.rb +++ b/railties/lib/rails/source_annotation_extractor.rb @@ -18,6 +18,12 @@ def self.directories @@directories ||= %w(app config db lib test) + (ENV['SOURCE_ANNOTATION_DIRECTORIES'] || '').split(',') end + # Registers additional directories to be included + # SourceAnnotationExtractor::Annotation.register_directories("spec","another") + def self.register_directories(*dirs) + directories.push(*dirs) + end + def self.extensions @@extensions ||= {} end diff --git a/railties/test/application/rake/notes_test.rb b/railties/test/application/rake/notes_test.rb index 50def9beb02ce..71b7480f644d3 100644 --- a/railties/test/application/rake/notes_test.rb +++ b/railties/test/application/rake/notes_test.rb @@ -126,6 +126,19 @@ def teardown end end + test 'register additional directories' do + app_file "app/spec/spec_helper.rb", "# TODO: note in spec" + app_file "app/spec/models/user_spec.rb", "# TODO: note in model spec" + add_to_config %q{ config.annotations.register_directories("spec") } + + + run_rake_notes do |output, lines| + assert_match(/note in spec/, output) + assert_match(/note in model spec/, output) + assert_equal 2, lines.size + end + end + private def run_rake_notes(command = 'bin/rails notes') From 80abee6662ed001c0ee9f59c323e8c39c62220ca Mon Sep 17 00:00:00 2001 From: John Meehan Date: Tue, 5 Jul 2016 09:01:31 +0100 Subject: [PATCH 2/3] removed extra blank line --- railties/test/application/rake/notes_test.rb | 1 - 1 file changed, 1 deletion(-) diff --git a/railties/test/application/rake/notes_test.rb b/railties/test/application/rake/notes_test.rb index 71b7480f644d3..a6caf007cdd18 100644 --- a/railties/test/application/rake/notes_test.rb +++ b/railties/test/application/rake/notes_test.rb @@ -131,7 +131,6 @@ def teardown app_file "app/spec/models/user_spec.rb", "# TODO: note in model spec" add_to_config %q{ config.annotations.register_directories("spec") } - run_rake_notes do |output, lines| assert_match(/note in spec/, output) assert_match(/note in model spec/, output) From 22a94d9ac4be7c1ee0482f671cd7d0ae6dd7cca5 Mon Sep 17 00:00:00 2001 From: John Meehan Date: Tue, 5 Jul 2016 15:34:13 +0100 Subject: [PATCH 3/3] Fix test to try `spec/` directory as opposed to `app/spec` which I had accidently set it to. Made the change and test still passes. --- railties/test/application/rake/notes_test.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/railties/test/application/rake/notes_test.rb b/railties/test/application/rake/notes_test.rb index a6caf007cdd18..a94e3020995b5 100644 --- a/railties/test/application/rake/notes_test.rb +++ b/railties/test/application/rake/notes_test.rb @@ -127,8 +127,8 @@ def teardown end test 'register additional directories' do - app_file "app/spec/spec_helper.rb", "# TODO: note in spec" - app_file "app/spec/models/user_spec.rb", "# TODO: note in model spec" + app_file "spec/spec_helper.rb", "# TODO: note in spec" + app_file "spec/models/user_spec.rb", "# TODO: note in model spec" add_to_config %q{ config.annotations.register_directories("spec") } run_rake_notes do |output, lines|