public
Rubygem
Description: Makes tests easy on the fingers and the eyes
Homepage: http://www.thoughtbot.com/projects/shoulda
Clone URL: git://github.com/thoughtbot/shoulda.git
fixes to should_ensure_length_in_range 
http://tammer.lighthouseapp.com/projects/5807/tickets/11

git-svn-id: https://svn.thoughtbot.com/plugins/shoulda/trunk@373 
7bbfaf0e-4d1d-0410-9690-a8bb5f8ef2aa
tsaleh (author)
Thu Feb 28 14:40:02 -0800 2008
commit  a50e871bd72cac33f78ef951986c19f922d22ecc
tree    ae4753a36bcb14cabc3b5cdb09bd3c7e73197030
parent  b3bcf0f8dbbe7c3aee3b2feff613387689fd3ba0
...
177
178
179
 
180
181
182
183
 
184
185
186
187
 
 
188
189
190
 
 
 
 
 
 
 
 
 
 
191
192
193
 
194
195
196
197
 
 
198
199
 
 
 
 
 
 
 
 
 
 
200
201
202
...
177
178
179
180
181
182
 
183
184
185
186
187
 
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
 
204
205
206
207
208
 
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
0
@@ -177,26 +177,49 @@ module ThoughtBot # :nodoc:
0
         klass = model_class
0
         min_length = range.first
0
         max_length = range.last
0
+ same_length = (min_length == max_length)
0
 
0
         if min_length > 0
0
- min_value = "x" * (min_length - 1)
0
           should "not allow #{attribute} to be less than #{min_length} chars long" do
0
+ min_value = "x" * (min_length - 1)
0
             assert object = klass.find(:first), "Can't find first #{klass}"
0
             object.send("#{attribute}=", min_value)
0
             assert !object.save, "Saved #{klass} with #{attribute} set to \"#{min_value}\""
0
- assert object.errors.on(attribute), "There are no errors set on #{attribute} after being set to \"#{min_value}\""
0
+ assert object.errors.on(attribute),
0
+ "There are no errors set on #{attribute} after being set to \"#{min_value}\""
0
             assert_contains(object.errors.on(attribute), short_message, "when set to \"#{min_value}\"")
0
           end
0
         end
0
+
0
+ if min_length > 0
0
+ should "allow #{attribute} to be exactly #{min_length} chars long" do
0
+ min_value = "x" * min_length
0
+ assert object = klass.find(:first), "Can't find first #{klass}"
0
+ object.send("#{attribute}=", min_value)
0
+ object.save
0
+ assert_does_not_contain(object.errors.on(attribute), short_message, "when set to \"#{min_value}\"")
0
+ end
0
+ end
0
     
0
- max_value = "x" * (max_length + 1)
0
         should "not allow #{attribute} to be more than #{max_length} chars long" do
0
+ max_value = "x" * (max_length + 1)
0
           assert object = klass.find(:first), "Can't find first #{klass}"
0
           object.send("#{attribute}=", max_value)
0
           assert !object.save, "Saved #{klass} with #{attribute} set to \"#{max_value}\""
0
- assert object.errors.on(attribute), "There are no errors set on #{attribute} after being set to \"#{max_value}\""
0
+ assert object.errors.on(attribute),
0
+ "There are no errors set on #{attribute} after being set to \"#{max_value}\""
0
           assert_contains(object.errors.on(attribute), long_message, "when set to \"#{max_value}\"")
0
         end
0
+
0
+ unless same_length
0
+ should "allow #{attribute} to be exactly #{max_length} chars long" do
0
+ max_value = "x" * max_length
0
+ assert object = klass.find(:first), "Can't find first #{klass}"
0
+ object.send("#{attribute}=", max_value)
0
+ object.save
0
+ assert_does_not_contain(object.errors.on(attribute), long_message, "when set to \"#{max_value}\"")
0
+ end
0
+ end
0
       end
0
 
0
       # Ensure that the attribute is in the range specified

Comments

    No one has commented yet.