rails-schema-validations 0.9 → 0.9.2
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.
- data/README +4 -3
- data/lib/rails-schema-validations.rb +1 -1
- data/test/test_helper.rb +0 -1
- data/test/validations_from_schema_test.rb +6 -0
- metadata +4 -3
data/README
CHANGED
@@ -9,12 +9,13 @@ validations_from_schema
|
|
9
9
|
Generated Validations
|
10
10
|
=====================
|
11
11
|
|
12
|
-
| schema type | rails validation | extra
|
12
|
+
| schema type | rails validation | extra constraints |
|
13
13
|
|-------------|---------------------------|---------------------------|
|
14
14
|
| non-null | validates_presence_of | |
|
15
|
-
| string | validates_length_of | :
|
15
|
+
| string | validates_length_of | :maximum |
|
16
16
|
| integer | validates_numericality_of | :only_integer, :less_than |
|
17
17
|
| float | validates_numericality_of | |
|
18
|
+
| boolean | validates_inclusion_of | |
|
18
19
|
|
19
20
|
for boolean non-null it uses validates_inclusion_of :in => [true,false]
|
20
21
|
|
@@ -24,5 +25,5 @@ To exclude a column use the `:except => ['excluded']` option.
|
|
24
25
|
|
25
26
|
Warning
|
26
27
|
=======
|
27
|
-
Tested on MySQL.
|
28
|
+
Tested on MySQL. Rails 2.3 and Rails 3
|
28
29
|
Assume it doesn't work on your database unless you modify the test suite to run against your db and all tests pass
|
@@ -17,7 +17,7 @@ module ActiveRecord::Validations::ClassMethods
|
|
17
17
|
validates_numericality_of col.name, :allow_nil => col.null
|
18
18
|
#when :time, :datetime
|
19
19
|
when :string
|
20
|
-
if col.limit
|
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
|
23
23
|
when :boolean
|
data/test/test_helper.rb
CHANGED
@@ -21,6 +21,9 @@ def load_schema
|
|
21
21
|
|
22
22
|
t.integer :indexed_id, :null => false
|
23
23
|
t.integer :unique_id, :null => false
|
24
|
+
|
25
|
+
# very edge case of MySQL enum column
|
26
|
+
t.string "enum", :limit => 0, :null => false
|
24
27
|
end
|
25
28
|
|
26
29
|
add_index 'models', ['indexed_id']
|
@@ -86,4 +89,7 @@ context Model do
|
|
86
89
|
|
87
90
|
# ignore
|
88
91
|
asserts_no_error_on :id, nil
|
92
|
+
|
93
|
+
asserts_no_error_on :enum, 'enum'
|
94
|
+
asserts_error_on :enum, nil
|
89
95
|
end
|
metadata
CHANGED
@@ -1,12 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rails-schema-validations
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 63
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 9
|
9
|
-
|
9
|
+
- 2
|
10
|
+
version: 0.9.2
|
10
11
|
platform: ruby
|
11
12
|
authors:
|
12
13
|
- Greg Weber
|
@@ -14,7 +15,7 @@ autorequire:
|
|
14
15
|
bindir: bin
|
15
16
|
cert_chain: []
|
16
17
|
|
17
|
-
date: 2010-
|
18
|
+
date: 2010-11-28 00:00:00 -08:00
|
18
19
|
default_executable:
|
19
20
|
dependencies: []
|
20
21
|
|