closure_tree 3.10.0 → 3.10.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
- SHA512:
3
- metadata.gz: e94fc2a743703667fdfdc150ad5d24ea7799956355191476d15856f81213154f4f2cc8a0981ca978ad80278ccc1201b38ccd9143e1ec00e1ffa243a238ad1d8a
4
- data.tar.gz: b5c221f82dbf36750c90a834632b550baa0b2e7d82bc3d9f41621716958e0ed26eb29be8ab480800ff5509b0dafd207dfef558f2079189a5b4f1be8b9eea6809
5
2
  SHA1:
6
- metadata.gz: 6f2021ccd1462a82b2735a5b28219c4d870a69a3
7
- data.tar.gz: e8559d6b2aeed3aa0dffb07998b3655972ad9b8b
3
+ metadata.gz: 50404d7f26719cd30625a177d0c7fbc9c4396843
4
+ data.tar.gz: 38ae281b5a8f92005839a0c2f08a4e4774881001
5
+ SHA512:
6
+ metadata.gz: c862247bb1c73a3e98bd531a51a49274d7478453ee77777927fdad9a88502aa5f733183690c538e49a37d307bbb868d726239189671eac6782ac0b618966a0dc
7
+ data.tar.gz: 6b533b01ff64e084af4c41e669d0847dc98f8464634b78e365ab2cc6d4245e7f4a0991b65701ca869ff67e4e3151ba30283b85d6f99553bbff9bfd345439cc5c
data/README.md CHANGED
@@ -444,6 +444,17 @@ Parallelism is not tested with Rails 3.0.x nor 3.1.x due to this
444
444
 
445
445
  ## Change log
446
446
 
