table_warnings 0.0.7 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,67 @@
1
+ require 'helper'
2
+
3
+ class Gente < ActiveRecord::Base
4
+ col :llc_name
5
+ end
6
+ Gente.auto_upgrade!
7
+
8
+ class PetRojo < ActiveRecord::Base
9
+ col :handler_id, :type => :integer
10
+ col :trainer_id
11
+ belongs_to :handler, :class_name => 'Gente'
12
+ belongs_to :trainer, :class_name => 'Gente', :primary_key => :llc_name
13
+ warn_if_nonexistent_owner_except :handler
14
+ end
15
+ PetRojo.auto_upgrade!
16
+
17
+ class PetAzul < ActiveRecord::Base
18
+ col :handler_id, :type => :integer
19
+ col :trainer_id
20
+ belongs_to :handler, :class_name => 'Gente'
21
+ belongs_to :trainer, :class_name => 'Gente', :primary_key => :llc_name
22
+ warn_if_nonexistent_owner_except :trainer
23
+ end
24
+ PetAzul.auto_upgrade!
25
+
26
+ class PetVerde < ActiveRecord::Base
27
+ col :handler_id, :type => :integer
28
+ col :trainer_id
29
+ belongs_to :handler, :class_name => 'Gente'
30
+ belongs_to :trainer, :class_name => 'Gente', :primary_key => :llc_name
31
+ warn_if_nonexistent_owner_except :trainer, :allow_null => true
32
+ end
33
+ PetVerde.auto_upgrade!
34
+
35
+ describe TableWarnings do
36
+ describe :warn_if_nonexistent_owner_except do
37
+ before do
38
+ Gente.force_create! :llc_name => 'My Small Business, LLC'
39
+ end
40
+ it "takes a single belongs-to association name" do
41
+ assert_causes_warning PetRojo, /nonexistent.*trainer/i do
42
+ PetRojo.force_create!
43
+ end
44
+ end
45
+ it "checks the value of foreign keys not just their presence" do
46
+ assert_causes_warning PetRojo, /nonexistent.*trainer/i do
47
+ PetRojo.force_create! :trainer_id => 999999
48
+ end
49
+ end
50
+ it "doesn't raise false warnings" do
51
+ assert_does_not_cause_warning PetRojo do
52
+ PetRojo.force_create! :trainer_id => Gente.first.llc_name
53
+ end
54
+ end
55
+ it "regards nulls as nonexistent even if the association primary key column contains nulls" do
56
+ assert_causes_warning PetAzul, /nonexistent.*handler/i do
57
+ PetAzul.force_create!
58
+ end
59
+ end
60
+ it "allows nulls if explicitly requested" do
61
+ assert_does_not_cause_warning PetVerde do
62
+ PetVerde.force_create!
63
+ end
64
+ end
65
+
66
+ end
67
+ end
@@ -0,0 +1,120 @@
1
+ require 'helper'
2
+
3
+ class PetA < ActiveRecord::Base
4
+ col :birthday, :type => :datetime
5
+ col :gender
6
+ warn_if_nulls_except :birthday
7
+ end
8
+ PetA.auto_upgrade!
9
+
10
+ class PetB < ActiveRecord::Base
11
+ col :birthday, :type => :datetime
12
+ col :gender
13
+ warn_if_nulls_except :birthday, :gender
14
+ end
15
+ PetB.auto_upgrade!
16
+
17
+ class PetC < ActiveRecord::Base
18
+ col :birthday, :type => :datetime
19
+ col :gender
20
+ warn_if_nulls_except /irthda/
21
+ end
22
+ PetC.auto_upgrade!
23
+
24
+ class PetD < ActiveRecord::Base
25
+ col :birthday, :type => :datetime
26
+ col :gender
27
+ warn_if_nulls_except /irthda/, /ende/
28
+ end
29
+ PetD.auto_upgrade!
30
+
31
+ class PetE < ActiveRecord::Base
32
+ col :birthday, :type => :datetime
33
+ col :gender
34
+ col :certified, :type => :boolean
35
+ warn_if_nulls_except :birthday, :conditions => { :certified => true }
36
+ end
37
+ PetE.auto_upgrade!
38
+
39
+ class PetF < ActiveRecord::Base
40
+ col :birthday, :type => :datetime
41
+ col :gender
42
+ col :sire
43
+ col :certified, :type => :boolean
44
+ warn_if_nulls_except :birthday, :gender, :conditions => { :certified => true }
45
+ end
46
+ PetF.auto_upgrade!
47
+
48
+ class PetG < ActiveRecord::Base
49
+ col :birthday, :type => :datetime
50
+ col :gender
51
+ col :certified, :type => :boolean
52
+ warn_if_nulls_except /irthda/, :conditions => { :certified => true }
53
+ end
54
+ PetG.auto_upgrade!
55
+
56
+ class PetH < ActiveRecord::Base
57
+ col :birthday, :type => :datetime
58
+ col :gender
59
+ col :sire
60
+ col :certified, :type => :boolean
61
+ warn_if_nulls_except /irthda/, /ende/, :conditions => { :certified => true }
62
+ end
63
+ PetH.auto_upgrade!
64
+
65
+ describe TableWarnings do
66
+ describe :warn_if_nulls_except do
67
+ it "takes a single column" do
68
+ assert_causes_warning PetA, /null.*gender/i do
69
+ PetA.force_create!
70
+ end
71
+ end
72
+ it "takes multiple columns" do
73
+ assert_does_not_cause_warning PetB do
74
+ PetB.force_create!
75
+ end
76
+ end
77
+ it "takes a single regexp" do
78
+ assert_causes_warning PetC, /null.*gender/i do
79
+ PetC.force_create!
80
+ end
81
+ end
82
+ it "takes multiple regexps" do
83
+ assert_does_not_cause_warning PetD do
84
+ PetD.force_create!
85
+ end
86
+ end
87
+ it "takes a single column and a condition" do
88
+ assert_does_not_cause_warning PetE do
89
+ PetE.force_create!
90
+ end
91
+ assert_causes_warning PetE, /null.*gender/i do
92
+ PetE.force_create! :certified => true
93
+ end
94
+ end
95
+ it "takes multiple columns and a condition" do
96
+ assert_does_not_cause_warning PetF do
97
+ PetF.force_create!
98
+ end
99
+ assert_causes_warning PetF, /null.*sire/i do
100
+ PetF.force_create! :certified => true
101
+ end
102
+ end
103
+ it "takes a single regexp and a condition" do
104
+ assert_does_not_cause_warning PetG do
105
+ PetG.force_create!
106
+ end
107
+ assert_causes_warning PetG, /null.*gender/i do
108
+ PetG.force_create! :certified => true
109
+ end
110
+ end
111
+ it "takes multiple regexps and a condition" do
112
+ assert_does_not_cause_warning PetH do
113
+ PetH.force_create!
114
+ end
115
+ assert_causes_warning PetH, /null.*sire/i do
116
+ PetH.force_create! :certified => true
117
+ end
118
+ end
119
+ end
120
+ end
@@ -0,0 +1,114 @@
1
+ require 'helper'
2
+
3
+ class Pet1 < ActiveRecord::Base
4
+ col :birthday, :type => :datetime
5
+ warn_if_nulls :birthday
6
+ end
7
+ Pet1.auto_upgrade!
8
+
9
+ class Pet2 < ActiveRecord::Base
10
+ col :birthday, :type => :datetime
11
+ col :gender
12
+ warn_if_nulls :birthday, :gender
13
+ end
14
+ Pet2.auto_upgrade!
15
+
16
+ class Pet3 < ActiveRecord::Base
17
+ col :birthday, :type => :datetime
18
+ warn_if_nulls /irthda/
19
+ end
20
+ Pet3.auto_upgrade!
21
+
22
+ class Pet4 < ActiveRecord::Base
23
+ col :birthday, :type => :datetime
24
+ col :gender
25
+ warn_if_nulls /irthda/, /ende/
26
+ end
27
+ Pet4.auto_upgrade!
28
+
29
+ class Pet5 < ActiveRecord::Base
30
+ col :birthday, :type => :datetime
31
+ col :certified, :type => :boolean
32
+ warn_if_nulls :birthday, :conditions => { :certified => true }
33
+ end
34
+ Pet5.auto_upgrade!
35
+
36
+ class Pet6 < ActiveRecord::Base
37
+ col :birthday, :type => :datetime
38
+ col :gender
39
+ col :certified, :type => :boolean
40
+ warn_if_nulls :birthday, :gender, :conditions => { :certified => true }
41
+ end
42
+ Pet6.auto_upgrade!
43
+
44
+ class Pet7 < ActiveRecord::Base
45
+ col :birthday, :type => :datetime
46
+ col :certified, :type => :boolean
47
+ warn_if_nulls /irthda/, :conditions => { :certified => true }
48
+ end
49
+ Pet7.auto_upgrade!
50
+
51
+ class Pet8 < ActiveRecord::Base
52
+ col :birthday, :type => :datetime
53
+ col :gender
54
+ col :certified, :type => :boolean
55
+ warn_if_nulls /irthda/, /ende/, :conditions => { :certified => true }
56
+ end
57
+ Pet8.auto_upgrade!
58
+
59
+ describe TableWarnings do
60
+ describe :warn_if_nulls do
61
+ it "takes a single column" do
62
+ assert_causes_warning Pet1, /null.*birthday/i do
63
+ Pet1.force_create!
64
+ end
65
+ end
66
+ it "takes multiple columns" do
67
+ assert_causes_warning Pet2, [/null.*birthday/i, /null.*gender/i] do
68
+ Pet2.force_create!
69
+ end
70
+ end
71
+ it "takes a single regexp" do
72
+ assert_causes_warning Pet3, /null.*birthday/i do
73
+ Pet3.force_create!
74
+ end
75
+ end
76
+ it "takes multiple regexps" do
77
+ assert_causes_warning Pet4, [/null.*birthday/i, /null.*gender/i] do
78
+ Pet4.force_create!
79
+ end
80
+ end
81
+ it "takes a single column and a condition" do
82
+ assert_does_not_cause_warning Pet5 do
83
+ Pet5.force_create!
84
+ end
85
+ assert_causes_warning Pet5, /null.*birthday/i do
86
+ Pet5.force_create! :certified => true
87
+ end
88
+ end
89
+ it "takes multiple columns and a condition" do
90
+ assert_does_not_cause_warning Pet6 do
91
+ Pet6.force_create!
92
+ end
93
+ assert_causes_warning Pet6, [/null.*birthday/i, /null.*gender/i] do
94
+ Pet6.force_create! :certified => true
95
+ end
96
+ end
97
+ it "takes a single regexp and a condition" do
98
+ assert_does_not_cause_warning Pet7 do
99
+ Pet7.force_create!
100
+ end
101
+ assert_causes_warning Pet7, /null.*birthday/i do
102
+ Pet7.force_create! :certified => true
103
+ end
104
+ end
105
+ it "takes multiple regexps and a condition" do
106
+ assert_does_not_cause_warning Pet8 do
107
+ Pet8.force_create!
108
+ end
109
+ assert_causes_warning Pet8, [/null.*birthday/i, /null.*gender/i] do
110
+ Pet8.force_create! :certified => true
111
+ end
112
+ end
113
+ end
114
+ end
@@ -0,0 +1,18 @@
1
+ require 'helper'
2
+
3
+ class PetUno < ActiveRecord::Base
4
+ col :age, :type => :integer
5
+ # sad!
6
+ warn_unless_range :age, :min => 0, :max => 20
7
+ end
8
+ PetUno.auto_upgrade!
9
+
10
+ describe TableWarnings do
11
+ describe :warn_unless_range do
12
+ it "takes a single column and range" do
13
+ assert_causes_warning PetUno, /range.*age/i do
14
+ PetUno.force_create! :age => 100
15
+ end
16
+ end
17
+ end
18
+ 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: 0.0.7
4
+ version: 1.0.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-10-04 00:00:00.000000000Z
12
+ date: 2012-06-07 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activerecord
16
- requirement: &2154337840 !ruby/object:Gem::Requirement
16
+ requirement: !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,15 @@ dependencies:
21
21
  version: '0'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *2154337840
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
25
30
  - !ruby/object:Gem::Dependency
