rails-schema-validations 0.4 → 0.5
Sign up to get free protection for your applications and to get access to all the features.
@@ -4,17 +4,20 @@ module ActiveRecord::Validations::ClassMethods
|
|
4
4
|
self.content_columns.map do |col|
|
5
5
|
case col.type
|
6
6
|
when :integer
|
7
|
-
|
7
|
+
# assuming unsigned!
|
8
|
+
validates_numericality_of col.name, :only_integer => true, :allow_nil => col.null,
|
9
|
+
:less_than => (2 ** (8 * col.limit)) / 2
|
8
10
|
when :float
|
11
|
+
# less_than would need to look at col.scale, col.float
|
9
12
|
validates_numericality_of col.name, :allow_nil => col.null
|
10
|
-
#when :time, :datetime
|
13
|
+
#when :time, :datetime
|
14
|
+
when :string
|
15
|
+
if col.limit
|
16
|
+
validates_length_of col.name, :maximum => col.limit, :allow_nil => col.null
|
17
|
+
end
|
11
18
|
end
|
12
19
|
end.compact + content_columns.map do |col|
|
13
20
|
validates_presence_of col.name unless col.null
|
14
|
-
end.compact + content_columns.map do |col|
|
15
|
-
if col.limit
|
16
|
-
validates_length_of col.name, :maximum => col.limit, :allow_nil => col.null
|
17
|
-
end
|
18
21
|
end
|
19
22
|
end
|
20
23
|
end
|
@@ -14,8 +14,8 @@ def load_schema
|
|
14
14
|
t.send(kind, "#{kind}_notnull", :null => false)
|
15
15
|
end
|
16
16
|
%w(string integer).each do |kind|
|
17
|
-
t.send(kind, "#{kind}_limit", :limit =>
|
18
|
-
t.send(kind, "#{kind}_limit_notnull", :limit =>
|
17
|
+
t.send(kind, "#{kind}_limit", :limit => 4)
|
18
|
+
t.send(kind, "#{kind}_limit_notnull", :limit => 4, :null => false)
|
19
19
|
end
|
20
20
|
t.timestamps
|
21
21
|
end
|
@@ -61,8 +61,8 @@ context Model do
|
|
61
61
|
asserts_error_on :integer_limit, 1.1
|
62
62
|
|
63
63
|
asserts_error_on :string_limit, '12345678910'
|
64
|
-
asserts_error_on :integer_limit,
|
64
|
+
asserts_error_on :integer_limit, 2 ** (8 * 4)
|
65
65
|
|
66
66
|
asserts_no_error_on :string_limit, '12'
|
67
|
-
asserts_no_error_on :integer_limit,
|
67
|
+
asserts_no_error_on :integer_limit, 2 ** (8 * 3)
|
68
68
|
end
|
metadata
CHANGED
@@ -1,12 +1,12 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rails-schema-validations
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 1
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
|
-
-
|
9
|
-
version: "0.
|
8
|
+
- 5
|
9
|
+
version: "0.5"
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Greg Weber
|