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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: aeb9fa64fe237e89b17e1f7e7cc9019ed6e16c92
4
- data.tar.gz: b7efe30384468425e438904a4670ad852412df3b
3
+ metadata.gz: 8999070427c2a970512966469469db85bf257c57
4
+ data.tar.gz: a046eb206c0cf82a467ed08c725644007b9ce57b
5
5
  SHA512:
6
- metadata.gz: 420b1b6dd7603ba7a604f6e93f0ca68f05b88fb64d43427079c3cd05dcb1ad0cfb55aedec7a859c710f809028c36cb32b4942b5c646a78af8258cf343791d55e
7
- data.tar.gz: 69f7e812f395c42f69b0fc1dda70744ad92c7649977aa7a8ee758bbfdfa62c9e6d0ee5fd8cad2ac80c5daca58e930333673b5472690c2a24715edf95f155a491
6
+ metadata.gz: 427c779f06110f0a377bd40377e09bdcbdbb1681d58b1ebfba957e5586eaf9f33473e8ca5306ec481d3e4677fbd8a79865af3204779de65af84a91618548e449
7
+ data.tar.gz: '05518682e31a3fb8c7e37023c854284fef7e69b3d2f348dc00a5c1d5b1de23bfe58c02b3ddc6fca0453d461699fa5d25491c7e5ebd6b2a87a2a2912ed578db36'
@@ -1,4 +1,4 @@
1
1
  source 'https://rubygems.org'
2
2
  gemspec
3
3
 
4
- gem 'activerecord', github: 'rails/rails'
4
+ gem 'activerecord', '~> 5.0.0'
@@ -1,5 +1,5 @@
1
1
  module ActiveRecord
2
2
  module DatabaseValidations
3
- VERSION = "0.3.0"
3
+ VERSION = "0.3.1"
4
4
  end
5
5
  end
@@ -63,8 +63,13 @@ module ActiveRecord
63
63
 
64
64
  def attribute_validators(klass, attribute)
65
65
  @constraint_validators[attribute] ||= begin
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)
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.0
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-05-16 00:00:00.000000000 Z
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.11
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.