data_checks 0.1.1 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +14 -0
- data/README.md +6 -0
- data/lib/data_checks/check_run.rb +1 -1
- data/lib/data_checks/config.rb +4 -0
- data/lib/data_checks/ensure_equal.rb +30 -0
- data/lib/data_checks/ensure_less.rb +3 -9
- data/lib/data_checks/ensure_more.rb +3 -9
- data/lib/data_checks/ensure_no.rb +2 -3
- data/lib/data_checks/version.rb +1 -1
- data/lib/data_checks.rb +1 -0
- data/lib/generators/data_checks/install_generator.rb +2 -6
- data/lib/generators/data_checks/templates/initializer.rb.tt +2 -1
- metadata +7 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6b83ce0d2930d4e168a3622d8e233cc2a77893062508a0babad2faf9ec5e3f58
|
4
|
+
data.tar.gz: 23cf5db0c7fcb99baa1c65f815c36c554c06e0e5523ee29ce5c2ce6b0a9a3743
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e53875e40ada24436d58f31c6aa8e2e2eba0030283efb3cec5fd9ba1fae466f2297094c40d35c36594fea5a702b3c1846d164458f837f63476894c2f993a4eb5
|
7
|
+
data.tar.gz: 27ab0bb74134ed8f1d23d49a2e47ab3e6b24c0a25f09f73f7be1fa1a8e320de36bad91a7c93f94cd8eb098a72af83e0c078117140d3696b6ab21ef0b1dfed42c
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,19 @@
|
|
1
1
|
## master (unreleased)
|
2
2
|
|
3
|
+
## 0.3.0 (2024-08-10)
|
4
|
+
|
5
|
+
- Drop support for older activerecord and ruby versions
|
6
|
+
|
7
|
+
## 0.2.0 (2023-11-09)
|
8
|
+
|
9
|
+
- Add `ensure_equal` check method
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
ensure_equal :featured_projects, to: 100 do
|
13
|
+
FeaturedProject.count
|
14
|
+
end
|
15
|
+
```
|
16
|
+
|
3
17
|
## 0.1.1 (2022-11-26)
|
4
18
|
|
5
19
|
- Do not prematurely load `ActiveRecord::Base`
|
data/README.md
CHANGED
@@ -4,6 +4,11 @@ This gem provides a small DSL to check your data for inconsistencies and anomali
|
|
4
4
|
|
5
5
|
[![Build Status](https://github.com/fatkodima/data_checks/actions/workflows/test.yml/badge.svg?branch=master)](https://github.com/fatkodima/data_checks/actions/workflows/test.yml)
|
6
6
|
|
7
|
+
## Requirements
|
8
|
+
|
9
|
+
- ruby 3.0+
|
10
|
+
- activerecord 7.0+
|
11
|
+
|
7
12
|
## Installation
|
8
13
|
|
9
14
|
Add this line to your application's Gemfile:
|
@@ -133,6 +138,7 @@ end
|
|
133
138
|
* `ensure_any` will check that the result of a given block is `> 0`
|
134
139
|
* `ensure_more` will check that the result of a given block is `>` than a given number or that it contains more than a given number of items
|
135
140
|
* `ensure_less` will check that the result of a given block is `<` than a given number or that it contains less than a given number of items
|
141
|
+
* `ensure_equal` will check that the result of a given block is `==` to the given number or that it contains a given number of items
|
136
142
|
|
137
143
|
```ruby
|
138
144
|
ensure_no :images_without_previews do
|
data/lib/data_checks/config.rb
CHANGED
@@ -0,0 +1,30 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module DataChecks
|
4
|
+
class EnsureEqual < Check
|
5
|
+
private
|
6
|
+
def handle_result(result)
|
7
|
+
expected = options.fetch(:to)
|
8
|
+
passing = true
|
9
|
+
count = 0
|
10
|
+
|
11
|
+
case result
|
12
|
+
when Numeric
|
13
|
+
if result != expected
|
14
|
+
passing = false
|
15
|
+
count = result
|
16
|
+
end
|
17
|
+
when Enumerable
|
18
|
+
count = result.size
|
19
|
+
if count != expected
|
20
|
+
passing = false
|
21
|
+
entries = result
|
22
|
+
end
|
23
|
+
else
|
24
|
+
raise ArgumentError, "Unsupported result: '#{result.class.name}' for 'ensure_equal'"
|
25
|
+
end
|
26
|
+
|
27
|
+
CheckResult.new(check: self, passing: passing, count: count, entries: entries)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -5,23 +5,17 @@ module DataChecks
|
|
5
5
|
private
|
6
6
|
def handle_result(result)
|
7
7
|
expected = options.fetch(:than)
|
8
|
-
passing = true
|
9
8
|
|
10
9
|
case result
|
11
10
|
when Numeric
|
12
11
|
count = result
|
13
|
-
|
14
|
-
|
15
|
-
end
|
16
|
-
when Enumerable, ActiveRecord::Relation
|
17
|
-
count = result.count
|
18
|
-
if count >= expected
|
19
|
-
passing = false
|
20
|
-
end
|
12
|
+
when Enumerable
|
13
|
+
count = result.size
|
21
14
|
else
|
22
15
|
raise ArgumentError, "Unsupported result: '#{result.class.name}' for 'ensure_less'"
|
23
16
|
end
|
24
17
|
|
18
|
+
passing = count < expected
|
25
19
|
CheckResult.new(check: self, passing: passing, count: count)
|
26
20
|
end
|
27
21
|
end
|
@@ -5,23 +5,17 @@ module DataChecks
|
|
5
5
|
private
|
6
6
|
def handle_result(result)
|
7
7
|
expected = options.fetch(:than)
|
8
|
-
passing = true
|
9
8
|
|
10
9
|
case result
|
11
10
|
when Numeric
|
12
11
|
count = result
|
13
|
-
|
14
|
-
|
15
|
-
end
|
16
|
-
when Enumerable, ActiveRecord::Relation
|
17
|
-
count = result.count
|
18
|
-
if count <= expected
|
19
|
-
passing = false
|
20
|
-
end
|
12
|
+
when Enumerable
|
13
|
+
count = result.size
|
21
14
|
else
|
22
15
|
raise ArgumentError, "Unsupported result: '#{result.class.name}' for 'ensure_more'"
|
23
16
|
end
|
24
17
|
|
18
|
+
passing = count > expected
|
25
19
|
CheckResult.new(check: self, passing: passing, count: count)
|
26
20
|
end
|
27
21
|
end
|
@@ -13,9 +13,8 @@ module DataChecks
|
|
13
13
|
passing = false
|
14
14
|
count = result
|
15
15
|
end
|
16
|
-
|
17
|
-
|
18
|
-
unless result.empty?
|
16
|
+
when Enumerable
|
17
|
+
unless result.to_a.empty? # loads records for ActiveRecord::Relation
|
19
18
|
passing = false
|
20
19
|
count = result.size
|
21
20
|
entries = result
|
data/lib/data_checks/version.rb
CHANGED
data/lib/data_checks.rb
CHANGED
@@ -10,7 +10,7 @@ module DataChecks
|
|
10
10
|
source_root File.expand_path("templates", __dir__)
|
11
11
|
|
12
12
|
def create_migration_file
|
13
|
-
migration_template("migration.rb", File.join(
|
13
|
+
migration_template("migration.rb", File.join(db_migrate_path, "install_data_checks.rb"))
|
14
14
|
end
|
15
15
|
|
16
16
|
def copy_initializer_file
|
@@ -19,11 +19,7 @@ module DataChecks
|
|
19
19
|
|
20
20
|
private
|
21
21
|
def start_after
|
22
|
-
self.class.next_migration_number(
|
23
|
-
end
|
24
|
-
|
25
|
-
def migrations_dir
|
26
|
-
ar_version >= 5.1 ? db_migrate_path : "db/migrate"
|
22
|
+
self.class.next_migration_number(db_migrate_path)
|
27
23
|
end
|
28
24
|
|
29
25
|
def ar_version
|
@@ -12,7 +12,8 @@ DataChecks.configure do
|
|
12
12
|
|
13
13
|
# ==> Configure checks
|
14
14
|
#
|
15
|
-
# Available checks are :ensure_no, :ensure_any, :ensure_more,
|
15
|
+
# Available checks are :ensure_no, :ensure_any, :ensure_more, :ensure_less,
|
16
|
+
# and :ensure_equal.
|
16
17
|
#
|
17
18
|
# ensure_no :users_without_emails do
|
18
19
|
# User.where(email: nil).count
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: data_checks
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- fatkodima
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2024-08-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '
|
19
|
+
version: '7.0'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '
|
26
|
+
version: '7.0'
|
27
27
|
description:
|
28
28
|
email:
|
29
29
|
- fatkodima123@gmail.com
|
@@ -39,6 +39,7 @@ files:
|
|
39
39
|
- lib/data_checks/check_result.rb
|
40
40
|
- lib/data_checks/check_run.rb
|
41
41
|
- lib/data_checks/config.rb
|
42
|
+
- lib/data_checks/ensure_equal.rb
|
42
43
|
- lib/data_checks/ensure_less.rb
|
43
44
|
- lib/data_checks/ensure_more.rb
|
44
45
|
- lib/data_checks/ensure_no.rb
|
@@ -73,14 +74,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
73
74
|
requirements:
|
74
75
|
- - ">="
|
75
76
|
- !ruby/object:Gem::Version
|
76
|
-
version:
|
77
|
+
version: 3.0.0
|
77
78
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
78
79
|
requirements:
|
79
80
|
- - ">="
|
80
81
|
- !ruby/object:Gem::Version
|
81
82
|
version: '0'
|
82
83
|
requirements: []
|
83
|
-
rubygems_version: 3.
|
84
|
+
rubygems_version: 3.4.19
|
84
85
|
signing_key:
|
85
86
|
specification_version: 4
|
86
87
|
summary: Regression testing for data
|