text_based_nested_set 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 801c7e1b6c9348f8d13efbde0c51d6cf76b85287
4
- data.tar.gz: 148ad9c927c282fcd9568b97db9bdc44a474f634
3
+ metadata.gz: c72f8e427941cd6feea390a265b733a43abb67d5
4
+ data.tar.gz: 9f53448a0eeac510ca11ec8bb7810113f11542bc
5
5
  SHA512:
6
- metadata.gz: 4ec694a77e0dc41ff0af8c5fb97ce857bc3f61e313a5e4a8c8e8b0a31d564e5c09efbb125784d9deff3a7a93c7331059f46bdcde3d89771f03922e2ec3cb408b
7
- data.tar.gz: 00a489336c447a164b5e3a20ba70477b917dad493fda790ed05cf005b9a9cd88380e9849aade04a31d9fef498782e99e09062c3c46f3e06fb040229ac7fa5e1c
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
@@ -1,3 +1,3 @@
1
1
  module TextBasedNestedSet
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
@@ -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(5)
11
- # | | |__child_1_2_1(8)
12
- # | |__child_1_3(6)
13
- # |__child_2(3)
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: 3, 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: 5, name: "child_1_2", parent_id: 2, path: "/0/1/2/", position: 1)
19
- @child_1_3 = create(:category, id: 6, name: "child_1_3", parent_id: 2, path: "/0/1/2/", position: 2)
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: 8, name: "child_1_2_1", parent_id: 5, path: "/0/1/2/5/", position: 0)
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/5/")
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/5/')
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/5/')
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, @child_1_1_1, @child_1_2_1])
118
- expect(@root.descendants).to eq([@child_1, @child_2, @child_1_1, @child_1_2, @child_1_3, @child_1_1_1, @child_1_2_1])
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(3).name).to eq('child_2')
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.2
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-09 00:00:00.000000000 Z
11
+ date: 2015-02-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler