typed_dag 2.0.1 → 2.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +2 -2
- data/lib/typed_dag/version.rb +1 -1
- metadata +3 -141
- data/spec/spec_helper.rb +0 -89
- data/spec/support/helpers.rb +0 -47
- data/spec/test_app/Rakefile +0 -6
- data/spec/test_app/app/assets/config/manifest.js +0 -4
- data/spec/test_app/app/assets/javascripts/application.js +0 -13
- data/spec/test_app/app/assets/javascripts/cable.js +0 -13
- data/spec/test_app/app/assets/stylesheets/application.css +0 -15
- data/spec/test_app/app/channels/application_cable/channel.rb +0 -4
- data/spec/test_app/app/channels/application_cable/connection.rb +0 -4
- data/spec/test_app/app/controllers/application_controller.rb +0 -3
- data/spec/test_app/app/helpers/application_helper.rb +0 -2
- data/spec/test_app/app/jobs/application_job.rb +0 -2
- data/spec/test_app/app/mailers/application_mailer.rb +0 -4
- data/spec/test_app/app/models/application_record.rb +0 -3
- data/spec/test_app/app/models/message.rb +0 -2
- data/spec/test_app/app/models/relation.rb +0 -2
- data/spec/test_app/app/views/layouts/application.html.erb +0 -14
- data/spec/test_app/app/views/layouts/mailer.html.erb +0 -13
- data/spec/test_app/app/views/layouts/mailer.text.erb +0 -1
- data/spec/test_app/bin/bundle +0 -3
- data/spec/test_app/bin/rails +0 -4
- data/spec/test_app/bin/rake +0 -4
- data/spec/test_app/bin/setup +0 -38
- data/spec/test_app/bin/update +0 -29
- data/spec/test_app/bin/yarn +0 -11
- data/spec/test_app/config.ru +0 -5
- data/spec/test_app/config/application.rb +0 -26
- data/spec/test_app/config/boot.rb +0 -5
- data/spec/test_app/config/cable.yml +0 -10
- data/spec/test_app/config/database.mysql.yml.travis +0 -9
- data/spec/test_app/config/database.postgresql.yml.travis +0 -9
- data/spec/test_app/config/database.yml +0 -23
- data/spec/test_app/config/environment.rb +0 -5
- data/spec/test_app/config/environments/development.rb +0 -54
- data/spec/test_app/config/environments/production.rb +0 -91
- data/spec/test_app/config/environments/test.rb +0 -42
- data/spec/test_app/config/initializers/application_controller_renderer.rb +0 -6
- data/spec/test_app/config/initializers/assets.rb +0 -14
- data/spec/test_app/config/initializers/backtrace_silencers.rb +0 -7
- data/spec/test_app/config/initializers/cookies_serializer.rb +0 -5
- data/spec/test_app/config/initializers/filter_parameter_logging.rb +0 -4
- data/spec/test_app/config/initializers/inflections.rb +0 -16
- data/spec/test_app/config/initializers/mime_types.rb +0 -4
- data/spec/test_app/config/initializers/typed_dag.rb +0 -12
- data/spec/test_app/config/initializers/wrap_parameters.rb +0 -14
- data/spec/test_app/config/locales/en.yml +0 -33
- data/spec/test_app/config/puma.rb +0 -56
- data/spec/test_app/config/routes.rb +0 -3
- data/spec/test_app/config/secrets.yml +0 -32
- data/spec/test_app/config/spring.rb +0 -6
- data/spec/test_app/db/development.sqlite3 +0 -0
- data/spec/test_app/db/migrate/20170831093433_create_nodes_and_endges.rb +0 -22
- data/spec/test_app/db/schema.rb +0 -35
- data/spec/test_app/db/test.sqlite3 +0 -0
- data/spec/test_app/log/development.log +0 -101
- data/spec/test_app/log/test.log +0 -0
- data/spec/test_app/package.json +0 -5
- data/spec/test_app/public/404.html +0 -67
- data/spec/test_app/public/422.html +0 -67
- data/spec/test_app/public/500.html +0 -66
- data/spec/test_app/public/apple-touch-icon-precomposed.png +0 -0
- data/spec/test_app/public/apple-touch-icon.png +0 -0
- data/spec/test_app/public/favicon.ico +0 -0
- data/spec/typed_dag/configuration.rb +0 -92
- data/spec/typed_dag/edge_spec.rb +0 -578
- data/spec/typed_dag/node_spec.rb +0 -2178
- data/spec/typed_dag/sql/add_closure_spec.rb +0 -116
- data/spec/typed_dag/sql/truncate_closure_spec.rb +0 -112
- data/spec/typed_dag_spec.rb +0 -7
@@ -1,116 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
RSpec.describe TypedDag::Sql::AddClosure do
|
4
|
-
include TypedDag::Specs::Helpers
|
5
|
-
|
6
|
-
describe '.sql' do
|
7
|
-
let(:relation) { Relation.new id: 11, ancestor_id: 4, descendant_id: 6, invalidate: 1 }
|
8
|
-
|
9
|
-
it 'produces the correct sql' do
|
10
|
-
expected_sql = if mysql_db?
|
11
|
-
<<-SQL
|
12
|
-
INSERT INTO
|
13
|
-
|
14
|
-
relations
|
15
|
-
|
16
|
-
(ancestor_id,
|
17
|
-
descendant_id,
|
18
|
-
hierarchy,
|
19
|
-
invalidate,
|
20
|
-
count)
|
21
|
-
SELECT
|
22
|
-
ancestor_id,
|
23
|
-
descendant_id,
|
24
|
-
hierarchy,
|
25
|
-
invalidate,
|
26
|
-
SUM(count) AS count
|
27
|
-
FROM
|
28
|
-
(SELECT
|
29
|
-
r1.ancestor_id,
|
30
|
-
r2.descendant_id,
|
31
|
-
CASE
|
32
|
-
WHEN r1.descendant_id = r2.ancestor_id AND (r1.hierarchy > 0 OR r2.hierarchy > 0)
|
33
|
-
THEN r1.hierarchy + r2.hierarchy
|
34
|
-
WHEN r1.descendant_id != r2.ancestor_id
|
35
|
-
THEN r1.hierarchy + r2.hierarchy + 0
|
36
|
-
ELSE 0
|
37
|
-
END AS hierarchy,
|
38
|
-
CASE
|
39
|
-
WHEN r1.descendant_id = r2.ancestor_id AND (r1.invalidate > 0 OR r2.invalidate > 0)
|
40
|
-
THEN r1.invalidate + r2.invalidate
|
41
|
-
WHEN r1.descendant_id != r2.ancestor_id
|
42
|
-
THEN r1.invalidate + r2.invalidate + 1
|
43
|
-
ELSE 0
|
44
|
-
END AS invalidate,
|
45
|
-
r1.count * r2.count AS count
|
46
|
-
FROM
|
47
|
-
relations r1
|
48
|
-
JOIN
|
49
|
-
relations r2
|
50
|
-
ON
|
51
|
-
(r1.descendant_id = 4 AND r2.ancestor_id = 6 AND NOT (r1.ancestor_id = 4 AND r2.descendant_id = 6))) unique_rows
|
52
|
-
GROUP BY
|
53
|
-
ancestor_id,
|
54
|
-
descendant_id,
|
55
|
-
hierarchy,
|
56
|
-
invalidate
|
57
|
-
ON DUPLICATE KEY
|
58
|
-
UPDATE count = relations.count + VALUES(count)
|
59
|
-
SQL
|
60
|
-
else
|
61
|
-
<<-SQL
|
62
|
-
INSERT INTO
|
63
|
-
|
64
|
-
relations
|
65
|
-
|
66
|
-
(ancestor_id,
|
67
|
-
descendant_id,
|
68
|
-
hierarchy,
|
69
|
-
invalidate,
|
70
|
-
count)
|
71
|
-
SELECT
|
72
|
-
ancestor_id,
|
73
|
-
descendant_id,
|
74
|
-
hierarchy,
|
75
|
-
invalidate,
|
76
|
-
SUM(count) AS count
|
77
|
-
FROM
|
78
|
-
(SELECT
|
79
|
-
r1.ancestor_id,
|
80
|
-
r2.descendant_id,
|
81
|
-
CASE
|
82
|
-
WHEN r1.descendant_id = r2.ancestor_id AND (r1.hierarchy > 0 OR r2.hierarchy > 0)
|
83
|
-
THEN r1.hierarchy + r2.hierarchy
|
84
|
-
WHEN r1.descendant_id != r2.ancestor_id
|
85
|
-
THEN r1.hierarchy + r2.hierarchy + 0
|
86
|
-
ELSE 0
|
87
|
-
END AS hierarchy,
|
88
|
-
CASE
|
89
|
-
WHEN r1.descendant_id = r2.ancestor_id AND (r1.invalidate > 0 OR r2.invalidate > 0)
|
90
|
-
THEN r1.invalidate + r2.invalidate
|
91
|
-
WHEN r1.descendant_id != r2.ancestor_id
|
92
|
-
THEN r1.invalidate + r2.invalidate + 1
|
93
|
-
ELSE 0
|
94
|
-
END AS invalidate,
|
95
|
-
r1.count * r2.count AS count
|
96
|
-
FROM
|
97
|
-
relations r1
|
98
|
-
JOIN
|
99
|
-
relations r2
|
100
|
-
ON
|
101
|
-
(r1.descendant_id = 4 AND r2.ancestor_id = 6 AND NOT (r1.ancestor_id = 4 AND r2.descendant_id = 6))) unique_rows
|
102
|
-
GROUP BY
|
103
|
-
ancestor_id,
|
104
|
-
descendant_id,
|
105
|
-
hierarchy,
|
106
|
-
invalidate
|
107
|
-
ON CONFLICT (ancestor_id, descendant_id, hierarchy, invalidate)
|
108
|
-
DO UPDATE SET count = relations.count + EXCLUDED.count
|
109
|
-
SQL
|
110
|
-
end
|
111
|
-
|
112
|
-
expect(harmonize_string(described_class.sql(relation)))
|
113
|
-
.to eql harmonize_string(expected_sql)
|
114
|
-
end
|
115
|
-
end
|
116
|
-
end
|
@@ -1,112 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
RSpec.describe TypedDag::Sql::TruncateClosure do
|
4
|
-
include TypedDag::Specs::Helpers
|
5
|
-
|
6
|
-
describe '.sql' do
|
7
|
-
let(:relation) { Relation.new ancestor_id: 4, descendant_id: 6, invalidate: 1 }
|
8
|
-
|
9
|
-
it 'produces the correct sql' do
|
10
|
-
expected_sql = if mysql_db?
|
11
|
-
<<-SQL
|
12
|
-
UPDATE
|
13
|
-
relations
|
14
|
-
JOIN
|
15
|
-
(SELECT
|
16
|
-
ancestor_id,
|
17
|
-
descendant_id,
|
18
|
-
hierarchy,
|
19
|
-
invalidate,
|
20
|
-
SUM(count) AS count
|
21
|
-
FROM
|
22
|
-
(SELECT
|
23
|
-
r1.ancestor_id,
|
24
|
-
r2.descendant_id,
|
25
|
-
CASE
|
26
|
-
WHEN r1.descendant_id = r2.ancestor_id AND (r1.hierarchy > 0 OR r2.hierarchy > 0)
|
27
|
-
THEN r1.hierarchy + r2.hierarchy
|
28
|
-
WHEN r1.descendant_id != r2.ancestor_id
|
29
|
-
THEN r1.hierarchy + r2.hierarchy + 0
|
30
|
-
ELSE 0
|
31
|
-
END AS hierarchy,
|
32
|
-
CASE
|
33
|
-
WHEN r1.descendant_id = r2.ancestor_id AND (r1.invalidate > 0 OR r2.invalidate > 0)
|
34
|
-
THEN r1.invalidate + r2.invalidate
|
35
|
-
WHEN r1.descendant_id != r2.ancestor_id
|
36
|
-
THEN r1.invalidate + r2.invalidate + 1
|
37
|
-
ELSE 0
|
38
|
-
END AS invalidate,
|
39
|
-
r1.count * r2.count AS count
|
40
|
-
FROM
|
41
|
-
relations r1
|
42
|
-
JOIN
|
43
|
-
relations r2
|
44
|
-
ON
|
45
|
-
(r1.descendant_id = 4 AND r2.ancestor_id = 6 AND NOT (r1.ancestor_id = 4 AND r2.descendant_id = 6))) unique_rows
|
46
|
-
GROUP BY
|
47
|
-
ancestor_id,
|
48
|
-
descendant_id,
|
49
|
-
hierarchy,
|
50
|
-
invalidate) removed_relations
|
51
|
-
ON relations.ancestor_id = removed_relations.ancestor_id
|
52
|
-
AND relations.descendant_id = removed_relations.descendant_id
|
53
|
-
AND relations.hierarchy = removed_relations.hierarchy
|
54
|
-
AND relations.invalidate = removed_relations.invalidate
|
55
|
-
SET
|
56
|
-
relations.count = relations.count - removed_relations.count
|
57
|
-
SQL
|
58
|
-
else
|
59
|
-
expected_sql = <<-SQL
|
60
|
-
UPDATE
|
61
|
-
relations
|
62
|
-
SET
|
63
|
-
count = relations.count - removed_relations.count
|
64
|
-
FROM
|
65
|
-
(SELECT
|
66
|
-
ancestor_id,
|
67
|
-
descendant_id,
|
68
|
-
hierarchy,
|
69
|
-
invalidate,
|
70
|
-
SUM(count) AS count
|
71
|
-
FROM
|
72
|
-
(SELECT
|
73
|
-
r1.ancestor_id,
|
74
|
-
r2.descendant_id,
|
75
|
-
CASE
|
76
|
-
WHEN r1.descendant_id = r2.ancestor_id AND (r1.hierarchy > 0 OR r2.hierarchy > 0)
|
77
|
-
THEN r1.hierarchy + r2.hierarchy
|
78
|
-
WHEN r1.descendant_id != r2.ancestor_id
|
79
|
-
THEN r1.hierarchy + r2.hierarchy + 0
|
80
|
-
ELSE 0
|
81
|
-
END AS hierarchy,
|
82
|
-
CASE
|
83
|
-
WHEN r1.descendant_id = r2.ancestor_id AND (r1.invalidate > 0 OR r2.invalidate > 0)
|
84
|
-
THEN r1.invalidate + r2.invalidate
|
85
|
-
WHEN r1.descendant_id != r2.ancestor_id
|
86
|
-
THEN r1.invalidate + r2.invalidate + 1
|
87
|
-
ELSE 0
|
88
|
-
END AS invalidate,
|
89
|
-
r1.count * r2.count AS count
|
90
|
-
FROM
|
91
|
-
relations r1
|
92
|
-
JOIN
|
93
|
-
relations r2
|
94
|
-
ON
|
95
|
-
(r1.descendant_id = 4 AND r2.ancestor_id = 6 AND NOT (r1.ancestor_id = 4 AND r2.descendant_id = 6))) unique_rows
|
96
|
-
GROUP BY
|
97
|
-
ancestor_id,
|
98
|
-
descendant_id,
|
99
|
-
hierarchy,
|
100
|
-
invalidate) removed_relations
|
101
|
-
WHERE relations.ancestor_id = removed_relations.ancestor_id
|
102
|
-
AND relations.descendant_id = removed_relations.descendant_id
|
103
|
-
AND relations.hierarchy = removed_relations.hierarchy
|
104
|
-
AND relations.invalidate = removed_relations.invalidate
|
105
|
-
SQL
|
106
|
-
|
107
|
-
expect(harmonize_string(described_class.sql(relation)))
|
108
|
-
.to eql harmonize_string(expected_sql)
|
109
|
-
end
|
110
|
-
end
|
111
|
-
end
|
112
|
-
end
|