diff --git a/lib/application_checker.rb b/lib/application_checker.rb index 967a91b..03aa788 100644 --- a/lib/application_checker.rb +++ b/lib/application_checker.rb @@ -112,6 +112,27 @@ module Rails end end + # Check for deprecated constants + def check_deprecated_constants + files = [] + ["RAILS_ENV", "RAILS_ROOT", "RAILS_DEFAULT_LOGGER"].each do |v| + lines = grep_for(v, "app/") + files += extract_filenames(lines) || [] + + lines = grep_for(v, "lib/") + files += extract_filenames(lines) || [] + end + + unless files.empty? + alert( + "Deprecated constant(s)", + "Constants like RAILS_ENV, RAILS_ROOT, and RAILS_DEFAULT_LOGGER are now deprecated.", + "http://litanyagainstfear.com/blog/2010/02/03/the-rails-module/", + files.uniq + ) + end + end + # Check for old-style config.gem calls def check_gems lines = grep_for("config.gem ", "config/*.rb") diff --git a/test/application_checker_test.rb b/test/application_checker_test.rb index 3634477..caadc55 100644 --- a/test/application_checker_test.rb +++ b/test/application_checker_test.rb @@ -147,6 +147,20 @@ class ApplicationCheckerTest < ActiveSupport::TestCase assert !@checker.alerts.has_key?("Old router API") end + def test_check_deprecated_constants_in_app_code + make_file("app/controllers/", "thing_controller.rb", "class ThingController; THING = RAILS_ENV; end;") + @checker.check_deprecated_constants + + assert @checker.alerts.has_key?("Deprecated constant(s)") + end + + def test_check_deprecated_constants_in_lib + make_file("lib/", "extra_thing.rb", "class ExtraThing; THING = RAILS_ENV; end;") + @checker.check_deprecated_constants + + assert @checker.alerts.has_key?("Deprecated constant(s)") + end + def teardown clear_files