data_checks 0.1.1 → 0.2.0
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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +10 -0
- data/README.md +1 -0
- data/lib/data_checks/config.rb +4 -0
- data/lib/data_checks/ensure_equal.rb +31 -0
- data/lib/data_checks/ensure_less.rb +2 -8
- data/lib/data_checks/ensure_more.rb +2 -8
- data/lib/data_checks/ensure_no.rb +1 -1
- data/lib/data_checks/version.rb +1 -1
- data/lib/data_checks.rb +1 -0
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 990db04b3558c8b10439aa6af136f5415cffcfdf368ddd886db4c0c18b707896
|
4
|
+
data.tar.gz: 7acf51bdf1f5dc5b537577359257e33b110f0b2c3eb554ad8959eb25052c75c4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 337bc667143363ae190de87729e3fbf17b940ebdaa1cd7ee701ed8f83e80b8dda30eb7db0ebdccd81231587c297df9ac662bf1bac23b0fa3c37f2bf828e382a1
|
7
|
+
data.tar.gz: 0b00bc6ee4b76e30023a4da4d20e9c9afb5b5f0d91936cfb21f024be8773e06e78db513df6e3776540a53cce7e0188d5ae3a6e1d714442ee01772afa3282b9c4
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,15 @@
|
|
1
1
|
## master (unreleased)
|
2
2
|
|
3
|
+
## 0.2.0 (2023-11-09)
|
4
|
+
|
5
|
+
- Add `ensure_equal` check method
|
6
|
+
|
7
|
+
```ruby
|
8
|
+
ensure_equal :featured_projects, to: 100 do
|
9
|
+
FeaturedProject.count
|
10
|
+
end
|
11
|
+
```
|
12
|
+
|
3
13
|
## 0.1.1 (2022-11-26)
|
4
14
|
|
5
15
|
- Do not prematurely load `ActiveRecord::Base`
|
data/README.md
CHANGED
@@ -133,6 +133,7 @@ end
|
|
133
133
|
* `ensure_any` will check that the result of a given block is `> 0`
|
134
134
|
* `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
135
|
* `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
|
136
|
+
* `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
137
|
|
137
138
|
```ruby
|
138
139
|
ensure_no :images_without_previews do
|
data/lib/data_checks/config.rb
CHANGED
@@ -0,0 +1,31 @@
|
|
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
|
+
# In ActiveRecord <= 4.2 ActiveRecord::Relation is not an Enumerable!
|
18
|
+
when Enumerable, ActiveRecord::Relation
|
19
|
+
count = result.size
|
20
|
+
if count != expected
|
21
|
+
passing = false
|
22
|
+
entries = result
|
23
|
+
end
|
24
|
+
else
|
25
|
+
raise ArgumentError, "Unsupported result: '#{result.class.name}' for 'ensure_equal'"
|
26
|
+
end
|
27
|
+
|
28
|
+
CheckResult.new(check: self, passing: passing, count: count, entries: entries)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
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
|
-
if result >= expected
|
14
|
-
passing = false
|
15
|
-
end
|
16
12
|
when Enumerable, ActiveRecord::Relation
|
17
|
-
count = result.
|
18
|
-
if count >= expected
|
19
|
-
passing = false
|
20
|
-
end
|
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
|
-
if result <= expected
|
14
|
-
passing = false
|
15
|
-
end
|
16
12
|
when Enumerable, ActiveRecord::Relation
|
17
|
-
count = result.
|
18
|
-
if count <= expected
|
19
|
-
passing = false
|
20
|
-
end
|
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
|
@@ -15,7 +15,7 @@ module DataChecks
|
|
15
15
|
end
|
16
16
|
# In ActiveRecord <= 4.2 ActiveRecord::Relation is not an Enumerable!
|
17
17
|
when Enumerable, ActiveRecord::Relation
|
18
|
-
unless result.empty?
|
18
|
+
unless result.to_a.empty? # loads records for ActiveRecord::Relation
|
19
19
|
passing = false
|
20
20
|
count = result.size
|
21
21
|
entries = result
|
data/lib/data_checks/version.rb
CHANGED
data/lib/data_checks.rb
CHANGED
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.2.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: 2023-11-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|
@@ -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
|
@@ -80,7 +81,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
80
81
|
- !ruby/object:Gem::Version
|
81
82
|
version: '0'
|
82
83
|
requirements: []
|
83
|
-
rubygems_version: 3.
|
84
|
+
rubygems_version: 3.4.10
|
84
85
|
signing_key:
|
85
86
|
specification_version: 4
|
86
87
|
summary: Regression testing for data
|