validates_lengths_from_database 0.5.0 → 0.5.1

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: 11cac7bb47bda407a7ef1ed3c928d7a364c9522c
4
- data.tar.gz: eb71d89711455e1c869155f98694fc1029a9f68c
3
+ metadata.gz: f73da6eb753b718d07fa7eb50a117bbdd51e6d96
4
+ data.tar.gz: d5a31be0048cea9e7960487582b75d3becc4fd65
5
5
  SHA512:
6
- metadata.gz: e4ebd4890711a54a80410beccff3ac20e7e20ee9ca8626c46c40b553d6b0f9e028d0b6a227f28f763ca6f3c8c1f6eb5b09d83d0a5d70c956c233ed336e533be7
7
- data.tar.gz: 2c82869d46cea0bcbdc51485b8b7f2e0c579a3060580eff52c82538d294849110d5bceaa726512a95ac9e11a90b5bfa8b37da87e9ac6519bec4d6c676b31f2aa
6
+ metadata.gz: 351f1fcf3f3e9f2c674050775f1ef6150f07a952aa341e4702c67b5411f8abdc33a38b373deb2ca65774a1ea3c8c6f6876f39a4939c5dec05df9a4aa71956731
7
+ data.tar.gz: 0211d47b6bf46d5cfba5baea54d57ab872e963c8d9a66e1da7f023f423084f5cfc9e691981e7166106aa92bd937841500fec398377d5b4bb0efae258f44e2d7b
@@ -1,3 +1,12 @@
1
+ == v0.5.1 (2017-04-27)
2
+
3
+ * Fix sharing options between models - thanks @iNecas
4
+
5
+ == v0.5.0 (2016-01-28)
6
+
7
+ * Drop support for rails 2
8
+ * Implement lazy-evaluation of column information for better compatibility with early load orders - thanks @domcleal.
9
+
1
10
  == v0.4.0 (2015-01-03)
2
11
 
3
12
  * Drop support for ruby 1.8.7 and 1.9.2 - too many issues with backwards-compatibility
@@ -1,8 +1,8 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- validates_lengths_from_database (0.4.0)
5
- activerecord (>= 2.3.2)
4
+ validates_lengths_from_database (0.5.0)
5
+ activerecord (>= 3)
6
6
 
7
7
  GEM
8
8
  remote: http://rubygems.org/
@@ -15,7 +15,7 @@ GEM
15
15
  activerecord-deprecated_finders (~> 1.0.2)
16
16
  activesupport (= 4.0.12)
17
17
  arel (~> 4.0.0)
18
- activerecord-deprecated_finders (1.0.3)
18
+ activerecord-deprecated_finders (1.0.4)
19
19
  activesupport (4.0.12)
20
20
  i18n (~> 0.6, >= 0.6.9)
21
21
  minitest (~> 4.2)
@@ -55,7 +55,7 @@ PLATFORMS
55
55
  ruby
56
56
 
57
57
  DEPENDENCIES
58
- activesupport (>= 2.3.2)
58
+ activesupport (>= 3)
59
59
  appraisal (~> 1.0.2)
60
60
  i18n
61
61
  iconv (~> 1.0.4)
@@ -67,4 +67,4 @@ DEPENDENCIES
67
67
  validates_lengths_from_database!
68
68
 
69
69
  BUNDLED WITH
70
- 1.10.6
70
+ 1.11.2
@@ -16,9 +16,9 @@ module ValidatesLengthsFromDatabase
16
16
  options[:limit] ||= {}
17
17
 
18
18
  if options[:limit] and !options[:limit].is_a?(Hash)
19
- options[:limit] = {:string => options[:limit], :text => options[:limit]}
19
+ options[:limit] = {:string => options[:limit], :text => options[:limit], :decimal => options[:limit], :integer => options[:limit], :float => options[:limit]}
20
20
  end
