[patch] Support for :scope_to attributes that don't respond to .next
Reported by Murray Steele | May 20th, 2008 @ 07:45 AM
If we have attributes where the instance doesn't respond to .next (for example a Time object, or some serialized attribute that creates a Hash, or other complex Object) and we are using them to validate the uniqueness of another attribute the should_require_unique_attributes tests will fail when they attempt to call existing.send(scope).next.
This patch provides the ability to supply a :change_scoped_to_values option to should_require_unique_attributes that is a proc object which will be called instead of .next. The proc will be called with the name of the scoped attribute and the current value and the result will be used as the changed value for checking the scope.
NOTE: I've done the work for this patch and my other one (#34) in the same local branch, so this patch is based on the patch for #34. If we decide against #34 then I'll redo this one on it's own.
Comments and changes to this ticket
-
Murray Steele May 21st, 2008 @ 04:53 AM
Along with #34 the patches for this ticket are now on their own github fork, http://github.com/h-lame/shoulda...
-
Tammer Saleh June 26th, 2008 @ 04:10 PM
- → State changed from new to refused
- → Tag changed from to active_record_helper should_require_unique_attributes
Hi Murray,
Same reasoning as #34
I appreciate the patch, but I think this falls into the 20%, where a hand written should statement would be more clear than using the macros.
Tammer
Please Login or create a free account to add a new comment.
You can update this ticket by sending an email to from your email client. (help)
Create your profile
Help contribute to this project by taking a few moments to create your personal profile. Create your profile »
