activerecord-databasevalidations 0.2.5 → 0.2.6

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: 8c11efae478930073f88dc28f6b2475f8c7007b6
4
- data.tar.gz: 2007c8ba0229680b0fcffd2037d9e3de6ea24477
3
+ metadata.gz: 773b5d266abadfa6217235afa17fd1bd36a94bf2
4
+ data.tar.gz: 329ce44970fde33714067d8ee71765039850aac3
5
5
  SHA512:
6
- metadata.gz: 1964dd60bb60504b4d8340915de87fcd6bb03804a542f24b67094fbf59ef3f1c71d3a3beffc99289eafccfec44bc23226ffe03c751a912fec7dbe1a9936228df
7
- data.tar.gz: 63af8cccba1e2df89e6734f174eec31702b4f1b73e5c8574daf9896c19496148cc3d6bdf06ecaac3a8c56e6764b217e2f38f66badb91cf83dddc535ff60f1c65
6
+ metadata.gz: b4733b9f3b656c5baf7a94fb19bf3851f04ae9c69a0264814be7db8b24c37f82e7c8d6bc91f4e0683d9674279875a69e26e8bebbe38854face905b55fdbaa288
7
+ data.tar.gz: d5089f0a50188e16e6d952c992198795555d7a8a6c0c495fbda0beb442e6610c2dfe749571b23a518338202568f5e1c488b8cd9c42d86272af97fb6fa5e79205
data/.travis.yml CHANGED
@@ -3,8 +3,6 @@ language: ruby
3
3
  cache: bundler
4
4
 
5
5
  rvm:
6
- - 1.9.3
7
- - 2.0.0
8
6
  - 2.1.8
9
7
  - 2.2.4
10
8
  - 2.3.0
@@ -17,15 +15,8 @@ gemfile:
17
15
 
18
16
  matrix:
19
17
  exclude:
20
- - rvm: 1.9.3
21
- gemfile: Gemfile.activerecord50
22
- - rvm: 2.0.0
23
- gemfile: Gemfile.activerecord50
24
18
  - rvm: 2.1.8
25
19
  gemfile: Gemfile.activerecord50
26
20
 
27
- allow_failures:
28
- - gemfile: Gemfile.activerecord50
29
-
30
21
  before_script:
31
22
  - mysql -e 'create database database_validations;'
data/CHANGELOG.md CHANGED
@@ -1 +1,4 @@
1
1
 
2
+ # 0.2.6 (March 23, 2016)
3
+
4
+ * Rails 5 support (#17)
@@ -5,5 +5,6 @@ require 'active_record/database_validations/version'
5
5
  require 'active_record/database_validations/mysql'
6
6
  require 'active_record/validations/database_constraints'
7
7
  require 'active_record/validations/string_truncator'
8
+ require 'active_record/validations/typed_column'
8
9
 
9
10
  I18n.load_path << File.dirname(__FILE__) + '/database_validations/locale/en.yml'
@@ -50,6 +50,7 @@ module ActiveRecord
50
50
  end
51
51
 
52
52
  def self.determine_encoding(column)
53
+ column = ActiveRecord::Validations::TypedColumn.new(column)
53
54
  return nil unless column.text?
54
55
  case column.collation
55
56
  when /\Autf8/; Encoding::UTF_8
@@ -1,5 +1,5 @@
1
1
  module ActiveRecord
2
2
  module DatabaseValidations
3
- VERSION = "0.2.5"
3
+ VERSION = "0.2.6"
4
4
  end
5
5
  end
@@ -64,6 +64,7 @@ module ActiveRecord
64
64
  def attribute_validators(klass, attribute)
65
65
  @constraint_validators[attribute] ||= begin
66
66
  column = klass.columns_hash[attribute.to_s] or raise ArgumentError.new("Model #{self.class.name} does not have column #{column_name}!")
67
+ column = ActiveRecord::Validations::TypedColumn.new(column)
67
68
 
68
69
  [
69
70
  not_null_validator(klass, column),
@@ -0,0 +1,33 @@
1
+ # Rails 5 doesn't provide `column.number?`-ish methods.
2
+ # This delegator proxies type-related methods to superclass
3
+ # or implements them when they are not available
4
+
5
+ module ActiveRecord
6
+ module Validations
7
+ class TypedColumn < SimpleDelegator
8
+ def number?
9
+ if __getobj__.respond_to?(:number?)
10
+ super
11
+ else
12
+ type == :decimal || type == :integer
13
+ end
14
+ end
15
+
16
+ def text?
17
+ if __getobj__.respond_to?(:text?)
18
+ super
19
+ else
20
+ type == :text || type == :string
21
+ end
22
+ end
23
+
24
+ def binary?
25
+ if __getobj__.respond_to?(:binary?)
26
+ super
27
+ else
28
+ type == :binary
29
+ end
30
+ end
31
+ end
32
+ end
33
+ end
@@ -159,7 +159,7 @@ class DatabaseConstraintsValidatorTest < Minitest::Test
159
159
  def test_integer_range
160
160
  subvalidators = Num._validators[:bigint].first.attribute_validators(Num, :bigint)
161
161
  assert_equal 1, subvalidators.length
162
- assert_kind_of ActiveModel::Validations::NumericalityValidator, range_validator = subvalidators.first
162
+ assert_kind_of ActiveModel::Validations::NumericalityValidator, subvalidators.first
163
163
 
164
164
  inside_upper_bound = Num.new(tinyint: 127)
165
165
  assert inside_upper_bound.valid?
@@ -181,7 +181,7 @@ class DatabaseConstraintsValidatorTest < Minitest::Test
181
181
  def unsigned_integer_range
182
182
  subvalidators = Num._validators[:unsigned_int].first.attribute_validators(Num, :unsigned_int)
183
183
  assert_equal 1, subvalidators.length
184
- assert_kind_of ActiveModel::Validations::NumericalityValidator, range_validator = subvalidators.first
184
+ assert_kind_of ActiveModel::Validations::NumericalityValidator, subvalidators.first
185
185
 
186
186
  inside_upper_bound = Num.new(unsigned_int: 4_294_967_295)
187
187
  assert inside_upper_bound.valid?
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: activerecord-databasevalidations
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.5
4
+ version: 0.2.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Willem van Bergen
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-03-22 00:00:00.000000000 Z
11
+ date: 2016-03-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
@@ -131,6 +131,7 @@ files:
131
131
  - lib/active_record/database_validations/version.rb
132
132
  - lib/active_record/validations/database_constraints.rb
133
133
  - lib/active_record/validations/string_truncator.rb
134
+ - lib/active_record/validations/typed_column.rb
134
135
  - lib/activerecord-databasevalidations.rb
135
136
  - lib/activerecord/databasevalidations.rb
136
137
  - test/basic_multilingual_plane_validator_test.rb