Skip to content

Commit

Permalink
Fixed syntax for previous test I created; added before_validation_on_…
Browse files Browse the repository at this point in the history
…* deprecation check
  • Loading branch information
Josh Delsman authored and jm committed Jul 27, 2010
1 parent 9eb81b7 commit aa21839
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 6 deletions.
24 changes: 21 additions & 3 deletions lib/application_checker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def check_ar_methods
end
end

def check_validation_methods
def check_validation_on_methods
files = []

["validate_on_create", "validate_on_update"].each do |v|
Expand All @@ -61,13 +61,31 @@ def check_validation_methods

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
Expand Down
13 changes: 10 additions & 3 deletions test/application_checker_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,18 @@ def test_check_ar_methods_in_models
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
Expand Down

0 comments on commit aa21839

Please sign in to comment.