validates_lengths_from_database 0.5.2 → 0.6.0

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7d17fe52e66ac67d1cfc3a81dd72fee22a6050b7
4
- data.tar.gz: 636155e6624043e9981dd9961eb990aa7059febf
3
+ metadata.gz: 8a2017e0b6fb3a3f8a69d7756dcbd581421d4520
4
+ data.tar.gz: cf44cca0ce1ffcf4b86afd8e188c44ede1db10ad
5
5
  SHA512:
6
- metadata.gz: d500d14353f1297f9dc3c35a5333e4cedd81fcc1172867264d77299550c5fd3de9e58ae56231c47b09da517ef6e0f3fe2382a75bfdb95d5f1f6981ff706d5219
7
- data.tar.gz: 445d4c872b1add3772218b3811e112823981935d4cd2f477fccae00fb9cfa56c11dbe49ff5fd10b76b0e0acc09e6ec0ebc9c6683300e3761dd27fa03f9c3650f
6
+ metadata.gz: 3aeba2873a46956abf4097a30eb0fb05a8934db8c13338aa69f3670d97a02d3c68689c2d5c8dc0f78ca8a34d026f0616f1d6e3914fec53b77db1fd77f8731a9c
7
+ data.tar.gz: 3e1ab91da9556d596daba58909c660ef1f924948c85c6eef9ff57d72c41837cb0606c153c78d9f19ed26de1376343015aa46dd9c241cea57ff230b79348e1406
@@ -1,3 +1,7 @@
1
+ == v0.6.0 (2017-05-02)
2
+
3
+ * Drop support for integer length validations (too many issues)
4
+
1
5
  == v0.5.2 (2017-04-28)
2
6
 
3
7
  * Fix handling with STI models - thanks @iNecas
@@ -54,20 +54,19 @@ module ValidatesLengthsFromDatabase
54
54
  column_schema = self.class.columns.find {|c| c.name == column }
55
55
  next if column_schema.nil?
56
56
  next if column_schema.respond_to?(:array) && column_schema.array
57
-
58
- if [:string, :text, :integer, :decimal, :float].include?(column_schema.type)
59
- column_limit = options[:limit][column_schema.type] || column_schema.limit
60
-
61
- ActiveModel::Validations::LengthValidator.new(:maximum => column_limit, :allow_blank => true, :attributes => [column]).validate(self) if column_limit
62
-
63
- if column_schema.type == :decimal && column_schema.precision && column_schema.scale
64
-
57
+ next unless [:string, :text, :decimal].include?(column_schema.type)
58
+ case column_schema.type
59
+ when :string, :text
60
+ column_limit = options[:limit][column_schema.type] || column_schema.limit
61
+ if column_limit
62
+ ActiveModel::Validations::LengthValidator.new(:maximum => column_limit, :allow_blank => true, :attributes => [column]).validate(self)
63
+ end
64
+ when :decimal
65
+ if column_schema.precision && column_schema.scale
65
66
  max_val = (10 ** column_schema.precision)/(10 ** column_schema.scale)
66
-
67
67
  ActiveModel::Validations::NumericalityValidator.new(:less_than => max_val, :allow_blank => true, :attributes => [column]).validate(self)
68
68
  end
69
69
  end
70
-
71
70
  end
72
71
  end
73
72
  end
@@ -1,3 +1,3 @@
1
1
  module ValidatesLengthsFromDatabase
2
- VERSION = "0.5.2"
2
+ VERSION = "0.6.0"
3
3
  end
@@ -130,8 +130,6 @@ describe ValidatesLengthsFromDatabase do
130
130
  @article.errors["string_2"].join.should =~ /too long/
131
131
  @article.errors["text_1"].join.should =~ /too long/ unless postgresql? # PostgreSQL doesn't support limits on text columns
132
132
  @article.errors["decimal_1"].join.should =~ /less than/
133
- @article.errors["integer_1"].join.should =~ /too long/
134
- @article.errors["float_1"].join.should =~ /too long/
135
133
  end
136
134
  end
137
135
 
@@ -203,9 +201,6 @@ describe ValidatesLengthsFromDatabase do
203
201
  @article.errors["string_1"].join.should =~ /too long/
204
202
  @article.errors["string_2"].join.should =~ /too long/
205
203
  @article.errors["text_1"].join.should =~ /too long/
206
- @article.errors["decimal_1"].join.should =~ /too long/
207
- @article.errors["integer_1"].join.should =~ /too long/
208
- @article.errors["float_1"].join.should =~ /too long/
209
204
  end
210
205
  end
211
206
 
@@ -219,11 +214,11 @@ describe ValidatesLengthsFromDatabase do
219
214
  end
220
215
  end
221
216
 
222
- context "Model with validates_lengths_from_database :limit => {:string => 5, :text => 100, :integer => 100, :decimal => 100, :float => 100}" do
217
+ context "Model with validates_lengths_from_database :limit => {:string => 5, :text => 100}" do
223
218
  before do
224
219
  class ArticleValidateSpecificLimit < ActiveRecord::Base
225
220
  self.table_name = "articles_high_limit"
226
- validates_lengths_from_database :limit => {:string => 5, :text => 100, :integer => 100, :decimal => 100, :float => 100}
221
+ validates_lengths_from_database :limit => {:string => 5, :text => 100}
227
222
  end
228
223
  end
229
224
 
@@ -239,8 +234,6 @@ describe ValidatesLengthsFromDatabase do
239
234
  @article.errors["string_2"].join.should =~ /too long/
240
235
  @article.errors["text_1"].should_not be_present
241
236
  @article.errors["decimal_1"].should_not be_present
242
- @article.errors["integer_1"].should_not be_present
243
- @article.errors["float_1"].should_not be_present
244
237
  end
245
238
  end
246
239
  end
@@ -265,8 +258,6 @@ describe ValidatesLengthsFromDatabase do
265
258
  (@article.errors["string_2"] || []).should be_empty
266
259
  @article.errors["text_1"].join.should =~ /too long/ unless postgresql? # PostgreSQL doesn't support limits on text columns
267
260
  (@article.errors["decimal_1"] || []).should be_empty
268
- (@article.errors["integer_1"] || []).should be_empty
269
- (@article.errors["float_1"] || []).should be_empty
270
261
  end
271
262
  end
272
263
 
@@ -298,9 +289,7 @@ describe ValidatesLengthsFromDatabase do
298
289
  (@article.errors["string_1"] || []).should be_empty
299
290
  (@article.errors["text_1"] || []).should be_empty
300
291
  @article.errors["decimal_1"].join.should =~ /less than/
301
- @article.errors["integer_1"].join.should =~ /too long/
302
292
  @article.errors["string_2"].join.should =~ /too long/
303
- @article.errors["float_1"].join.should =~ /too long/
304
293
  end
305
294
  end
306
295
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: validates_lengths_from_database
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.2
4
+ version: 0.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ben Hughes
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-04-28 00:00:00.000000000 Z
11
+ date: 2017-05-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord