This project is archived and is in readonly mode.
Make ActiveModel::Errors#add_on_blank and #add_on_empty accept an options hash and make various Validators pass their options
-
Mateo Murphy
+1 This would definitely be helpful for plugin development
-
José Valim
- Assigned user changed from Yehuda Katz (wycats) to José Valim
Thanks Sven, good patch! However, I don't think it's necessary to filter the options. It adds extra complexity to the code and I cannot see any reason. Wdyt?
-
Yehuda Katz (wycats)
- State changed from new to incomplete
-
Dan Pickett
- Tag changed from activemodel, messages, validation to activemodel, bugmash, messages, validation
Can some bugmashers add some feedback as it relates to option filtering? If it's deemed unnecessary, can the patch be modified to remove the filtering?
-
Jeroen van Dijk
This patch does not apply cleanly anymore. I will try to extract the parts that should apply and see if the filtering is needed.
-
Jeroen van Dijk
I have adapted the patch so that it applies on master, some small cleanups here and there.
The filtering is currently needed, because the tests in i18n_generate_message_validation_test.rb have a very precise expectations of how methods are being called. Here is an example:
def test_errors_add_on_empty_generates_message @person.errors.expects(:generate_message).with(:title, :empty, {}) @person.errors.add_on_empty :title endI would like to make that more flexible so the code can be more flexible. This code already gives a lot more flexibility.
I have ran all tests for activemodel and activerecord. I have added Sven Fuchs to the authors.
-
Jeroen van Dijk
I forgot the patch...
-
Rizwan Reza
- Tag changed from activemodel, bugmash, messages, validation to activemodel, bugmash, bugmash-review, messages, validation
- State changed from incomplete to open
+1 verified
All tests pass on master.
Here's the patch without whitespace errors. Preserves authorship.
-
Repository
- State changed from open to committed
(from [bc1c8d58ec45593acba614d1d0fecb49adef08ff]) Make ActiveModel::Errors#add_on_blank and #add_on_empty accept an options hash and make various Validators pass their (filtered) options.
This makes it possible to pass additional options through Validators to message
generation. E.g. plugin authors want to add validates_presence_of :foo, :format
=> "some format".Also, cleanup the :default vs :message options confusion in ActiveModel
validation message generation.Also, deprecate ActiveModel::Errors#add_on_blank(attributes, custom_message) in
favor of ActiveModel::Errors#add_on_blank(attributes, options).Original patch by Sven Fuchs, some minor changes and has been changed to be applicable to master again
[#4057 state:committed]
Signed-off-by: Jeremy Kemper jeremy@bitsweat.net
http://github.com/rails/rails/commit/bc1c8d58ec45593acba614d1d0fecb... -
Rizwan Reza
- Tag changed from activemodel, bugmash, bugmash-review, messages, validation to activemodel, messages, validation
-
José Valim
- State changed from committed to incomplete
Sorry, but I had to revert. Please check the comments in d6cbb27e7b260c970bf7 ( http://github.com/rails/rails/commit/d6cbb27e7b260c970bf7d07dc0b059... ).
-
José Valim
- Tag changed from activemodel, messages, validation to activemodel, bugmash, messages, validation
-
Jeroen van Dijk
The goal of the commit was to make the validations more flexible. The whitelist approach was an intermediate solution to satisfy the strict tests. My plan was to see how I could make the tests more flexible to make the code more flexible and have the whitelist removed. I thought that would be easier when the whitelist was in one spot.
Anyhow, I think I know how to approach this problem better now. I'll work on a new patch.
-
Rizwan Reza
- Tag changed from activemodel, bugmash, messages, validation to activemodel, messages, validation
- State changed from incomplete to wontfix
-
Rizwan Reza
Jeroen, open the ticket when you attach the fix.
-
Rizwan Reza
- State changed from wontfix to incomplete
-
Jeroen van Dijk
- Tag changed from activemodel, messages, validation to activemodel, bugmash-review, messages, validation
Here is my latest patch. I have done a lot of refactoring in the tests to make sure things aren't repeated all over the place.
Each validators cleans it on own options now. The Errors object only filters :if, :unless and :on.
-
José Valim
- State changed from incomplete to open
-
Rizwan Reza
- No changes were found…
-
Simon Jefford
+1 Patch applies and tests run.
I have, however, taken the liberty of removing whitespace errors - patch preserves authorship.
-
José Valim
Sorry, but patch does not apply anymore. Would anyone mind to rebase? Also, there is a TODO: in the tests, would be nice if we could apply the tests without the TODO.
-
Repository
- State changed from open to resolved
(from [0421fb7a913c1c8a7e07a395106bbc65e75e9d45]) Refactor previous commit a bit [#4057 state:resolved] http://github.com/rails/rails/commit/0421fb7a913c1c8a7e07a395106bbc...