26
31
  name: activesupport
27
- requirement: &2154337420 !ruby/object:Gem::Requirement
32
+ requirement: !ruby/object:Gem::Requirement
28
33
  none: false
29
34
  requirements:
30
35
  - - ! '>='
@@ -32,10 +37,15 @@ dependencies:
32
37
  version: '0'
33
38
  type: :runtime
34
39
  prerelease: false
35
- version_requirements: *2154337420
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
36
46
  - !ruby/object:Gem::Dependency
37
47
  name: fastercsv
38
- requirement: &2154337000 !ruby/object:Gem::Requirement
48
+ requirement: !ruby/object:Gem::Requirement
39
49
  none: false
40
50
  requirements:
41
51
  - - ! '>='
@@ -43,10 +53,15 @@ dependencies:
43
53
  version: '0'
44
54
  type: :development
45
55
  prerelease: false
46
- version_requirements: *2154337000
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
47
62
  - !ruby/object:Gem::Dependency
48
- name: rake
49
- requirement: &2154336580 !ruby/object:Gem::Requirement
63
+ name: active_record_inline_schema
64
+ requirement: !ruby/object:Gem::Requirement
50
65
  none: false
51
66
  requirements:
52
67
  - - ! '>='
@@ -54,10 +69,15 @@ dependencies:
54
69
  version: '0'
