jnunemaker-validatable 1.7.3 → 1.7.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -2,13 +2,11 @@
2
2
 
3
3
  Validatable is a library for adding validations.
4
4
 
5
- by Jay[http://jayfields.blogspot.com] Fields[http://jayfields.blogspot.com]
5
+ Created by Jay Fields, updated by John Nunemaker
6
6
 
7
- == Download and Installation
8
-
9
- You can download Validatable from here[http://rubyforge.org/projects/validatable] or install it with the following command.
10
-
11
- $ gem install validatable
7
+ == Installation
8
+
9
+ $ gem install jnunemaker-validatable -s http://gemcutter.org
12
10
 
13
11
  == License
14
12
 
data/Rakefile CHANGED
@@ -4,7 +4,7 @@ require 'rake'
4
4
  begin
5
5
  require 'jeweler'
6
6
  Jeweler::Tasks.new do |gem|
7
- gem.name = "validatable"
7
+ gem.name = "jnunemaker-validatable"
8
8
  gem.summary = %Q{Validatable is a library for adding validations.}
9
9
  gem.email = "nunemaker@gmail.com"
10
10
  gem.homepage = "http://github.com/jnunemaker/validatable"
@@ -1,4 +1,4 @@
1
1
  ---
2
2
  :major: 1
3
3
  :minor: 7
4
- :patch: 3
4
+ :patch: 4
@@ -4,18 +4,20 @@ module Validatable
4
4
  def validate_children(instance, group)
5
5
  self.children_to_validate.each do |child_validation|
6
6
  next unless child_validation.should_validate?(instance)
7
- child = instance.send child_validation.attribute
8
- if (child.respond_to?(:valid_for_group?))
9
- child.valid_for_group?(group)
10
- else
11
- child.valid?
12
- end
13
- child.errors.each do |attribute, messages|
14
- if messages.is_a?(String)
15
- add_error(instance, child_validation.map[attribute.to_sym] || attribute, messages)
7
+ child_or_children = instance.send child_validation.attribute
8
+ [child_or_children].flatten.each do |child|
9
+ if (child.respond_to?(:valid_for_group?))
10
+ child.valid_for_group?(group)
16
11
  else
17
- messages.each do |message|
18
- add_error(instance, child_validation.map[attribute.to_sym] || attribute, message)
12
+ child.valid?
13
+ end
14
+ child.errors.each do |attribute, messages|
15
+ if messages.is_a?(String)
16
+ add_error(instance, child_validation.map[attribute.to_sym] || attribute, messages)
17
+ else
18
+ messages.each do |message|
19
+ add_error(instance, child_validation.map[attribute.to_sym] || attribute, message)
20
+ end
19
21
  end
20
22
  end
21
23
  end
@@ -138,7 +138,53 @@ functional_tests do
138
138
  instance.valid?
139
139
  instance.errors.on(:address)
140
140
  end
141
+
142
+ expect "is invalid" do
143
+ child_class = Class.new do
144
+ include Validatable
145
+ attr_accessor :name, :address
146
+ validates_presence_of :name
147
+ validates_format_of :address, :with => /.+/
148
+ end
149
+ klass = Class.new do
150
+ include Validatable
151
+ include_errors_from :child
152
+ define_method :child do
153
+ valid_child = child_class.new
154
+ valid_child.name = "nom de plume"
155
+ valid_child.address = "nowhere"
156
+ [valid_child, child_class.new]
157
+ end
158
+ end
159
+ instance = klass.new
160
+ instance.valid?
161
+ instance.errors.on(:address)
162
+ end
141
163
 
164
+ expect true do
165
+ child_class = Class.new do
166
+ include Validatable
167
+ attr_accessor :name, :address
168
+ validates_presence_of :name
169
+ validates_format_of :address, :with => /.+/
170
+ end
171
+ klass = Class.new do
172
+ include Validatable
173
+ include_errors_from :child
174
+ define_method :child do
175
+ valid_child = child_class.new
176
+ valid_child.name = "nom de plume"
177
+ valid_child.address = "nowhere"
178
+ also_valid = child_class.new
179
+ also_valid.name = "nom de guerre"
180
+ also_valid.address = "somewhere else"
181
+ [valid_child, valid_child]
182
+ end
183
+ end
184
+ instance = klass.new
185
+ instance.valid?
186
+ end
187
+
142
188
  expect "can't be empty" do
143
189
  child_class = Class.new do
144
190
  include Validatable
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jnunemaker-validatable
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.7.3
4
+ version: 1.7.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jay Fields
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2009-10-02 00:00:00 -04:00
13
+ date: 2009-10-11 00:00:00 -04:00
14
14
  default_executable:
15
15
  dependencies: []
16
16