add should_ensure_maximum method
Reported by Nate | October 22nd, 2008 @ 03:01 PM
would like to add a method to make testing fields with maximum values easier.
should_ensure_maximum :field, 10
Comments and changes to this ticket
-

seban October 22nd, 2008 @ 05:41 PM
I am not sure that this method is needed. Why can't use should_ensure_value_in_range with rane = 0...MAX?
-
Nate October 22nd, 2008 @ 05:43 PM
This is pushed to: git://github.com/youngnh/shoulda.git
cebc3bf8ee6d8d0e3af6ae23bf609b423b7d2df0
branch adding_ensure_maximum
-
-
gaffo October 22nd, 2008 @ 05:56 PM
Agreed, this would be nice to have as range doesn't cover -infinity <= MAX
-
-

-

Kyle Cross November 12th, 2008 @ 10:25 AM
I think that there should also be a method to test minimum as well. There are many times that we want to test that something does not drop below a certain value. I think that splitting should_ensure_value_in_range to both should_ensure_maximum and should_ensure minimum would greatly help me with testing
-
Seth Ladd November 18th, 2008 @ 01:46 PM
This is what I use:
def self.should_ensure_length_no_longer_than(attribute, max_length, opts = {})
long_message = get_options!([opts], :long_message) long_message ||= I18n.translate('activerecord.errors.messages.too_long', :count => max_length) klass = model_class should "not allow #{attribute} to be more than #{max_length} chars long" do invalid_value = "x" * (max_length+1) assert_bad_value(klass, attribute, invalid_value, long_message) endend
-
Amos King November 18th, 2008 @ 02:33 PM
Seth, you are ensuring length and not value. should_ensure_length_no_longer_than is exactly the method I need but I want it for a value and not a length.
I want to test: value <= 10
Not value.length <= 10
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 »