447
+ ### 3.10.1
448
+
449
+ * Multipart constant names like "Admin::PageHierarchy" are now supported.
450
+ Resolves [issue 47](https://github.com/mceachen/closure_tree/issues/47).
451
+ Thanks for the perfect pull request, [Simon Menke](https://github.com/fd)!
452
+
453
+ * Committing transactions involving large numbers of hierarchy model classes was very slow due
454
+ to hash collisions in the hierarchy class. A better hash implementation addressed
455
+ [issue 48](https://github.com/mceachen/closure_tree/issues/48).
456
+ Thanks, [Joel Turkel](https://github.com/jturkel)!
457
+
447
458
  ### 3.10.0
448
459
 
449
460
  * Added ```#roots_and_descendants_preordered```.
@@ -29,17 +29,19 @@ module ClosureTree
29
29
  # Auto-inject the hierarchy table
30
30
  # See https://github.com/patshaughnessy/class_factory/blob/master/lib/class_factory/class_factory.rb
31
31
  class_attribute :hierarchy_class
32
- self.hierarchy_class = Object.const_set hierarchy_class_name, Class.new(ActiveRecord::Base)
32
+ self.hierarchy_class = ct_class.parent.const_set short_hierarchy_class_name, Class.new(ActiveRecord::Base)
33
33
 
34
34
  self.hierarchy_class.class_eval <<-RUBY
35
35
  belongs_to :ancestor, :class_name => "#{ct_class.to_s}"
36
36
  belongs_to :descendant, :class_name => "#{ct_class.to_s}"
37
37
  attr_accessible :ancestor, :descendant, :generations
38
- def ==(comparison_object)
39
- comparison_object.instance_of?(self.class) &&
40
- self.attributes == comparison_object.attributes
38
+ def ==(other)
39
+ self.class == other.class && ancestor == other.ancestor && descendant == other.descendant
41
40
  end
42
41
  alias :eql? :==
42
+ def hash
43
+ ancestor_id.hash << 31 ^ descendant_id.hash
44
+ end
43
45
  RUBY
44
46
 
45
47
  self.hierarchy_class.table_name = hierarchy_table_name
@@ -51,4 +53,4 @@ module ClosureTree
51
53
  end
52
54
  end
53
55
  end
54
- end
56
+ end
@@ -37,6 +37,19 @@ module ClosureTree
37
37
  closure_tree_options[:hierarchy_class_name] || ct_class.to_s + "Hierarchy"
38
38
  end
39
39
 
40
+
41
+ #
42
+ # Returns the constant name of the hierarchy_class
43
+ #
44
+ # @return [String] the constant name
45
+ #
46
+ # @example
47
+ # Namespace::Model.hierarchy_class_name # => "Namespace::ModelHierarchy"
48
+ # Namespace::Model.short_hierarchy_class_name # => "ModelHierarchy"
49
+ def short_hierarchy_class_name
50
+ hierarchy_class_name.split('::').last
51
+ end
52
+
40
53
  def quoted_hierarchy_table_name
41
54
  connection.quote_table_name hierarchy_table_name
42
55
  end
@@ -1,3 +1,3 @@
1
1
  module ClosureTree
2
- VERSION = "3.10.0" unless defined?(::ClosureTree::VERSION)
2
+ VERSION = "3.10.1" unless defined?(::ClosureTree::VERSION)
3
3
  end
@@ -95,4 +95,15 @@ ActiveRecord::Schema.define(:version => 0) do
95
95
  t.integer "descendant_id", :null => false
96
96
  t.integer "generations", :null => false
97
97
  end
98
+
99
+ create_table "namespace_types", :force => true do |t|
100
+ t.string "name"
101
+ t.integer "parent_id"
102
+ end
103
+
104
+ create_table "namespace_type_hierarchies", :id => false, :force => true do |t|
105
+ t.integer "ancestor_id", :null => false
106
+ t.integer "descendant_id", :null => false
107
+ t.integer "generations", :null => false
108
+ end
98
109
  end
@@ -0,0 +1,13 @@
1
+ require 'spec_helper'
2
+
3
+ describe Namespace::Type do
4
+
5
+ context "class injection" do
6
+ it "should build hierarchy classname correctly" do
7
+ Namespace::Type.hierarchy_class.to_s.should == "Namespace::TypeHierarchy"
8
+ Namespace::Type.hierarchy_class_name.should == "Namespace::TypeHierarchy"
9
+ Namespace::Type.short_hierarchy_class_name.should == "TypeHierarchy"
10
+ end
11
+ end
12
+
13
+ end
@@ -42,4 +42,4 @@ describe "threadhot" do
42
42
  end
43
43
 
44
44
  # SQLite doesn't like parallelism, and Rails 3.0 and 3.1 have known threading issues. SKIP.
45
- end if ((ENV["DB"] != "sqlite3") && (ActiveRecord::VERSION::STRING =~ /^3.2/))
45
+ end if ((ENV["DB"] != "sqlite") && (ActiveRecord::VERSION::STRING =~ /^3.2/))
@@ -65,3 +65,10 @@ end
65
65
  class CuisineType < ActiveRecord::Base
66
66
  acts_as_tree
67
67
  end
68
+
69
+ module Namespace
70
+ class Type < ActiveRecord::Base
71
+ acts_as_tree :dependent => :destroy
72
+ attr_accessible :name
73
+ end
74
+ end
@@ -130,6 +130,15 @@ shared_examples_for "Tag (1)" do
130
130
  TagHierarchy.find_all_by_ancestor_id(@root.id).should == root_hiers
131
131
  TagHierarchy.find_all_by_descendant_id(@root.id).should == root_hiers
132
132
  end
133
+
134
+ it "should have different hash codes for each hierarchy model" do
135
+ hashes = TagHierarchy.all.map(&:hash)
136
+ hashes.should =~ hashes.uniq
137
+ end
138
+
139
+ it "should return the same hash code for equal hierarchy models" do
140
+ TagHierarchy.first.hash.should == TagHierarchy.first.hash
141
+ end
133
142
  end
134
143
 
135
144
  it "performs as the readme says it does" do
@@ -244,6 +253,7 @@ shared_examples_for "Tag (2)" do
244
253
  it "should build hierarchy classname correctly" do
245
254
  Tag.hierarchy_class.to_s.should == "TagHierarchy"
246
255
  Tag.hierarchy_class_name.should == "TagHierarchy"
256
+ Tag.short_hierarchy_class_name.should == "TagHierarchy"
247
257
  end
248
258
 
249
259
  it "should have a correct parent column name" do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: closure_tree
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.10.0
4
+ version: 3.10.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matthew McEachen
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2013-03-13 00:00:00 Z
12
+ date: 2013-03-23 00:00:00 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activerecord
@@ -142,6 +142,7 @@ files:
142
142
  - spec/fixtures/tags.yml
143
143
  - spec/hash_tree_spec.rb
144
144
  - spec/label_spec.rb
145
+ - spec/namespace_type_spec.rb
145
146
  - spec/parallel_prepend_sibling_spec.rb
146
147
  - spec/parallel_spec.rb
147
148
  - spec/spec_helper.rb
@@ -179,6 +180,7 @@ test_files:
179
180
  - spec/fixtures/tags.yml
180
181
  - spec/hash_tree_spec.rb
181
182
  - spec/label_spec.rb
183
+ - spec/namespace_type_spec.rb
182
184
  - spec/parallel_prepend_sibling_spec.rb
183
185
  - spec/parallel_spec.rb
184
186
  - spec/spec_helper.rb