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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b3cbc2903e74311d8f505bf1886d34893d917560
4
- data.tar.gz: 2343ae4917d6c5ab9e5c2ac40d36accdb6d1bf82
3
+ metadata.gz: a5d849122ca6f0e6f08d91e2cb391407fc7fc227
4
+ data.tar.gz: f8645f3bc0d1fcb7da740dc1e2f28e86570f0b01
5
5
  SHA512:
6
- metadata.gz: 874b8960af4dcfdca8aba841ac4e127911602b507a4ccd627ab3f3f68a79a54f2204d08e5273c3de5e278b8a36e7758e0c8578c94cb2d67f5c91798967cbfc29
7
- data.tar.gz: 4831460cb621f41c72df57fb422954d6a9a2b95e6e3473625296a7353117ab3adacc560423a2da73ae19a0c1686c38a6d85ac2a792410a9ed1f51cd9818fe86d
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` | `:validates ... numericality: { greater_than: ..., less_than: ... }` |
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 :decimal range validation. Thanks to [@felixbuenemann](https://github.com/felixbuenemann)
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
- limit = 10 ** (column.precision - column.scale)
112
- validate_logged :validates_numericality_of, name, :allow_nil => true, :greater_than => -limit, :less_than => limit
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
@@ -1,3 +1,3 @@
1
1
  module SchemaValidations
2
- VERSION = "2.1.0"
2
+ VERSION = "2.1.1"
3
3
  end
@@ -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 :rating, :precision => 2, :scale => 1
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 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)
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.0
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-03-23 00:00:00.000000000 Z
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