schema_validations 2.0.2 → 2.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +5 -0
- data/lib/schema_validations/active_record/validations.rb +4 -0
- data/lib/schema_validations/version.rb +1 -1
- data/spec/validations_spec.rb +6 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b3cbc2903e74311d8f505bf1886d34893d917560
|
4
|
+
data.tar.gz: 2343ae4917d6c5ab9e5c2ac40d36accdb6d1bf82
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 874b8960af4dcfdca8aba841ac4e127911602b507a4ccd627ab3f3f68a79a54f2204d08e5273c3de5e278b8a36e7758e0c8578c94cb2d67f5c91798967cbfc29
|
7
|
+
data.tar.gz: 4831460cb621f41c72df57fb422954d6a9a2b95e6e3473625296a7353117ab3adacc560423a2da73ae19a0c1686c38a6d85ac2a792410a9ed1f51cd9818fe86d
|
data/README.md
CHANGED
@@ -71,6 +71,7 @@ Data types:
|
|
71
71
|
| `:boolean` | `:validates ... inclusion: { in: [true, false] }` |
|
72
72
|
| `:float` | `:validates ... numericality: true` |
|
73
73
|
| `:integer` | `:validates ... numericality: { only_integer: true, greater_than_or_equal_to: ..., less_than: ... }` |
|
74
|
+
| `:decimal` | `:validates ... numericality: { greater_than: ..., less_than: ... }` |
|
74
75
|
|
75
76
|
|
76
77
|
## What if I want something special?
|
@@ -185,6 +186,10 @@ Earlier versions of SchemaValidations supported:
|
|
185
186
|
|
186
187
|
## Release Notes
|
187
188
|
|
189
|
+
### 2.1.0
|
190
|
+
|
191
|
+
* Added :decimal range validation. Thanks to [@felixbuenemann](https://github.com/felixbuenemann)
|
192
|
+
|
188
193
|
### 2.0.2
|
189
194
|
|
190
195
|
* Use schema_monkey rather than Railties
|
@@ -98,6 +98,7 @@ module SchemaValidations
|
|
98
98
|
datatype = case
|
99
99
|
when respond_to?(:defined_enums) && defined_enums.has_key?(column.name) then :enum
|
100
100
|
when column.type == :integer then :integer
|
101
|
+
when column.type == :decimal then :decimal
|
101
102
|
when column.number? then :numeric
|
102
103
|
when column.text? then :text
|
103
104
|
when column.type == :boolean then :boolean
|
@@ -106,6 +107,9 @@ module SchemaValidations
|
|
106
107
|
case datatype
|
107
108
|
when :integer
|
108
109
|
load_integer_column_validations(name, column)
|
110
|
+
when :decimal
|
111
|
+
limit = 10 ** (column.precision - column.scale)
|
112
|
+
validate_logged :validates_numericality_of, name, :allow_nil => true, :greater_than => -limit, :less_than => limit
|
109
113
|
when :numeric
|
110
114
|
validate_logged :validates_numericality_of, name, :allow_nil => true
|
111
115
|
when :text
|
data/spec/validations_spec.rb
CHANGED
@@ -12,6 +12,7 @@ describe "Validations" do
|
|
12
12
|
t.integer :votes
|
13
13
|
t.float :average_mark, :null => false
|
14
14
|
t.boolean :active, :null => false
|
15
|
+
t.decimal :rating, :precision => 2, :scale => 1
|
15
16
|
end
|
16
17
|
add_index :articles, :title, :unique => true
|
17
18
|
add_index :articles, [:state, :active], :unique => true
|
@@ -94,6 +95,11 @@ describe "Validations" do
|
|
94
95
|
expect(Article.new(votes: -2147483649).error_on(:votes).size).to eq(1)
|
95
96
|
end
|
96
97
|
|
98
|
+
it "should validate the range of rating" do
|
99
|
+
expect(Article.new(rating: 10).error_on(:rating).size).to eq(1)
|
100
|
+
expect(Article.new(rating: -10).error_on(:rating).size).to eq(1)
|
101
|
+
end
|
102
|
+
|
97
103
|
it "should validate average_mark numericality" do
|
98
104
|
expect(Article.new(:average_mark => "high").error_on(:average_mark).size).to eq(1)
|
99
105
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: schema_validations
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.0
|
4
|
+
version: 2.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ronen Barzel
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2016-03-
|
12
|
+
date: 2016-03-23 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: schema_plus_columns
|