closure_tree 3.3.0 → 3.3.1

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
@@ -317,6 +317,16 @@ Closure tree is [tested under every combination](https://secure.travis-ci.org/mc
317
317
 
318
318
  ## Change log
319
319
 
320
+ ### 3.3.1
321
+
322
+ * Added support for partially-unsaved hierarchies [issue 13](https://github.com/mceachen/closure_tree/issues/13):
323
+ ```
324
+ a = Tag.new(name: "a")
325
+ b = Tag.new(name: "b")
326
+ a.children << b
327
+ a.save
328
+ ```
329
+
320
330
  ### 3.3.0
321
331
 
322
332
  * Added [```hash_tree```](#nested-hashes).
@@ -240,6 +240,8 @@ module ClosureTree
240
240
 
241
241
  def ct_after_save
242
242
  rebuild! if changes[parent_column_name] || @was_new_record
243
+ @was_new_record = false # we aren't new anymore.
244
+ true # don't cancel anything.
243
245
  end
244
246
 
245
247
  def rebuild!
@@ -1,3 +1,3 @@
1
1
  module ClosureTree
2
- VERSION = "3.3.0" unless defined?(::ClosureTree::VERSION)
2
+ VERSION = "3.3.1" unless defined?(::ClosureTree::VERSION)
3
3
  end
@@ -1,8 +1,8 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  def nuke_db
4
- Label.delete_all
5
4
  LabelHierarchy.delete_all
5
+ Label.delete_all
6
6
  end
7
7
 
8
8
  describe Label do
@@ -4,8 +4,8 @@ shared_examples_for Tag do
4
4
  describe "empty db" do
5
5
 
6
6
  def nuke_db
7
- Tag.delete_all
8
7
  TagHierarchy.delete_all
8
+ Tag.delete_all
9
9
  end
10
10
 
11
11
  before :each do
@@ -353,6 +353,24 @@ shared_examples_for Tag do
353
353
  city.self_and_ancestors.should == [city, tags(:california), tags(:united_states), tags(:places)]
354
354
  end
355
355
 
356
+ it "performs as the readme says it does" do
357
+ grandparent = Tag.create(:name => 'Grandparent')
358
+ parent = grandparent.children.create(:name => 'Parent')
359
+ child1 = Tag.create(:name => 'First Child')
360
+ parent.children << child1
361
+ child2 = Tag.create(:name => 'Second Child')
362
+ parent.add_child child2
363
+ grandparent.self_and_descendants.collect(&:name).should ==
364
+ ["Grandparent", "Parent", "First Child", "Second Child"]
365
+ child1.ancestry_path.should ==
366
+ ["Grandparent", "Parent", "First Child"]
367
+ d = Tag.find_or_create_by_path %w(a b c d)
368
+ h = Tag.find_or_create_by_path %w(e f g h)
369
+ e = h.root
370
+ d.add_child(e) # "d.children << e" would work too, of course
371
+ h.ancestry_path.should == %w(a b c d e f g h)
372
+ end
373
+
356
374
  end
357
375
  end
358
376
 
@@ -3,8 +3,8 @@ require 'spec_helper'
3
3
  describe "empty db" do
4
4
 
5
5
  before :each do
6
- User.delete_all
7
6
  ReferralHierarchy.delete_all
7
+ User.delete_all
8
8
  end
9
9
 
10
10
  context "empty db" do
@@ -87,21 +87,33 @@ describe "empty db" do
87
87
  u.root.indirect_contracts.to_a.should =~ [c1, c2]
88
88
  end
89
89
 
90
- it "performs as the readme says it does" do
91
- grandparent = Tag.create(:name => 'Grandparent')
92
- parent = grandparent.children.create(:name => 'Parent')
93
- child1 = Tag.create(:name => 'First Child')
94
- parent.children << child1
95
- child2 = Tag.create(:name => 'Second Child')
96
- parent.add_child child2
97
- grandparent.self_and_descendants.collect(&:name).should ==
98
- ["Grandparent", "Parent", "First Child", "Second Child"]
99
- child1.ancestry_path.should ==
100
- ["Grandparent", "Parent", "First Child"]
101
- d = Tag.find_or_create_by_path %w(a b c d)
102
- h = Tag.find_or_create_by_path %w(e f g h)
103
- e = h.root
104
- d.add_child(e) # "d.children << e" would work too, of course
105
- h.ancestry_path.should == %w(a b c d e f g h)
90
+
91
+ it "supports << on shallow unsaved hierarchies" do
92
+ a = User.new(:email => "a")
93
+ b = User.new(:email => "b")
94
+ a.children << b
95
+ a.save
96
+ User.roots.should == [a]
97
+ User.leaves.should == [b]
98
+ b.ancestry_path.should == %w(a b)
99
+ end
100
+
101
+ it "supports << on deep unsaved hierarchies" do
102
+ a = User.new(:email => "a")
103
+ b1 = User.new(:email => "b1")
104
+ a.children << b1
105
+ b2 = User.new(:email => "b2")
106
+ a.children << b2
107
+ c1 = User.new(:email => "c1")
108
+ b2.children << c1
109
+ c2 = User.new(:email => "c2")
110
+ b2.children << c2
111
+ d = User.new(:email => "d")
112
+ c2.children << d
113
+
114
+ a.save
115
+ User.roots.should == [a]
116
+ User.leaves.should == [b1, c1, d]
117
+ d.ancestry_path.should == %w(a b2 c2 d)
106
118
  end
107
119
  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.0
4
+ version: 3.3.1
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-07-22 00:00:00.000000000 Z
12
+ date: 2012-08-08 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activerecord
@@ -193,7 +193,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
193
193
  version: '0'
194
194
  segments:
195
195
  - 0
196
- hash: 1888023415669580942
196
+ hash: 2911561954531339982
197
197
  required_rubygems_version: !ruby/object:Gem::Requirement
198
198
  none: false
199
199
  requirements:
@@ -202,7 +202,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
202
202
  version: '0'
203
203
  segments:
204
204
  - 0
205
- hash: 1888023415669580942
205
+ hash: 2911561954531339982
206
206
  requirements: []
207
207
  rubyforge_project:
208
208
  rubygems_version: 1.8.21