From 9eb81b7134cb8332490e7951c7b4f3907747ca64 Mon Sep 17 00:00:00 2001 From: Josh Delsman Date: Sat, 17 Jul 2010 12:54:55 +0800 Subject: [PATCH] Added check for validate_on_create and validate_on_update, which have both been removed in Rails 3 --- lib/application_checker.rb | 18 ++++++++++++++++++ test/application_checker_test.rb | 7 +++++++ 2 files changed, 25 insertions(+) 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")