Will now output the relative path to a file rather than an absolute

This commit is contained in:
Ryan Bigg 2011-04-08 09:22:18 +10:00
parent cbdae476d9
commit 961d5d5ff7
3 changed files with 59 additions and 23 deletions

View File

@ -41,7 +41,7 @@ module Rails
lines = grep_for("named_scope", "app/models/") lines = grep_for("named_scope", "app/models/")
files = extract_filenames(lines) files = extract_filenames(lines)
if files unless files.empty?
alert( alert(
"named_scope is now just scope", "named_scope is now just scope",
"The named_scope method has been renamed to just scope.", "The named_scope method has been renamed to just scope.",
@ -173,9 +173,10 @@ module Rails
# Check for old-style config.gem calls # Check for old-style config.gem calls
def check_gems def check_gems
lines = grep_for("config.gem ", "config/*.rb") lines = grep_for("config.gem ", "config/*.rb")
lines += grep_for("config.gem ", "config/**/*.rb")
files = extract_filenames(lines) files = extract_filenames(lines)
if files unless files.empty?
alert( alert(
"Old gem bundling (config.gems)", "Old gem bundling (config.gems)",
"The old way of bundling is gone now. You need a Gemfile for bundler.", "The old way of bundling is gone now. You need a Gemfile for bundler.",
@ -191,7 +192,7 @@ module Rails
lines = grep_for("deliver_", "app/models/ #{base_path}app/controllers/ #{base_path}app/observers/") lines = grep_for("deliver_", "app/models/ #{base_path}app/controllers/ #{base_path}app/observers/")
files = extract_filenames(lines) files = extract_filenames(lines)
if files unless files.empty?
alert( alert(
"Deprecated ActionMailer API", "Deprecated ActionMailer API",
"You're using the old ActionMailer API to send e-mails in a controller, model, or observer.", "You're using the old ActionMailer API to send e-mails in a controller, model, or observer.",
@ -225,7 +226,7 @@ module Rails
grep_for("def manifest", g).empty? grep_for("def manifest", g).empty?
end.compact end.compact
if !files.empty? unless files.empty?
alert( alert(
"Old Rails generator API", "Old Rails generator API",
"A plugin in the app is using the old generator API (a new one may be available at http://github.com/trydionel/rails3-generators).", "A plugin in the app is using the old generator API (a new one may be available at http://github.com/trydionel/rails3-generators).",
@ -269,7 +270,7 @@ module Rails
files = extract_filenames(lines) files = extract_filenames(lines)
if files if !files.blank?
alert( alert(
"Deprecated ERb helper calls", "Deprecated ERb helper calls",
"Block helpers that use concat (e.g., form_for) should use <%= instead of <%. The current form will continue to work for now, but you will get deprecation warnings since this form will go away in the future.", "Block helpers that use concat (e.g., form_for) should use <%= instead of <%. The current form will continue to work for now, but you will get deprecation warnings since this form will go away in the future.",
@ -303,7 +304,7 @@ module Rails
lines = grep_for("ActionController::Base.cookie_verifier_secret = ", "config/**/*") lines = grep_for("ActionController::Base.cookie_verifier_secret = ", "config/**/*")
files = extract_filenames(lines) files = extract_filenames(lines)
if files unless files.empty?
alert( alert(
"Deprecated cookie secret setting", "Deprecated cookie secret setting",
"Previously, cookie secret was set directly on ActionController::Base; it's now config.secret_token.", "Previously, cookie secret was set directly on ActionController::Base; it's now config.secret_token.",
@ -317,7 +318,7 @@ module Rails
lines = grep_for("ActionController::Base.session = {", "config/**/*") lines = grep_for("ActionController::Base.session = {", "config/**/*")
files = extract_filenames(lines) files = extract_filenames(lines)
if files unless files.empty?
alert( alert(
"Deprecated session secret setting", "Deprecated session secret setting",
"Previously, session secret was set directly on ActionController::Base; it's now config.secret_token.", "Previously, session secret was set directly on ActionController::Base; it's now config.secret_token.",
@ -332,7 +333,7 @@ module Rails
lines = grep_for("ActionController::Base.session_store", "config/**/*") lines = grep_for("ActionController::Base.session_store", "config/**/*")
files = extract_filenames(lines) files = extract_filenames(lines)
if files unless files.empty?
alert( alert(
"Old session store setting", "Old session store setting",
"Previously, session store was set directly on ActionController::Base; it's now config.session_store :whatever.", "Previously, session store was set directly on ActionController::Base; it's now config.session_store :whatever.",
@ -401,14 +402,18 @@ module Rails
# Extract the filenames from the grep output # Extract the filenames from the grep output
def extract_filenames(output) def extract_filenames(output)
if @probably_has_grep if @probably_has_grep
extract_filenames_from_grep(output) filenames = extract_filenames_from_grep(output)
else else
extract_filenames_from_rak(output) filenames = extract_filenames_from_rak(output)
end
filenames.compact.map do |f|
f.gsub(base_path, "")
end end
end end
def extract_filenames_from_grep(output) def extract_filenames_from_grep(output)
return nil if output.empty? return [] if output.empty?
output.split("\n").map do |fn| output.split("\n").map do |fn|
if m = fn.match(/^(.+?):/) if m = fn.match(/^(.+?):/)
@ -418,7 +423,7 @@ module Rails
end end
def extract_filenames_from_rak(output) def extract_filenames_from_rak(output)
return nil if output.empty? return [] if output.empty?
output.split("\n").uniq output.split("\n").uniq
end end

View File

@ -15,7 +15,7 @@ FileUtils.mkdir_p BASE_ROOT
module Rails module Rails
module Upgrading module Upgrading
class ApplicationChecker class ApplicationChecker
attr_reader :alerts attr_reader :alerts, :culprits
def base_path def base_path
BASE_ROOT + "/" BASE_ROOT + "/"
@ -27,10 +27,12 @@ module Rails
def initialize def initialize
@alerts = {} @alerts = {}
@culprits = {}
end end
def alert(title, text, more_info_url, culprits) def alert(title, text, more_info_url, culprits)
@alerts[title] = [text, more_info_url, culprits] @alerts[title] = [text, more_info_url]
@culprits[title] = culprits
end end
end end
end end
@ -55,7 +57,9 @@ class ApplicationCheckerTest < ActiveSupport::TestCase
make_file("app/models", "post.rb", "Post.find(:all)") make_file("app/models", "post.rb", "Post.find(:all)")
@checker.check_ar_methods @checker.check_ar_methods
assert @checker.alerts.has_key?("Soon-to-be-deprecated ActiveRecord calls") key = "Soon-to-be-deprecated ActiveRecord calls"
assert @checker.alerts.has_key?(key)
assert_equal "app/models/post.rb", @checker.culprits[key].first
end end
def test_check_svn_subdirs_are_not_included def test_check_svn_subdirs_are_not_included
@ -133,6 +137,18 @@ class ApplicationCheckerTest < ActiveSupport::TestCase
assert @checker.alerts.has_key?("Old gem bundling (config.gems)") assert @checker.alerts.has_key?("Old gem bundling (config.gems)")
end end
def test_check_gems_finds_nothing
@checker.check_gems
assert_equal false, @checker.alerts.has_key?("Old gem bundling (config.gems)")
end
def test_check_mailer_finds_nothing
@checker.check_mailers
assert_equal false, @checker.alerts.has_key?("Old ActionMailer class API")
end
def test_check_mailer_syntax def test_check_mailer_syntax
make_file("app/models/", "notifications.rb", "def signup\nrecipients @users\n end") make_file("app/models/", "notifications.rb", "def signup\nrecipients @users\n end")
@checker.check_mailers @checker.check_mailers
@ -224,6 +240,11 @@ class ApplicationCheckerTest < ActiveSupport::TestCase
assert @checker.alerts.has_key?("Deprecated constant(s)") assert @checker.alerts.has_key?("Deprecated constant(s)")
end end
def test_check_deprecated_cookie_finds_nothing
@checker.check_old_cookie_secret
assert_equal false, @checker.alerts.has_key?("Deprecated cookie secret setting")
end
def test_check_deprecated_cookie_settings def test_check_deprecated_cookie_settings
make_file("config/initializers/", "more_settings.rb", "ActionController::Base.cookie_verifier_secret = 'OMG'") make_file("config/initializers/", "more_settings.rb", "ActionController::Base.cookie_verifier_secret = 'OMG'")
@checker.check_old_cookie_secret @checker.check_old_cookie_secret
@ -231,6 +252,11 @@ class ApplicationCheckerTest < ActiveSupport::TestCase
assert @checker.alerts.has_key?("Deprecated cookie secret setting") assert @checker.alerts.has_key?("Deprecated cookie secret setting")
end end
def test_check_deprecated_session_finds_nothing
@checker.check_old_session_secret
assert_equal false, @checker.alerts.has_key?("Deprecated session secret setting")
end
def test_check_deprecated_session_secret def test_check_deprecated_session_secret
make_file("config/initializers/", "more_settings.rb", "ActionController::Base.session = {\n:whatever => 'woot'\n}") make_file("config/initializers/", "more_settings.rb", "ActionController::Base.session = {\n:whatever => 'woot'\n}")
@checker.check_old_session_secret @checker.check_old_session_secret
@ -238,6 +264,11 @@ class ApplicationCheckerTest < ActiveSupport::TestCase
assert @checker.alerts.has_key?("Deprecated session secret setting") assert @checker.alerts.has_key?("Deprecated session secret setting")
end end
def test_check_old_session_setting_finds_nothing
@checker.check_old_session_setting
assert_equal false, @checker.alerts.has_key?("Old session store setting")
end
def test_check_deprecated_session_settings def test_check_deprecated_session_settings
make_file("config/initializers/", "more_settings.rb", "ActionController::Base.session_store = :cookie\nthings.awesome(:whatever)") make_file("config/initializers/", "more_settings.rb", "ActionController::Base.session_store = :cookie\nthings.awesome(:whatever)")
@checker.check_old_session_setting @checker.check_old_session_setting
@ -264,7 +295,7 @@ class ApplicationCheckerTest < ActiveSupport::TestCase
make_file("app/views/users/", "another_test.html.erb", "<b>blah blah blah</b><% @some_items.each do |item| %> <label>doo dah</label> <%= item %> <% end %>") make_file("app/views/users/", "another_test.html.erb", "<b>blah blah blah</b><% @some_items.each do |item| %> <label>doo dah</label> <%= item %> <% end %>")
@checker.check_old_helpers @checker.check_old_helpers
assert_equal @checker.alerts.has_key?("Deprecated ERb helper calls"), false assert_equal false, @checker.alerts.has_key?("Deprecated ERb helper calls")
end end
def test_check_old_ajax_helpers def test_check_old_ajax_helpers

View File

@ -171,6 +171,6 @@ end
upgrader = Rails::Upgrading::RoutesUpgrader.new upgrader = Rails::Upgrading::RoutesUpgrader.new
upgrader.routes_code = routes_code upgrader.routes_code = routes_code
assert_equal new_routes_code, upgrader.generate_new_routes assert_equal new_routes_code.strip, upgrader.generate_new_routes.strip
end end
end end