assistance 0.1.3 → 0.1.4

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG CHANGED
@@ -1,3 +1,7 @@
1
+ === 0.1.4 (2008-02-08)
2
+
3
+ * Added inheritance of validations.
4
+
1
5
  === 0.1.3 (2008-02-04)
2
6
 
3
7
  * Fixed case statement in Inflector to work in Ruby 1.9.
data/Rakefile CHANGED
@@ -9,7 +9,7 @@ include FileUtils
9
9
  # Configuration
10
10
  ##############################################################################
11
11
  NAME = "assistance"
12
- VERS = "0.1.3"
12
+ VERS = "0.1.4"
13
13
  CLEAN.include ["**/.*.sw?", "pkg/*", ".config", "doc/*", "coverage/*"]
14
14
  RDOC_OPTS = [
15
15
  "--quiet",
@@ -115,7 +115,7 @@ module Validation
115
115
  def validations
116
116
  @validations ||= Hash.new {|h, k| h[k] = []}
117
117
  end
118
-
118
+
119
119
  # Returns true if validations are defined.
120
120
  def has_validations?
121
121
  !validations.empty?
@@ -123,12 +123,19 @@ module Validation
123
123
 
124
124
  # Validates the given instance.
125
125
  def validate(o)
126
+ if superclass.respond_to?(:validate) && !@skip_superclass_validations
127
+ superclass.validate(o)
128
+ end
126
129
  validations.each do |att, procs|
127
130
  v = o.send(att)
128
131
  procs.each {|p| p[o, att, v]}
129
132
  end
130
133
  end
131
134
 
135
+ def skip_superclass_validations
136
+ @skip_superclass_validations = true
137
+ end
138
+
132
139
  # Adds a validation for each of the given attributes using the supplied
133
140
  # block. The block must accept three arguments: instance, attribute and
134
141
  # value, e.g.:
@@ -289,3 +289,53 @@ describe "Validations" do
289
289
  @m.should be_valid
290
290
  end
291
291
  end
292
+
293
+ context "Superclass validations" do
294
+ setup do
295
+ @c1 = Class.new do
296
+ include Validation
297
+ attr_accessor :value
298
+ validates_length_of :value, :minimum => 5
299
+ end
300
+
301
+ @c2 = Class.new(@c1) do
302
+ validates_format_of :value, :with => /^[a-z]+$/
303
+ end
304
+ end
305
+
306
+ specify "should be checked when validating" do
307
+ o = @c2.new
308
+ o.value = 'ab'
309
+ o.valid?.should == false
310
+ o.errors.full_messages.should == [
311
+ 'value is too short'
312
+ ]
313
+
314
+ o.value = '12'
315
+ o.valid?.should == false
316
+ o.errors.full_messages.should == [
317
+ 'value is too short',
318
+ 'value is invalid'
319
+ ]
320
+
321
+ o.value = 'abcde'
322
+ o.valid?.should be_true
323
+ end
324
+
325
+ specify "should be skipped if skip_superclass_validations is called" do
326
+ @c2.skip_superclass_validations
327
+
328
+ o = @c2.new
329
+ o.value = 'ab'
330
+ o.valid?.should be_true
331
+
332
+ o.value = '12'
333
+ o.valid?.should == false
334
+ o.errors.full_messages.should == [
335
+ 'value is invalid'
336
+ ]
337
+
338
+ o.value = 'abcde'
339
+ o.valid?.should be_true
340
+ end
341
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: assistance
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ezra Zygmuntowicz, Sam Smoot, Sharon Rosner
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2008-02-04 00:00:00 +02:00
12
+ date: 2008-02-08 00:00:00 +02:00
13
13
  default_executable:
14
14
  dependencies: []
15
15
 
@@ -27,7 +27,6 @@ files:
27
27
  - COPYING
28
28
  - README
29
29
  - Rakefile
30
- - doc/rdoc
31
30
  - spec/blank_spec.rb
32
31
  - spec/connection_pool_spec.rb
33
32
  - spec/extract_options.rb