Check for old-style constants and link to qrush's excellent post if we find one
This commit is contained in:
parent
366d1393c5
commit
b257acf322
@ -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")
|
||||
|
@ -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
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user