Avoid using before_validation or before_save to change the values
Everyone can contribute. Help move this issue forward while earning points, leveling up and collecting rewards.
The following discussion from gitlab-ce!12509 should be addressed:
-
@grzesiek started a discussion: (+7 comments)
The reason why I think changing the values in validation is bad is because:
@grzesiek Do you mean we should remove
/inbefore_validate? It was like that before, but to think about it, I really don't like the idea that callingvalid?would change the data:project.valid? # => then data would be changedI think this is surprising and changing data isn't really validating.
An alternative way would be overriding the assignment method like this:
def ci_config_file=(value)
# Strip all leading slashes so that //foo -> foo
super(value&.sub(%r{\A/+}, ''))
end
Edited by 🤖 GitLab Bot 🤖