validatious-on-rails 0.3.2 → 0.3.3

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.
@@ -157,6 +157,15 @@ module ValidatiousOnRails
157
157
 
158
158
  class << self
159
159
 
160
+ def validate_blank(validation)
161
+ %{
162
+ var isBlank = /^[\s\t\n]*$/.test(value);
163
+ if (#{validation.options[:allow_blank] == true} && isBlank) {
164
+ return true;
165
+ };
166
+ }
167
+ end
168
+
160
169
  # Generate a unique valdiator ID to avoid clashes.
161
170
  # Note: Ruby #hash is way faster than SHA1 (etc.) - just replace any negative sign.
162
171
  #
@@ -11,8 +11,9 @@ module ValidatiousOnRails
11
11
  name, alias_name = self.class.generate_name(validation, :in, self.class.generate_id(validation.options[:in].inspect))
12
12
  super name, options
13
13
  self.message = self.class.generate_message(validation)
14
- self.accept_empty = validation.options[:allow_blank] || validation.options[:allow_nil]
14
+ self.accept_empty = validation.options[:allow_nil]
15
15
  self.fn = %{
16
+ #{self.class.validate_blank(validation)}
16
17
  var exclusion_values = #{validation.options[:in].to_json};
17
18
  for (var i = 0; i < exclusion_values.length; i++) {
18
19
  if (exclusion_values[i] == value) { return false; }
@@ -20,8 +20,9 @@ module ValidatiousOnRails
20
20
  name, alias_name = self.class.generate_name(validation, :with, self.class.generate_id(validation.options[:with].inspect))
21
21
  super name, options
22
22
  self.message = self.class.generate_message(validation)
23
- self.accept_empty = validation.options[:allow_blank] || validation.options[:allow_nil]
23
+ self.accept_empty = validation.options[:allow_nil]
24
24
  self.fn = %{
25
+ #{self.class.validate_blank(validation)}
25
26
  return #{validation.options[:with].inspect}.test(value);
26
27
  }
27
28
  self.fn.freeze
@@ -11,8 +11,9 @@ module ValidatiousOnRails
11
11
  name, alias_name = self.class.generate_name(validation, :in, self.class.generate_id(validation.options[:in].inspect))
12
12
  super name, options
13
13
  self.message = self.class.generate_message(validation)
14
- self.accept_empty = validation.options[:allow_blank] || validation.options[:allow_nil]
14
+ self.accept_empty = validation.options[:allow_nil]
15
15
  self.fn = %{
16
+ #{self.class.validate_blank(validation)}
16
17
  var inclusion_values = #{validation.options[:in].to_json};
17
18
  for (var i = 0; i < inclusion_values.length; i++) {
18
19
  if (inclusion_values[i] == value) { return true; }
@@ -12,8 +12,9 @@ module ValidatiousOnRails
12
12
  super name, options
13
13
  self.params = ['count']
14
14
  self.message = self.class.generate_message(validation, :key => :wrong_length)
15
- self.accept_empty = validation.options[:allow_blank] || validation.options[:allow_nil]
15
+ self.accept_empty = validation.options[:allow_nil]
16
16
  self.fn = %{
17
+ #{self.class.validate_blank(validation)}
17
18
  value += '';
18
19
  return value == params[0];
19
20
  }
@@ -12,8 +12,9 @@ module ValidatiousOnRails
12
12
  super name, options
13
13
  self.params = ['count']
14
14
  self.message = self.class.generate_message(validation, :key => :too_long)
15
- self.accept_empty = validation.options[:allow_blank] || validation.options[:allow_nil]
15
+ self.accept_empty = validation.options[:allow_nil]
16
16
  self.fn = %{
17
+ #{self.class.validate_blank(validation)}
17
18
  value += '';
18
19
  return value.length <= params[0];
19
20
  }
@@ -12,8 +12,9 @@ module ValidatiousOnRails
12
12
  super name, options
13
13
  self.params = ['count']
14
14
  self.message = self.class.generate_message(validation, :key => :too_short)
15
- self.accept_empty = validation.options[:allow_blank] || validation.options[:allow_nil]
15
+ self.accept_empty = validation.options[:allow_nil]
16
16
  self.fn = %{
17
+ #{self.class.validate_blank(validation)}
17
18
  value += '';
18
19
  return value.length >= params[0];
19
20
  }
@@ -17,7 +17,7 @@ class HelpersTest < ::ActionView::TestCase
17
17
  context "custom_validatious_validators" do
18
18
 
19
19
  test "should not output custom validators if there are none" do
20
- helper_output = ::ValidatiousOnRails::Helpers.attached_validators
20
+ helper_output = javascript_for_validatious
21
21
  assert_equal '', helper_output.to_s
22
22
  end
23
23
 
@@ -25,14 +25,12 @@ class HelpersTest < ::ActionView::TestCase
25
25
  form_for(::BogusItem.new, :url => '/bogus_items') do |f|
26
26
  concat f.text_field(:url)
27
27
  end
28
-
29
- # FIXME: Not sure how to test content_for-helpers...returns nil.
30
- concat ::ValidatiousOnRails::Helpers.attached_validators
28
+ concat javascript_for_validatious
31
29
 
32
30
  # In parts...
33
- # assert_match /<script.+>.*v2.Validator.*<\/script>/, output_buffer
34
- # assert_match /<script.*id="custom_validatious_validators".*>/, helper_output
35
- # assert_match /<script.*type="text\/javascript".*>/, helper_output
31
+ assert_match /<script.+>.*v2.Validator.*<\/script>/, output_buffer
32
+ assert_match /<script.*id="custom_validators".*>/, output_buffer
33
+ assert_match /<script.*type="text\/javascript".*>/, output_buffer
36
34
  end
37
35
 
38
36
  end
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.2
4
+ version: 0.3.3
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-08 00:00:00 +02:00
13
+ date: 2009-10-10 00:00:00 +02:00
14
14
  default_executable:
15
15
  dependencies: []
16
16