21
- @@validate_lengths_from_database_options = options
21
+ @validate_lengths_from_database_options = options
22
22
 
23
23
  validate :validate_lengths_from_database
24
24
 
@@ -26,7 +26,7 @@ module ValidatesLengthsFromDatabase
26
26
  end
27
27
 
28
28
  def validate_lengths_from_database_options
29
- @@validate_lengths_from_database_options
29
+ @validate_lengths_from_database_options
30
30
  end
31
31
  end
32
32
 
@@ -44,13 +44,21 @@ module ValidatesLengthsFromDatabase
44
44
  columns_to_validate.each do |column|
45
45
  column_schema = self.class.columns.find {|c| c.name == column }
46
46
  next if column_schema.nil?
47
- next if ![:string, :text].include?(column_schema.type)
48
47
  next if column_schema.respond_to?(:array) && column_schema.array
49
48
 
50
- column_limit = options[:limit][column_schema.type] || column_schema.limit
51
- next unless column_limit
49
+ if [:string, :text, :integer, :decimal, :float].include?(column_schema.type)
50
+ column_limit = options[:limit][column_schema.type] || column_schema.limit
51
+
52
+ ActiveModel::Validations::LengthValidator.new(:maximum => column_limit, :allow_blank => true, :attributes => [column]).validate(self) if column_limit
53
+
54
+ if column_schema.type == :decimal && column_schema.precision && column_schema.scale
55
+
56
+ max_val = (10 ** column_schema.precision)/(10 ** column_schema.scale)
57
+
58
+ ActiveModel::Validations::NumericalityValidator.new(:less_than => max_val, :allow_blank => true, :attributes => [column]).validate(self)
59
+ end
60
+ end
52
61
 
53
- ActiveModel::Validations::LengthValidator.new(:maximum => column_limit, :allow_blank => true, :attributes => [column]).validate(self)
54
62
  end
55
63
  end
56
64
  end
@@ -1,3 +1,3 @@
1
1
  module ValidatesLengthsFromDatabase
2
- VERSION = "0.5.0"
2
+ VERSION = "0.5.1"
3
3
  end
@@ -11,7 +11,10 @@ ActiveRecord::Schema.define(:version => 0) do
11
11
  end
12
12
 
13
13
  t.date :date_1
14
- t.integer :integer_1
14
+
15
+ t.integer :integer_1, :limit => 5
16
+ t.decimal :decimal_1, :precision => 5, :scale => 2
17
+ t.float :float_1, :limit => 5
15
18
 
16
19
  if database_supports_arrays?
17
20
  t.string :array_1, :array => true, :limit => 5
@@ -24,6 +27,8 @@ ActiveRecord::Schema.define(:version => 0) do
24
27
  t.text :text_1
25
28
  t.date :date_1
26
29
  t.integer :integer_1
30
+ t.decimal :decimal_1, :precision => 11, :scale => 2
31
+ t.float :float_1
27
32
 
28
33
  if database_supports_arrays?
29
34
  t.string :array_1, :array => true
@@ -7,7 +7,9 @@ describe ValidatesLengthsFromDatabase do
7
7
  :string_2 => "123456789",
8
8
  :text_1 => "123456789",
9
9
  :date_1 => Date.today,
10
- :integer_1 => 123
10
+ :integer_1 => 123456789,
11
+ :decimal_1 => 123456789.01,
12
+ :float_1 => 123456789.01
11
13
  }
12
14
 
13
15
  SHORT_ATTRIBUTES = {
@@ -15,7 +17,9 @@ describe ValidatesLengthsFromDatabase do
15
17
  :string_2 => "12",
16
18
  :text_1 => "12",
17
19
  :date_1 => Date.today,
18
- :integer_1 => 123
20
+ :integer_1 => 123,
21
+ :decimal_1 => 12.34,
22
+ :float_1 => 12.34
19
23
  }
20
24
 
21
25
  before(:all) do
