activerecord-databasevalidations 0.3.0 → 0.3.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 +4 -4
- data/Gemfile.activerecord50 +1 -1
- data/lib/active_record/database_validations/version.rb +1 -1
- data/lib/active_record/validations/database_constraints.rb +7 -2
- data/test/basic_multilingual_plane_validator_test.rb +11 -0
- data/test/database_constraints_validator_test.rb +13 -0
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8999070427c2a970512966469469db85bf257c57
|
4
|
+
data.tar.gz: a046eb206c0cf82a467ed08c725644007b9ce57b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 427c779f06110f0a377bd40377e09bdcbdbb1681d58b1ebfba957e5586eaf9f33473e8ca5306ec481d3e4677fbd8a79865af3204779de65af84a91618548e449
|
7
|
+
data.tar.gz: '05518682e31a3fb8c7e37023c854284fef7e69b3d2f348dc00a5c1d5b1de23bfe58c02b3ddc6fca0453d461699fa5d25491c7e5ebd6b2a87a2a2912ed578db36'
|
data/Gemfile.activerecord50
CHANGED
@@ -63,8 +63,13 @@ module ActiveRecord
|
|
63
63
|
|
64
64
|
def attribute_validators(klass, attribute)
|
65
65
|
@constraint_validators[attribute] ||= begin
|
66
|
-
|
67
|
-
|
66
|
+
column_definition = klass.columns_hash[attribute.to_s]
|
67
|
+
|
68
|
+
unless column_definition
|
69
|
+
raise ArgumentError.new("Model #{klass.name} does not have column #{attribute.to_s}!")
|
70
|
+
end
|
71
|
+
|
72
|
+
column = ActiveRecord::Validations::TypedColumn.new(column_definition)
|
68
73
|
|
69
74
|
[
|
70
75
|
not_null_validator(klass, column),
|
@@ -40,4 +40,15 @@ class BasicMultilingualPlaneValidatorTest < Minitest::Test
|
|
40
40
|
@model.unicode = 'ü'.encode('ISO-8859-15')
|
41
41
|
assert @model.valid?
|
42
42
|
end
|
43
|
+
|
44
|
+
def test_utf8mb3_japanese
|
45
|
+
@model.unicode = 'これは普通なストリングです'
|
46
|
+
assert @model.valid?
|
47
|
+
end
|
48
|
+
|
49
|
+
def test_utf8mb4_kanji
|
50
|
+
@model.unicode = '𠜎𠜱𠝹𠱓𠱸𠲖𠳏𠳕𠴕𠵼𠵿𠸎𠸏𠹷'
|
51
|
+
assert @model.invalid?
|
52
|
+
assert_equal ["contains characters outside Unicode's basic multilingual plane"], @model.errors[:unicode]
|
53
|
+
end
|
43
54
|
end
|
@@ -17,6 +17,8 @@ ActiveRecord::Migration.suppress_messages do
|
|
17
17
|
t.string :mb4_string
|
18
18
|
end
|
19
19
|
|
20
|
+
ActiveRecord::Migration.create_table("empties", force: true)
|
21
|
+
|
20
22
|
ActiveRecord::Migration.create_table("nums", force: true) do |t|
|
21
23
|
t.column :decimal, "DECIMAL(5,2)"
|
22
24
|
t.column :unsigned_decimal, "DECIMAL(5,2) UNSIGNED"
|
@@ -39,6 +41,12 @@ class Bar < ActiveRecord::Base
|
|
39
41
|
validates :mb4_string, database_constraints: :basic_multilingual_plane
|
40
42
|
end
|
41
43
|
|
44
|
+
class Empty < ActiveRecord::Base
|
45
|
+
attr_accessor :not_a_column
|
46
|
+
|
47
|
+
validates(:not_a_column, database_constraints: [:size])
|
48
|
+
end
|
49
|
+
|
42
50
|
class Num < ActiveRecord::Base
|
43
51
|
validates :decimal, :unsigned_decimal, :tinyint, :smallint, :mediumint, :int, :bigint, :unsigned_int, database_constraints: :range
|
44
52
|
end
|
@@ -53,6 +61,11 @@ class DatabaseConstraintsValidatorTest < Minitest::Test
|
|
53
61
|
assert_raises(ArgumentError) { Bar.validates(:mb4_string, database_constraints: [:size, :bogus]) }
|
54
62
|
end
|
55
63
|
|
64
|
+
def test_column_validation
|
65
|
+
exception = assert_raises(ArgumentError) { Empty.new.valid? }
|
66
|
+
assert_equal "Model Empty does not have column not_a_column!", exception.message
|
67
|
+
end
|
68
|
+
|
56
69
|
def test_validators_are_defined
|
57
70
|
assert_kind_of ActiveRecord::Validations::DatabaseConstraintsValidator, Foo._validators[:string].first
|
58
71
|
assert_kind_of ActiveRecord::Validations::DatabaseConstraintsValidator, Foo._validators[:tinytext].first
|
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.3.
|
4
|
+
version: 0.3.1
|
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: 2017-
|
11
|
+
date: 2017-10-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|
@@ -164,7 +164,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
164
164
|
version: '0'
|
165
165
|
requirements: []
|
166
166
|
rubyforge_project:
|
167
|
-
rubygems_version: 2.6.
|
167
|
+
rubygems_version: 2.6.12
|
168
168
|
signing_key:
|
169
169
|
specification_version: 4
|
170
170
|
summary: Add validations to your ActiveRecord models based on MySQL database constraints.
|