fbe 0.30.0 → 0.31.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/fbe.gemspec +1 -1
- data/lib/fbe/conclude.rb +27 -10
- data/lib/fbe.rb +1 -1
- metadata +1 -31
- data/renovate.json +0 -6
- data/test/fbe/middleware/test_formatter.rb +0 -104
- data/test/fbe/middleware/test_rate_limit.rb +0 -152
- data/test/fbe/middleware/test_sqlite_store.rb +0 -446
- data/test/fbe/middleware/test_trace.rb +0 -168
- data/test/fbe/test_award.rb +0 -126
- data/test/fbe/test_bylaws.rb +0 -111
- data/test/fbe/test_conclude.rb +0 -172
- data/test/fbe/test_copy.rb +0 -39
- data/test/fbe/test_delete.rb +0 -117
- data/test/fbe/test_delete_one.rb +0 -56
- data/test/fbe/test_enter.rb +0 -35
- data/test/fbe/test_fb.rb +0 -102
- data/test/fbe/test_github_graph.rb +0 -169
- data/test/fbe/test_if_absent.rb +0 -107
- data/test/fbe/test_issue.rb +0 -26
- data/test/fbe/test_iterate.rb +0 -253
- data/test/fbe/test_just_one.rb +0 -33
- data/test/fbe/test_kill_if.rb +0 -39
- data/test/fbe/test_octo.rb +0 -791
- data/test/fbe/test_overwrite.rb +0 -103
- data/test/fbe/test_pmp.rb +0 -34
- data/test/fbe/test_regularly.rb +0 -27
- data/test/fbe/test_repeatedly.rb +0 -31
- data/test/fbe/test_sec.rb +0 -21
- data/test/fbe/test_tombstone.rb +0 -56
- data/test/fbe/test_unmask_repos.rb +0 -66
- data/test/fbe/test_who.rb +0 -25
- data/test/test__helper.rb +0 -45
- data/test/test_fbe.rb +0 -17
data/test/fbe/test_award.rb
DELETED
@@ -1,126 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
# SPDX-FileCopyrightText: Copyright (c) 2024-2025 Zerocracy
|
4
|
-
# SPDX-License-Identifier: MIT
|
5
|
-
|
6
|
-
require 'loog'
|
7
|
-
require_relative '../../lib/fbe/award'
|
8
|
-
require_relative '../test__helper'
|
9
|
-
|
10
|
-
# Test.
|
11
|
-
# Author:: Yegor Bugayenko (yegor256@gmail.com)
|
12
|
-
# Copyright:: Copyright (c) 2024 Yegor Bugayenko
|
13
|
-
# License:: MIT
|
14
|
-
class TestAward < Fbe::Test
|
15
|
-
def test_simple
|
16
|
-
a = Fbe::Award.new(
|
17
|
-
'
|
18
|
-
(award
|
19
|
-
(explain "When a bug is resolved by the person who was assigned to it, a reward is granted to this person")
|
20
|
-
(in hours "hours passed between bug reported and closed")
|
21
|
-
(let max 36)
|
22
|
-
(let basis 30)
|
23
|
-
(give basis "as a basis")
|
24
|
-
(let fee 10)
|
25
|
-
(aka
|
26
|
-
(set b1
|
27
|
-
(if
|
28
|
-
(and
|
29
|
-
(lt hours max)
|
30
|
-
(not (eq hours 0)))
|
31
|
-
fee 0))
|
32
|
-
(give b1 "for resolving the bug in ${hours} (<${max}) hours")
|
33
|
-
"add ${+fee} if it was resolved in less than ${max} hours")
|
34
|
-
(set days (div hours 24))
|
35
|
-
(set b2 (times days -1))
|
36
|
-
(let worst -20)
|
37
|
-
(set b2 (max b2 worst))
|
38
|
-
(let at_least -5)
|
39
|
-
(set b2 (if (lt b2 at_least) b2 0))
|
40
|
-
(set b2 (between b2 3 120))
|
41
|
-
(give b2 "for holding the bug open for too long (${days} days)"))
|
42
|
-
',
|
43
|
-
judge: '', global: {}, loog: Loog::NULL, options: nil
|
44
|
-
)
|
45
|
-
b = a.bill(hours: 10)
|
46
|
-
assert_operator(b.points, :<=, 100)
|
47
|
-
assert_operator(b.points, :>=, 5)
|
48
|
-
assert_equal(40, b.points)
|
49
|
-
g = b.greeting
|
50
|
-
[
|
51
|
-
'You\'ve earned +40 points for this',
|
52
|
-
'+10 for resolving the bug in 10',
|
53
|
-
'bug in 10 (<36) hours',
|
54
|
-
'+30 as a basis'
|
55
|
-
].each { |t| assert_includes(g, t, g) }
|
56
|
-
md = a.bylaw.markdown
|
57
|
-
[
|
58
|
-
'First, assume that _hours_ is hours',
|
59
|
-
', and award _b₂_'
|
60
|
-
].each { |t| assert_includes(md, t, md) }
|
61
|
-
end
|
62
|
-
|
63
|
-
def test_some_terms
|
64
|
-
{
|
65
|
-
'(let x 25)' => 0,
|
66
|
-
'(award (give (times 5 0.25 "fun")))' => 1,
|
67
|
-
'(award (give 25 "for being a good boy"))' => 25,
|
68
|
-
'(award (give (between 42 -10 -50) "empty"))' => -10,
|
69
|
-
'(award (give (between -3 -10 -50) "empty"))' => 0,
|
70
|
-
'(award (give (between -100 -50 -10) "empty"))' => -50
|
71
|
-
}.each do |q, v|
|
72
|
-
a = Fbe::Award.new(q)
|
73
|
-
assert_equal(v, a.bill.points, q)
|
74
|
-
end
|
75
|
-
end
|
76
|
-
|
77
|
-
def test_some_greetings
|
78
|
-
{
|
79
|
-
'(award (give (times 7 0.25 "fun")))' => 'You\'ve earned +2 points. ',
|
80
|
-
'(award (give (times 5 0.25 "fun")))' => 'You\'ve earned +1 points. ',
|
81
|
-
'(award (give 25 "for being a good boy"))' => 'You\'ve earned +25 points. ',
|
82
|
-
'(award (let x 0.1) (set b (times x 14)) (give b "fun"))' => 'You\'ve earned +1 points. '
|
83
|
-
}.each do |q, v|
|
84
|
-
a = Fbe::Award.new(q)
|
85
|
-
assert_equal(v, a.bill.greeting, q)
|
86
|
-
end
|
87
|
-
end
|
88
|
-
|
89
|
-
def test_must_not_give_anything_when_too_small_value
|
90
|
-
{
|
91
|
-
'(award (give (between 0 5 20)))' => 0,
|
92
|
-
'(award (give (between 13 5 20)))' => 13,
|
93
|
-
'(award (give (between 3 5 20)))' => 0,
|
94
|
-
'(award (give (between 25 5 20)))' => 20,
|
95
|
-
'(award (give (between 0 -10 -30)))' => 0,
|
96
|
-
'(award (give (between -2 -10 -30)))' => 0,
|
97
|
-
'(award (give (between -15 -10 -30)))' => -15,
|
98
|
-
'(award (give (between -50 -10 -30)))' => -30
|
99
|
-
}.each do |q, v|
|
100
|
-
a = Fbe::Award.new(q)
|
101
|
-
assert_equal(v, a.bill.points, q)
|
102
|
-
end
|
103
|
-
end
|
104
|
-
|
105
|
-
def test_some_policies
|
106
|
-
{
|
107
|
-
'(award (let x_a 25) (set z (plus x_a 1)) (give z "..."))' =>
|
108
|
-
'First, let _x-a_ be equal to **25**. Then, set _z_ to _x-a_ + **1**, and award _z_.',
|
109
|
-
'(award (aka (let x 17) (give x "hey") "add ${x} when necessary"))' =>
|
110
|
-
'Just add **17** when necessary'
|
111
|
-
}.each do |q, t|
|
112
|
-
md = Fbe::Award.new(q).bylaw.markdown
|
113
|
-
assert_includes(md, t, md)
|
114
|
-
end
|
115
|
-
end
|
116
|
-
|
117
|
-
def test_shorten_when_one_number
|
118
|
-
g = Fbe::Award.new('(award (give 23 "for love"))').bill.greeting
|
119
|
-
assert_equal('You\'ve earned +23 points. ', g, g)
|
120
|
-
end
|
121
|
-
|
122
|
-
def test_shorten_when_nothing
|
123
|
-
g = Fbe::Award.new('(award (give 0 "for none"))').bill.greeting
|
124
|
-
assert_equal('You\'ve earned nothing. ', g, g)
|
125
|
-
end
|
126
|
-
end
|
data/test/fbe/test_bylaws.rb
DELETED
@@ -1,111 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
# SPDX-FileCopyrightText: Copyright (c) 2024-2025 Zerocracy
|
4
|
-
# SPDX-License-Identifier: MIT
|
5
|
-
|
6
|
-
require 'loog'
|
7
|
-
require_relative '../../lib/fbe/award'
|
8
|
-
require_relative '../../lib/fbe/bylaws'
|
9
|
-
require_relative '../test__helper'
|
10
|
-
|
11
|
-
# Test.
|
12
|
-
# Author:: Yegor Bugayenko (yegor256@gmail.com)
|
13
|
-
# Copyright:: Copyright (c) 2024 Yegor Bugayenko
|
14
|
-
# License:: MIT
|
15
|
-
class TestBylaws < Fbe::Test
|
16
|
-
def test_simple
|
17
|
-
laws = Fbe.bylaws
|
18
|
-
assert_operator(laws.size, :>, 1)
|
19
|
-
refute_nil(laws['published-release-was-rewarded'])
|
20
|
-
end
|
21
|
-
|
22
|
-
def test_check_all_bills
|
23
|
-
awards = {
|
24
|
-
'published-release-was-rewarded' => {
|
25
|
-
{ hoc: 0, contributors: 1 } => 24,
|
26
|
-
{ hoc: 10, contributors: 1 } => 24,
|
27
|
-
{ hoc: 100, contributors: 1 } => 24,
|
28
|
-
{ hoc: 500, contributors: 1 } => 29,
|
29
|
-
{ hoc: 1_000, contributors: 1 } => 32,
|
30
|
-
{ hoc: 10_000, contributors: 1 } => 32,
|
31
|
-
{ hoc: 30_000, contributors: 1 } => 32
|
32
|
-
},
|
33
|
-
'resolved-bug-was-rewarded' => {
|
34
|
-
{ hours: 1, self: 0 } => 12,
|
35
|
-
{ hours: 48, self: 0 } => 6,
|
36
|
-
{ hours: 80, self: 0 } => 5,
|
37
|
-
{ hours: 300, self: 0 } => 4,
|
38
|
-
{ hours: 3_000, self: 0 } => 4,
|
39
|
-
{ hours: 30_000, self: 0 } => 4,
|
40
|
-
{ hours: 1, self: 1 } => 4
|
41
|
-
},
|
42
|
-
'push-to-master-was-punished' => {
|
43
|
-
{} => -16
|
44
|
-
},
|
45
|
-
'code-review-was-rewarded' => {
|
46
|
-
{ hoc: 0, comments: 0, self: 0 } => 4,
|
47
|
-
{ hoc: 3, comments: 0, self: 0 } => 4,
|
48
|
-
{ hoc: 78, comments: 7, self: 0 } => 12,
|
49
|
-
{ hoc: 120, comments: 4, self: 0 } => 4,
|
50
|
-
{ hoc: 600, comments: 1, self: 0 } => 8,
|
51
|
-
{ hoc: 500, comments: 40, self: 0 } => 24,
|
52
|
-
{ hoc: 5_000, comments: 100, self: 0 } => 24,
|
53
|
-
{ hoc: 100, comments: 50, self: 1 } => 4,
|
54
|
-
{ hoc: 10_000, comments: 200, self: 1 } => 4
|
55
|
-
},
|
56
|
-
'code-contribution-was-rewarded' => {
|
57
|
-
{ hoc: 0, comments: 0, reviews: 0 } => 4,
|
58
|
-
{ hoc: 3, comments: 0, reviews: 0 } => 4,
|
59
|
-
{ hoc: 78, comments: 0, reviews: 0 } => 4,
|
60
|
-
{ hoc: 78, comments: 1, reviews: 0 } => 4,
|
61
|
-
{ hoc: 50, comments: 15, reviews: 0 } => 4,
|
62
|
-
{ hoc: 50, comments: 25, reviews: 0 } => 4,
|
63
|
-
{ hoc: 180, comments: 7, reviews: 2 } => 24,
|
64
|
-
{ hoc: 199, comments: 8, reviews: 3 } => 24,
|
65
|
-
{ hoc: 150, comments: 5, reviews: 1 } => 24,
|
66
|
-
{ hoc: 500, comments: 25, reviews: 2 } => 4,
|
67
|
-
{ hoc: 99, comments: 6, reviews: 1 } => 16,
|
68
|
-
{ hoc: 1_500, comments: 3, reviews: 0 } => 4,
|
69
|
-
{ hoc: 15_000, comments: 40, reviews: 0 } => 4
|
70
|
-
},
|
71
|
-
'bug-report-was-rewarded' => {
|
72
|
-
{} => 12
|
73
|
-
},
|
74
|
-
'enhancement-suggestion-was-rewarded' => {
|
75
|
-
{} => 12
|
76
|
-
},
|
77
|
-
'dud-was-punished' => {
|
78
|
-
{} => -16
|
79
|
-
},
|
80
|
-
'bad-branch-name-was-punished' => {
|
81
|
-
{} => -12
|
82
|
-
},
|
83
|
-
'long-pull-was-punished' => {
|
84
|
-
{} => -8
|
85
|
-
}
|
86
|
-
}
|
87
|
-
awards.each do |title, pairs|
|
88
|
-
formula = Fbe.bylaws[title]
|
89
|
-
refute_nil(formula, title)
|
90
|
-
a = Fbe::Award.new(formula)
|
91
|
-
help = [
|
92
|
-
" '#{title.tr('_', '-')}' => {\n ",
|
93
|
-
pairs.map do |args, _|
|
94
|
-
[
|
95
|
-
'{',
|
96
|
-
args.empty? ? '' : "#{args.map { |k, v| " #{k}: #{v.to_s.gsub(/(?<!^)([0-9]{3})$/, '_\1')}" }.join(',')} ",
|
97
|
-
"} => #{a.bill(args).points}"
|
98
|
-
].join
|
99
|
-
end.join(",\n "),
|
100
|
-
"\n },"
|
101
|
-
].join
|
102
|
-
pairs.each do |args, points|
|
103
|
-
b = a.bill(args)
|
104
|
-
next if b.points == points
|
105
|
-
raise \
|
106
|
-
"Wrong reward of #{b.points} points from #{title}, " \
|
107
|
-
"while #{points} expected (#{args}): #{b.greeting}\n\n#{help}"
|
108
|
-
end
|
109
|
-
end
|
110
|
-
end
|
111
|
-
end
|
data/test/fbe/test_conclude.rb
DELETED
@@ -1,172 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
# SPDX-FileCopyrightText: Copyright (c) 2024-2025 Zerocracy
|
4
|
-
# SPDX-License-Identifier: MIT
|
5
|
-
|
6
|
-
require 'factbase'
|
7
|
-
require 'factbase/syntax'
|
8
|
-
require 'judges/options'
|
9
|
-
require 'loog'
|
10
|
-
require_relative '../../lib/fbe/conclude'
|
11
|
-
require_relative '../../lib/fbe/fb'
|
12
|
-
require_relative '../test__helper'
|
13
|
-
|
14
|
-
# Test.
|
15
|
-
# Author:: Yegor Bugayenko (yegor256@gmail.com)
|
16
|
-
# Copyright:: Copyright (c) 2024-2025 Zerocracy
|
17
|
-
# License:: MIT
|
18
|
-
class TestConclude < Fbe::Test
|
19
|
-
def test_with_defaults
|
20
|
-
$fb = Factbase.new
|
21
|
-
$global = {}
|
22
|
-
$options = Judges::Options.new
|
23
|
-
$loog = Loog::NULL
|
24
|
-
$judge = ''
|
25
|
-
Fbe.conclude do
|
26
|
-
# nothing
|
27
|
-
end
|
28
|
-
end
|
29
|
-
|
30
|
-
def test_draw
|
31
|
-
$fb = Factbase.new
|
32
|
-
$global = {}
|
33
|
-
$loog = Loog::NULL
|
34
|
-
$options = Judges::Options.new
|
35
|
-
$fb.insert.foo = 1
|
36
|
-
$fb.insert.bar = 2
|
37
|
-
Fbe.conclude(judge: 'judge-one') do
|
38
|
-
on '(exists foo)'
|
39
|
-
draw do |n, prev|
|
40
|
-
n.sum = prev.foo + 1
|
41
|
-
'Something funny and long enough to pass the requirements: long and long and long and long and long and long.'
|
42
|
-
end
|
43
|
-
end
|
44
|
-
f = $fb.query('(exists sum)').each.to_a[0]
|
45
|
-
assert_equal(2, f.sum)
|
46
|
-
assert_equal('judge-one', f.what)
|
47
|
-
assert_includes(f.details, 'funny')
|
48
|
-
end
|
49
|
-
|
50
|
-
def test_draw_with_rollback
|
51
|
-
$fb = Factbase.new
|
52
|
-
$global = {}
|
53
|
-
$loog = Loog::NULL
|
54
|
-
$options = Judges::Options.new
|
55
|
-
$fb.insert.foo = 1
|
56
|
-
Fbe.conclude(judge: 'judge-one') do
|
57
|
-
on '(exists foo)'
|
58
|
-
draw do |n, prev|
|
59
|
-
n.hello = prev.foo
|
60
|
-
throw :rollback
|
61
|
-
end
|
62
|
-
end
|
63
|
-
assert_equal(1, $fb.size)
|
64
|
-
end
|
65
|
-
|
66
|
-
def test_consider
|
67
|
-
fb = Factbase.new
|
68
|
-
fb.insert.foo = 1
|
69
|
-
options = Judges::Options.new
|
70
|
-
Fbe.conclude(fb:, judge: 'issue-was-closed', loog: Loog::NULL, options:, global: {}) do
|
71
|
-
on '(exists foo)'
|
72
|
-
consider do |_prev|
|
73
|
-
fb.insert.bar = 42
|
74
|
-
end
|
75
|
-
end
|
76
|
-
f = fb.query('(exists bar)').each.to_a[0]
|
77
|
-
assert_equal(42, f.bar)
|
78
|
-
end
|
79
|
-
|
80
|
-
def test_considers_until_quota
|
81
|
-
WebMock.disable_net_connect!
|
82
|
-
fb = Factbase.new
|
83
|
-
5.times do
|
84
|
-
fb.insert.foo = 1
|
85
|
-
end
|
86
|
-
options = Judges::Options.new
|
87
|
-
stub_request(:get, %r{https://api.github.com/users/.*}).to_return(
|
88
|
-
{
|
89
|
-
body: { id: rand(100) }.to_json,
|
90
|
-
headers: { 'Content-Type' => 'application/json', 'X-RateLimit-Remaining' => '999' }
|
91
|
-
},
|
92
|
-
{
|
93
|
-
body: { id: rand(100) }.to_json,
|
94
|
-
headers: { 'Content-Type' => 'application/json', 'X-RateLimit-Remaining' => '9' }
|
95
|
-
}
|
96
|
-
)
|
97
|
-
stub_request(:get, 'https://api.github.com/rate_limit').to_return(
|
98
|
-
{ body: '{"rate":{"remaining":51}}', headers: { 'X-RateLimit-Remaining' => '51' } }
|
99
|
-
)
|
100
|
-
global = {}
|
101
|
-
o = Fbe.octo(loog: Loog::NULL, options:, global:)
|
102
|
-
Fbe.conclude(fb:, judge: 'boom', loog: Loog::NULL, options:, global:) do
|
103
|
-
quota_aware
|
104
|
-
on '(exists foo)'
|
105
|
-
consider do |f|
|
106
|
-
f.bar = o.user("user-#{rand(100)}")[:id]
|
107
|
-
end
|
108
|
-
end
|
109
|
-
assert_equal(2, fb.query('(exists bar)').each.to_a.size)
|
110
|
-
end
|
111
|
-
|
112
|
-
def test_ignores_globals
|
113
|
-
$fb = nil
|
114
|
-
$loog = nil
|
115
|
-
$options = nil
|
116
|
-
$global = nil
|
117
|
-
fb = Factbase.new
|
118
|
-
fb.insert.foo = 1
|
119
|
-
Fbe.conclude(fb:, judge: 'judge-xxx', loog: Loog::NULL, global: {}, options: Judges::Options.new) do
|
120
|
-
on '(exists foo)'
|
121
|
-
draw do |n, prev|
|
122
|
-
n.sum = prev.foo + 1
|
123
|
-
'something funny'
|
124
|
-
end
|
125
|
-
end
|
126
|
-
assert_equal(2, fb.size)
|
127
|
-
end
|
128
|
-
|
129
|
-
def test_stop_if_timeout_exceeded
|
130
|
-
$fb = Factbase.new
|
131
|
-
$fb.insert.then do |f|
|
132
|
-
f._id = 1
|
133
|
-
f.foo = 5
|
134
|
-
end
|
135
|
-
$fb.insert.then do |f|
|
136
|
-
f._id = 2
|
137
|
-
f.foo = 4
|
138
|
-
end
|
139
|
-
$fb.insert.then do |f|
|
140
|
-
f._id = 3
|
141
|
-
f.bar = 3
|
142
|
-
end
|
143
|
-
$fb.insert.then do |f|
|
144
|
-
f._id = 4
|
145
|
-
f.foo = 2
|
146
|
-
end
|
147
|
-
$fb.insert.then do |f|
|
148
|
-
f._id = 5
|
149
|
-
f.foo = 1
|
150
|
-
end
|
151
|
-
$global = {}
|
152
|
-
$options = Judges::Options.new({ 'testing' => true })
|
153
|
-
$loog = Loog::NULL
|
154
|
-
$judge = ''
|
155
|
-
total = 0
|
156
|
-
now = Time.now
|
157
|
-
time = Minitest::Mock.new
|
158
|
-
time.expect(:now, now)
|
159
|
-
time.expect(:now, now + 4)
|
160
|
-
time.expect(:now, now + 8)
|
161
|
-
time.expect(:now, now + 12)
|
162
|
-
Fbe.conclude(time: time) do
|
163
|
-
on '(exists foo)'
|
164
|
-
timeout 10
|
165
|
-
consider do |f|
|
166
|
-
total += f.foo
|
167
|
-
end
|
168
|
-
end
|
169
|
-
assert_equal(9, total)
|
170
|
-
time.verify
|
171
|
-
end
|
172
|
-
end
|
data/test/fbe/test_copy.rb
DELETED
@@ -1,39 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
# SPDX-FileCopyrightText: Copyright (c) 2024-2025 Zerocracy
|
4
|
-
# SPDX-License-Identifier: MIT
|
5
|
-
|
6
|
-
require 'factbase'
|
7
|
-
require_relative '../../lib/fbe/copy'
|
8
|
-
require_relative '../test__helper'
|
9
|
-
|
10
|
-
# Test.
|
11
|
-
# Author:: Yegor Bugayenko (yegor256@gmail.com)
|
12
|
-
# Copyright:: Copyright (c) 2024-2025 Zerocracy
|
13
|
-
# License:: MIT
|
14
|
-
class TestCopy < Fbe::Test
|
15
|
-
def test_simple_copy
|
16
|
-
fb = Factbase.new
|
17
|
-
f1 = fb.insert
|
18
|
-
f1._id = 1
|
19
|
-
f1.foo = 42
|
20
|
-
f2 = fb.insert
|
21
|
-
f2._id = 2
|
22
|
-
Fbe.copy(f1, f2)
|
23
|
-
assert_equal(2, f2._id)
|
24
|
-
assert_equal([2], f2['_id'])
|
25
|
-
assert_equal(42, f2.foo)
|
26
|
-
assert_equal([42], f2['foo'])
|
27
|
-
end
|
28
|
-
|
29
|
-
def test_with_except
|
30
|
-
fb = Factbase.new
|
31
|
-
f1 = fb.insert
|
32
|
-
f1._id = 1
|
33
|
-
f1.foo = 42
|
34
|
-
f2 = fb.insert
|
35
|
-
f2._id = 2
|
36
|
-
Fbe.copy(f1, f2, except: ['foo'])
|
37
|
-
assert_nil(f2['foo'])
|
38
|
-
end
|
39
|
-
end
|
data/test/fbe/test_delete.rb
DELETED
@@ -1,117 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
# SPDX-FileCopyrightText: Copyright (c) 2024-2025 Zerocracy
|
4
|
-
# SPDX-License-Identifier: MIT
|
5
|
-
|
6
|
-
require 'factbase'
|
7
|
-
require 'judges/options'
|
8
|
-
require 'loog'
|
9
|
-
require_relative '../../lib/fbe/delete'
|
10
|
-
require_relative '../../lib/fbe/fb'
|
11
|
-
require_relative '../test__helper'
|
12
|
-
|
13
|
-
# Test.
|
14
|
-
# Author:: Yegor Bugayenko (yegor256@gmail.com)
|
15
|
-
# Copyright:: Copyright (c) 2024-2025 Zerocracy
|
16
|
-
# License:: MIT
|
17
|
-
class TestDelete < Fbe::Test
|
18
|
-
def test_deletes_one_property
|
19
|
-
fb = Factbase.new
|
20
|
-
f = fb.insert
|
21
|
-
f.foo = 42
|
22
|
-
f.hey = 4
|
23
|
-
f._id = 555
|
24
|
-
Fbe.delete(f, 'foo', 'bar', fb:)
|
25
|
-
assert_equal(1, fb.size)
|
26
|
-
assert_equal(1, fb.query('(exists hey)').each.to_a.size)
|
27
|
-
assert_equal(4, fb.query('(exists hey)').each.first.hey)
|
28
|
-
end
|
29
|
-
|
30
|
-
def test_deletes_when_many
|
31
|
-
fb = Factbase.new
|
32
|
-
f = fb.insert
|
33
|
-
f.foo = 42
|
34
|
-
f.foo = 'hello'
|
35
|
-
f.bar = 4
|
36
|
-
f._id = 555
|
37
|
-
Fbe.delete(f, 'bar', fb:)
|
38
|
-
assert_equal(1, fb.size)
|
39
|
-
assert_equal([42, 'hello'], fb.query('(exists foo)').each.first['foo'])
|
40
|
-
end
|
41
|
-
|
42
|
-
def test_deletes_nothing
|
43
|
-
fb = Factbase.new
|
44
|
-
f = fb.insert
|
45
|
-
f.foo = 42
|
46
|
-
f.foo = 'hello'
|
47
|
-
f._id = 555
|
48
|
-
Fbe.delete(f, 'bar', fb:)
|
49
|
-
assert_equal(1, fb.size)
|
50
|
-
assert_equal([42, 'hello'], fb.query('(exists foo)').each.first['foo'])
|
51
|
-
end
|
52
|
-
|
53
|
-
def test_deletes_two_properties
|
54
|
-
fb = Factbase.new
|
55
|
-
f = fb.insert
|
56
|
-
f.foo = 42
|
57
|
-
f.hey = 4
|
58
|
-
f._id = 555
|
59
|
-
Fbe.delete(f, 'foo', 'hey', fb:)
|
60
|
-
assert_equal(1, fb.size)
|
61
|
-
assert_equal(0, fb.query('(exists hey)').each.to_a.size)
|
62
|
-
end
|
63
|
-
|
64
|
-
def test_deletes_safely
|
65
|
-
$fb = Factbase.new
|
66
|
-
$global = {}
|
67
|
-
$options = Judges::Options.new(job_id: 42)
|
68
|
-
$loog = Loog::Buffer.new
|
69
|
-
f = Fbe.fb.insert
|
70
|
-
f.foo = 'hello'
|
71
|
-
Fbe.delete(f, 'foo')
|
72
|
-
f2 = Fbe.fb.query('(always)').each.to_a.first
|
73
|
-
assert_equal([1], f2['_id'])
|
74
|
-
assert_equal([42], f2['_job'])
|
75
|
-
end
|
76
|
-
|
77
|
-
def test_deletes_id
|
78
|
-
fb = Factbase.new
|
79
|
-
f = fb.insert
|
80
|
-
f._id = 44
|
81
|
-
Fbe.delete(f, '_id', fb:)
|
82
|
-
f2 = fb.query('(always)').each.to_a.first
|
83
|
-
assert_nil(f2['_id'])
|
84
|
-
assert_empty(f2.all_properties)
|
85
|
-
end
|
86
|
-
|
87
|
-
def test_deletes_in_transaction
|
88
|
-
$fb = Factbase.new
|
89
|
-
$global = {}
|
90
|
-
$options = Judges::Options.new(job_id: 42)
|
91
|
-
$loog = Loog::Buffer.new
|
92
|
-
Fbe.fb.txn do |fbt|
|
93
|
-
fbt.insert.then do |f|
|
94
|
-
f.issue = 444
|
95
|
-
f.where = 'github'
|
96
|
-
f.repository = 555
|
97
|
-
f.who = 887
|
98
|
-
f.when = Time.now
|
99
|
-
f.foo = 1
|
100
|
-
end
|
101
|
-
end
|
102
|
-
f1 = Fbe.fb.query('(always)').each.to_a.first
|
103
|
-
Fbe.delete(f1, 'foo')
|
104
|
-
f2 = Fbe.fb.query('(always)').each.to_a.first
|
105
|
-
assert_nil(f2['foo'])
|
106
|
-
end
|
107
|
-
|
108
|
-
def test_deletes_when_duplicate_id
|
109
|
-
fb = Factbase.new
|
110
|
-
f = fb.insert
|
111
|
-
f._id = 44
|
112
|
-
f._id = 45
|
113
|
-
Fbe.delete(f, '_id', fb:)
|
114
|
-
f2 = fb.query('(always)').each.to_a.first
|
115
|
-
assert_nil(f2['_id'])
|
116
|
-
end
|
117
|
-
end
|
data/test/fbe/test_delete_one.rb
DELETED
@@ -1,56 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
# SPDX-FileCopyrightText: Copyright (c) 2024-2025 Zerocracy
|
4
|
-
# SPDX-License-Identifier: MIT
|
5
|
-
|
6
|
-
require 'factbase'
|
7
|
-
require 'judges/options'
|
8
|
-
require 'loog'
|
9
|
-
require_relative '../../lib/fbe/delete_one'
|
10
|
-
require_relative '../../lib/fbe/fb'
|
11
|
-
require_relative '../test__helper'
|
12
|
-
|
13
|
-
# Test.
|
14
|
-
# Author:: Yegor Bugayenko (yegor256@gmail.com)
|
15
|
-
# Copyright:: Copyright (c) 2024-2025 Zerocracy
|
16
|
-
# License:: MIT
|
17
|
-
class TestDeleteOne < Fbe::Test
|
18
|
-
def test_deletes_one_value
|
19
|
-
fb = Factbase.new
|
20
|
-
f = fb.insert
|
21
|
-
f.foo = 42
|
22
|
-
f.foo = 'hello'
|
23
|
-
f._id = 555
|
24
|
-
Fbe.delete_one(f, 'foo', 42, fb:)
|
25
|
-
assert_equal(1, fb.size)
|
26
|
-
assert_equal(1, fb.query('(exists foo)').each.to_a.size)
|
27
|
-
assert_equal(0, fb.query('(eq foo 42)').each.to_a.size)
|
28
|
-
assert_equal(['hello'], fb.query('(exists foo)').each.first['foo'])
|
29
|
-
end
|
30
|
-
|
31
|
-
def test_deletes_when_many
|
32
|
-
fb = Factbase.new
|
33
|
-
f = fb.insert
|
34
|
-
f.foo = 42
|
35
|
-
f.foo = 'hello'
|
36
|
-
f.bar = 44
|
37
|
-
f._id = 555
|
38
|
-
Fbe.delete_one(f, 'bar', 44, fb:)
|
39
|
-
assert_equal(1, fb.size)
|
40
|
-
assert_equal(1, fb.query('(exists foo)').each.to_a.size)
|
41
|
-
assert_equal(1, fb.query('(eq foo 42)').each.to_a.size)
|
42
|
-
assert_equal([42, 'hello'], fb.query('(exists foo)').each.first['foo'])
|
43
|
-
end
|
44
|
-
|
45
|
-
def test_deletes_nothing
|
46
|
-
fb = Factbase.new
|
47
|
-
f = fb.insert
|
48
|
-
f.foo = 42
|
49
|
-
f.foo = 'hello'
|
50
|
-
f._id = 555
|
51
|
-
Fbe.delete_one(f, 'bar', 42, fb:)
|
52
|
-
assert_equal(1, fb.size)
|
53
|
-
assert_equal(1, fb.query('(exists foo)').each.to_a.size)
|
54
|
-
assert_equal(1, fb.query('(eq foo 42)').each.to_a.size)
|
55
|
-
end
|
56
|
-
end
|
data/test/fbe/test_enter.rb
DELETED
@@ -1,35 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
# SPDX-FileCopyrightText: Copyright (c) 2024-2025 Zerocracy
|
4
|
-
# SPDX-License-Identifier: MIT
|
5
|
-
|
6
|
-
require 'judges/options'
|
7
|
-
require 'loog'
|
8
|
-
require 'webmock/minitest'
|
9
|
-
require_relative '../../lib/fbe/enter'
|
10
|
-
require_relative '../test__helper'
|
11
|
-
|
12
|
-
# Test.
|
13
|
-
# Author:: Yegor Bugayenko (yegor256@gmail.com)
|
14
|
-
# Copyright:: Copyright (c) 2024-2025 Zerocracy
|
15
|
-
# License:: MIT
|
16
|
-
class TestEnter < Fbe::Test
|
17
|
-
def test_simple
|
18
|
-
WebMock.disable_net_connect!
|
19
|
-
options = Judges::Options.new({ 'zerocracy_token' => '00000-0000-0000-00000' })
|
20
|
-
stub_request(:get, 'https://api.zerocracy.com/csrf')
|
21
|
-
.to_return(body: 'token')
|
22
|
-
stub_request(:get, 'https://api.zerocracy.com/valves/result?badge=foo')
|
23
|
-
.to_return(status: 204)
|
24
|
-
stub_request(:post, 'https://api.zerocracy.com/valves/add?job=0')
|
25
|
-
.with(body: '_csrf=token&badge=foo&name&result=hi&why=no%20reason')
|
26
|
-
.to_return(status: 302)
|
27
|
-
assert_equal('hi', Fbe.enter('foo', 'no reason', options:, loog: Loog::NULL) { 'hi' })
|
28
|
-
end
|
29
|
-
|
30
|
-
def test_in_testing_mode
|
31
|
-
WebMock.enable_net_connect!
|
32
|
-
options = Judges::Options.new({ 'testing' => true })
|
33
|
-
assert_equal('hi', Fbe.enter('foo', 'no reason', options:, loog: Loog::NULL) { 'hi' })
|
34
|
-
end
|
35
|
-
end
|