@@ -102,6 +106,11 @@ describe ValidatesLengthsFromDatabase do
102
106
  self.table_name = "articles"
103
107
  validates_lengths_from_database
104
108
  end
109
+
110
+ class ArticleValidateText < ActiveRecord::Base
111
+ self.table_name = "articles"
112
+ validates_lengths_from_database :only => [:text_1]
113
+ end
105
114
  end
106
115
 
107
116
  context "an article with overloaded attributes" do
@@ -115,6 +124,9 @@ describe ValidatesLengthsFromDatabase do
115
124
  @article.errors["string_1"].join.should =~ /too long/
116
125
  @article.errors["string_2"].join.should =~ /too long/
117
126
  @article.errors["text_1"].join.should =~ /too long/ unless postgresql? # PostgreSQL doesn't support limits on text columns
127
+ @article.errors["decimal_1"].join.should =~ /less than/
128
+ @article.errors["integer_1"].join.should =~ /too long/
129
+ @article.errors["float_1"].join.should =~ /too long/
118
130
  end
119
131
  end
120
132
 
@@ -156,23 +168,27 @@ describe ValidatesLengthsFromDatabase do
156
168
  @article.errors["string_1"].join.should =~ /too long/
157
169
  @article.errors["string_2"].join.should =~ /too long/
158
170
  @article.errors["text_1"].join.should =~ /too long/
171
+ @article.errors["decimal_1"].join.should =~ /too long/
172
+ @article.errors["integer_1"].join.should =~ /too long/
173
+ @article.errors["float_1"].join.should =~ /too long/
159
174
  end
160
175
  end
161
176
 
162
177
  context "an article with short attributes" do
163
178
  before { @article = ArticleValidateLimit.new(SHORT_ATTRIBUTES); @article.valid? }
164
179
 
180
+
165
181
  it "should be valid" do
166
182
  @article.should be_valid
167
183
  end
168
184
  end
169
185
  end
170
186
 
171
- context "Model with validates_lengths_from_database :limit => {:string => 5, :text => 100}" do
187
+ context "Model with validates_lengths_from_database :limit => {:string => 5, :text => 100, :integer => 100, :decimal => 100, :float => 100}" do
172
188
  before do
173
189
  class ArticleValidateSpecificLimit < ActiveRecord::Base
174
190
  self.table_name = "articles_high_limit"
175
- validates_lengths_from_database :limit => {:string => 5, :text => 100}
191
+ validates_lengths_from_database :limit => {:string => 5, :text => 100, :integer => 100, :decimal => 100, :float => 100}
176
192
  end
177
193
  end
178
194
 
@@ -187,6 +203,9 @@ describe ValidatesLengthsFromDatabase do
187
203
  @article.errors["string_1"].join.should =~ /too long/
188
204
  @article.errors["string_2"].join.should =~ /too long/
189
205
  @article.errors["text_1"].should_not be_present
206
+ @article.errors["decimal_1"].should_not be_present
207
+ @article.errors["integer_1"].should_not be_present
208
+ @article.errors["float_1"].should_not be_present
190
209
  end
191
210
  end
192
211
  end
@@ -210,6 +229,9 @@ describe ValidatesLengthsFromDatabase do
210
229
  @article.errors["string_1"].join.should =~ /too long/
211
230
  (@article.errors["string_2"] || []).should be_empty
212
231
  @article.errors["text_1"].join.should =~ /too long/ unless postgresql? # PostgreSQL doesn't support limits on text columns
232
+ (@article.errors["decimal_1"] || []).should be_empty
233
+ (@article.errors["integer_1"] || []).should be_empty
234
+ (@article.errors["float_1"] || []).should be_empty
213
235
  end
214
236
  end
215
237
 
@@ -240,7 +262,10 @@ describe ValidatesLengthsFromDatabase do
240
262
  it "should have errors on columns other than string_1 and text_1 only" do
241
263
  (@article.errors["string_1"] || []).should be_empty
