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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7bbc167cf3bd0b5da8157c01558742ba809d6efb
4
- data.tar.gz: 0e478898f5ce6d7f5338e03e0010d72179e4e06c
3
+ metadata.gz: db1cabb3ee1b18be9f92f9853620457505b28313
4
+ data.tar.gz: 7f793f56fd7cc961824d3239bad6a0ad05cf05b9
5
5
  SHA512:
6
- metadata.gz: d166959c57a0f15af70b4cedf85c51a8a41f676bb9fb9f8e656c1d00b7816a1685cd6b540343dce5619ed7238a5b37a7550f10a6c39014c0aee7cc6f5d59f8ec
7
- data.tar.gz: c135af6ebcfa1d6d9a1a8dca65f11f90ac37d6bff1ca0cf9deb223523f01a218af3244eebb706e42cb6390bf22675ed6d10ede83b6c0cb1cbe4594aded4e9570
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 ||= connection.indexes(table_name)
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: column.null }
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
- validations[:uniqueness] = scope.empty? ? true : { scope: scope }
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: column.null }
83
+ allow_nil: true }
82
84
  when :decimal
83
85
  validations[:numericality] = { only_integer: false,
84
- allow_nil: column.null }
86
+ allow_nil: true }
85
87
  end
86
88
  end
87
89
 
@@ -1,3 +1,3 @@
1
1
  module Valhammer
2
- VERSION = '0.1.0'
2
+ VERSION = '0.1.1'
3
3
  end
@@ -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: false } }
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) { { scope: ['organisation_id'], case_sensitive: true } }
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 allow_nil' do
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
- context 'without allow_nil' do
109
- let(:opts) { { only_integer: true, allow_nil: false } }
110
- it 'sets allow_nil to false for socialness' do
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: false } }
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.0
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-02 00:00:00.000000000 Z
11
+ date: 2015-03-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord