data_sanity 0.1.5 → 0.1.6

Sign up to get free protection for your applications and to get access to all the features.
@@ -14,12 +14,18 @@ module DataSanity
14
14
  end
15
15
 
16
16
  def investigate
17
- @models.each do |model_string|
18
- model = model_string.constantize
19
- validate_all(model) if @all
20
- if @random
21
- validate_criteria(model, @criteria[model_string]) and return if @criteria && @criteria[model_string].present?
22
- validate_random(model)
17
+ if @all
18
+ @models.each do |model_string|
19
+ model = model_string.constantize
20
+ validate_all(model) if @all
21
+ end
22
+ elsif @criteria
23
+ @criteria.keys.each do |model|
24
+ validate_criteria(model.constantize, @criteria[model])
25
+ end
26
+ else
27
+ @models.each do |model_string|
28
+ validate_random(model_string.constantize)
23
29
  end
24
30
  end
25
31
  end
@@ -1,3 +1,3 @@
1
1
  module DataSanity
2
- VERSION = "0.1.5"
2
+ VERSION = "0.1.6"
3
3
  end
@@ -54,19 +54,19 @@ describe "DataSanity::Inspector" do
54
54
  DataInspector.first.primary_key_value.should == first_person.id.to_s
55
55
  YAML.load(DataInspector.first.validation_errors).should == first_person.errors.full_messages
56
56
  end
57
-
57
+
58
58
  it "should check for errors on the model and populate fields in DataInspector even if valid? raises exception" do
59
59
  inspector = DataSanity::Inspector.new
60
-
60
+
61
61
  exception = Exception.new
62
-
62
+
63
63
  booming_mock = mock(:person)
64
64
  booming_mock.should_receive(:valid?).and_raise(exception)
65
65
  Person.should_receive(:all).and_return([booming_mock])
66
66
 
67
67
  inspector.investigate
68
68
  DataInspector.count.should == 1
69
-
69
+
70
70
  YAML.load(DataInspector.first.validation_errors).should_not be_blank
71
71
  end
72
72
  end
@@ -121,8 +121,8 @@ describe "DataSanity::Inspector" do
121
121
  Car.new(:name => "Santro", :make => "HHH", :color => "NotAColor", :person => Person.last).save(:validate => false)
122
122
 
123
123
  inspector.investigate
124
- DataInspector.count.should == 3
125
- DataInspector.all.collect(&:table_name).should == ["Car", "Person", "Person"]
124
+ DataInspector.count.should == 2
125
+ DataInspector.all.collect(&:table_name).should == ["Person", "Person"]
126
126
  end
127
127
 
128
128
  it "should check all distinct values of field for which a criteria exists" do
@@ -144,14 +144,19 @@ describe "DataSanity::Inspector" do
144
144
  update_data_sanity_criteria(criteria_car_make)
145
145
  inspector = DataSanity::Inspector.new(:validate => "random", :records_per_model => "2")
146
146
 
147
- 5.times { |i| Car.new(:name => "Car Name#{i}", :make => "Brand1").save(:validate => false) }
148
- 5.times { |i| Car.new(:name => "Car Name#{i}", :make => "Brand2").save(:validate => false) }
147
+ Car.new(:name => "Car Name1", :make => "Brand1").save(:validate => false)
148
+ Car.new(:name => "Car Name2", :make => "Brand2").save(:validate => false)
149
+ Car.new(:name => "Car Name3", :make => "Brand1").save(:validate => false)
150
+ Car.new(:name => "Car Name4", :make => "Brand2").save(:validate => false)
151
+ Car.new(:name => "Car Name5", :make => "Brand1").save(:validate => false)
152
+ Car.new(:name => "Car Name6", :make => "Brand2").save(:validate => false)
153
+ Car.new(:name => "Car Name7", :make => "Brand3").save(:validate => false)
149
154
 
150
155
  inspector.investigate
151
156
 
152
- DataInspector.count.should == 4
153
- DataInspector.all.collect(&:table_name).should == ["Car", "Car", "Car", "Car"]
154
- Car.find(DataInspector.all.collect(&:primary_key_value)).collect(&:make).should == ["Brand1", "Brand1", "Brand2", "Brand2"]
157
+ DataInspector.count.should == 5
158
+ DataInspector.all.collect(&:table_name).uniq.should == ["Car"]
159
+ Car.find(DataInspector.all.collect(&:primary_key_value)).collect(&:make).sort.should == ["Brand1", "Brand1", "Brand2", "Brand2", "Brand3"]
155
160
  end
156
161
 
157
162
  it "should select minimum of records_per_model and records matching a criteria" do
@@ -166,6 +171,19 @@ describe "DataSanity::Inspector" do
166
171
  DataInspector.count.should == 4
167
172
  end
168
173
 
174
+ it "should be able to look at multiple criteria" do
175
+ update_data_sanity_criteria(criteria_multiple)
176
+ inspector = DataSanity::Inspector.new(:validate => "random", :records_per_model => "1")
177
+
178
+ 2.times { |i| Car.new(:name => "Car Name#{i}", :make => "Brand1").save(:validate => false) }
179
+ 2.times { Person.new(:name => "Saju").save(:validate => false) }
180
+
181
+ inspector.investigate
182
+
183
+ DataInspector.count.should == 2
184
+ DataInspector.all.collect(&:table_name).sort.should == ["Person", "Car"].sort
185
+ end
186
+
169
187
  after :each do
170
188
  cleanup_data_sanity_criteria
171
189
  end
@@ -182,4 +200,9 @@ describe "DataSanity::Inspector" do
182
200
  make"
183
201
  end
184
202
 
203
+ def criteria_multiple
204
+ "Car:
205
+ Person:"
206
+ end
207
+
185
208
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: data_sanity
3
3
  version: !ruby/object:Gem::Version
4
- hash: 17
4
+ hash: 23
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 1
9
- - 5
10
- version: 0.1.5
9
+ - 6
10
+ version: 0.1.6
11
11
  platform: ruby
12
12
  authors:
13
13
  - Habibullah, Rahul, Jigyasa, Jyotsna, Hephzibah, Garima
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2012-04-10 00:00:00 Z
18
+ date: 2012-04-13 00:00:00 Z
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
21
  name: rails