Skip to content

Commit

Permalink
Fix base validation
Browse files Browse the repository at this point in the history
  • Loading branch information
treagod committed Aug 21, 2024
1 parent a6ee5ee commit cb46f0a
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 13 deletions.
11 changes: 3 additions & 8 deletions src/marten/db/field/base.cr
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,7 @@ module Marten
def perform_validation(record : Model)
value = record.get_field_value(id)

validate_null(record, value)
validate_blank(record, value)
validate_presence(record, value)

validate(record, value)
end
Expand Down Expand Up @@ -144,14 +143,10 @@ module Marten
def validate(record, value)
end

protected def validate_null(record : Model, value)
protected def validate_presence(record : Model, value)
if value.nil? && !@null
record.errors.add(id, null_error_message(record), type: :null)
end
end

protected def validate_blank(record : Model, value)
if empty_value?(value) && !@blank
elsif empty_value?(value) && !@blank
record.errors.add(id, blank_error_message(record), type: :blank)
end
end
Expand Down
6 changes: 1 addition & 5 deletions src/marten/db/field/slug.cr
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,7 @@ module Marten
end
end

protected def validate_null(record : Model, value)
super if slugify.nil?
end

protected def validate_blank(record : Model, value)
protected def validate_presence(record : Model, value)
super if slugify.nil?
end

Expand Down

0 comments on commit cb46f0a

Please sign in to comment.