242
264
  (@article.errors["text_1"] || []).should be_empty
265
+ @article.errors["decimal_1"].join.should =~ /less than/
266
+ @article.errors["integer_1"].join.should =~ /too long/
243
267
  @article.errors["string_2"].join.should =~ /too long/
268
+ @article.errors["float_1"].join.should =~ /too long/
244
269
  end
245
270
  end
246
271
 
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.0
4
+ version: 0.5.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ben Hughes
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-01-29 00:00:00.000000000 Z
11
+ date: 2017-04-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
@@ -16,28 +16,28 @@ dependencies:
16
16
  requirements:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: 2.3.2
19
+ version: '3'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
- version: 2.3.2
26
+ version: '3'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: activesupport
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - ">="
32
32
  - !ruby/object:Gem::Version
33
- version: 2.3.2
33
+ version: '3'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - ">="
39
39
  - !ruby/object:Gem::Version
40
- version: 2.3.2
40
+ version: '3'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: rspec
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -174,8 +174,6 @@ files:
174
174
  - spec/db/test.sqlite3
175
175
  - spec/spec_helper.rb
176
176
  - spec/validates_lengths_from_database_spec.rb
177
- - validates_lengths_from_database-0.4.0.gem
178
- - validates_lengths_from_database.gemspec
179
177
  homepage: http://github.com/rubiety/validates_lengths_from_database
180
178
  licenses: []
181
179
  metadata: {}
@@ -195,9 +193,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
195
193
  version: 1.3.4
196
194
  requirements: []
197
195
  rubyforge_project: validates_lengths_from_database
198
- rubygems_version: 2.4.8
196
+ rubygems_version: 2.6.11
199
197
  signing_key:
200
198
  specification_version: 4
201
199
  summary: Automatic maximum-length validations.
202
200
  test_files: []
203
- has_rdoc:
@@ -1,37 +0,0 @@
1
- # -*- encoding: utf-8 -*-
2
- $:.push File.expand_path("../lib", __FILE__)
3
- require "validates_lengths_from_database/version"
4
-
5
- Gem::Specification.new do |s|
6
- s.name = "validates_lengths_from_database"
7
- s.version = ValidatesLengthsFromDatabase::VERSION
8
- s.author = "Ben Hughes"
9
- s.email = "ben@railsgarden.com"
10
- s.homepage = "http://github.com/rubiety/validates_lengths_from_database"
11
- s.summary = "Automatic maximum-length validations."
12
- s.description = "Introspects your database string field maximum lengths and automatically defines length validations."
13
-
14
- s.files = Dir["{lib,spec,rails}/**/*", "[A-Z]*", "init.rb"]
15
- s.require_path = "lib"
16
-
17
- s.rubyforge_project = s.name
18
- s.required_rubygems_version = ">= 1.3.4"
19
- s.required_ruby_version = ">= 1.9.3"
20
-
21
- s.add_dependency("activerecord", [">= 2.3.2"])
22
- s.add_development_dependency("activesupport", [">= 2.3.2"])
23
- s.add_development_dependency("rspec", ["~> 2.0"])
24
- s.add_development_dependency("sqlite3", ["~> 1.3.4"])
25
- s.add_development_dependency("appraisal", ["~> 1.0.2"])
26
- s.add_development_dependency("pg", ["~> 0.17.1"])
27
- s.add_development_dependency("rdoc", ["~> 3.12"])
28
- s.add_development_dependency "rake"
29
-
30
- # I'm not sure why this isn't installed along with activesupport,
31
- # but for whatever reason running `bundle install` doesn't install
32
- # i18n so I'm adding it here for now.
33
- # https://github.com/rails/rails/blob/master/activesupport/activesupport.gemspec#L19 ?
34
- s.add_development_dependency("i18n")
35
- s.add_development_dependency("iconv", "~> 1.0.4")
36
- end
37
-