acts_as_tree 2.6.0 → 2.6.1

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: c1348043cad77cbacfb197eb2d96ff6e1ac84be3
4
- data.tar.gz: 305512fe8ce041f273a65fe951343e8a37555a93
3
+ metadata.gz: 12616559e89eeee23f6e37d97779cc5e1f3c50de
4
+ data.tar.gz: 32344222affc6cd7746e14fe4a0d218e0fca5e35
5
5
  SHA512:
6
- metadata.gz: 81a7871c4c36509e001435e8161415fe067768bf8080b1ef824e7d95ec2a710075a3974fc141eb7d15f3d87c3b6d5dbe4a4d9b858d1f32a66555b26cd7885b83
7
- data.tar.gz: 033de96f25e5a03f3e605a6c7940ce440819bf0754154ac24dfac1568c34880107647e7d4164ef102d3ad2b07e7f50d6ea634a997b4de10fd65ffdbf5bc7de94
6
+ metadata.gz: 484644c639c9dceda0c847ac3e57e861ed3429316116ae5d1f34547f8109a0d99811a3a98a205a5e7b6bc50b25348104bb8e03da1043d8b4cc0e8f34d870408f
7
+ data.tar.gz: 75cf6219da3b6d5a87c46246b16431d81dd5966df06e82d23996e474078afa1d734ab02e0a1afbd544393421ee0f305beff914b29e76cfbe551b3f25438892b3
data/README.md CHANGED
@@ -74,6 +74,9 @@ We no longer support Ruby 1.8 or versions of Rails/ActiveRecord older than 3.0.
74
74
  Moving forward we will do our best to support the latest versions of ActiveRecord and Ruby.
75
75
 
76
76
  ## Change Log
77
+ * 2.6.1 - January 18, 2017
78
+ * Avoid conflicts of `#level` method with existing column, see #57, #58, #60 -- markhgbrewster
79
+ * Fix tests on rails 4.2 with ruby < 2.1 -- felixbuenemann
77
80
  * 2.6.0 - October 9, 2016
78
81
  * Add generations methods, see #56 -- markhgbrewster
79
82
  * 2.5.1 - September 8, 2016
@@ -146,7 +149,7 @@ Moving forward we will do our best to support the latest versions of ActiveRecor
146
149
  people know that 1101.1.1 has breaking differences from 1100.0. If you're
147
150
  adding new features, but not changing existing functionality bump the minor
148
151
  version, if you're shipping a bugfix, just bump the patch.
149
- 2. Following the above rules, change the version found in lib/acts_as_tree/version.rb.
152
+ 2. Following the above rules, change the version found in lib/acts\_as\_tree/version.rb.
150
153
  3. Make sure the Change log in the README includes a brief summary of the versions
151
154
  changes, with credit to the contributors.
152
155
  4. Commit these changes in one "release-prep" commit (on the master branch).
@@ -2,5 +2,6 @@ source "https://rubygems.org"
2
2
 
3
3
  gem "rails", "~> 4.2.0"
4
4
  gem "mime-types", "< 3"
5
+ gem "nokogiri", "< 1.7"
5
6
 
6
7
  gemspec path: "../"
@@ -127,11 +127,12 @@ module ActsAsTree
127
127
 
128
128
  # Returns a hash of all nodes grouped by their level in the tree structure.
129
129
  #
130
- # Class.generations { 0=> [root1, root2], 1=> [root1child1, root1child2, root2child1, root2child2] }
130
+ # Class.generations # => { 0=> [root1, root2], 1=> [root1child1, root1child2, root2child1, root2child2] }
131
131
  def self.generations
132
- all.group_by{ |node| node.level }
132
+ all.group_by{ |node| node.tree_level }
133
133
  end
134
134
 
135
+
135
136
  if configuration[:counter_cache]
136
137
  after_update :update_parents_counter_cache
137
138
 
@@ -290,25 +291,38 @@ module ActsAsTree
290
291
 
291
292
  # Returns all the nodes at the same level in the tree as the current node.
292
293
  #
293
- # root1child1.generation [root1child2, root2child1, root2child2]
294
+ # root1child1.generation # => [root1child2, root2child1, root2child2]
294
295
  def generation
295
296
  self_and_generation - [self]
296
297
  end
297
298
 
298
299
  # Returns a reference to the current node and all the nodes at the same level as it in the tree.
299
300
  #
300
- # root1child1.generation [root1child1, root1child2, root2child1, root2child2]
301
+ # root1child1.self_and_generation # => [root1child1, root1child2, root2child1, root2child2]
301
302
  def self_and_generation
302
- self.class.select {|node| node.level == self.level }
303
+ self.class.select {|node| node.tree_level == self.tree_level }
303
304
  end
