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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8a2017e0b6fb3a3f8a69d7756dcbd581421d4520
|
4
|
+
data.tar.gz: cf44cca0ce1ffcf4b86afd8e188c44ede1db10ad
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3aeba2873a46956abf4097a30eb0fb05a8934db8c13338aa69f3670d97a02d3c68689c2d5c8dc0f78ca8a34d026f0616f1d6e3914fec53b77db1fd77f8731a9c
|
7
|
+
data.tar.gz: 3e1ab91da9556d596daba58909c660ef1f924948c85c6eef9ff57d72c41837cb0606c153c78d9f19ed26de1376343015aa46dd9c241cea57ff230b79348e1406
|
data/CHANGELOG.rdoc
CHANGED
@@ -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
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
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
|
@@ -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
|
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
|
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.
|
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-
|
11
|
+
date: 2017-05-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|