diff --git a/lib/application_checker.rb b/lib/application_checker.rb index da43304..c4bec6c 100644 --- a/lib/application_checker.rb +++ b/lib/application_checker.rb @@ -50,6 +50,24 @@ module Rails ) end end + + def check_validation_methods + files = [] + + ["validate_on_create", "validate_on_update"].each do |v| + lines = grep_for(v, "app/models/") + files += extract_filenames(lines) || [] + end + + if files + alert( + "Removed validate_on_* methods", + "Validate-on-callback methods (validate_on_create/validate_on_destroy) have been removed", + "https://rails.lighthouseapp.com/projects/8994/tickets/3880-validate_on_create-and-validate_on_update-no-longer-seem-to-exist", + files + ) + end + end # Check for deprecated router syntax def check_routes diff --git a/test/application_checker_test.rb b/test/application_checker_test.rb index 53bdb39..d0b23df 100644 --- a/test/application_checker_test.rb +++ b/test/application_checker_test.rb @@ -57,6 +57,13 @@ class ApplicationCheckerTest < ActiveSupport::TestCase assert @checker.alerts.has_key?("Soon-to-be-deprecated ActiveRecord calls") end + + def test_check_validation_methods + make_file("app/models", "post.rb", "validate_on_create :comments_valid?") + @checker.check_validation_methods + + assert @checker.alerts.has_key?("Removed validate_on_* methods") + end def test_named_scope_left_over make_file("app/models", "post.rb", "named_scope :failure")