55
70
  type: :development
56
71
  prerelease: false
57
- version_requirements: *2154336580
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
58
78
  - !ruby/object:Gem::Dependency
59
- name: mini_record-compat
60
- requirement: &2154336160 !ruby/object:Gem::Requirement
79
+ name: sqlite3
80
+ requirement: !ruby/object:Gem::Requirement
61
81
  none: false
62
82
  requirements:
63
83
  - - ! '>='
@@ -65,10 +85,31 @@ dependencies:
65
85
  version: '0'
66
86
  type: :development
67
87
  prerelease: false
68
- version_requirements: *2154336160
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ! '>='
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
69
94
  - !ruby/object:Gem::Dependency
70
- name: sqlite3
71
- requirement: &2154335740 !ruby/object:Gem::Requirement
95
+ name: minitest
96
+ requirement: !ruby/object:Gem::Requirement
97
+ none: false
98
+ requirements:
99
+ - - ! '>='
100
+ - !ruby/object:Gem::Version
101
+ version: '0'
102
+ type: :development
103
+ prerelease: false
104
+ version_requirements: !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - ! '>='
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ - !ruby/object:Gem::Dependency
111
+ name: minitest-reporters
112
+ requirement: !ruby/object:Gem::Requirement
72
113
  none: false
73
114
  requirements:
