pg_ltree 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/MIT-LICENSE +20 -0
- data/Rakefile +29 -0
- data/lib/pg_ltree/ltree.rb +190 -0
- data/lib/pg_ltree/scoped_for.rb +45 -0
- data/lib/pg_ltree/version.rb +8 -0
- data/lib/pg_ltree.rb +5 -0
- data/lib/tasks/pg_ltree_tasks.rake +4 -0
- data/test/doc/_index.html +88 -0
- data/test/doc/class_list.html +58 -0
- data/test/doc/css/common.css +1 -0
- data/test/doc/css/full_list.css +57 -0
- data/test/doc/css/style.css +339 -0
- data/test/doc/file_list.html +57 -0
- data/test/doc/frames.html +26 -0
- data/test/doc/index.html +88 -0
- data/test/doc/js/app.js +219 -0
- data/test/doc/js/full_list.js +181 -0
- data/test/doc/js/jquery.js +4 -0
- data/test/doc/method_list.html +57 -0
- data/test/doc/top-level-namespace.html +102 -0
- data/test/dummy/README.rdoc +28 -0
- data/test/dummy/Rakefile +6 -0
- data/test/dummy/app/assets/javascripts/application.js +13 -0
- data/test/dummy/app/assets/stylesheets/application.css +15 -0
- data/test/dummy/app/controllers/application_controller.rb +5 -0
- data/test/dummy/app/helpers/application_helper.rb +2 -0
- data/test/dummy/app/models/not_uniq_tree_node.rb +6 -0
- data/test/dummy/app/models/tree_node.rb +3 -0
- data/test/dummy/app/views/layouts/application.html.erb +14 -0
- data/test/dummy/bin/bundle +3 -0
- data/test/dummy/bin/rails +4 -0
- data/test/dummy/bin/rake +4 -0
- data/test/dummy/bin/setup +29 -0
- data/test/dummy/config/application.rb +26 -0
- data/test/dummy/config/boot.rb +5 -0
- data/test/dummy/config/database.yml.example +14 -0
- data/test/dummy/config/environment.rb +5 -0
- data/test/dummy/config/environments/development.rb +41 -0
- data/test/dummy/config/environments/production.rb +79 -0
- data/test/dummy/config/environments/test.rb +42 -0
- data/test/dummy/config/initializers/assets.rb +11 -0
- data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/test/dummy/config/initializers/cookies_serializer.rb +3 -0
- data/test/dummy/config/initializers/filter_parameter_logging.rb +4 -0
- data/test/dummy/config/initializers/inflections.rb +16 -0
- data/test/dummy/config/initializers/mime_types.rb +4 -0
- data/test/dummy/config/initializers/session_store.rb +3 -0
- data/test/dummy/config/initializers/wrap_parameters.rb +14 -0
- data/test/dummy/config/locales/en.yml +23 -0
- data/test/dummy/config/routes.rb +56 -0
- data/test/dummy/config/secrets.yml +22 -0
- data/test/dummy/config.ru +4 -0
- data/test/dummy/db/migrate/20150809114511_enable_postgres_ltree.rb +13 -0
- data/test/dummy/db/migrate/20150809114528_create_tree_node.rb +7 -0
- data/test/dummy/db/migrate/20150809114547_create_not_uniq_tree_node.rb +8 -0
- data/test/dummy/db/schema.rb +29 -0
- data/test/dummy/log/development.log +718 -0
- data/test/dummy/log/test.log +34557 -0
- data/test/dummy/public/404.html +67 -0
- data/test/dummy/public/422.html +67 -0
- data/test/dummy/public/500.html +66 -0
- data/test/dummy/public/favicon.ico +0 -0
- data/test/pg_ltree/ltree_test.rb +154 -0
- data/test/pg_ltree/scoped_for_test.rb +157 -0
- data/test/pg_ltree_test.rb +7 -0
- data/test/test_helper.rb +26 -0
- metadata +199 -0
@@ -0,0 +1,67 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<title>The page you were looking for doesn't exist (404)</title>
|
5
|
+
<meta name="viewport" content="width=device-width,initial-scale=1">
|
6
|
+
<style>
|
7
|
+
body {
|
8
|
+
background-color: #EFEFEF;
|
9
|
+
color: #2E2F30;
|
10
|
+
text-align: center;
|
11
|
+
font-family: arial, sans-serif;
|
12
|
+
margin: 0;
|
13
|
+
}
|
14
|
+
|
15
|
+
div.dialog {
|
16
|
+
width: 95%;
|
17
|
+
max-width: 33em;
|
18
|
+
margin: 4em auto 0;
|
19
|
+
}
|
20
|
+
|
21
|
+
div.dialog > div {
|
22
|
+
border: 1px solid #CCC;
|
23
|
+
border-right-color: #999;
|
24
|
+
border-left-color: #999;
|
25
|
+
border-bottom-color: #BBB;
|
26
|
+
border-top: #B00100 solid 4px;
|
27
|
+
border-top-left-radius: 9px;
|
28
|
+
border-top-right-radius: 9px;
|
29
|
+
background-color: white;
|
30
|
+
padding: 7px 12% 0;
|
31
|
+
box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
|
32
|
+
}
|
33
|
+
|
34
|
+
h1 {
|
35
|
+
font-size: 100%;
|
36
|
+
color: #730E15;
|
37
|
+
line-height: 1.5em;
|
38
|
+
}
|
39
|
+
|
40
|
+
div.dialog > p {
|
41
|
+
margin: 0 0 1em;
|
42
|
+
padding: 1em;
|
43
|
+
background-color: #F7F7F7;
|
44
|
+
border: 1px solid #CCC;
|
45
|
+
border-right-color: #999;
|
46
|
+
border-left-color: #999;
|
47
|
+
border-bottom-color: #999;
|
48
|
+
border-bottom-left-radius: 4px;
|
49
|
+
border-bottom-right-radius: 4px;
|
50
|
+
border-top-color: #DADADA;
|
51
|
+
color: #666;
|
52
|
+
box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
|
53
|
+
}
|
54
|
+
</style>
|
55
|
+
</head>
|
56
|
+
|
57
|
+
<body>
|
58
|
+
<!-- This file lives in public/404.html -->
|
59
|
+
<div class="dialog">
|
60
|
+
<div>
|
61
|
+
<h1>The page you were looking for doesn't exist.</h1>
|
62
|
+
<p>You may have mistyped the address or the page may have moved.</p>
|
63
|
+
</div>
|
64
|
+
<p>If you are the application owner check the logs for more information.</p>
|
65
|
+
</div>
|
66
|
+
</body>
|
67
|
+
</html>
|
@@ -0,0 +1,67 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<title>The change you wanted was rejected (422)</title>
|
5
|
+
<meta name="viewport" content="width=device-width,initial-scale=1">
|
6
|
+
<style>
|
7
|
+
body {
|
8
|
+
background-color: #EFEFEF;
|
9
|
+
color: #2E2F30;
|
10
|
+
text-align: center;
|
11
|
+
font-family: arial, sans-serif;
|
12
|
+
margin: 0;
|
13
|
+
}
|
14
|
+
|
15
|
+
div.dialog {
|
16
|
+
width: 95%;
|
17
|
+
max-width: 33em;
|
18
|
+
margin: 4em auto 0;
|
19
|
+
}
|
20
|
+
|
21
|
+
div.dialog > div {
|
22
|
+
border: 1px solid #CCC;
|
23
|
+
border-right-color: #999;
|
24
|
+
border-left-color: #999;
|
25
|
+
border-bottom-color: #BBB;
|
26
|
+
border-top: #B00100 solid 4px;
|
27
|
+
border-top-left-radius: 9px;
|
28
|
+
border-top-right-radius: 9px;
|
29
|
+
background-color: white;
|
30
|
+
padding: 7px 12% 0;
|
31
|
+
box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
|
32
|
+
}
|
33
|
+
|
34
|
+
h1 {
|
35
|
+
font-size: 100%;
|
36
|
+
color: #730E15;
|
37
|
+
line-height: 1.5em;
|
38
|
+
}
|
39
|
+
|
40
|
+
div.dialog > p {
|
41
|
+
margin: 0 0 1em;
|
42
|
+
padding: 1em;
|
43
|
+
background-color: #F7F7F7;
|
44
|
+
border: 1px solid #CCC;
|
45
|
+
border-right-color: #999;
|
46
|
+
border-left-color: #999;
|
47
|
+
border-bottom-color: #999;
|
48
|
+
border-bottom-left-radius: 4px;
|
49
|
+
border-bottom-right-radius: 4px;
|
50
|
+
border-top-color: #DADADA;
|
51
|
+
color: #666;
|
52
|
+
box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
|
53
|
+
}
|
54
|
+
</style>
|
55
|
+
</head>
|
56
|
+
|
57
|
+
<body>
|
58
|
+
<!-- This file lives in public/422.html -->
|
59
|
+
<div class="dialog">
|
60
|
+
<div>
|
61
|
+
<h1>The change you wanted was rejected.</h1>
|
62
|
+
<p>Maybe you tried to change something you didn't have access to.</p>
|
63
|
+
</div>
|
64
|
+
<p>If you are the application owner check the logs for more information.</p>
|
65
|
+
</div>
|
66
|
+
</body>
|
67
|
+
</html>
|
@@ -0,0 +1,66 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<title>We're sorry, but something went wrong (500)</title>
|
5
|
+
<meta name="viewport" content="width=device-width,initial-scale=1">
|
6
|
+
<style>
|
7
|
+
body {
|
8
|
+
background-color: #EFEFEF;
|
9
|
+
color: #2E2F30;
|
10
|
+
text-align: center;
|
11
|
+
font-family: arial, sans-serif;
|
12
|
+
margin: 0;
|
13
|
+
}
|
14
|
+
|
15
|
+
div.dialog {
|
16
|
+
width: 95%;
|
17
|
+
max-width: 33em;
|
18
|
+
margin: 4em auto 0;
|
19
|
+
}
|
20
|
+
|
21
|
+
div.dialog > div {
|
22
|
+
border: 1px solid #CCC;
|
23
|
+
border-right-color: #999;
|
24
|
+
border-left-color: #999;
|
25
|
+
border-bottom-color: #BBB;
|
26
|
+
border-top: #B00100 solid 4px;
|
27
|
+
border-top-left-radius: 9px;
|
28
|
+
border-top-right-radius: 9px;
|
29
|
+
background-color: white;
|
30
|
+
padding: 7px 12% 0;
|
31
|
+
box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
|
32
|
+
}
|
33
|
+
|
34
|
+
h1 {
|
35
|
+
font-size: 100%;
|
36
|
+
color: #730E15;
|
37
|
+
line-height: 1.5em;
|
38
|
+
}
|
39
|
+
|
40
|
+
div.dialog > p {
|
41
|
+
margin: 0 0 1em;
|
42
|
+
padding: 1em;
|
43
|
+
background-color: #F7F7F7;
|
44
|
+
border: 1px solid #CCC;
|
45
|
+
border-right-color: #999;
|
46
|
+
border-left-color: #999;
|
47
|
+
border-bottom-color: #999;
|
48
|
+
border-bottom-left-radius: 4px;
|
49
|
+
border-bottom-right-radius: 4px;
|
50
|
+
border-top-color: #DADADA;
|
51
|
+
color: #666;
|
52
|
+
box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
|
53
|
+
}
|
54
|
+
</style>
|
55
|
+
</head>
|
56
|
+
|
57
|
+
<body>
|
58
|
+
<!-- This file lives in public/500.html -->
|
59
|
+
<div class="dialog">
|
60
|
+
<div>
|
61
|
+
<h1>We're sorry, but something went wrong.</h1>
|
62
|
+
</div>
|
63
|
+
<p>If you are the application owner check the logs for more information.</p>
|
64
|
+
</div>
|
65
|
+
</body>
|
66
|
+
</html>
|
File without changes
|
@@ -0,0 +1,154 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class PgLtree::LtreeTest < ActiveSupport::TestCase
|
4
|
+
|
5
|
+
def setup
|
6
|
+
%w(
|
7
|
+
Top
|
8
|
+
Top.Science
|
9
|
+
Top.Science.Astronomy
|
10
|
+
Top.Science.Astronomy.Astrophysics
|
11
|
+
Top.Science.Astronomy.Cosmology
|
12
|
+
Top.Hobbies
|
13
|
+
Top.Hobbies.Amateurs_Astronomy
|
14
|
+
Top.Collections
|
15
|
+
Top.Collections.Pictures
|
16
|
+
Top.Collections.Pictures.Astronomy
|
17
|
+
Top.Collections.Pictures.Astronomy.Stars
|
18
|
+
Top.Collections.Pictures.Astronomy.Galaxies
|
19
|
+
Top.Collections.Pictures.Astronomy.Astronauts
|
20
|
+
).each do |path|
|
21
|
+
TreeNode.create! path: path
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def teardown
|
26
|
+
TreeNode.delete_all
|
27
|
+
end
|
28
|
+
|
29
|
+
test "Default configuration" do
|
30
|
+
assert_equal TreeNode.ltree_path_column, :path
|
31
|
+
end
|
32
|
+
|
33
|
+
test "Custom configuration" do
|
34
|
+
assert_equal NotUniqTreeNode.ltree_path_column, :new_path
|
35
|
+
end
|
36
|
+
|
37
|
+
test '#roots' do
|
38
|
+
assert_equal TreeNode.roots.pluck(:path), ['Top']
|
39
|
+
end
|
40
|
+
|
41
|
+
test '#at_depth' do
|
42
|
+
assert_equal TreeNode.at_depth(5).pluck(:path), %w(
|
43
|
+
Top.Collections.Pictures.Astronomy.Stars
|
44
|
+
Top.Collections.Pictures.Astronomy.Galaxies
|
45
|
+
Top.Collections.Pictures.Astronomy.Astronauts
|
46
|
+
)
|
47
|
+
end
|
48
|
+
|
49
|
+
test '#leaves' do
|
50
|
+
assert_equal TreeNode.leaves.pluck(:path), %w(
|
51
|
+
Top.Science.Astronomy.Astrophysics
|
52
|
+
Top.Science.Astronomy.Cosmology
|
53
|
+
Top.Hobbies.Amateurs_Astronomy
|
54
|
+
Top.Collections.Pictures.Astronomy.Stars
|
55
|
+
Top.Collections.Pictures.Astronomy.Galaxies
|
56
|
+
Top.Collections.Pictures.Astronomy.Astronauts
|
57
|
+
)
|
58
|
+
end
|
59
|
+
|
60
|
+
test '#where_path_liked' do
|
61
|
+
assert_equal TreeNode.where_path_liked('*{2}.Astronomy|Pictures').pluck(:path), %w(
|
62
|
+
Top.Science.Astronomy
|
63
|
+
Top.Collections.Pictures
|
64
|
+
)
|
65
|
+
end
|
66
|
+
|
67
|
+
test '.root?' do
|
68
|
+
assert TreeNode.find_by(path: 'Top').root?
|
69
|
+
assert_not TreeNode.find_by(path: 'Top.Science').root?
|
70
|
+
end
|
71
|
+
|
72
|
+
test '.depth' do
|
73
|
+
assert_equal TreeNode.find_by(path: 'Top.Hobbies.Amateurs_Astronomy').depth, 3
|
74
|
+
end
|
75
|
+
|
76
|
+
test '.root' do
|
77
|
+
assert_equal TreeNode.find_by(path: 'Top.Hobbies.Amateurs_Astronomy').root.path, 'Top'
|
78
|
+
end
|
79
|
+
|
80
|
+
test '.parent' do
|
81
|
+
assert_equal TreeNode.find_by(path: 'Top.Collections.Pictures.Astronomy.Astronauts').parent.path,
|
82
|
+
'Top.Collections.Pictures.Astronomy'
|
83
|
+
end
|
84
|
+
|
85
|
+
test '.leaves' do
|
86
|
+
assert_equal TreeNode.find_by(path: 'Top.Science').leaves.pluck(:path), %w(
|
87
|
+
Top.Science.Astronomy.Astrophysics
|
88
|
+
Top.Science.Astronomy.Cosmology
|
89
|
+
)
|
90
|
+
end
|
91
|
+
|
92
|
+
test '.leaf?' do
|
93
|
+
assert_not TreeNode.find_by(path: 'Top').leaf?
|
94
|
+
assert TreeNode.find_by(path: 'Top.Collections.Pictures.Astronomy.Astronauts').leaf?
|
95
|
+
end
|
96
|
+
|
97
|
+
test '.self_and_ancestors' do
|
98
|
+
assert_equal TreeNode.find_by(path: 'Top.Collections.Pictures.Astronomy.Astronauts').self_and_ancestors.pluck(:path), %w(
|
99
|
+
Top
|
100
|
+
Top.Collections
|
101
|
+
Top.Collections.Pictures
|
102
|
+
Top.Collections.Pictures.Astronomy
|
103
|
+
Top.Collections.Pictures.Astronomy.Astronauts
|
104
|
+
)
|
105
|
+
end
|
106
|
+
|
107
|
+
test '.ancestors' do
|
108
|
+
assert_equal TreeNode.find_by(path: 'Top.Collections.Pictures.Astronomy.Astronauts').ancestors.pluck(:path), %w(
|
109
|
+
Top
|
110
|
+
Top.Collections
|
111
|
+
Top.Collections.Pictures
|
112
|
+
Top.Collections.Pictures.Astronomy
|
113
|
+
)
|
114
|
+
end
|
115
|
+
|
116
|
+
test '.self_and_descendents' do
|
117
|
+
assert_equal TreeNode.find_by(path: 'Top.Science').self_and_descendents.pluck(:path), %w(
|
118
|
+
Top.Science
|
119
|
+
Top.Science.Astronomy
|
120
|
+
Top.Science.Astronomy.Astrophysics
|
121
|
+
Top.Science.Astronomy.Cosmology
|
122
|
+
)
|
123
|
+
end
|
124
|
+
|
125
|
+
test '.descendents' do
|
126
|
+
assert_equal TreeNode.find_by(path: 'Top.Science').descendents.pluck(:path), %w(
|
127
|
+
Top.Science.Astronomy
|
128
|
+
Top.Science.Astronomy.Astrophysics
|
129
|
+
Top.Science.Astronomy.Cosmology
|
130
|
+
)
|
131
|
+
end
|
132
|
+
|
133
|
+
test '.self_and_siblings' do
|
134
|
+
assert_equal TreeNode.find_by(path: 'Top.Collections.Pictures.Astronomy.Stars').self_and_siblings.pluck(:path), %w(
|
135
|
+
Top.Collections.Pictures.Astronomy.Stars
|
136
|
+
Top.Collections.Pictures.Astronomy.Galaxies
|
137
|
+
Top.Collections.Pictures.Astronomy.Astronauts
|
138
|
+
)
|
139
|
+
end
|
140
|
+
|
141
|
+
|
142
|
+
test '.siblings' do
|
143
|
+
assert_equal TreeNode.find_by(path: 'Top.Collections.Pictures.Astronomy.Stars').siblings.pluck(:path), %w(
|
144
|
+
Top.Collections.Pictures.Astronomy.Galaxies
|
145
|
+
Top.Collections.Pictures.Astronomy.Astronauts
|
146
|
+
)
|
147
|
+
end
|
148
|
+
|
149
|
+
test '.children' do
|
150
|
+
assert_equal TreeNode.find_by(path: 'Top.Hobbies').children.pluck(:path), %w(
|
151
|
+
Top.Hobbies.Amateurs_Astronomy
|
152
|
+
)
|
153
|
+
end
|
154
|
+
end
|
@@ -0,0 +1,157 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class PgLtree::ScopedForTest < ActiveSupport::TestCase
|
4
|
+
|
5
|
+
def setup
|
6
|
+
%w(
|
7
|
+
Top
|
8
|
+
Top.Science
|
9
|
+
Top.Science.Astronomy
|
10
|
+
Top.Science.Astronomy.Astrophysics
|
11
|
+
Top.Science.Astronomy.Cosmology
|
12
|
+
Top.Hobbies
|
13
|
+
Top.Hobbies.Amateurs_Astronomy
|
14
|
+
Top.Collections
|
15
|
+
Top.Collections.Pictures
|
16
|
+
Top.Collections.Pictures.Astronomy
|
17
|
+
Top.Collections.Pictures.Astronomy.Stars
|
18
|
+
Top.Collections.Pictures.Astronomy.Galaxies
|
19
|
+
Top.Collections.Pictures.Astronomy.Astronauts
|
20
|
+
).each do |path|
|
21
|
+
%i( active deactive ).each do |status|
|
22
|
+
NotUniqTreeNode.create! new_path: path, status: status
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def teardown
|
28
|
+
NotUniqTreeNode.delete_all
|
29
|
+
end
|
30
|
+
|
31
|
+
test '#roots' do
|
32
|
+
assert_equal NotUniqTreeNode.roots.pluck(:new_path), ['Top', 'Top']
|
33
|
+
end
|
34
|
+
|
35
|
+
test '#at_depth' do
|
36
|
+
assert_equal NotUniqTreeNode.at_depth(5).pluck(:new_path), %w(
|
37
|
+
Top.Collections.Pictures.Astronomy.Stars
|
38
|
+
Top.Collections.Pictures.Astronomy.Stars
|
39
|
+
Top.Collections.Pictures.Astronomy.Galaxies
|
40
|
+
Top.Collections.Pictures.Astronomy.Galaxies
|
41
|
+
Top.Collections.Pictures.Astronomy.Astronauts
|
42
|
+
Top.Collections.Pictures.Astronomy.Astronauts
|
43
|
+
)
|
44
|
+
end
|
45
|
+
|
46
|
+
test '#leaves' do
|
47
|
+
assert_equal NotUniqTreeNode.where(status: :active).leaves.pluck(:new_path), %w(
|
48
|
+
Top.Science.Astronomy.Astrophysics
|
49
|
+
Top.Science.Astronomy.Cosmology
|
50
|
+
Top.Hobbies.Amateurs_Astronomy
|
51
|
+
Top.Collections.Pictures.Astronomy.Stars
|
52
|
+
Top.Collections.Pictures.Astronomy.Galaxies
|
53
|
+
Top.Collections.Pictures.Astronomy.Astronauts
|
54
|
+
)
|
55
|
+
end
|
56
|
+
|
57
|
+
test '#where_path_liked' do
|
58
|
+
assert_equal NotUniqTreeNode.where_path_liked('*{2}.Astronomy|Pictures').pluck(:new_path), %w(
|
59
|
+
Top.Science.Astronomy
|
60
|
+
Top.Science.Astronomy
|
61
|
+
Top.Collections.Pictures
|
62
|
+
Top.Collections.Pictures
|
63
|
+
)
|
64
|
+
end
|
65
|
+
|
66
|
+
def not_uniq_tree_node_find_by_path(path)
|
67
|
+
NotUniqTreeNode.find_by(status: :active, new_path: path)
|
68
|
+
end
|
69
|
+
|
70
|
+
test '.root?' do
|
71
|
+
assert not_uniq_tree_node_find_by_path('Top').root?
|
72
|
+
assert_not not_uniq_tree_node_find_by_path('Top.Science').root?
|
73
|
+
end
|
74
|
+
|
75
|
+
test '.depth' do
|
76
|
+
assert_equal not_uniq_tree_node_find_by_path('Top.Hobbies.Amateurs_Astronomy').depth, 3
|
77
|
+
end
|
78
|
+
|
79
|
+
test '.root' do
|
80
|
+
assert_equal not_uniq_tree_node_find_by_path('Top.Hobbies.Amateurs_Astronomy').root.new_path, 'Top'
|
81
|
+
end
|
82
|
+
|
83
|
+
test '.parent' do
|
84
|
+
assert_equal not_uniq_tree_node_find_by_path('Top.Collections.Pictures.Astronomy.Astronauts').parent.new_path,
|
85
|
+
'Top.Collections.Pictures.Astronomy'
|
86
|
+
end
|
87
|
+
|
88
|
+
test '.leaves' do
|
89
|
+
assert_equal not_uniq_tree_node_find_by_path('Top.Science').leaves.pluck(:new_path), %w(
|
90
|
+
Top.Science.Astronomy.Astrophysics
|
91
|
+
Top.Science.Astronomy.Cosmology
|
92
|
+
)
|
93
|
+
end
|
94
|
+
|
95
|
+
test '.leaf?' do
|
96
|
+
assert_not not_uniq_tree_node_find_by_path('Top').leaf?
|
97
|
+
assert not_uniq_tree_node_find_by_path('Top.Collections.Pictures.Astronomy.Astronauts').leaf?
|
98
|
+
end
|
99
|
+
|
100
|
+
test '.self_and_ancestors' do
|
101
|
+
assert_equal not_uniq_tree_node_find_by_path('Top.Collections.Pictures.Astronomy.Astronauts').self_and_ancestors.pluck(:new_path), %w(
|
102
|
+
Top
|
103
|
+
Top.Collections
|
104
|
+
Top.Collections.Pictures
|
105
|
+
Top.Collections.Pictures.Astronomy
|
106
|
+
Top.Collections.Pictures.Astronomy.Astronauts
|
107
|
+
)
|
108
|
+
end
|
109
|
+
|
110
|
+
test '.ancestors' do
|
111
|
+
assert_equal not_uniq_tree_node_find_by_path('Top.Collections.Pictures.Astronomy.Astronauts').ancestors.pluck(:new_path), %w(
|
112
|
+
Top
|
113
|
+
Top.Collections
|
114
|
+
Top.Collections.Pictures
|
115
|
+
Top.Collections.Pictures.Astronomy
|
116
|
+
)
|
117
|
+
end
|
118
|
+
|
119
|
+
test '.self_and_descendents' do
|
120
|
+
assert_equal not_uniq_tree_node_find_by_path('Top.Science').self_and_descendents.pluck(:new_path), %w(
|
121
|
+
Top.Science
|
122
|
+
Top.Science.Astronomy
|
123
|
+
Top.Science.Astronomy.Astrophysics
|
124
|
+
Top.Science.Astronomy.Cosmology
|
125
|
+
)
|
126
|
+
end
|
127
|
+
|
128
|
+
test '.descendents' do
|
129
|
+
assert_equal not_uniq_tree_node_find_by_path('Top.Science').descendents.pluck(:new_path), %w(
|
130
|
+
Top.Science.Astronomy
|
131
|
+
Top.Science.Astronomy.Astrophysics
|
132
|
+
Top.Science.Astronomy.Cosmology
|
133
|
+
)
|
134
|
+
end
|
135
|
+
|
136
|
+
test '.self_and_siblings' do
|
137
|
+
assert_equal not_uniq_tree_node_find_by_path('Top.Collections.Pictures.Astronomy.Stars').self_and_siblings.pluck(:new_path), %w(
|
138
|
+
Top.Collections.Pictures.Astronomy.Stars
|
139
|
+
Top.Collections.Pictures.Astronomy.Galaxies
|
140
|
+
Top.Collections.Pictures.Astronomy.Astronauts
|
141
|
+
)
|
142
|
+
end
|
143
|
+
|
144
|
+
|
145
|
+
test '.siblings' do
|
146
|
+
assert_equal not_uniq_tree_node_find_by_path('Top.Collections.Pictures.Astronomy.Stars').siblings.pluck(:new_path), %w(
|
147
|
+
Top.Collections.Pictures.Astronomy.Galaxies
|
148
|
+
Top.Collections.Pictures.Astronomy.Astronauts
|
149
|
+
)
|
150
|
+
end
|
151
|
+
|
152
|
+
test '.children' do
|
153
|
+
assert_equal not_uniq_tree_node_find_by_path('Top.Hobbies').children.pluck(:new_path), %w(
|
154
|
+
Top.Hobbies.Amateurs_Astronomy
|
155
|
+
)
|
156
|
+
end
|
157
|
+
end
|
data/test/test_helper.rb
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
# Configure Rails Environment
|
2
|
+
ENV["RAILS_ENV"] = "test"
|
3
|
+
|
4
|
+
require File.expand_path("../../test/dummy/config/environment.rb", __FILE__)
|
5
|
+
ActiveRecord::Migrator.migrations_paths = [File.expand_path("../../test/dummy/db/migrate", __FILE__)]
|
6
|
+
require "rails/test_help"
|
7
|
+
|
8
|
+
# Filter out Minitest backtrace while allowing backtrace from other libraries
|
9
|
+
# to be shown.
|
10
|
+
Minitest.backtrace_filter = Minitest::BacktraceFilter.new
|
11
|
+
|
12
|
+
# Load support files
|
13
|
+
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each { |f| require f }
|
14
|
+
|
15
|
+
# Load fixtures from the engine
|
16
|
+
if ActiveSupport::TestCase.respond_to?(:fixture_path=)
|
17
|
+
ActiveSupport::TestCase.fixture_path = File.expand_path("../fixtures", __FILE__)
|
18
|
+
ActiveSupport::TestCase.fixtures :all
|
19
|
+
end
|
20
|
+
|
21
|
+
require 'simplecov'
|
22
|
+
require 'coveralls'
|
23
|
+
SimpleCov.formatter = Coveralls::SimpleCov::Formatter
|
24
|
+
SimpleCov.start do
|
25
|
+
add_filter '/test/'
|
26
|
+
end
|