Add more checks for beta that's dropping soon: check for old ERb calls with block helpers and check for old session/cookie settings

This commit is contained in:
Jeremy McAnally 2010-03-31 15:26:51 -05:00
parent ce22c72ee8
commit 33cbc3509b
2 changed files with 67 additions and 0 deletions

View File

@ -221,6 +221,51 @@ module Rails
end
end
# Checks for old-style ERb helpers
def check_old_helpers
lines = grep_for("<% .* do.*%>", "app/views/**/*")
files = extract_filenames(lines)
if files
alert(
"Deprecated ERb helper calls",
"Calls to helpers like form_for and other buffer-appending methods now require the = to be present on the ERb call (i.e., <%=). The only exceptions to this are helpers like content_for and cache.",
"http://weblog.rubyonrails.org/",
files
)
end
end
# Checks for old cookie secret settings
def check_old_cookie_setting
lines = grep_for("ActionController::Base.session = {", "config/**/*")
files = extract_filenames(lines)
if files
alert(
"Deprecated cookie secret setting",
"Previously, session store was set directly on ActionController::Base; now it's now config.cookie_secret.",
"http://weblog.rubyonrails.org/",
files
)
end
end
# Checks for old session settings
def check_old_session_setting
lines = grep_for("ActionController::Base.session_store", "config/**/*")
files = extract_filenames(lines)
if files
alert(
"Old session store setting",
"Previously, session store was set directly on ActionController::Base; now it's now config.session_store :whatever.",
"http://weblog.rubyonrails.org/",
files
)
end
end
private
# Find a string in a set of files; calls +find_with_grep+ and +find_with_rak+
# depending on platform.

View File

@ -1,5 +1,6 @@
require 'test_helper'
require 'application_checker'
require 'fileutils'
tmp_dir = "#{File.dirname(__FILE__)}/fixtures/tmp"
@ -161,6 +162,27 @@ class ApplicationCheckerTest < ActiveSupport::TestCase
assert @checker.alerts.has_key?("Deprecated constant(s)")
end
def test_check_deprecated_cookie_settings
make_file("config/initializers/", "more_settings.rb", "ActionController::Base.session = {\n:whatever => 'woot'\n}")
@checker.check_old_cookie_setting
assert @checker.alerts.has_key?("Deprecated cookie secret setting")
end
def test_check_deprecated_session_settings
make_file("config/initializers/", "more_settings.rb", "ActionController::Base.session_store = :cookie\nthings.awesome(:whatever)")
@checker.check_old_session_setting
assert @checker.alerts.has_key?("Old session store setting")
end
def test_check_helpers
make_file("app/views/users/", "test.html.erb", "<b>blah blah blah</b><% form_for(:thing) do |f| %> <label>doo dah</label> <%= f.whatever %> <% end %>")
@checker.check_old_helpers
assert @checker.alerts.has_key?("Deprecated ERb helper calls")
end
def teardown
clear_files