ActiveModel::Errors#generate_message without i18n_scope, and more test cases for #add #3319
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
ActiveModel::Errors#generate_message requires that the model we're adding errors to implements i18n_scope. This is not obvious from the documentation, and it is also not necessary as there are translation fallbacks that don't use i18n_scope.
The first of the three commits skips the translation defaults where i18n_scope is used if the model doesn't respond to it.
I also noticed that there were no tests on ActiveModel::Errors#add when message is a Symbol, or when message is a Proc. I wrote tests for these cases, each in it's own commit to make it easier if you'd like to pull these but not the commit dealing with i18n_scope.
Please bear in mind that, if you'd like to keep the requirement for 18n_scope on the model, the test case for when message is a Symbol won't pass. If generate_message doesn't check if the model responds, the test needs a minimal implementation of Person.i18n_scope to pass. I'll be happy to fix this.
PS. This is my first contribution to Rails. Yay! \o/
I attended an Open Source Hack Night in Stockholm on October 11. Kudos to Valtech for organizing it.