Mail API checker no longer reports false positives from updated Mail files.
This commit is contained in:
parent
7915c8df40
commit
6674c844b9
|
@ -165,8 +165,8 @@ module Rails
|
||||||
end
|
end
|
||||||
|
|
||||||
files = []
|
files = []
|
||||||
["recipients ", "attachment ", "subject ", "from "].each do |v|
|
["recipients ", "attachment(?!s) ", "(?<!:)subject ", "(?<!:)from "].each do |v|
|
||||||
lines = grep_for(v, "app/models/")
|
lines = grep_for_with_perl_regex(v, "app/models/")
|
||||||
files += extract_filenames(lines) || []
|
files += extract_filenames(lines) || []
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -300,16 +300,20 @@ module Rails
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
def grep_for_with_perl_regex(text, where = "./", double_quote = false)
|
||||||
|
grep_for(text, where, double_quote, true)
|
||||||
|
end
|
||||||
|
|
||||||
# Find a string in a set of files; calls +find_with_grep+ and +find_with_rak+
|
# Find a string in a set of files; calls +find_with_grep+ and +find_with_rak+
|
||||||
# depending on platform.
|
# depending on platform.
|
||||||
#
|
#
|
||||||
# TODO: Figure out if this works on Windows.
|
# TODO: Figure out if this works on Windows.
|
||||||
def grep_for(text, where = "./", double_quote = false)
|
def grep_for(text, where = "./", double_quote = false, perl_regex = false)
|
||||||
# If they're on Windows, they probably don't have grep.
|
# If they're on Windows, they probably don't have grep.
|
||||||
@probably_has_grep ||= (Config::CONFIG['host_os'].downcase =~ /mswin|windows|mingw/).nil?
|
@probably_has_grep ||= (Config::CONFIG['host_os'].downcase =~ /mswin|windows|mingw/).nil?
|
||||||
|
|
||||||
lines = if @probably_has_grep
|
lines = if @probably_has_grep
|
||||||
find_with_grep(text, base_path + where, double_quote)
|
find_with_grep(text, base_path + where, double_quote, perl_regex)
|
||||||
else
|
else
|
||||||
find_with_rak(text, base_path + where, double_quote)
|
find_with_rak(text, base_path + where, double_quote)
|
||||||
end
|
end
|
||||||
|
@ -326,13 +330,13 @@ module Rails
|
||||||
end
|
end
|
||||||
|
|
||||||
# Use the grep utility to find a string in a set of files
|
# Use the grep utility to find a string in a set of files
|
||||||
def find_with_grep(text, where, double_quote)
|
def find_with_grep(text, where, double_quote, perl_regex = false)
|
||||||
value = ""
|
value = ""
|
||||||
# Specifically double quote for finding 'test_help'
|
# Specifically double quote for finding 'test_help'
|
||||||
command = if double_quote
|
command = if double_quote
|
||||||
"grep -r --exclude=\*.svn\* \"#{text}\" #{where}"
|
"grep -r #{"-P" if perl_regex} --exclude=\*.svn\* \"#{text}\" #{where}"
|
||||||
else
|
else
|
||||||
"grep -r --exclude=\*.svn\* '#{text}' #{where}"
|
"grep -r #{"-P" if perl_regex} --exclude=\*.svn\* '#{text}' #{where}"
|
||||||
end
|
end
|
||||||
|
|
||||||
Open3.popen3(command) do |stdin, stdout, stderr|
|
Open3.popen3(command) do |stdin, stdout, stderr|
|
||||||
|
|
|
@ -120,6 +120,48 @@ class ApplicationCheckerTest < ActiveSupport::TestCase
|
||||||
assert @checker.alerts.has_key?("Old ActionMailer class API")
|
assert @checker.alerts.has_key?("Old ActionMailer class API")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_check_mailer_syntax_from
|
||||||
|
make_file("app/models/", "notifications.rb", "def signup\nfrom @user\n end")
|
||||||
|
@checker.check_mailers
|
||||||
|
|
||||||
|
assert @checker.alerts.has_key?("Old ActionMailer class API")
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_check_mailer_syntax_subject
|
||||||
|
make_file("app/models/", "notifications.rb", "def signup\nsubject @subject\n end")
|
||||||
|
@checker.check_mailers
|
||||||
|
|
||||||
|
assert @checker.alerts.has_key?("Old ActionMailer class API")
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_check_mailer_syntax_attachment
|
||||||
|
make_file("app/models/", "notifications.rb", "def signup\nattachment 'application/pdf' do |a|\n end")
|
||||||
|
@checker.check_mailers
|
||||||
|
|
||||||
|
assert @checker.alerts.has_key?("Old ActionMailer class API")
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_new_check_mailer_syntax_from
|
||||||
|
make_file("app/models/", "notifications.rb", "def signup\n:from => @users\n end")
|
||||||
|
@checker.check_mailers
|
||||||
|
|
||||||
|
assert ! @checker.alerts.has_key?("Old ActionMailer class API")
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_new_check_mailer_syntax_subject
|
||||||
|
make_file("app/models/", "notifications.rb", "def signup\n:subject => @users\n end")
|
||||||
|
@checker.check_mailers
|
||||||
|
|
||||||
|
assert ! @checker.alerts.has_key?("Old ActionMailer class API")
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_new_check_mailer_syntax_attachments
|
||||||
|
make_file("app/models/", "notifications.rb", "def signup\nattachments['an-image.jp'] = File.read('an-image.jpg')\n end")
|
||||||
|
@checker.check_mailers
|
||||||
|
|
||||||
|
assert ! @checker.alerts.has_key?("Old ActionMailer class API")
|
||||||
|
end
|
||||||
|
|
||||||
def test_check_mailer_api
|
def test_check_mailer_api
|
||||||
make_file("app/controllers/", "thing_controller.rb", "def signup\n Notifications.deliver_signup\n end")
|
make_file("app/controllers/", "thing_controller.rb", "def signup\n Notifications.deliver_signup\n end")
|
||||||
@checker.check_mailers
|
@checker.check_mailers
|
||||||
|
|
Loading…
Reference in New Issue