jnunemaker-validatable 1.7.1 → 1.7.2
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION.yml +1 -1
- data/lib/validations/validation_base.rb +6 -1
- data/test/functional/test_validatable.rb +36 -0
- metadata +4 -3
data/VERSION.yml
CHANGED
@@ -63,7 +63,12 @@ module Validatable
|
|
63
63
|
|
64
64
|
def should_validate?(instance)
|
65
65
|
result = validate_this_time?(instance)
|
66
|
-
|
66
|
+
case self.if
|
67
|
+
when Proc
|
68
|
+
result &&= instance.instance_eval(&self.if)
|
69
|
+
when Symbol, String
|
70
|
+
result &&= instance.instance_eval(self.if.to_s)
|
71
|
+
end
|
67
72
|
result
|
68
73
|
end
|
69
74
|
|
@@ -255,6 +255,42 @@ functional_tests do
|
|
255
255
|
instance = klass.new
|
256
256
|
instance.valid?
|
257
257
|
end
|
258
|
+
|
259
|
+
test ':if with symbol should work' do
|
260
|
+
klass = Class.new do
|
261
|
+
include Validatable
|
262
|
+
attr_accessor :name, :name_required
|
263
|
+
validates_presence_of :name, :if => :name_required?
|
264
|
+
|
265
|
+
def name_required?
|
266
|
+
name_required
|
267
|
+
end
|
268
|
+
end
|
269
|
+
instance = klass.new
|
270
|
+
instance.name_required = false
|
271
|
+
assert instance.valid?
|
272
|
+
instance.name_required = true
|
273
|
+
assert !instance.valid?
|
274
|
+
assert_equal "can't be empty", instance.errors.on(:name)
|
275
|
+
end
|
276
|
+
|
277
|
+
test ':if with string should work' do
|
278
|
+
klass = Class.new do
|
279
|
+
include Validatable
|
280
|
+
attr_accessor :name, :name_required
|
281
|
+
validates_presence_of :name, :if => 'name_required?'
|
282
|
+
|
283
|
+
def name_required?
|
284
|
+
name_required
|
285
|
+
end
|
286
|
+
end
|
287
|
+
instance = klass.new
|
288
|
+
instance.name_required = false
|
289
|
+
assert instance.valid?
|
290
|
+
instance.name_required = true
|
291
|
+
assert !instance.valid?
|
292
|
+
assert_equal "can't be empty", instance.errors.on(:name)
|
293
|
+
end
|
258
294
|
|
259
295
|
test "classes only have valid_for_* methods for groups that appear in their validations" do
|
260
296
|
class_with_group_one = Class.new do
|
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.
|
4
|
+
version: 1.7.2
|
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-07-
|
13
|
+
date: 2009-07-27 00:00:00 -07:00
|
14
14
|
default_executable:
|
15
15
|
dependencies: []
|
16
16
|
|
@@ -69,6 +69,7 @@ files:
|
|
69
69
|
- test/unit/test_validation_base.rb
|
70
70
|
has_rdoc: true
|
71
71
|
homepage: http://github.com/jnunemaker/validatable
|
72
|
+
licenses:
|
72
73
|
post_install_message:
|
73
74
|
rdoc_options:
|
74
75
|
- --charset=UTF-8
|
@@ -89,7 +90,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
89
90
|
requirements: []
|
90
91
|
|
91
92
|
rubyforge_project:
|
92
|
-
rubygems_version: 1.
|
93
|
+
rubygems_version: 1.3.5
|
93
94
|
signing_key:
|
94
95
|
specification_version: 2
|
95
96
|
summary: Validatable is a library for adding validations.
|