Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clear errors before validating models #279

Conversation

spicybackend
Copy link
Contributor

Allow successive and independent calls to check model validity.

Currently validation checking is not independent and errors are left over from previous checks.

model.name = ""
model.valid? # => false, fails on validation for presence
name.name = "name"
model.valid? # => false, fails because errors are left over from previous validation

After this change validation checks clear previous errors before running the associated validators to add errors back onto the model.

model.name = ""
model.valid? # => false, fails on validation for presence
name.name = "name"
model.valid? # => true

This is not particularly useful for production code, but allows for more flexibility in specs.

Copy link
Member

@robacarp robacarp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks @yumoose ! I like it

Copy link
Member

@drujensen drujensen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💯

@drujensen drujensen merged commit c2ed42d into amberframework:master Sep 8, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants