acts_as_tree 1.5.0 → 1.5.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +5 -3
- data/acts_as_tree.gemspec +1 -0
- data/lib/acts_as_tree.rb +1 -1
- data/lib/acts_as_tree/version.rb +1 -1
- data/test/acts_as_tree_test.rb +56 -7
- metadata +28 -14
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1c41a4e1bb7566bed286be2b6d709d809d1efab1
|
4
|
+
data.tar.gz: 4c3136bd0e036383541e9b28260918c8bcabd99e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: da1d685d61ea99d02e4293ccca0e48630730b972b72d391b4b8669d27ab50aebbb3b07b9d8de57d1c415f2d52f4605f79c0045c77f9c4039b29ab186d5440b6a
|
7
|
+
data.tar.gz: 8a93205c2921f71a909dc6c16e651e47a4c2c4c5ab7dd9cd80f517b7413f7675c04b9e1eaff12289cd7b784c3c581056c8045cb70253380a90bacf3e3cdb648f
|
data/README.md
CHANGED
@@ -8,8 +8,6 @@ ActsAsTree extends ActiveRecord to add simple support for organizing items into
|
|
8
8
|
|
9
9
|
```ruby
|
10
10
|
class Category < ActiveRecord::Base
|
11
|
-
include ActsAsTree
|
12
|
-
|
13
11
|
acts_as_tree order: "name"
|
14
12
|
end
|
15
13
|
|
@@ -27,7 +25,6 @@ We also have a convenient `Presentation` module you can mixin if you want a litt
|
|
27
25
|
|
28
26
|
```ruby
|
29
27
|
class Category < ActiveRecord::Base
|
30
|
-
include ActsAsTree
|
31
28
|
extend ActsAsTree::Presentation
|
32
29
|
|
33
30
|
acts_as_tree order: "name"
|
@@ -51,6 +48,8 @@ We no longer support Ruby 1.8 or versions of Rails/ActiveRecord older than 3.0.
|
|
51
48
|
Moving forward we will do our best to support the latest versions of ActiveRecord and Ruby.
|
52
49
|
|
53
50
|
## Change Log
|
51
|
+
* 1.5.1 - March 28, 2014
|
52
|
+
* Fixing descendants modification bug. See #20 -- amerine, tmuerell
|
54
53
|
* 1.5.0 - December 16th, 2013
|
55
54
|
* `Added new descendants method` -- adamkleingit
|
56
55
|
* Fixed warning message -- akicho8
|
@@ -86,6 +85,9 @@ Moving forward we will do our best to support the latest versions of ActiveRecor
|
|
86
85
|
your own version, that is fine but bump version in a commit by itself so we can
|
87
86
|
ignore when we pull)
|
88
87
|
5. Send us a pull request. Bonus points for topic branches.
|
88
|
+
6. All contributors to this project, after their first accepted patch, are given push
|
89
|
+
access to the repository and are welcome as full contributors to ActsAsTree. All
|
90
|
+
we ask is that all changes go through CI and a Pull Request before merging.
|
89
91
|
|
90
92
|
## License (MIT)
|
91
93
|
|
data/acts_as_tree.gemspec
CHANGED
data/lib/acts_as_tree.rb
CHANGED
@@ -152,7 +152,7 @@ module ActsAsTree
|
|
152
152
|
#
|
153
153
|
# root.descendants # => [child1, child2, subchild1, subchild2, subchild3, subchild4]
|
154
154
|
def descendants
|
155
|
-
children.each_with_object(children) {|child, arr|
|
155
|
+
children.each_with_object(children.to_a) {|child, arr|
|
156
156
|
arr.concat child.descendants
|
157
157
|
}.uniq
|
158
158
|
end
|
data/lib/acts_as_tree/version.rb
CHANGED
data/test/acts_as_tree_test.rb
CHANGED
@@ -1,8 +1,9 @@
|
|
1
|
-
require '
|
1
|
+
require 'minitest/autorun'
|
2
|
+
require 'minitest/benchmark'
|
2
3
|
require 'active_record'
|
3
4
|
require 'acts_as_tree'
|
4
5
|
|
5
|
-
class
|
6
|
+
class MiniTest::Unit::TestCase
|
6
7
|
def assert_queries(num = 1)
|
7
8
|
$query_count = 0
|
8
9
|
yield
|
@@ -62,7 +63,7 @@ class RecursivelyCascadedTreeMixin < Mixin
|
|
62
63
|
has_one :first_child, class_name: 'RecursivelyCascadedTreeMixin', foreign_key: :parent_id
|
63
64
|
end
|
64
65
|
|
65
|
-
class TreeTest <
|
66
|
+
class TreeTest < MiniTest::Unit::TestCase
|
66
67
|
|
67
68
|
def setup
|
68
69
|
setup_db
|
@@ -230,10 +231,58 @@ class TreeTest < Test::Unit::TestCase
|
|
230
231
|
TreeMixin.tree_view(:id)
|
231
232
|
assert_equal tree_view_outputs, $stdout.string
|
232
233
|
end
|
234
|
+
end
|
235
|
+
|
236
|
+
class TestDeepDescendantsPerformance < MiniTest::Unit::TestCase
|
237
|
+
def setup
|
238
|
+
teardown_db
|
239
|
+
setup_db
|
240
|
+
@root1 = TreeMixin.create!
|
241
|
+
create_cascade_children @root1, "root1", 10
|
242
|
+
|
243
|
+
@root2 = TreeMixin.create!
|
244
|
+
create_cascade_children @root2, "root2", 20
|
245
|
+
|
246
|
+
@root3 = TreeMixin.create!
|
247
|
+
create_cascade_children @root3, "root3", 30
|
248
|
+
|
249
|
+
@root4 = TreeMixin.create!
|
250
|
+
create_cascade_children @root4, "root4", 40
|
251
|
+
|
252
|
+
@root5 = TreeMixin.create!
|
253
|
+
create_cascade_children @root5, "root5", 50
|
254
|
+
end
|
233
255
|
|
256
|
+
def teardown
|
257
|
+
teardown_db
|
258
|
+
end
|
259
|
+
|
260
|
+
def self.bench_range
|
261
|
+
[1, 2, 3, 4, 5]
|
262
|
+
end
|
263
|
+
|
264
|
+
def bench_descendants
|
265
|
+
assert_performance_linear 0.99 do |x|
|
266
|
+
obj = instance_variable_get "@root#{x}"
|
267
|
+
obj.descendants
|
268
|
+
end
|
269
|
+
end
|
270
|
+
|
271
|
+
def create_cascade_children parent, parent_name, count
|
272
|
+
first_child_name = "@#{parent_name}_child1"
|
273
|
+
first_record = TreeMixin.create! parent_id: parent.id
|
274
|
+
instance_variable_set first_child_name, first_record
|
275
|
+
|
276
|
+
(2...count).each do |child_count|
|
277
|
+
name = "@#{parent_name}_child#{child_count}"
|
278
|
+
prev = instance_variable_get "@#{parent_name}_child#{child_count - 1}"
|
279
|
+
new_record = TreeMixin.create! parent_id: prev.id
|
280
|
+
instance_variable_set name, new_record
|
281
|
+
end
|
282
|
+
end
|
234
283
|
end
|
235
284
|
|
236
|
-
class TreeTestWithEagerLoading <
|
285
|
+
class TreeTestWithEagerLoading < MiniTest::Unit::TestCase
|
237
286
|
|
238
287
|
def setup
|
239
288
|
teardown_db
|
@@ -294,7 +343,7 @@ class TreeTestWithEagerLoading < Test::Unit::TestCase
|
|
294
343
|
end
|
295
344
|
end
|
296
345
|
|
297
|
-
class TreeTestWithoutOrder <
|
346
|
+
class TreeTestWithoutOrder < MiniTest::Unit::TestCase
|
298
347
|
|
299
348
|
def setup
|
300
349
|
setup_db
|
@@ -315,7 +364,7 @@ class TreeTestWithoutOrder < Test::Unit::TestCase
|
|
315
364
|
end
|
316
365
|
end
|
317
366
|
|
318
|
-
class UnsavedTreeTest <
|
367
|
+
class UnsavedTreeTest < MiniTest::Unit::TestCase
|
319
368
|
def setup
|
320
369
|
setup_db
|
321
370
|
@root = TreeMixin.new
|
@@ -333,7 +382,7 @@ class UnsavedTreeTest < Test::Unit::TestCase
|
|
333
382
|
end
|
334
383
|
|
335
384
|
|
336
|
-
class TreeTestWithCounterCache <
|
385
|
+
class TreeTestWithCounterCache < MiniTest::Unit::TestCase
|
337
386
|
def setup
|
338
387
|
teardown_db
|
339
388
|
setup_db
|
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.5.
|
4
|
+
version: 1.5.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Erik Dahlstrand
|
@@ -11,50 +11,64 @@ authors:
|
|
11
11
|
autorequire:
|
12
12
|
bindir: bin
|
13
13
|
cert_chain: []
|
14
|
-
date:
|
14
|
+
date: 2014-03-28 00:00:00.000000000 Z
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
17
17
|
name: activerecord
|
18
18
|
requirement: !ruby/object:Gem::Requirement
|
19
19
|
requirements:
|
20
|
-
- -
|
20
|
+
- - ">="
|
21
21
|
- !ruby/object:Gem::Version
|
22
22
|
version: 3.0.0
|
23
23
|
type: :runtime
|
24
24
|
prerelease: false
|
25
25
|
version_requirements: !ruby/object:Gem::Requirement
|
26
26
|
requirements:
|
27
|
-
- -
|
27
|
+
- - ">="
|
28
28
|
- !ruby/object:Gem::Version
|
29
29
|
version: 3.0.0
|
30
30
|
- !ruby/object:Gem::Dependency
|
31
31
|
name: sqlite3
|
32
32
|
requirement: !ruby/object:Gem::Requirement
|
33
33
|
requirements:
|
34
|
-
- -
|
34
|
+
- - ">="
|
35
35
|
- !ruby/object:Gem::Version
|
36
36
|
version: '0'
|
37
37
|
type: :development
|
38
38
|
prerelease: false
|
39
39
|
version_requirements: !ruby/object:Gem::Requirement
|
40
40
|
requirements:
|
41
|
-
- -
|
41
|
+
- - ">="
|
42
42
|
- !ruby/object:Gem::Version
|
43
43
|
version: '0'
|
44
44
|
- !ruby/object:Gem::Dependency
|
45
45
|
name: rdoc
|
46
46
|
requirement: !ruby/object:Gem::Requirement
|
47
47
|
requirements:
|
48
|
-
- -
|
48
|
+
- - ">="
|
49
49
|
- !ruby/object:Gem::Version
|
50
50
|
version: '0'
|
51
51
|
type: :development
|
52
52
|
prerelease: false
|
53
53
|
version_requirements: !ruby/object:Gem::Requirement
|
54
54
|
requirements:
|
55
|
-
- -
|
55
|
+
- - ">="
|
56
56
|
- !ruby/object:Gem::Version
|
57
57
|
version: '0'
|
58
|
+
- !ruby/object:Gem::Dependency
|
59
|
+
name: minitest
|
60
|
+
requirement: !ruby/object:Gem::Requirement
|
61
|
+
requirements:
|
62
|
+
- - "~>"
|
63
|
+
- !ruby/object:Gem::Version
|
64
|
+
version: 4.7.5
|
65
|
+
type: :development
|
66
|
+
prerelease: false
|
67
|
+
version_requirements: !ruby/object:Gem::Requirement
|
68
|
+
requirements:
|
69
|
+
- - "~>"
|
70
|
+
- !ruby/object:Gem::Version
|
71
|
+
version: 4.7.5
|
58
72
|
description: A gem that adds simple support for organizing ActiveRecord models into
|
59
73
|
parent–children relationships.
|
60
74
|
email:
|
@@ -65,8 +79,8 @@ executables: []
|
|
65
79
|
extensions: []
|
66
80
|
extra_rdoc_files: []
|
67
81
|
files:
|
68
|
-
- .gitignore
|
69
|
-
- .travis.yml
|
82
|
+
- ".gitignore"
|
83
|
+
- ".travis.yml"
|
70
84
|
- Gemfile
|
71
85
|
- README.md
|
72
86
|
- Rakefile
|
@@ -85,22 +99,22 @@ licenses: []
|
|
85
99
|
metadata: {}
|
86
100
|
post_install_message:
|
87
101
|
rdoc_options:
|
88
|
-
- --charset=UTF-8
|
102
|
+
- "--charset=UTF-8"
|
89
103
|
require_paths:
|
90
104
|
- lib
|
91
105
|
required_ruby_version: !ruby/object:Gem::Requirement
|
92
106
|
requirements:
|
93
|
-
- -
|
107
|
+
- - ">="
|
94
108
|
- !ruby/object:Gem::Version
|
95
109
|
version: '0'
|
96
110
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
97
111
|
requirements:
|
98
|
-
- -
|
112
|
+
- - ">="
|
99
113
|
- !ruby/object:Gem::Version
|
100
114
|
version: '0'
|
101
115
|
requirements: []
|
102
116
|
rubyforge_project:
|
103
|
-
rubygems_version: 2.
|
117
|
+
rubygems_version: 2.2.2
|
104
118
|
signing_key:
|
105
119
|
specification_version: 4
|
106
120
|
summary: Provides a simple tree behaviour to active_record models.
|