activerecord-databasevalidations 0.4.0 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +5 -14
- data/activerecord-databasevalidations.gemspec +2 -2
- data/gemfiles/Gemfile.activerecord52 +1 -1
- data/gemfiles/{Gemfile.activerecord50 → Gemfile.activerecord60} +1 -1
- data/lib/active_record/database_validations/mysql.rb +6 -2
- data/lib/active_record/database_validations/version.rb +1 -1
- data/test/data_loss_test.rb +5 -5
- data/test/database_constraints_validator_test.rb +3 -3
- data/test/varchar_default_size_test.rb +2 -2
- metadata +7 -10
- data/gemfiles/Gemfile.activerecord-edge +0 -4
- data/gemfiles/Gemfile.activerecord51 +0 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 86138fed43c841609f1a4b0f1952d956e84040d14bc966731ce8ffd56a533309
|
4
|
+
data.tar.gz: e133a86b1cb4c996c609c00e5b683fadab0d28bcfd696502cfc330c6a40d23d6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: df4cb11a72a91ff8073a94c0bc1d5641cc9d674efd237b643c223ce49a3a8a660e185d3044fa78b416cdf0bd87494ea2b0d9338b9950675e182a9e7ce49b7054
|
7
|
+
data.tar.gz: f87e0c673004f5b1a16763c297da0744993388ca0d48ac6857f9a2b4b68f34409c2bb2c3e893706f7f5a96ec1e3688a7a6df2077a1947ba8beb4884c8044ace7
|
data/.travis.yml
CHANGED
@@ -1,25 +1,16 @@
|
|
1
1
|
sudo: false
|
2
2
|
language: ruby
|
3
3
|
cache: bundler
|
4
|
+
services:
|
5
|
+
- mysql
|
4
6
|
|
5
7
|
rvm:
|
6
|
-
- 2.
|
7
|
-
- 2.
|
8
|
-
- 2.4.1
|
9
|
-
- 2.5.0
|
8
|
+
- '2.5'
|
9
|
+
- '2.6'
|
10
10
|
|
11
11
|
gemfile:
|
12
|
-
- gemfiles/Gemfile.activerecord50
|
13
|
-
- gemfiles/Gemfile.activerecord51
|
14
12
|
- gemfiles/Gemfile.activerecord52
|
15
|
-
- gemfiles/Gemfile.
|
16
|
-
|
17
|
-
matrix:
|
18
|
-
exclude:
|
19
|
-
- rvm: 2.2.2
|
20
|
-
gemfile: gemfiles/Gemfile.activerecord-edge
|
21
|
-
- rvm: 2.3.0
|
22
|
-
gemfile: gemfiles/Gemfile.activerecord-edge
|
13
|
+
- gemfiles/Gemfile.activerecord60
|
23
14
|
|
24
15
|
before_script:
|
25
16
|
- mysql -e 'create database database_validations;'
|
@@ -18,9 +18,9 @@ Gem::Specification.new do |spec|
|
|
18
18
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
19
|
spec.require_paths = ["lib"]
|
20
20
|
|
21
|
-
spec.required_ruby_version = '>= 2.
|
21
|
+
spec.required_ruby_version = '>= 2.5'
|
22
22
|
|
23
|
-
spec.add_runtime_dependency "activerecord", ">= 5.
|
23
|
+
spec.add_runtime_dependency "activerecord", ">= 5.2"
|
24
24
|
spec.add_runtime_dependency "rejectu"
|
25
25
|
|
26
26
|
spec.add_development_dependency "bundler", "~> 1.5"
|
@@ -64,8 +64,12 @@ module ActiveRecord
|
|
64
64
|
|
65
65
|
def self.value_for_column(value, column_encoding = nil)
|
66
66
|
value = value.to_s unless value.is_a?(String)
|
67
|
-
|
68
|
-
|
67
|
+
|
68
|
+
if requires_transcoding?(value, column_encoding)
|
69
|
+
return value.encode(Encoding::UTF_8)
|
70
|
+
end
|
71
|
+
|
72
|
+
value
|
69
73
|
end
|
70
74
|
end
|
71
75
|
end
|
data/test/data_loss_test.rb
CHANGED
@@ -33,8 +33,8 @@ class DataLossTest < Minitest::Test
|
|
33
33
|
end
|
34
34
|
|
35
35
|
def test_decimal_silently_changes_out_of_bound_values
|
36
|
-
maximum = BigDecimal
|
37
|
-
delta = BigDecimal
|
36
|
+
maximum = BigDecimal(10 ** (Unicorn.columns_hash['decimal'].precision - Unicorn.columns_hash['decimal'].scale))
|
37
|
+
delta = BigDecimal(10 ** -(Unicorn.columns_hash['decimal'].scale), Unicorn.columns_hash['decimal'].precision)
|
38
38
|
|
39
39
|
refute_data_loss Unicorn.new(decimal: maximum - delta)
|
40
40
|
assert_data_loss Unicorn.new(decimal: maximum)
|
@@ -42,8 +42,8 @@ class DataLossTest < Minitest::Test
|
|
42
42
|
assert_data_loss Unicorn.new(decimal: 0 - maximum)
|
43
43
|
|
44
44
|
|
45
|
-
maximum = BigDecimal
|
46
|
-
delta = BigDecimal
|
45
|
+
maximum = BigDecimal(10 ** (Unicorn.columns_hash['unsigned_decimal'].precision - Unicorn.columns_hash['unsigned_decimal'].scale))
|
46
|
+
delta = BigDecimal(10 ** -(Unicorn.columns_hash['unsigned_decimal'].scale), Unicorn.columns_hash['unsigned_decimal'].precision)
|
47
47
|
|
48
48
|
refute_data_loss Unicorn.new(unsigned_decimal: maximum - delta)
|
49
49
|
assert_data_loss Unicorn.new(unsigned_decimal: maximum)
|
@@ -99,7 +99,7 @@ class DataLossTest < Minitest::Test
|
|
99
99
|
end
|
100
100
|
|
101
101
|
def test_utf8mb3_field_sliently_truncates_strings_after_first_4byte_character
|
102
|
-
emoji =
|
102
|
+
emoji = "\u{1F4A9}"
|
103
103
|
assert_equal 1, emoji.length
|
104
104
|
assert_equal 4, emoji.bytesize
|
105
105
|
assert_data_loss Unicorn.new(string: emoji)
|
@@ -98,7 +98,7 @@ class DatabaseConstraintsValidatorTest < Minitest::Test
|
|
98
98
|
assert_equal 1, subvalidators.length
|
99
99
|
assert_kind_of ActiveModel::Validations::BytesizeValidator, subvalidators.first
|
100
100
|
assert_equal 65535, subvalidators.first.options[:maximum]
|
101
|
-
|
101
|
+
assert_nil subvalidators.first.encoding
|
102
102
|
end
|
103
103
|
|
104
104
|
def test_not_null_text_field_defines_requested_bytesize_validator_and_unicode_validator
|
@@ -120,7 +120,7 @@ class DatabaseConstraintsValidatorTest < Minitest::Test
|
|
120
120
|
|
121
121
|
def test_should_not_create_a_validator_for_a_utf8mb4_field
|
122
122
|
assert Bar._validators[:mb4_string].first.attribute_validators(Bar, :mb4_string).empty?
|
123
|
-
emoji = Bar.new(mb4_string: '
|
123
|
+
emoji = Bar.new(mb4_string: '')
|
124
124
|
assert emoji.valid?
|
125
125
|
refute_data_loss emoji
|
126
126
|
end
|
@@ -214,7 +214,7 @@ class DatabaseConstraintsValidatorTest < Minitest::Test
|
|
214
214
|
end
|
215
215
|
|
216
216
|
def test_error_messages
|
217
|
-
foo = Foo.new(string: 'ü' * 41, checked: nil, not_null_text:
|
217
|
+
foo = Foo.new(string: 'ü' * 41, checked: nil, not_null_text: "\u{1F4A9}")
|
218
218
|
refute foo.save
|
219
219
|
|
220
220
|
assert_equal ["is too long (maximum is 40 characters)"], foo.errors[:string]
|
@@ -14,7 +14,7 @@ class VarcharDefaultSizeTest < Minitest::Test
|
|
14
14
|
ActiveRecord::Migration.add_index(:varchars, :string, unique: true)
|
15
15
|
end
|
16
16
|
|
17
|
-
assert_match
|
18
|
-
assert_equal
|
17
|
+
assert_match(/\Autf8mb4_/, Varchar.columns_hash['string'].collation)
|
18
|
+
assert_equal(191, Varchar.columns_hash['string'].limit)
|
19
19
|
end
|
20
20
|
end
|
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.
|
4
|
+
version: 0.5.0
|
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:
|
11
|
+
date: 2019-10-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '5.
|
19
|
+
version: '5.2'
|
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: '5.
|
26
|
+
version: '5.2'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: rejectu
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -110,10 +110,8 @@ files:
|
|
110
110
|
- README.md
|
111
111
|
- Rakefile
|
112
112
|
- activerecord-databasevalidations.gemspec
|
113
|
-
- gemfiles/Gemfile.activerecord-edge
|
114
|
-
- gemfiles/Gemfile.activerecord50
|
115
|
-
- gemfiles/Gemfile.activerecord51
|
116
113
|
- gemfiles/Gemfile.activerecord52
|
114
|
+
- gemfiles/Gemfile.activerecord60
|
117
115
|
- lib/active_model/validations/basic_multilingual_plane.rb
|
118
116
|
- lib/active_model/validations/bytesize.rb
|
119
117
|
- lib/active_model/validations/not_null.rb
|
@@ -149,15 +147,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
149
147
|
requirements:
|
150
148
|
- - ">="
|
151
149
|
- !ruby/object:Gem::Version
|
152
|
-
version: 2.
|
150
|
+
version: '2.5'
|
153
151
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
154
152
|
requirements:
|
155
153
|
- - ">="
|
156
154
|
- !ruby/object:Gem::Version
|
157
155
|
version: '0'
|
158
156
|
requirements: []
|
159
|
-
|
160
|
-
rubygems_version: 2.7.6
|
157
|
+
rubygems_version: 3.0.4
|
161
158
|
signing_key:
|
162
159
|
specification_version: 4
|
163
160
|
summary: Add validations to your ActiveRecord models based on MySQL database constraints.
|