closure_tree 3.3.1 → 3.3.2

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/README.md CHANGED
@@ -308,7 +308,7 @@ root.children.collect(&:name)
308
308
 
309
309
  ## Testing
310
310
 
311
- Closure tree is [tested under every combination](https://secure.travis-ci.org/mceachen/closure_tree.png?branch=master) of
311
+ Closure tree is [tested under every combination](http://travis-ci.org/#!/mceachen/closure_tree) of
312
312
 
313
313
  * Ruby 1.8.7 and Ruby 1.9.3
314
314
  * The latest Rails 3.0, 3.1, and 3.2 branches, and
@@ -317,6 +317,10 @@ Closure tree is [tested under every combination](https://secure.travis-ci.org/mc
317
317
 
318
318
  ## Change log
319
319
 
320
+ ### 3.3.2
321
+
322
+ * Merged calebphillips' patch for a more efficient leaves query
323
+
320
324
  ### 3.3.1
321
325
 
322
326
  * Added support for partially-unsaved hierarchies [issue 13](https://github.com/mceachen/closure_tree/issues/13):
@@ -86,13 +86,20 @@ module ClosureTree
86
86
  end
87
87
 
88
88
  def self.leaves
89
- s = where("#{quoted_table_name}.#{primary_key} IN
90
- (SELECT ancestor_id
91
- FROM #{quoted_hierarchy_table_name}
92
- GROUP BY 1
93
- HAVING MAX(#{quoted_hierarchy_table_name}.generations) = 0)")
89
+ s = joins(leaves_join_sql)
94
90
  order_option ? s.order(order_option) : s
95
91
  end
92
+
93
+ def self.leaves_join_sql
94
+ <<-SQL
95
+ INNER JOIN
96
+ (SELECT ancestor_id
97
+ FROM #{quoted_hierarchy_table_name}
98
+ GROUP BY 1
99
+ HAVING MAX(#{quoted_hierarchy_table_name}.generations) = 0) AS leaves
100
+ ON (#{quoted_table_name}.#{primary_key} = leaves.ancestor_id)
101
+ SQL
102
+ end
96
103
  end
97
104
  end
98
105
 
@@ -1,3 +1,3 @@
1
1
  module ClosureTree
2
- VERSION = "3.3.1" unless defined?(::ClosureTree::VERSION)
2
+ VERSION = "3.3.2" unless defined?(::ClosureTree::VERSION)
3
3
  end
@@ -0,0 +1,21 @@
1
+ require 'spec_helper'
2
+
3
+ describe CuisineType do
4
+ it "finds self and parents properly" do
5
+ e = CuisineType.new(:name => "e")
6
+ m = CuisineType.new(:name => "m")
7
+ e.children << m
8
+ e.save
9
+
10
+ m.parent.should == e
11
+ m.self_and_ancestors.should == [m, e]
12
+
13
+ # make sure reloading doesn't affect the self_and_ancestors:
14
+ m.reload
15
+ m.self_and_ancestors.should == [m, e]
16
+ end
17
+
18
+ it "sets the table_name of the hierarchy class properly" do
19
+ CuisineTypeHierarchy.table_name.should == "cuisine_type_hierarchies"
20
+ end
21
+ end
@@ -59,4 +59,14 @@ ActiveRecord::Schema.define(:version => 0) do
59
59
  add_index :label_hierarchies, [:ancestor_id, :descendant_id], :unique => true
60
60
  add_index :label_hierarchies, [:descendant_id]
61
61
 
62
+ create_table "cuisine_types", :force => true do |t|
63
+ t.string "name"
64
+ t.integer "parent_id"
65
+ end
66
+
67
+ create_table "cuisine_type_hierarchies", :id => false, :force => true do |t|
68
+ t.integer "ancestor_id", :null => false
69
+ t.integer "descendant_id", :null => false
70
+ t.integer "generations", :null => false
71
+ end
62
72
  end
@@ -56,3 +56,7 @@ end
56
56
 
57
57
  class DirectoryLabel < Label
58
58
  end
59
+
60
+ class CuisineType < ActiveRecord::Base
61
+ acts_as_tree
62
+ end
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.3.1
4
+ version: 3.3.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-08-08 00:00:00.000000000 Z
12
+ date: 2012-08-27 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activerecord
@@ -170,6 +170,7 @@ files:
170
170
  - MIT-LICENSE
171
171
  - Rakefile
172
172
  - README.md
173
+ - spec/cuisine_type_spec.rb
173
174
  - spec/db/database.yml
174
175
  - spec/db/schema.rb
175
176
  - spec/fixtures/labels.yml
@@ -193,7 +194,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
193
194
  version: '0'
194
195
  segments:
195
196
  - 0
196
- hash: 2911561954531339982
197
+ hash: 2505204839193156816
197
198
  required_rubygems_version: !ruby/object:Gem::Requirement
198
199
  none: false
199
200
  requirements:
@@ -202,14 +203,15 @@ required_rubygems_version: !ruby/object:Gem::Requirement
202
203
  version: '0'
203
204
  segments:
204
205
  - 0
205
- hash: 2911561954531339982
206
+ hash: 2505204839193156816
206
207
  requirements: []
207
208
  rubyforge_project:
208
- rubygems_version: 1.8.21
209
+ rubygems_version: 1.8.23
209
210
  signing_key:
210
211
  specification_version: 3
211
212
  summary: Hierarchies for ActiveRecord models using a Closure Tree storage algorithm
212
213
  test_files:
214
+ - spec/cuisine_type_spec.rb
213
215
  - spec/db/database.yml
214
216
  - spec/db/schema.rb
215
217
  - spec/fixtures/labels.yml