Fixed syntax for previous test I created; added before_validation_on_* deprecation check

This commit is contained in:
Josh Delsman 2010-07-17 13:02:42 +08:00 committed by Jeremy McAnally
parent 9eb81b7134
commit aa218395d3
2 changed files with 31 additions and 6 deletions

View File

@ -51,7 +51,7 @@ module Rails
end
end
def check_validation_methods
def check_validation_on_methods
files = []
["validate_on_create", "validate_on_update"].each do |v|
@ -61,14 +61,32 @@ module Rails
if files
alert(
"Removed validate_on_* methods",
"Validate-on-callback methods (validate_on_create/validate_on_destroy) have been removed",
"Updated syntax for validate_on_* methods",
"Validate-on-callback methods (validate_on_create/validate_on_destroy) have been changed to validate :x, :on => :create",
"https://rails.lighthouseapp.com/projects/8994/tickets/3880-validate_on_create-and-validate_on_update-no-longer-seem-to-exist",
files
)
end
end
def check_before_validation_on_methods
files = []
%w(before_validation_on_create before_validation_on_update).each do |v|
lines = grep_for(v, "app/models/")
files += extract_filenames(lines) || []
end
if files
alert(
"Updated syntax for before_validation_on_* methods",
"before_validation_on_* methods have been changed to before_validation(:on => :create/:update) { ... }",
"https://rails.lighthouseapp.com/projects/8994/tickets/4699-before_validation_on_create-and-before_validation_on_update-doesnt-exist",
files
)
end
end
# Check for deprecated router syntax
def check_routes
lines = ["map\\.", "ActionController::Routing::Routes", "\\.resources"].map do |v|

View File

@ -58,11 +58,18 @@ class ApplicationCheckerTest < ActiveSupport::TestCase
assert @checker.alerts.has_key?("Soon-to-be-deprecated ActiveRecord calls")
end
def test_check_validation_methods
def test_check_validation_on_methods
make_file("app/models", "post.rb", "validate_on_create :comments_valid?")
@checker.check_validation_methods
@checker.check_validation_on_methods
assert @checker.alerts.has_key?("Removed validate_on_* methods")
assert @checker.alerts.has_key?("Updated syntax for validate_on_* methods")
end
def test_check_before_validation_on_methods
make_file("app/models", "post.rb", "before_validation_on_create :comments_valid?")
@checker.check_before_validation_on_methods
assert @checker.alerts.has_key?("Updated syntax for before_validation_on_* methods")
end
def test_named_scope_left_over