validatious-on-rails 0.3.5 → 0.3.6
Sign up to get free protection for your applications and to get access to all the features.
@@ -40,6 +40,9 @@ module ValidatiousOnRails
|
|
40
40
|
# name along with a method/field.
|
41
41
|
#
|
42
42
|
def options_for(object_name, attribute_method, options = {}, existing_validators = nil)
|
43
|
+
# Handle Nested form.
|
44
|
+
object_name = options[:object].present? ? options[:object].class.name : object_name
|
45
|
+
|
43
46
|
validators = self.from_active_record(object_name, attribute_method)
|
44
47
|
validator_classes, validator_js = [options[:class]], []
|
45
48
|
|
@@ -66,7 +69,12 @@ module ValidatiousOnRails
|
|
66
69
|
#
|
67
70
|
def from_active_record(object_or_class, attribute_method)
|
68
71
|
validators = []
|
69
|
-
|
72
|
+
begin
|
73
|
+
klass = object_or_class.to_s.classify.constantize
|
74
|
+
rescue
|
75
|
+
::ValidatiousOnRails.log "Missing constant: #{object_or_class}", :debug
|
76
|
+
return validators
|
77
|
+
end
|
70
78
|
|
71
79
|
# Iterate thorugh the validations for the current class,
|
72
80
|
# and collect validation options.
|
@@ -23,7 +23,7 @@ module ValidatiousOnRails
|
|
23
23
|
self.accept_empty = validation.options[:allow_nil]
|
24
24
|
self.fn = %{
|
25
25
|
#{self.class.validate_blank(validation)}
|
26
|
-
return #{validation.options[:with].inspect}.test(value);
|
26
|
+
return #{validation.options[:with].inspect.gsub(/\\A/, '^').gsub(/\\z/, '$')}.test(value);
|
27
27
|
}
|
28
28
|
self.fn.freeze
|
29
29
|
end
|
@@ -8,7 +8,7 @@ module ValidatiousOnRails
|
|
8
8
|
def initialize(validation, options = {})
|
9
9
|
name = 'presence'
|
10
10
|
super name, options
|
11
|
-
self.message = self.class.generate_message(validation)
|
11
|
+
self.message = self.class.generate_message(validation, :key => :blank)
|
12
12
|
self.accept_empty = false
|
13
13
|
# Identical to Validatious "required" validator, but we want Rails I18n message support, so...
|
14
14
|
self.fn = %{
|
@@ -26,6 +26,15 @@ class ModelValidationsTest < ::ActiveSupport::TestCase
|
|
26
26
|
end
|
27
27
|
end
|
28
28
|
|
29
|
+
context "from_active_record" do
|
30
|
+
test "non concrete models" do
|
31
|
+
assert_nothing_raised(NameError) do
|
32
|
+
::ValidatiousOnRails::ModelValidations.from_active_record(:thing, :field_with_defaults)
|
33
|
+
end
|
34
|
+
assert_equal [], ::ValidatiousOnRails::ModelValidations.from_active_record(:thing, :field_with_defaults)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
29
38
|
context "acceptance_of" do
|
30
39
|
test "with defaults" do
|
31
40
|
validators = ::ValidatiousOnRails::ModelValidations.acceptance_of(
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: validatious-on-rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Christian Johansen
|
@@ -10,7 +10,7 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date: 2009-10-
|
13
|
+
date: 2009-10-17 00:00:00 +02:00
|
14
14
|
default_executable:
|
15
15
|
dependencies: []
|
16
16
|
|