rails-schema-validations 0.9.2 → 0.9.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -16,7 +16,7 @@ module ActiveRecord::Validations::ClassMethods
16
16
  # less_than would need to look at col.scale, col.float
17
17
  validates_numericality_of col.name, :allow_nil => col.null
18
18
  #when :time, :datetime
19
- when :string
19
+ when :string, :text
20
20
  if col.limit.to_i > 0 # Mysql enum type shows up as a string with a limit of 0
21
21
  validates_length_of col.name, :maximum => col.limit, :allow_nil => col.null
22
22
  end
@@ -9,12 +9,12 @@ def load_schema
9
9
 
10
10
  ActiveRecord::Schema.define do
11
11
  create_table "models", :force => true do |t|
12
- %w(string integer float datetime date boolean).each do |kind|
12
+ %w(text string integer float datetime date boolean).each do |kind|
13
13
  t.send(kind, kind)
14
14
  t.send(kind, "#{kind}_notnull", :null => false)
15
15
  t.send(kind, "#{kind}_excepted", :null => false)
16
16
  end
17
- %w(string integer).each do |kind|
17
+ %w(text string integer).each do |kind|
18
18
  t.send(kind, "#{kind}_limit", :limit => 4)
19
19
  t.send(kind, "#{kind}_limit_notnull", :limit => 4, :null => false)
20
20
  end
@@ -35,7 +35,7 @@ load_schema
35
35
 
36
36
  class Model < ActiveRecord::Base
37
37
  validations_from_schema :except => (
38
- %w(string integer float date datetime boolean). map {|s| "#{s}_excepted"})
38
+ %w(text string integer float date datetime boolean). map {|s| "#{s}_excepted"})
39
39
  end
40
40
 
41
41
  context Model do
@@ -58,13 +58,13 @@ context Model do
58
58
  end
59
59
 
60
60
  # null
61
- %w(string integer float date datetime boolean).each do |name|
61
+ %w(text string integer float date datetime boolean).each do |name|
62
62
  asserts_no_error_on name, nil
63
63
  asserts_error_on "#{name}_notnull", nil
64
64
  # ignore
65
65
  asserts_no_error_on "#{name}_excepted", nil
66
66
  end
67
- %w(string integer).each do |name|
67
+ %w(text string integer).each do |name|
68
68
  asserts_no_error_on "#{name}_limit", nil
69
69
  asserts_error_on "#{name}_limit_notnull", nil
70
70
  end
@@ -73,10 +73,13 @@ context Model do
73
73
  asserts_error_on :integer_limit, 1.1
74
74
 
75
75
  # limits
76
- asserts_error_on :string_limit, '12345678910'
77
- asserts_error_on :integer_limit, 2 ** (8 * 4)
78
76
  asserts_no_error_on :string_limit, '12'
79
77
  asserts_no_error_on :integer_limit, 2 ** (8 * 3)
78
+ asserts_no_error_on :text_limit, '12'
79
+
80
+ asserts_error_on :string_limit, '12345678910'
81
+ asserts_error_on :text_limit, 'a' * 2147
82
+ asserts_error_on :integer_limit, 2 ** (8 * 4)
80
83
 
81
84
  # not null indexed columns
82
85
  asserts_error_on :indexed_id, nil
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rails-schema-validations
3
3
  version: !ruby/object:Gem::Version
4
- hash: 63
4
+ hash: 61
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 9
9
- - 2
10
- version: 0.9.2
9
+ - 3
10
+ version: 0.9.3
11
11
  platform: ruby
12
12
  authors:
13
13
  - Greg Weber