diff --git a/lib/application_checker.rb b/lib/application_checker.rb index c4bec6c..99e56aa 100644 --- a/lib/application_checker.rb +++ b/lib/application_checker.rb @@ -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,13 +61,31 @@ 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 diff --git a/test/application_checker_test.rb b/test/application_checker_test.rb index d0b23df..1aa2d46 100644 --- a/test/application_checker_test.rb +++ b/test/application_checker_test.rb @@ -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