valhammer 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/valhammer/validations.rb +7 -5
- data/lib/valhammer/version.rb +1 -1
- data/spec/lib/valhammer/validations_spec.rb +10 -7
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: db1cabb3ee1b18be9f92f9853620457505b28313
|
4
|
+
data.tar.gz: 7f793f56fd7cc961824d3239bad6a0ad05cf05b9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e173041be8467d80bbb59a922bfb08c3c46ed8028c80ec36ae24d59019c99d360247859872cb2c5d8c8d9069188b692610bf8a4674434b61dbb17ef23380ea30
|
7
|
+
data.tar.gz: 1cd7c99c9d11dbcd3f43810c0be4f650d74b08764afb4c400a4872d6e0fce61a9a1ce9d8434b42f3cfcd89856dde43f4671a2313e706017a0086ed0d941f21b4
|
@@ -9,7 +9,7 @@ module Valhammer
|
|
9
9
|
private_constant :VALHAMMER_DEFAULT_OPTS, :VALHAMMER_EXCLUDED_FIELDS
|
10
10
|
|
11
11
|
def valhammer(opts = {})
|
12
|
-
@valhammer_indexes
|
12
|
+
@valhammer_indexes = connection.indexes(table_name)
|
13
13
|
opts = VALHAMMER_DEFAULT_OPTS.merge(opts)
|
14
14
|
columns_hash.each do |name, column|
|
15
15
|
valhammer_validate(name, column, opts)
|
@@ -56,7 +56,7 @@ module Valhammer
|
|
56
56
|
def valhammer_inclusion(validations, column, opts)
|
57
57
|
return unless opts[:inclusion] && column.type == :boolean
|
58
58
|
|
59
|
-
validations[:inclusion] = { in: [false, true], allow_nil:
|
59
|
+
validations[:inclusion] = { in: [false, true], allow_nil: true }
|
60
60
|
end
|
61
61
|
|
62
62
|
def valhammer_unique(validations, column, opts)
|
@@ -69,7 +69,9 @@ module Valhammer
|
|
69
69
|
return unless unique_keys.one?
|
70
70
|
|
71
71
|
scope = unique_keys.first.columns[0..-2]
|
72
|
-
|
72
|
+
|
73
|
+
opts = validations[:uniqueness] = { allow_nil: true }
|
74
|
+
opts[:scope] = scope if scope.any?
|
73
75
|
end
|
74
76
|
|
75
77
|
def valhammer_numeric(validations, column, opts)
|
@@ -78,10 +80,10 @@ module Valhammer
|
|
78
80
|
case column.type
|
79
81
|
when :integer
|
80
82
|
validations[:numericality] = { only_integer: true,
|
81
|
-
allow_nil:
|
83
|
+
allow_nil: true }
|
82
84
|
when :decimal
|
83
85
|
validations[:numericality] = { only_integer: false,
|
84
|
-
allow_nil:
|
86
|
+
allow_nil: true }
|
85
87
|
end
|
86
88
|
end
|
87
89
|
|
data/lib/valhammer/version.rb
CHANGED
@@ -38,7 +38,7 @@ RSpec.describe Valhammer::Validations do
|
|
38
38
|
end
|
39
39
|
|
40
40
|
context 'with a non-nullable boolean' do
|
41
|
-
let(:opts) { { in: [false, true], allow_nil:
|
41
|
+
let(:opts) { { in: [false, true], allow_nil: true } }
|
42
42
|
|
43
43
|
it { is_expected.to include(a_validator_for(:injected, :inclusion, opts)) }
|
44
44
|
end
|
@@ -88,7 +88,9 @@ RSpec.describe Valhammer::Validations do
|
|
88
88
|
context 'with a composite unique index' do
|
89
89
|
subject { Capability.validators }
|
90
90
|
|
91
|
-
let(:opts)
|
91
|
+
let(:opts) do
|
92
|
+
{ scope: ['organisation_id'], case_sensitive: true, allow_nil: true }
|
93
|
+
end
|
92
94
|
it { is_expected.to include(a_validator_for(:name, :uniqueness, opts)) }
|
93
95
|
end
|
94
96
|
|
@@ -101,13 +103,14 @@ RSpec.describe Valhammer::Validations do
|
|
101
103
|
end
|
102
104
|
|
103
105
|
context 'with an integer column' do
|
104
|
-
context 'with
|
106
|
+
context 'with a nullable column' do
|
105
107
|
let(:opts) { { only_integer: true, allow_nil: true } }
|
106
108
|
it { is_expected.to include(a_validator_for(:age, :numericality, opts)) }
|
107
109
|
end
|
108
|
-
|
109
|
-
|
110
|
-
|
110
|
+
|
111
|
+
context 'with a non-nullable column' do
|
112
|
+
let(:opts) { { only_integer: true, allow_nil: true } }
|
113
|
+
it 'allows a nil value in the numericality validator' do
|
111
114
|
expect(subject)
|
112
115
|
.to include(a_validator_for(:socialness, :numericality, opts))
|
113
116
|
end
|
@@ -115,7 +118,7 @@ RSpec.describe Valhammer::Validations do
|
|
115
118
|
end
|
116
119
|
|
117
120
|
context 'with a numeric column' do
|
118
|
-
let(:opts) { { only_integer: false, allow_nil:
|
121
|
+
let(:opts) { { only_integer: false, allow_nil: true } }
|
119
122
|
it { is_expected.to include(a_validator_for(:gpa, :numericality, opts)) }
|
120
123
|
end
|
121
124
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: valhammer
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Shaun Mangelsdorf
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-03-
|
11
|
+
date: 2015-03-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|