schema_validations 2.1.0 → 2.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +6 -2
- data/lib/schema_validations/active_record/validations.rb +4 -2
- data/lib/schema_validations/version.rb +1 -1
- data/spec/validations_spec.rb +17 -4
- 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: a5d849122ca6f0e6f08d91e2cb391407fc7fc227
|
4
|
+
data.tar.gz: f8645f3bc0d1fcb7da740dc1e2f28e86570f0b01
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 09ac9381a024e6a9f82ffe2e619217d5eb0c13dce2c83cedb5feb001faccf6ad65c7cd2d51a5291d20e969aad15adcadb4e880ebb6e55054291748b7cb30bdc1
|
7
|
+
data.tar.gz: d6359451dc9673a2cff5fdd768a0c5e42fe6df3acecf20412c769070f052d70da2f748b583363f1c7a0c5cb656b5884cf1848ab75ed41bf0efd19e025cf98084
|
data/README.md
CHANGED
@@ -71,7 +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
|
74
|
+
| `:decimal, precision: ...` | `:validates ... numericality: { greater_than: ..., less_than: ... }` |
|
75
75
|
|
76
76
|
|
77
77
|
## What if I want something special?
|
@@ -186,9 +186,13 @@ Earlier versions of SchemaValidations supported:
|
|
186
186
|
|
187
187
|
## Release Notes
|
188
188
|
|
189
|
+
### 2.1.1
|
190
|
+
|
191
|
+
* Bug fix for `:decimal` when `precision` is nil (#37)
|
192
|
+
|
189
193
|
### 2.1.0
|
190
194
|
|
191
|
-
* Added
|
195
|
+
* Added `:decimal` range validation. Thanks to [@felixbuenemann](https://github.com/felixbuenemann)
|
192
196
|
|
193
197
|
### 2.0.2
|
194
198
|
|
@@ -108,8 +108,10 @@ module SchemaValidations
|
|
108
108
|
when :integer
|
109
109
|
load_integer_column_validations(name, column)
|
110
110
|
when :decimal
|
111
|
-
|
112
|
-
|
111
|
+
if column.precision
|
112
|
+
limit = 10 ** (column.precision - (column.scale || 0))
|
113
|
+
validate_logged :validates_numericality_of, name, :allow_nil => true, :greater_than => -limit, :less_than => limit
|
114
|
+
end
|
113
115
|
when :numeric
|
114
116
|
validate_logged :validates_numericality_of, name, :allow_nil => true
|
115
117
|
when :text
|
data/spec/validations_spec.rb
CHANGED
@@ -12,7 +12,9 @@ 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 :
|
15
|
+
t.decimal :max10, :precision => 2, :scale => 1
|
16
|
+
t.decimal :arbitrary, :precision => nil, :scale => nil
|
17
|
+
t.decimal :max100, :precision => 2, :scale => nil
|
16
18
|
end
|
17
19
|
add_index :articles, :title, :unique => true
|
18
20
|
add_index :articles, [:state, :active], :unique => true
|
@@ -95,9 +97,20 @@ describe "Validations" do
|
|
95
97
|
expect(Article.new(votes: -2147483649).error_on(:votes).size).to eq(1)
|
96
98
|
end
|
97
99
|
|
98
|
-
it "should validate the range of
|
99
|
-
expect(Article.new(
|
100
|
-
expect(Article.new(
|
100
|
+
it "should validate the range of decimal precision with scale" do
|
101
|
+
expect(Article.new(max10: 10).error_on(:max10).size).to eq(1)
|
102
|
+
expect(Article.new(max10: 5).error_on(:max10).size).to eq(0)
|
103
|
+
expect(Article.new(max10: -10).error_on(:max10).size).to eq(1)
|
104
|
+
end
|
105
|
+
|
106
|
+
it "should validate the range of decimal precision without scale" do
|
107
|
+
expect(Article.new(max100: 100).error_on(:max100).size).to eq(1)
|
108
|
+
expect(Article.new(max100: 50).error_on(:max100).size).to eq(0)
|
109
|
+
expect(Article.new(max100: -100).error_on(:max100).size).to eq(1)
|
110
|
+
end
|
111
|
+
|
112
|
+
it "should not validate the range of arbitrary decimal" do
|
113
|
+
expect(Article.new(arbitrary: Float::MAX).error_on(:arbitrary).size).to eq(0)
|
101
114
|
end
|
102
115
|
|
103
116
|
it "should validate average_mark numericality" do
|
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.1.
|
4
|
+
version: 2.1.1
|
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-
|
12
|
+
date: 2016-04-06 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: schema_plus_columns
|