data_sanity 0.0.7 → 0.0.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/data_sanity/inspector.rb +2 -1
- data/lib/data_sanity/tasks.rb +2 -2
- data/lib/data_sanity/templates/data_sanity_criteria.yml +2 -5
- data/lib/data_sanity/version.rb +1 -1
- data/lib/data_sanity.rb +6 -4
- data/spec/data_sanity/inspector_spec.rb +17 -1
- data/spec/data_sanity/models/data_inspector_spec.rb +0 -1
- data/spec/support/helper.rb +8 -0
- data/spec/support/sample_app/db/schema.rb +1 -1
- metadata +3 -3
@@ -10,7 +10,7 @@ module DataSanity
|
|
10
10
|
@records_per_model = options[:records_per_model] || CONSIDERED_RECORDS
|
11
11
|
@models = load_models
|
12
12
|
file_path = "#{Rails.root}/config/data_sanity_criteria.yml"
|
13
|
-
@criteria = File.exists?(file_path) ? (YAML.load File.open(file_path).read) : false
|
13
|
+
@criteria = (File.exists?(file_path) ? (YAML.load File.open(file_path).read) : false) rescue false
|
14
14
|
end
|
15
15
|
|
16
16
|
def investigate
|
@@ -43,6 +43,7 @@ module DataSanity
|
|
43
43
|
|
44
44
|
def validate_criteria(model, criteria)
|
45
45
|
criteria.each do |attribute, values|
|
46
|
+
values = (model.select("DISTINCT(#{attribute})").collect(&attribute.to_sym)) if values.blank?
|
46
47
|
values.each do |value|
|
47
48
|
results = model.where(attribute.to_sym => value)
|
48
49
|
count = results.count
|
data/lib/data_sanity/tasks.rb
CHANGED
@@ -18,9 +18,9 @@ namespace :data_sanity do
|
|
18
18
|
end
|
19
19
|
|
20
20
|
desc 'Creating a sample criteria file'
|
21
|
-
task :
|
21
|
+
task :criteria do
|
22
22
|
Dir.chdir("#{Rails.root}") do
|
23
|
-
system "cp #{
|
23
|
+
system "cp #{SOURCE_PATH}/data_sanity/templates/data_sanity_criteria.yml #{Rails.root}/config/."
|
24
24
|
end
|
25
25
|
end
|
26
26
|
end
|
@@ -2,9 +2,6 @@
|
|
2
2
|
# This is a sample criteria.
|
3
3
|
# Start with Model Name and
|
4
4
|
#<Model Name>: # Criteria-Rule to be applied
|
5
|
-
# <field name>: #
|
6
|
-
#
|
7
|
-
# - 'Saju'
|
8
|
-
# - 'Taju'
|
9
|
-
# <age> # Anthing mentioned is considered for validations against all possible distinct values
|
5
|
+
# <field name>: ['Raju', 'kaju', 'Taju'] # Field is considered for validations against distinct values in array
|
6
|
+
# <age> # Field is considered for validations against all possible distinct values
|
10
7
|
############################################
|
data/lib/data_sanity/version.rb
CHANGED
data/lib/data_sanity.rb
CHANGED
@@ -1,6 +1,8 @@
|
|
1
1
|
require "rails"
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
require
|
6
|
-
require
|
3
|
+
SOURCE_PATH = File.dirname(__FILE__)
|
4
|
+
|
5
|
+
require SOURCE_PATH + "/data_sanity/inspector"
|
6
|
+
require SOURCE_PATH + "/data_sanity/railtie"
|
7
|
+
require SOURCE_PATH + "/data_sanity/models/data_inspector"
|
8
|
+
require SOURCE_PATH + "/data_sanity/version"
|
@@ -93,13 +93,29 @@ describe "DataSanity::Inspector" do
|
|
93
93
|
2.times { Person.new(:name => "Saju").save(:validate => false) }
|
94
94
|
2.times { Car.new(:name => "Santro").save(:validate => false) }
|
95
95
|
Person.new(:age => 20).save(:validate => false)
|
96
|
-
|
96
|
+
Car.new(:name => "800", :make => "Maruti", :color => "Black", :person => Person.first).save(:validate => false)
|
97
|
+
Car.new(:name => "Santro", :make => "HHH", :color => "NotAColor", :person => Person.last).save(:validate => false)
|
97
98
|
|
98
99
|
inspector.investigate
|
99
100
|
DataInspector.count.should == 3
|
100
101
|
DataInspector.all.collect(&:table_name).should == ["Car", "Person", "Person"]
|
101
102
|
end
|
102
103
|
|
104
|
+
it "should check all distinct values of field for which a criteria exists" do
|
105
|
+
update_data_sanity_criteria("Car:\n make")
|
106
|
+
inspector = DataSanity::Inspector.new(:validate => :random)
|
107
|
+
|
108
|
+
5.times { |i| Car.new(:name => "Car Name#{i}", :make => "Brand1").save(:validate => false) }
|
109
|
+
5.times { |i| Car.new(:name => "Car Name#{i}", :make => "Brand2").save(:validate => false) }
|
110
|
+
|
111
|
+
inspector.investigate
|
112
|
+
|
113
|
+
DataInspector.count.should == 2
|
114
|
+
DataInspector.all.collect(&:table_name).should == ["Car", "Car"]
|
115
|
+
Car.find(DataInspector.first.primary_key_value).make.should == "Brand1"
|
116
|
+
Car.find(DataInspector.last.primary_key_value).make.should == "Brand2"
|
117
|
+
end
|
118
|
+
|
103
119
|
after :each do
|
104
120
|
cleanup_data_sanity_criteria
|
105
121
|
end
|
data/spec/support/helper.rb
CHANGED
@@ -28,6 +28,14 @@ def setup_data_sanity_criteria
|
|
28
28
|
end
|
29
29
|
end
|
30
30
|
|
31
|
+
def update_data_sanity_criteria(criteria)
|
32
|
+
Dir.chdir("#{Rails.root}") do
|
33
|
+
file = File.open("config/data_sanity_criteria.yml", "w")
|
34
|
+
file << criteria
|
35
|
+
file.close
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
31
39
|
def cleanup_data_sanity_criteria
|
32
40
|
Dir.chdir("#{Rails.root}") do
|
33
41
|
system "rm config/data_sanity_criteria.yml"
|
@@ -10,7 +10,7 @@
|
|
10
10
|
#
|
11
11
|
# It's strongly recommended to check this file into your version control system.
|
12
12
|
|
13
|
-
ActiveRecord::Schema.define(:version =>
|
13
|
+
ActiveRecord::Schema.define(:version => 20111205065701) do
|
14
14
|
|
15
15
|
create_table "cars", :force => true do |t|
|
16
16
|
t.string "name"
|
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:
|
4
|
+
hash: 15
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
9
|
+
- 8
|
10
|
+
version: 0.0.8
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Habibullah, Rahul, Jigyasa, Jyotsna, Hephzibah, Garima
|