table_warnings 1.0.0 → 1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +10 -0
- data/lib/table_warnings.rb +3 -3
- data/lib/table_warnings/column.rb +1 -1
- data/lib/table_warnings/nonexistent_owner.rb +3 -3
- data/lib/table_warnings/size.rb +3 -3
- data/lib/table_warnings/version.rb +1 -1
- data/test/helper.rb +6 -5
- data/test/test_combinations.rb +1 -1
- data/test/test_warn_if_blanks.rb +17 -0
- data/test/test_warn_if_nonexistent_owner.rb +5 -5
- data/test/test_warn_if_nonexistent_owner_except.rb +5 -5
- data/test/{test_warn_if_nulls_in.rb → test_warn_if_nulls.rb} +4 -4
- data/test/test_warn_if_nulls_except.rb +6 -6
- data/test/test_warn_unless_size.rb +33 -0
- metadata +7 -3
data/CHANGELOG
CHANGED
data/lib/table_warnings.rb
CHANGED
@@ -37,11 +37,11 @@ module TableWarnings
|
|
37
37
|
pool = column_names.map do |column_name|
|
38
38
|
TableWarnings::Column.new self, column_name
|
39
39
|
end
|
40
|
-
|
40
|
+
exclusive_warnings = TableWarnings.registry.exclusive(self)
|
41
41
|
|
42
42
|
assignments = {}
|
43
43
|
# pass 1 - exclusives and covers
|
44
|
-
|
44
|
+
exclusive_warnings.each do |warning|
|
45
45
|
disposition = Disposition.new
|
46
46
|
disposition.exclusives = warning.exclusives pool
|
47
47
|
disposition.covers = warning.covers pool
|
@@ -55,7 +55,7 @@ module TableWarnings
|
|
55
55
|
end
|
56
56
|
end
|
57
57
|
# pass 2 - allow regexp matching, but only if somebody else didn't cover it
|
58
|
-
|
58
|
+
exclusive_warnings.each do |warning|
|
59
59
|
disposition = assignments[warning]
|
60
60
|
disposition.matches = warning.matches(pool).select do |match|
|
61
61
|
assignments.except(warning).none? { |_, other| other.covers.include?(match) }
|
@@ -9,9 +9,9 @@ module TableWarnings
|
|
9
9
|
def message(column)
|
10
10
|
if column.nonexistent_owners?(conditions) or (not allow_null? and column.nulls?(conditions))
|
11
11
|
if conditions.empty?
|
12
|
-
"
|
12
|
+
"Values in foreign key column #{column.name.inspect}#{null_warning} do not correspond to actual values in foreign table."
|
13
13
|
else
|
14
|
-
"
|
14
|
+
"Values in foreign key column #{column.name.inspect} under condition #{conditions.inspect}#{null_warning} do not correspond to actual values in foreign table."
|
15
15
|
end
|
16
16
|
end
|
17
17
|
end
|
@@ -24,7 +24,7 @@ module TableWarnings
|
|
24
24
|
|
25
25
|
def null_warning
|
26
26
|
if not allow_null?
|
27
|
-
' are
|
27
|
+
' are NULL and/or'
|
28
28
|
end
|
29
29
|
end
|
30
30
|
end
|
data/lib/table_warnings/size.rb
CHANGED
@@ -14,9 +14,9 @@ module TableWarnings
|
|
14
14
|
current_count = effective_count
|
15
15
|
unless allowed_size.include? current_count
|
16
16
|
if conditions.empty?
|
17
|
-
"
|
17
|
+
"Row count is expected to be #{allowed_size.to_s}, but is #{current_count}"
|
18
18
|
else
|
19
|
-
"
|
19
|
+
"Row count with conditions #{conditions.inspect} is expected to be #{allowed_size.to_s}, but is #{current_count}"
|
20
20
|
end
|
21
21
|
end
|
22
22
|
end
|
@@ -45,7 +45,7 @@ module TableWarnings
|
|
45
45
|
100_000..1_000_000
|
46
46
|
when :millions
|
47
47
|
1_000_000..1_000_000_000
|
48
|
-
when Range
|
48
|
+
when ::Range
|
49
49
|
approximate_size
|
50
50
|
when Numeric
|
51
51
|
approximate_size..approximate_size
|
data/test/helper.rb
CHANGED
@@ -67,7 +67,8 @@ class MiniTest::Spec
|
|
67
67
|
refute hits.many?, "#{model.name} had MULTIPLE warnings like #{expected_warning.inspect}: #{hits.inspect}"
|
68
68
|
end
|
69
69
|
|
70
|
-
def
|
70
|
+
def refute_warning(model, specific_unexpected_warning = nil)
|
71
|
+
raise if block_given?
|
71
72
|
warnings = model.table_warnings
|
72
73
|
if specific_unexpected_warning
|
73
74
|
refute(warnings.any? { |warning| warning =~ specific_unexpected_warning }, "#{model.name} unexpectedly had warning #{specific_unexpected_warning.inspect}")
|
@@ -79,7 +80,7 @@ class MiniTest::Spec
|
|
79
80
|
def assert_causes_warning(model, expected_warnings)
|
80
81
|
expected_warnings = [expected_warnings].flatten
|
81
82
|
expected_warnings.each do |expected_warning|
|
82
|
-
|
83
|
+
refute_warning model, expected_warning
|
83
84
|
end
|
84
85
|
warnings_before = model.table_warnings
|
85
86
|
yield
|
@@ -92,10 +93,10 @@ class MiniTest::Spec
|
|
92
93
|
refute unexpected_warnings.any?, "#{model.name} unexpectedly ALSO got warnings #{unexpected_warnings.inspect}"
|
93
94
|
end
|
94
95
|
|
95
|
-
def
|
96
|
-
|
96
|
+
def refute_causes_warning(model)
|
97
|
+
refute_warning model
|
97
98
|
yield
|
98
|
-
|
99
|
+
refute_warning model
|
99
100
|
end
|
100
101
|
|
101
102
|
end
|
data/test/test_combinations.rb
CHANGED
@@ -60,7 +60,7 @@ describe TableWarnings do
|
|
60
60
|
end
|
61
61
|
end
|
62
62
|
it "combines a positive regexp with conditions and a negative regexp with conditions" do
|
63
|
-
|
63
|
+
refute_causes_warning PetDelta do
|
64
64
|
PetDelta.force_create!
|
65
65
|
end
|
66
66
|
PetDelta.delete_all # !
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
class PetDoh < ActiveRecord::Base
|
4
|
+
col :gender
|
5
|
+
warn_if_blanks :gender
|
6
|
+
end
|
7
|
+
PetDoh.auto_upgrade!
|
8
|
+
|
9
|
+
describe TableWarnings do
|
10
|
+
describe :warn_if_nulls do
|
11
|
+
it "takes a single column" do
|
12
|
+
assert_causes_warning PetDoh, /blank.*gender/i do
|
13
|
+
PetDoh.force_create!
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -32,27 +32,27 @@ describe TableWarnings do
|
|
32
32
|
Person.force_create! :llc_name => 'My Small Business, LLC'
|
33
33
|
end
|
34
34
|
it "takes a single belongs-to association name" do
|
35
|
-
assert_causes_warning PetRed, /
|
35
|
+
assert_causes_warning PetRed, /handler.*do not correspond/i do
|
36
36
|
PetRed.force_create!
|
37
37
|
end
|
38
38
|
end
|
39
39
|
it "checks the value of foreign keys not just their presence" do
|
40
|
-
assert_causes_warning PetRed, /
|
40
|
+
assert_causes_warning PetRed, /handler.*do not correspond/i do
|
41
41
|
PetRed.force_create! :handler_id => 999999
|
42
42
|
end
|
43
43
|
end
|
44
44
|
it "doesn't raise false warnings" do
|
45
|
-
|
45
|
+
refute_causes_warning PetRed do
|
46
46
|
PetRed.force_create! :handler_id => Person.first.id
|
47
47
|
end
|
48
48
|
end
|
49
49
|
it "regards nulls as nonexistent even if the association primary key column contains nulls" do
|
50
|
-
assert_causes_warning PetBlue, /
|
50
|
+
assert_causes_warning PetBlue, /trainer.*do not correspond/i do
|
51
51
|
PetBlue.force_create!
|
52
52
|
end
|
53
53
|
end
|
54
54
|
it "allows nulls if explicitly requested" do
|
55
|
-
|
55
|
+
refute_causes_warning PetGreen do
|
56
56
|
PetGreen.force_create!
|
57
57
|
end
|
58
58
|
end
|
@@ -38,27 +38,27 @@ describe TableWarnings do
|
|
38
38
|
Gente.force_create! :llc_name => 'My Small Business, LLC'
|
39
39
|
end
|
40
40
|
it "takes a single belongs-to association name" do
|
41
|
-
assert_causes_warning PetRojo, /
|
41
|
+
assert_causes_warning PetRojo, /trainer.*do not correspond/i do
|
42
42
|
PetRojo.force_create!
|
43
43
|
end
|
44
44
|
end
|
45
45
|
it "checks the value of foreign keys not just their presence" do
|
46
|
-
assert_causes_warning PetRojo, /
|
46
|
+
assert_causes_warning PetRojo, /trainer.*do not correspond/i do
|
47
47
|
PetRojo.force_create! :trainer_id => 999999
|
48
48
|
end
|
49
49
|
end
|
50
50
|
it "doesn't raise false warnings" do
|
51
|
-
|
51
|
+
refute_causes_warning PetRojo do
|
52
52
|
PetRojo.force_create! :trainer_id => Gente.first.llc_name
|
53
53
|
end
|
54
54
|
end
|
55
55
|
it "regards nulls as nonexistent even if the association primary key column contains nulls" do
|
56
|
-
assert_causes_warning PetAzul, /
|
56
|
+
assert_causes_warning PetAzul, /handler.*do not correspond/i do
|
57
57
|
PetAzul.force_create!
|
58
58
|
end
|
59
59
|
end
|
60
60
|
it "allows nulls if explicitly requested" do
|
61
|
-
|
61
|
+
refute_causes_warning PetVerde do
|
62
62
|
PetVerde.force_create!
|
63
63
|
end
|
64
64
|
end
|
@@ -79,7 +79,7 @@ describe TableWarnings do
|
|
79
79
|
end
|
80
80
|
end
|
81
81
|
it "takes a single column and a condition" do
|
82
|
-
|
82
|
+
refute_causes_warning Pet5 do
|
83
83
|
Pet5.force_create!
|
84
84
|
end
|
85
85
|
assert_causes_warning Pet5, /null.*birthday/i do
|
@@ -87,7 +87,7 @@ describe TableWarnings do
|
|
87
87
|
end
|
88
88
|
end
|
89
89
|
it "takes multiple columns and a condition" do
|
90
|
-
|
90
|
+
refute_causes_warning Pet6 do
|
91
91
|
Pet6.force_create!
|
92
92
|
end
|
93
93
|
assert_causes_warning Pet6, [/null.*birthday/i, /null.*gender/i] do
|
@@ -95,7 +95,7 @@ describe TableWarnings do
|
|
95
95
|
end
|
96
96
|
end
|
97
97
|
it "takes a single regexp and a condition" do
|
98
|
-
|
98
|
+
refute_causes_warning Pet7 do
|
99
99
|
Pet7.force_create!
|
100
100
|
end
|
101
101
|
assert_causes_warning Pet7, /null.*birthday/i do
|
@@ -103,7 +103,7 @@ describe TableWarnings do
|
|
103
103
|
end
|
104
104
|
end
|
105
105
|
it "takes multiple regexps and a condition" do
|
106
|
-
|
106
|
+
refute_causes_warning Pet8 do
|
107
107
|
Pet8.force_create!
|
108
108
|
end
|
109
109
|
assert_causes_warning Pet8, [/null.*birthday/i, /null.*gender/i] do
|
@@ -70,7 +70,7 @@ describe TableWarnings do
|
|
70
70
|
end
|
71
71
|
end
|
72
72
|
it "takes multiple columns" do
|
73
|
-
|
73
|
+
refute_causes_warning PetB do
|
74
74
|
PetB.force_create!
|
75
75
|
end
|
76
76
|
end
|
@@ -80,12 +80,12 @@ describe TableWarnings do
|
|
80
80
|
end
|
81
81
|
end
|
82
82
|
it "takes multiple regexps" do
|
83
|
-
|
83
|
+
refute_causes_warning PetD do
|
84
84
|
PetD.force_create!
|
85
85
|
end
|
86
86
|
end
|
87
87
|
it "takes a single column and a condition" do
|
88
|
-
|
88
|
+
refute_causes_warning PetE do
|
89
89
|
PetE.force_create!
|
90
90
|
end
|
91
91
|
assert_causes_warning PetE, /null.*gender/i do
|
@@ -93,7 +93,7 @@ describe TableWarnings do
|
|
93
93
|
end
|
94
94
|
end
|
95
95
|
it "takes multiple columns and a condition" do
|
96
|
-
|
96
|
+
refute_causes_warning PetF do
|
97
97
|
PetF.force_create!
|
98
98
|
end
|
99
99
|
assert_causes_warning PetF, /null.*sire/i do
|
@@ -101,7 +101,7 @@ describe TableWarnings do
|
|
101
101
|
end
|
102
102
|
end
|
103
103
|
it "takes a single regexp and a condition" do
|
104
|
-
|
104
|
+
refute_causes_warning PetG do
|
105
105
|
PetG.force_create!
|
106
106
|
end
|
107
107
|
assert_causes_warning PetG, /null.*gender/i do
|
@@ -109,7 +109,7 @@ describe TableWarnings do
|
|
109
109
|
end
|
110
110
|
end
|
111
111
|
it "takes multiple regexps and a condition" do
|
112
|
-
|
112
|
+
refute_causes_warning PetH do
|
113
113
|
PetH.force_create!
|
114
114
|
end
|
115
115
|
assert_causes_warning PetH, /null.*sire/i do
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
class PetOdin < ActiveRecord::Base
|
4
|
+
warn_unless_size 0
|
5
|
+
end
|
6
|
+
PetOdin.auto_upgrade!
|
7
|
+
|
8
|
+
class PetDva < ActiveRecord::Base
|
9
|
+
warn_unless_size 0..1
|
10
|
+
end
|
11
|
+
PetDva.auto_upgrade!
|
12
|
+
|
13
|
+
describe TableWarnings do
|
14
|
+
describe :warn_unless_size do
|
15
|
+
it "takes an exact integer" do
|
16
|
+
assert_causes_warning PetOdin, /expected.*0/ do
|
17
|
+
PetOdin.force_create!
|
18
|
+
end
|
19
|
+
end
|
20
|
+
it "takes a range" do
|
21
|
+
refute_warning PetDva
|
22
|
+
|
23
|
+
refute_causes_warning PetDva do
|
24
|
+
PetDva.force_create!
|
25
|
+
end
|
26
|
+
|
27
|
+
assert_causes_warning PetDva, /expected.*0..1/ do
|
28
|
+
PetDva.force_create!
|
29
|
+
PetDva.force_create!
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: table_warnings
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -168,11 +168,13 @@ files:
|
|
168
168
|
- table_warnings.gemspec
|
169
169
|
- test/helper.rb
|
170
170
|
- test/test_combinations.rb
|
171
|
+
- test/test_warn_if_blanks.rb
|
171
172
|
- test/test_warn_if_nonexistent_owner.rb
|
172
173
|
- test/test_warn_if_nonexistent_owner_except.rb
|
174
|
+
- test/test_warn_if_nulls.rb
|
173
175
|
- test/test_warn_if_nulls_except.rb
|
174
|
-
- test/test_warn_if_nulls_in.rb
|
175
176
|
- test/test_warn_unless_range.rb
|
177
|
+
- test/test_warn_unless_size.rb
|
176
178
|
homepage: https://github.com/seamusabshere/table_warnings
|
177
179
|
licenses: []
|
178
180
|
post_install_message:
|
@@ -201,9 +203,11 @@ summary: It's called validations to remind people of per-record validations, but
|
|
201
203
|
test_files:
|
202
204
|
- test/helper.rb
|
203
205
|
- test/test_combinations.rb
|
206
|
+
- test/test_warn_if_blanks.rb
|
204
207
|
- test/test_warn_if_nonexistent_owner.rb
|
205
208
|
- test/test_warn_if_nonexistent_owner_except.rb
|
209
|
+
- test/test_warn_if_nulls.rb
|
206
210
|
- test/test_warn_if_nulls_except.rb
|
207
|
-
- test/test_warn_if_nulls_in.rb
|
208
211
|
- test/test_warn_unless_range.rb
|
212
|
+
- test/test_warn_unless_size.rb
|
209
213
|
has_rdoc:
|