74
115
  - - ! '>='
@@ -76,7 +117,28 @@ dependencies:
76
117
  version: '0'
77
118
  type: :development
78
119
  prerelease: false
79
- version_requirements: *2154335740
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ none: false
122
+ requirements:
123
+ - - ! '>='
124
+ - !ruby/object:Gem::Version
125
+ version: '0'
126
+ - !ruby/object:Gem::Dependency
127
+ name: yard
128
+ requirement: !ruby/object:Gem::Requirement
129
+ none: false
130
+ requirements:
131
+ - - ! '>='
132
+ - !ruby/object:Gem::Version
133
+ version: '0'
134
+ type: :development
135
+ prerelease: false
136
+ version_requirements: !ruby/object:Gem::Requirement
137
+ none: false
138
+ requirements:
139
+ - - ! '>='
140
+ - !ruby/object:Gem::Version
141
+ version: '0'
80
142
  description: Validate an entire [ActiveRecord] table, checking for things like blank
81
143
  rows or total number of rows
82
144
  email:
@@ -86,19 +148,31 @@ extensions: []
86
148
  extra_rdoc_files: []
87
149
  files:
88
150
  - .gitignore
151
+ - CHANGELOG
89
152
  - Gemfile
90
153
  - README.rdoc
91
154
  - Rakefile
92
155
  - lib/table_warnings.rb
93
- - lib/table_warnings/config.rb
156
+ - lib/table_warnings/arbitrary.rb
157
+ - lib/table_warnings/blank.rb
158
+ - lib/table_warnings/column.rb
159
+ - lib/table_warnings/debug.rb
160
+ - lib/table_warnings/exclusive.rb
161
+ - lib/table_warnings/nonexistent_owner.rb
162
+ - lib/table_warnings/null.rb
163
+ - lib/table_warnings/range.rb
164
+ - lib/table_warnings/registry.rb
165
+ - lib/table_warnings/scout.rb
166
+ - lib/table_warnings/size.rb
94
167
  - lib/table_warnings/version.rb
95
- - lib/table_warnings/warning.rb
96
- - lib/table_warnings/warning/arbitrary.rb
97
- - lib/table_warnings/warning/blank.rb
98
- - lib/table_warnings/warning/size.rb
99
168
  - table_warnings.gemspec
100
169
  - test/helper.rb
101
- - test/test_table_warnings.rb
170
+ - test/test_combinations.rb
171
+ - test/test_warn_if_nonexistent_owner.rb
172
+ - test/test_warn_if_nonexistent_owner_except.rb
173
+ - test/test_warn_if_nulls_except.rb
174
+ - test/test_warn_if_nulls_in.rb
175
+ - test/test_warn_unless_range.rb
102
176
  homepage: https://github.com/seamusabshere/table_warnings
103
177
  licenses: []
104
178
  post_install_message:
@@ -119,11 +193,17 @@ required_rubygems_version: !ruby/object:Gem::Requirement
119
193
  version: '0'
120
194
  requirements: []
121
195
  rubyforge_project: table_warnings
122
- rubygems_version: 1.8.6
196
+ rubygems_version: 1.8.24
123
197
  signing_key:
124
198
  specification_version: 3
125
199
  summary: It's called validations to remind people of per-record validations, but it
126
200
  works on the table, and is meant to be used after a table is completely populated.
127
201
  test_files:
128
202
  - test/helper.rb
129
- - test/test_table_warnings.rb
203
+ - test/test_combinations.rb
204
+ - test/test_warn_if_nonexistent_owner.rb
205
+ - test/test_warn_if_nonexistent_owner_except.rb
206
+ - test/test_warn_if_nulls_except.rb
207
+ - test/test_warn_if_nulls_in.rb
208
+ - test/test_warn_unless_range.rb
209
+ has_rdoc: