Skip to content

Commit

Permalink
validate_acceptance_of should add error for nil
Browse files Browse the repository at this point in the history
  • Loading branch information
paulcsmith committed Jun 7, 2018
1 parent ec32313 commit e32bd54
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
4 changes: 4 additions & 0 deletions spec/validations_spec.cr
Expand Up @@ -177,6 +177,10 @@ describe LuckyRecord::Validations do
user.terms.errors.should eq ["must be accepted"]
end

validate(terms: nil) do |user|
user.terms.errors.should eq ["must be accepted"]
end

validate(terms: true) do |user|
user.terms.errors.empty?.should be_true
end
Expand Down
2 changes: 1 addition & 1 deletion src/lucky_record/validations.cr
Expand Up @@ -10,7 +10,7 @@ module LuckyRecord::Validations
end

private def validate_acceptance_of(field : FillableField(Bool?) | Field(Bool?), message = "must be accepted")
if field.value == false
if field.value != true
field.add_error message
end
end
Expand Down

0 comments on commit e32bd54

Please sign in to comment.