text_based_nested_set 0.0.2 → 0.0.3
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/lib/text_based_nested_set/model.rb +1 -1
- data/lib/text_based_nested_set/version.rb +1 -1
- data/spec/text_based_nested_set_spec.rb +15 -15
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c72f8e427941cd6feea390a265b733a43abb67d5
|
4
|
+
data.tar.gz: 9f53448a0eeac510ca11ec8bb7810113f11542bc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3345259666272c83c3bcf68cf6c72a6c68200d5d08199acbbb786d601b7d9e312ea611b66a71edb60b67ba453cd39d8e8215295c8442d319f6840f5669be1448
|
7
|
+
data.tar.gz: b11900f37074b7415ef373bfd728e33bf443b9fb08a852e0f867522fbba1bbf5423ba42d78658b5f99e6a4c99a093fb101966afc727ae3548b7a6cafe12a6832
|
@@ -151,7 +151,7 @@ module BeyondAlbert
|
|
151
151
|
|
152
152
|
def descendants
|
153
153
|
descendants_path = self.path + self.id.to_s + '/%'
|
154
|
-
current_class.where("path LIKE ?", descendants_path)
|
154
|
+
current_class.where("path LIKE ?", descendants_path).order("LENGTH(path) ASC, position ASC")
|
155
155
|
end
|
156
156
|
|
157
157
|
def right_sibling
|
@@ -7,18 +7,18 @@ describe 'TextBasedNestedSet' do
|
|
7
7
|
# |__child_1(2)
|
8
8
|
# | |__child_1_1(4)
|
9
9
|
# | | |__child_1_1_1(7)
|
10
|
-
# | |__child_1_2(
|
11
|
-
# | | |__child_1_2_1(
|
12
|
-
# | |__child_1_3(
|
13
|
-
# |__child_2(
|
10
|
+
# | |__child_1_2(6)
|
11
|
+
# | | |__child_1_2_1(3)
|
12
|
+
# | |__child_1_3(5)
|
13
|
+
# |__child_2(8)
|
14
14
|
@root = create(:category, id: 1, parent_id: 0, path: "/0/", position: 0)
|
15
15
|
@child_1 = create(:category, id: 2, name: "child_1", parent_id: 1, path: "/0/1/", position: 0)
|
16
|
-
@child_2 = create(:category, id:
|
17
|
-
@child_1_1 = create(:category, id: 4, name: "child_1_1", parent_id: 2, path: "/0/1/2/", position: 0)
|
18
|
-
@child_1_2 = create(:category, id:
|
19
|
-
@child_1_3 = create(:category, id:
|
16
|
+
@child_2 = create(:category, id: 8, name: "child_2", parent_id: 1, path: "/0/1/", position: 1)
|
17
|
+
@child_1_1 = create(:category, id: 4, name: "child_1_1", parent_id: 2, path: "/0/1/2/", position: 0)
|
18
|
+
@child_1_2 = create(:category, id: 6, name: "child_1_2", parent_id: 2, path: "/0/1/2/", position: 1)
|
19
|
+
@child_1_3 = create(:category, id: 5, name: "child_1_3", parent_id: 2, path: "/0/1/2/", position: 2)
|
20
20
|
@child_1_1_1 = create(:category, id: 7, name: "child_1_1_1", parent_id: 4, path: "/0/1/2/4/", position: 0)
|
21
|
-
@child_1_2_1 = create(:category, id:
|
21
|
+
@child_1_2_1 = create(:category, id: 3, name: "child_1_2_1", parent_id: 6, path: "/0/1/2/6/", position: 0)
|
22
22
|
end
|
23
23
|
|
24
24
|
describe 'move_to_root' do
|
@@ -33,7 +33,7 @@ describe 'TextBasedNestedSet' do
|
|
33
33
|
expect(@child_1_2.position).to eq(0)
|
34
34
|
expect(@child_1_1.position).to eq(0)
|
35
35
|
expect(@child_1_3.position).to eq(1)
|
36
|
-
expect(@child_1_2_1.path).to eq("/0/
|
36
|
+
expect(@child_1_2_1.path).to eq("/0/6/")
|
37
37
|
expect(@child_1.descendants).to eq([@child_1_1, @child_1_3, @child_1_1_1])
|
38
38
|
end
|
39
39
|
end
|
@@ -50,7 +50,7 @@ describe 'TextBasedNestedSet' do
|
|
50
50
|
expect(@child_1_2.position).to eq(1)
|
51
51
|
expect(@child_2.position).to eq(2)
|
52
52
|
expect(@child_1_3.position).to eq(1)
|
53
|
-
expect(@child_1_2_1.path).to eq('/0/1/
|
53
|
+
expect(@child_1_2_1.path).to eq('/0/1/6/')
|
54
54
|
end
|
55
55
|
end
|
56
56
|
|
@@ -80,7 +80,7 @@ describe 'TextBasedNestedSet' do
|
|
80
80
|
expect(@child_1_2.path).to eq('/0/1/2/4/')
|
81
81
|
expect(@child_1_2.position).to eq(1)
|
82
82
|
expect(@child_1_3.position).to eq(1)
|
83
|
-
expect(@child_1_2_1.path).to eq('/0/1/2/4/
|
83
|
+
expect(@child_1_2_1.path).to eq('/0/1/2/4/6/')
|
84
84
|
end
|
85
85
|
end
|
86
86
|
|
@@ -114,8 +114,8 @@ describe 'TextBasedNestedSet' do
|
|
114
114
|
|
115
115
|
describe 'descendants' do
|
116
116
|
it "should return current node's all descendants" do
|
117
|
-
expect(@child_1.descendants).to eq([@child_1_1, @child_1_2, @child_1_3, @
|
118
|
-
expect(@root.descendants).to eq([@child_1, @child_2, @child_1_1, @child_1_2, @child_1_3, @
|
117
|
+
expect(@child_1.descendants).to eq([@child_1_1, @child_1_2, @child_1_3, @child_1_2_1, @child_1_1_1])
|
118
|
+
expect(@root.descendants).to eq([@child_1, @child_2, @child_1_1, @child_1_2, @child_1_3, @child_1_2_1, @child_1_1_1])
|
119
119
|
end
|
120
120
|
end
|
121
121
|
|
@@ -194,7 +194,7 @@ describe 'TextBasedNestedSet' do
|
|
194
194
|
it 'should destroy descendants when itself be destroyed' do
|
195
195
|
@child_1.destroy
|
196
196
|
expect(Category.find_by_id(4)).to eq(nil)
|
197
|
-
expect(Category.find_by_id(
|
197
|
+
expect(Category.find_by_id(8).name).to eq('child_2')
|
198
198
|
end
|
199
199
|
end
|
200
200
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: text_based_nested_set
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- beyondalbert
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-02-
|
11
|
+
date: 2015-02-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|