304
305
 
305
- # Returns the level (depth) of the current node
306
+ # Returns the level (depth) of the current node
306
307
  #
307
- # root1child1.level 1
308
- def level
308
+ # root1child1.tree_level # => 1
309
+ def tree_level
309
310
  self.ancestors.size
310
311
  end
311
312
 
313
+ # Returns the level (depth) of the current node unless level is a column on the node.
314
+ # Allows backwards compatibility with older versions of the gem.
315
+ # Allows integration with apps using level as a column name.
316
+ #
317
+ # root1child1.level # => 1
318
+ def level
319
+ if self.class.column_names.include?('level')
320
+ super
321
+ else
322
+ tree_level
323
+ end
324
+ end
325
+
312
326
  # Returns children (without subchildren) and current node itself.
313
327
  #
314
328
  # root.self_and_children # => [root, child1]
@@ -1,3 +1,3 @@
1
1
  module ActsAsTree
2
- VERSION = "2.6.0"
2
+ VERSION = "2.6.1"
3
3
  end
@@ -60,6 +60,12 @@ def setup_db(options = {})
60
60
  t.column :children_count, :integer, default: 0 if options[:counter_cache]
61
61
  t.timestamps null: false
62
62
  end
63
+
64
+ create_table :level_mixins, force: true do |t|
65
+ t.column :level, :string
66
+ t.column :parent_id, :integer
67
+ t.timestamps null: false
68
+ end
63
69
  end
64
70
 
65
71
  # Fix broken reset_column_information in some activerecord versions.
@@ -75,10 +81,23 @@ class Mixin < ActiveRecord::Base
75
81
  include ActsAsTree
76
82
  end
77
83
 
84
+ class LevelMixin < ActiveRecord::Base
85
+ include ActsAsTree
86
+ acts_as_tree foreign_key: "parent_id", order: "id"
87
+ end
88
+
78
89
  class TreeMixin < Mixin
79
90
  acts_as_tree foreign_key: "parent_id", order: "id"
80
91
  end
81
92
 
93
+ class TreeMixinWithLevelMethod < Mixin
94
+ acts_as_tree foreign_key: "parent_id", order: "id"
95
+
96
+ def level
97
+ 'Has Level Method'
98
+ end
99
+ end
100
+
82
101
  class TreeMixinWithoutOrder < Mixin
83
102
  acts_as_tree foreign_key: "parent_id"
84
103
  end
@@ -541,7 +560,7 @@ class ExternalTreeTest < TreeTest
541
560
  end
542
561
  end
543
562
 
544
- class GenertaionMethods < ActsAsTreeTestCase
563
+ class GenerationMethods < ActsAsTreeTestCase
545
564
  def setup
546
565
  setup_db
547
566
 
@@ -555,6 +574,8 @@ class GenertaionMethods < ActsAsTreeTestCase
555
574
  @root2_child2 = TreeMixin.create! parent_id: @root2.id
556
575
  @root2_child1_child = TreeMixin.create! parent_id: @root2_child1.id
557
576
  @root3 = TreeMixin.create!
577
+ @level_column = LevelMixin.create! level: 'Has Level Column'
578
+ @level_method = TreeMixinWithLevelMethod.create!
558
579
  end
559
580
 
560
581
  def test_generations
@@ -586,11 +607,23 @@ class GenertaionMethods < ActsAsTreeTestCase
586
607
  assert_equal [@child1_child_child], @child1_child_child.self_and_generation
587
608
  end
588
609
 
610
+ def test_tree_level
611
+ assert_equal 0, @root1.tree_level
612
+ assert_equal 1, @root_child1.tree_level
613
+ assert_equal 2, @child1_child.tree_level
614
+ assert_equal 3, @child1_child_child.tree_level
615
+ end
616
+
589
617
  def test_level
590
618
  assert_equal 0, @root1.level
591
619
  assert_equal 1, @root_child1.level
592
620
  assert_equal 2, @child1_child.level
593
621
  assert_equal 3, @child1_child_child.level
594
622
  end
623
+
624
+ def test_alias_tree_level
625
+ assert_equal 'Has Level Method', @level_method.level
626
+ assert_equal 'Has Level Column', @level_column.level
627
+ end
595
628
  end
596
629
 
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: 2.6.0
4
+ version: 2.6.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Erik Dahlstrand
@@ -12,7 +12,7 @@ authors:
12
12
  autorequire:
13
13
  bindir: bin
14
14
  cert_chain: []
15
- date: 2016-10-09 00:00:00.000000000 Z
15
+ date: 2017-01-18 00:00:00.000000000 Z
16
16
  dependencies:
17
17
  - !ruby/object:Gem::Dependency
18
18
  name: activerecord