text_based_nested_set 0.0.3 → 0.0.4

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: c72f8e427941cd6feea390a265b733a43abb67d5
4
- data.tar.gz: 9f53448a0eeac510ca11ec8bb7810113f11542bc
3
+ metadata.gz: 78749e7217cec62deb80deeead9fc78f0a772ef7
4
+ data.tar.gz: 8d4c60d74da99f5713ca8fb6b1c8d01c48de47e9
5
5
  SHA512:
6
- metadata.gz: 3345259666272c83c3bcf68cf6c72a6c68200d5d08199acbbb786d601b7d9e312ea611b66a71edb60b67ba453cd39d8e8215295c8442d319f6840f5669be1448
7
- data.tar.gz: b11900f37074b7415ef373bfd728e33bf443b9fb08a852e0f867522fbba1bbf5423ba42d78658b5f99e6a4c99a093fb101966afc727ae3548b7a6cafe12a6832
6
+ metadata.gz: baa53fc66973c9493c9e1a76fcf17ddbf478676b4ff82d098368286ea1317d80f49bae1a04b2ab5953136bfacd6d80219e03726019466e19b96fc80686964e5a
7
+ data.tar.gz: 08abf2d09fea02c5b9444268b6205a1362c48f837792f9bffcdef38e718c998304cff070b29b8291b1db8c570556c67abdc386a73e7c1161524b9da3bdd8d35f
data/.travis.yml ADDED
@@ -0,0 +1,9 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.1.2
4
+
5
+ before_script:
6
+ - mysql -e 'create database tb_nested_set_gem_test;'
7
+
8
+ script:
9
+ rspec spec
data/README.md CHANGED
@@ -1,3 +1,5 @@
1
+ [![Build Status](https://travis-ci.org/beyondalbert/text_based_nested_set.png?branch=master)](https://travis-ci.org/beyondalbert/text_based_nested_set)
2
+
1
3
  # TextBasedNestedSet
2
4
 
3
5
  this acts provides Text Based Nested Set functionality.
@@ -140,8 +140,7 @@ module BeyondAlbert
140
140
  end
141
141
 
142
142
  def self_and_ancestors
143
- parent_ids = self.path.split('/').select {|v| v != "" && v != "0"} << self.id
144
- current_class.where(id: parent_ids)
143
+ ancestors << self
145
144
  end
146
145
 
147
146
  def children
@@ -154,6 +153,10 @@ module BeyondAlbert
154
153
  current_class.where("path LIKE ?", descendants_path).order("LENGTH(path) ASC, position ASC")
155
154
  end
156
155
 
156
+ def self_and_descendants
157
+ descendants.unshift(self)
158
+ end
159
+
157
160
  def right_sibling
158
161
  right_siblings = current_class.where(path: self.path, position: self.position + 1)
159
162
  if right_siblings.empty?
@@ -1,3 +1,3 @@
1
1
  module TextBasedNestedSet
2
- VERSION = "0.0.3"
2
+ VERSION = "0.0.4"
3
3
  end
data/spec/db/database.yml CHANGED
@@ -3,5 +3,4 @@ mysql:
3
3
  host: localhost
4
4
  encoding: utf8
5
5
  database: tb_nested_set_gem_test
6
- username: root
7
- password: "albert"
6
+ username: root
@@ -119,6 +119,13 @@ describe 'TextBasedNestedSet' do
119
119
  end
120
120
  end
121
121
 
122
+ describe 'self_and_descendants' do
123
+ it "should return current node and it's all descendants" do
124
+ expect(@child_1.self_and_descendants).to eq([@child_1, @child_1_1, @child_1_2, @child_1_3, @child_1_2_1, @child_1_1_1])
125
+ expect(@root.self_and_descendants).to eq([@root, @child_1, @child_2, @child_1_1, @child_1_2, @child_1_3, @child_1_2_1, @child_1_1_1])
126
+ end
127
+ end
128
+
122
129
  describe 'right_sibling' do
123
130
  it "should return current node's right sibling" do
124
131
  expect(@child_1_2.right_sibling).to eq(@child_1_3)
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.3
4
+ version: 0.0.4
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-10 00:00:00.000000000 Z
11
+ date: 2015-02-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -131,6 +131,7 @@ extra_rdoc_files: []
131
131
  files:
132
132
  - ".gitignore"
133
133
  - ".rspec"
134
+ - ".travis.yml"
134
135
  - Gemfile
135
136
  - LICENSE.txt
136
137
  - README.md