acts_as_tree 1.2.0 → 1.3.0
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.
- data/.travis.yml +18 -1
- data/Gemfile +1 -1
- data/README.md +18 -14
- data/gemfiles/rails-3.0.gemfile +6 -0
- data/gemfiles/rails-3.1.gemfile +6 -0
- data/gemfiles/rails-3.2.gemfile +6 -0
- data/gemfiles/rails-4.0.gemfile +6 -0
- data/lib/acts_as_tree.rb +13 -5
- data/lib/acts_as_tree/version.rb +1 -1
- data/test/acts_as_tree_test.rb +12 -12
- metadata +6 -2
data/.travis.yml
CHANGED
@@ -2,4 +2,21 @@ language: ruby
|
|
2
2
|
rvm:
|
3
3
|
- 1.9.2
|
4
4
|
- 1.9.3
|
5
|
-
-
|
5
|
+
- 2.0.0
|
6
|
+
|
7
|
+
gemfile:
|
8
|
+
- gemfiles/rails-3.0.gemfile
|
9
|
+
- gemfiles/rails-3.1.gemfile
|
10
|
+
- gemfiles/rails-3.2.gemfile
|
11
|
+
- gemfiles/rails-4.0.gemfile
|
12
|
+
|
13
|
+
matrix:
|
14
|
+
exclude:
|
15
|
+
# rails 4.0 requries ruby 1.9.3 or newer
|
16
|
+
- rvm: 1.9.2
|
17
|
+
gemfile: gemfiles/rails-4.0.gemfile
|
18
|
+
# rails < 3.2 is unsupported on ruby 2.0
|
19
|
+
- rvm: 2.0.0
|
20
|
+
gemfile: gemfiles/rails-3.0.gemfile
|
21
|
+
- rvm: 2.0.0
|
22
|
+
gemfile: gemfiles/rails-3.1.gemfile
|
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -1,6 +1,5 @@
|
|
1
|
-
# ActsAsTree [][travis]
|
1
|
+
# ActsAsTree [][travis]
|
2
2
|
[travis]: (http://travis-ci.org/amerine/acts_as_tree)
|
3
|
-
[gemnasium]: (https://gemnasium.com/amerine/acts_as_tree)
|
4
3
|
|
5
4
|
|
6
5
|
ActsAsTree extends ActiveRecord to add simple support for organizing items into
|
@@ -8,28 +7,33 @@ parent–children relationships.
|
|
8
7
|
|
9
8
|
## Example
|
10
9
|
|
11
|
-
|
12
|
-
|
10
|
+
```ruby
|
11
|
+
class Category < ActiveRecord::Base
|
12
|
+
include ActsAsTree
|
13
13
|
|
14
|
-
|
15
|
-
|
14
|
+
acts_as_tree order: "name"
|
15
|
+
end
|
16
16
|
|
17
|
-
|
18
|
-
|
19
|
-
|
17
|
+
root = Category.create("name" => "root")
|
18
|
+
child1 = root.children.create("name" => "child1")
|
19
|
+
subchild1 = child1.children.create("name" => "subchild1")
|
20
20
|
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
21
|
+
root.parent # => nil
|
22
|
+
child1.parent # => root
|
23
|
+
root.children # => [child1]
|
24
|
+
root.children.first.children.first # => subchild1
|
25
|
+
```
|
25
26
|
|
26
27
|
## Compatibility
|
27
28
|
|
28
|
-
We no longer support Ruby 1.8 or versions
|
29
|
+
We no longer support Ruby 1.8 or versions of Rails/ActiveRecord older than 3.0. If you're using a version of ActiveRecord older than 3.0 please use 0.1.1.
|
29
30
|
|
30
31
|
Moving forward we will do our best to support the latest versions of ActiveRecord and Ruby.
|
31
32
|
|
32
33
|
## Change Log
|
34
|
+
* 1.3.0 - March 29th, 2013
|
35
|
+
* Rails 4.0 Support! -- mischa78
|
36
|
+
* Readme Fixes -- mischa78 & seanhussey
|
33
37
|
* 1.2.0 - October 29th, 2012
|
34
38
|
* Adding new `self_with_ancestors` accessor -- fbuenemann
|
35
39
|
* `roots` is now a scope.
|
data/lib/acts_as_tree.rb
CHANGED
@@ -75,11 +75,19 @@ module ActsAsTree
|
|
75
75
|
counter_cache: configuration[:counter_cache],
|
76
76
|
inverse_of: :children
|
77
77
|
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
78
|
+
if ActiveRecord::VERSION::MAJOR >= 4
|
79
|
+
has_many :children, lambda { order configuration[:order] },
|
80
|
+
class_name: name,
|
81
|
+
foreign_key: configuration[:foreign_key],
|
82
|
+
dependent: configuration[:dependent],
|
83
|
+
inverse_of: :parent
|
84
|
+
else
|
85
|
+
has_many :children, class_name: name,
|
86
|
+
foreign_key: configuration[:foreign_key],
|
87
|
+
order: configuration[:order],
|
88
|
+
dependent: configuration[:dependent],
|
89
|
+
inverse_of: :parent
|
90
|
+
end
|
83
91
|
|
84
92
|
class_eval <<-EOV
|
85
93
|
include ActsAsTree::InstanceMethods
|
data/lib/acts_as_tree/version.rb
CHANGED
data/test/acts_as_tree_test.rb
CHANGED
@@ -204,9 +204,9 @@ class TreeTestWithEagerLoading < Test::Unit::TestCase
|
|
204
204
|
end
|
205
205
|
|
206
206
|
def test_eager_association_loading
|
207
|
-
roots = TreeMixin.
|
208
|
-
|
209
|
-
|
207
|
+
roots = TreeMixin.includes(:children)
|
208
|
+
.where('mixins.parent_id IS NULL')
|
209
|
+
.order('mixins.id')
|
210
210
|
|
211
211
|
assert_equal [@root1, @root2, @root3], roots
|
212
212
|
|
@@ -218,25 +218,25 @@ class TreeTestWithEagerLoading < Test::Unit::TestCase
|
|
218
218
|
end
|
219
219
|
|
220
220
|
def test_eager_association_loading_with_recursive_cascading_three_levels_has_many
|
221
|
-
root_node = RecursivelyCascadedTreeMixin.
|
222
|
-
|
223
|
-
|
221
|
+
root_node = RecursivelyCascadedTreeMixin.includes({children: {children: :children}})
|
222
|
+
.order('mixins.id')
|
223
|
+
.first
|
224
224
|
|
225
225
|
assert_equal @rc4, assert_no_queries { root_node.children.first.children.first.children.first }
|
226
226
|
end
|
227
227
|
|
228
228
|
def test_eager_association_loading_with_recursive_cascading_three_levels_has_one
|
229
|
-
root_node = RecursivelyCascadedTreeMixin.
|
230
|
-
|
231
|
-
|
229
|
+
root_node = RecursivelyCascadedTreeMixin.includes({first_child: {first_child: :first_child}})
|
230
|
+
.order('mixins.id')
|
231
|
+
.first
|
232
232
|
|
233
233
|
assert_equal @rc4, assert_no_queries { root_node.first_child.first_child.first_child }
|
234
234
|
end
|
235
235
|
|
236
236
|
def test_eager_association_loading_with_recursive_cascading_three_levels_belongs_to
|
237
|
-
leaf_node = RecursivelyCascadedTreeMixin.
|
238
|
-
|
239
|
-
|
237
|
+
leaf_node = RecursivelyCascadedTreeMixin.includes({parent: {parent: :parent}})
|
238
|
+
.order('mixins.id DESC')
|
239
|
+
.first
|
240
240
|
|
241
241
|
assert_equal @rc1, assert_no_queries { leaf_node.parent.parent.parent }
|
242
242
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: acts_as_tree
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.3.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -12,7 +12,7 @@ authors:
|
|
12
12
|
autorequire:
|
13
13
|
bindir: bin
|
14
14
|
cert_chain: []
|
15
|
-
date:
|
15
|
+
date: 2013-03-29 00:00:00.000000000 Z
|
16
16
|
dependencies:
|
17
17
|
- !ruby/object:Gem::Dependency
|
18
18
|
name: activerecord
|
@@ -78,6 +78,10 @@ files:
|
|
78
78
|
- README.md
|
79
79
|
- Rakefile
|
80
80
|
- acts_as_tree.gemspec
|
81
|
+
- gemfiles/rails-3.0.gemfile
|
82
|
+
- gemfiles/rails-3.1.gemfile
|
83
|
+
- gemfiles/rails-3.2.gemfile
|
84
|
+
- gemfiles/rails-4.0.gemfile
|
81
85
|
- lib/acts_as_tree.rb
|
82
86
|
- lib/acts_as_tree/active_record/acts/tree.rb
|
83
87
|
- lib/acts_as_tree/railtie.rb
|