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
Added absence validator for active model. #7155
Conversation
|
+1 |
|
+1 Can confirm that needed this in almost every project with relatively complex models |
|
I use it on trees, where i need attributes to be empty on roots. But I think, there should be better examples. Anyone? |
|
With the |
|
+1 – Require first and last names for users older than 13, but prevent update for younger than 13. |
| end | ||
|
|
||
| def test_validates_acceptance_of_with_custom_error_using_quotes | ||
| Person.validates_absence_of :karma, :message => "This string contains 'single' and \"double\" quotes" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please use 1.9 hash syntax. Thanks.
|
I'm |
|
|
||
| module ActiveModel | ||
|
|
||
| # == Active Model Absence Validator |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you move this title to class AbsenceValidator?
|
@robotex82 Could you add a CHANGELOG entry please? Thanks! |
| Topic.validates_absence_of(:title, :content) | ||
|
|
||
| t = Topic.new | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove blank line.
|
I wonder if we should use @robotex82 thanks! |
|
Thank you guys! Sorry, I have been busy all the time, but i'll have a look at your suggestions asap. Hopefully before next weekend. Do you see any chance to have this merged into master for v4.0? |
|
@robotex82 I believe so :) |
|
I updated my local copy and changed add_on_not_blank to add_on_present. I had some trouble with updating and rebasing - I admit, I lack experience on this topic - but I hope I didn't mess up. Could someone please check my updated pull request? What do I have to do next? |
|
@robotex82 thanks, but apparently you have some commits that shouldn't be there, can you try a new rebase, so that we can see only your PR diff? |
|
I did: git rebase upstream/master is that correct? Excuse my noobish questions! I googled for the correct process of updating forks, rebasing, etc. but it's still not really clear to me. |
|
|
||
| module ActiveModel | ||
| module Validations | ||
| # == Active Model Absence Validator |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can remove this comment.
|
@robotex82 it's fine now, thanks. I added some comments, and we'll need a two changelog entries in Active Model, one for |
Changed add_on_not_blank to add_on_present
|
Should I append or prepend to the changelog? |
|
Hope it's ok now..... |
|
I added some minor comments, can you take a look at them before we merge? Also, what do you think about adding an example for the changelog entries, similar to the ones you added to the docs? (just look at other changelog examples to see how to format them). Other than that, just squash your commits and we're good to go :). Thanks! |
|
Well, I added the example to the changelog. But again I'm stuck with git :( I have a commit history like that: So I thought I google how to squash commits. I tried some things but I keep getting errors or the commits don't go away. So, please, could some of you experieced people, tell me how I package things up? Thanks, and sorry again...squashing, rabaseing, etc. is new stuff to me. @carlosantoniodasilva: I couldn't find your comments, where are they? |
|
@robotex82 just look at the pull request Now about the rebase, Jon has just given a quick explanation here, but if you still have doubts, please let me know. Thanks! |
|
@robotex82 I wrote something up explaining rebase here: http://blog.steveklabnik.com/posts/2012-11-08-how-to-squash-commits-in-a-github-pull-request |
|
@steveklabnik Ah true, I forgot that, awesome thanks |
|
You didn't forget that at all; I saw this comment, was like "man, I really need to put this in a place where I can find it again," posted it, and then linked it here. ;) |
|
Haha sorry, I thought I had seen that among your other contribution related posts. Awesome anyway, you were fast on that |
This is already handled by #find, it's a duplicate check, since find_with_ids is not called from anywhere else.
Closes rails#8121 The `plugin new` generator always adds the dummy app rake tasks, when a dummy app was created.
…bjects with unstable class names and instance variables. Refactor FlashHash to take values for its ivars in the constructor, to pretty up FlashHash.from_session_value. Remove stale comment on FlashHash: it is no longer Marshaled in the session so we can change its implementation. Remove blank lines I introduced in controller/test_case.rb. Unit tests for FlashHash#to_session_value. Put in a compatibility layer to accept FlashHash serializations from Rails 3.0+. Test that Rails 3.2 session flashes are correctly converted to the new format. Remove code path for processing Rails 3.0 FlashHashes since they can no longer deserialize.
…k the absence of attributes. Add `ActiveModel::Errors#add_on_present` method. Adds error messages to present attributes.
|
This looks ....wrong?! |
|
Looks like there are some extra commits now :) |
|
OT: Time to read a book about GIT. Suggestions? |
|
I read the section on rebasing, but I don't get this right. :( How do we get this right? Should I create a completely new pull request? |
|
Do this: http://blog.steveklabnik.com/posts/2012-11-08-how-to-squash-commits-in-a-github-pull-request But don't bother with the -i. |
|
@robotex82 Because it's been a month, and you're obviously having some trouble, and I had some time this morning, I took care of this. You can see the commit here: d72a07f I also took care of @frodsan 's comment about the 1.9 hash syntax, and double checked @carlosantoniodasilva 's comments about blank lines. Thank you for your pull request, hopefully you will overcome the |
|
@robotex82: I highly recommend the Mastering Git series by @tlberglund and @matthewmccullough: Full Disclosure: I know them both personally (and I appear in one of the videos) so I am a bit biased -- but trust me, watch these videos a few times through and you will level-up in your git-fu for sure. |
|
Awesome, thank you guys! Sorry for the late answer, but I've been very busy! While checking the commit, I discovered, that the CHANGELOG is messed up a little bit: Actual: Shouldn't it be: How do we get this right? Thanks again! |
|
Not sure what you mean, but the name goes after the change, at the end. |
Please accept my pull request for an absence validator.
See following discussion: https://groups.google.com/forum/#!topic/rubyonrails-core/KS_Olcnlw8w
I included passing tests and docs (Copied and adapted from the presence validator).
Thanks!
Saludos,
Roberto