acts_as_ordered_tree 1.0.3 → 1.0.4

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.
@@ -179,7 +179,7 @@ module ActsAsOrderedTree
179
179
  # Move the node to the child of another node with specify index
180
180
  def move_to_child_with_index(node, index)
181
181
  raise ActiveRecord::ActiveRecordError, "index cant be nil" unless index
182
- new_siblings = node.try(:children) || self.class.roots.delete_if { |root_node| root_node == self }
182
+ new_siblings = (node.try(:children) || self.class.roots).reject { |root_node| root_node == self }
183
183
 
184
184
  if new_siblings.empty?
185
185
  node ? move_to_child_of(node) : move_to_root
@@ -1,3 +1,3 @@
1
1
  module ActsAsOrderedTree
2
- VERSION = "1.0.3"
2
+ VERSION = "1.0.4"
3
3
  end
@@ -435,17 +435,24 @@ describe ActsAsOrderedTree do
435
435
  context "on_save_when_parent_changed" do
436
436
  example "move_1_to_root" do
437
437
  child_1.parent = nil
438
- child_1.save
438
+ expect{ child_1.save! }.to_not raise_exception
439
439
  expect(child_1.position).to eq 2
440
440
  expect([root, child_1]).to be_sorted
441
441
  end
442
442
 
443
443
  example "move_3_to_root" do
444
444
  child_3.parent = nil
445
- child_3.save
445
+ expect{ child_3.save! }.to_not raise_exception
446
446
  expect(child_3.position).to eq 2
447
447
  expect([root, child_3]).to be_sorted
448
448
  end
449
+
450
+ example "move_grandchild" do
451
+ grandchild = FactoryGirl.create(:default_with_counter_cache, :parent => child_3)
452
+ grandchild.parent = child_2
453
+ expect{ grandchild.save! }.to_not raise_exception
454
+ expect([grandchild]).to eq child_2.children
455
+ end
449
456
  end
450
457
 
451
458
  describe "#move_left" do
@@ -92,7 +92,7 @@ module RSpec::Matchers
92
92
  def with_temporary_callback
93
93
  kind, name = @callback.to_s.split('_')
94
94
 
95
- method_name = :"__temporary_callback_#{object_id}"
95
+ method_name = :"__temporary_callback_#{object_id.abs}"
96
96
 
97
97
  @subject.class.class_eval <<-CODE
98
98
  def #{method_name}
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: acts_as_ordered_tree
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.3
4
+ version: 1.0.4
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2012-08-16 00:00:00.000000000 Z
13
+ date: 2012-08-18 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: activerecord
@@ -164,13 +164,6 @@ executables: []
164
164
  extensions: []
165
165
  extra_rdoc_files: []
166
166
  files:
167
- - .gitignore
168
- - .rspec
169
- - Appraisals
170
- - Gemfile
171
- - README.md
172
- - Rakefile
173
- - acts_as_ordered_tree.gemspec
174
167
  - lib/acts_as_ordered_tree.rb
175
168
  - lib/acts_as_ordered_tree/class_methods.rb
176
169
  - lib/acts_as_ordered_tree/fake_scope.rb
@@ -197,7 +190,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
197
190
  version: '0'
198
191
  segments:
199
192
  - 0
200
- hash: -720580582503752285
193
+ hash: -557915249
201
194
  required_rubygems_version: !ruby/object:Gem::Requirement
202
195
  none: false
203
196
  requirements:
@@ -206,11 +199,17 @@ required_rubygems_version: !ruby/object:Gem::Requirement
206
199
  version: '0'
207
200
  segments:
208
201
  - 0
209
- hash: -720580582503752285
202
+ hash: -557915249
210
203
  requirements: []
211
204
  rubyforge_project: acts_as_ordered_tree
212
205
  rubygems_version: 1.8.24
213
206
  signing_key:
214
207
  specification_version: 3
215
208
  summary: ActiveRecord extension for sorted adjacency lists support
216
- test_files: []
209
+ test_files:
210
+ - spec/acts_as_ordered_tree_spec.rb
211
+ - spec/db/schema.rb
212
+ - spec/spec_helper.rb
213
+ - spec/support/factories.rb
214
+ - spec/support/matchers.rb
215
+ - spec/support/models.rb
data/.gitignore DELETED
@@ -1,8 +0,0 @@
1
- *.gem
2
- .bundle
3
- Gemfile.lock
4
- pkg/*
5
- .idea/*
6
- coverage/*
7
- .rbx/*
8
- gemfiles/*
data/.rspec DELETED
@@ -1,2 +0,0 @@
1
- --color
2
- --format progress
data/Appraisals DELETED
@@ -1,11 +0,0 @@
1
- appraise "rails3.0" do
2
- gem "activerecord", "~> 3.0.0"
3
- end
4
-
5
- appraise "rails3.1" do
6
- gem "activerecord", "~> 3.1.0"
7
- end
8
-
9
- appraise "rails3.2" do
10
- gem "activerecord", "~> 3.2.0"
11
- end
data/Gemfile DELETED
@@ -1,8 +0,0 @@
1
- source "http://rubygems.org"
2
-
3
- # Specify your gem's dependencies in acts_as_ordered_tree.gemspec
4
- gemspec
5
-
6
- gem "sqlite3", :platforms => :ruby
7
- gem "activerecord-jdbcsqlite3-adapter", :platforms => :jruby
8
- gem "simplecov", :platform => :ruby_19
data/README.md DELETED
@@ -1,107 +0,0 @@
1
- # Acts As Ordered Tree
2
- WARNING! THIS GEM IS NOT COMPATIBLE WITH <a href="http://ordered-tree.rubyforge.org">ordered_tree gem</a>.
3
-
4
- Specify this `acts_as` extension if you want to model an ordered tree structure ([adjacency list hierarchical structure](http://www.sqlsummit.com/AdjacencyList.htm)) by providing a parent association, a children association and a sort column. For proper use you should have a foreign key column, which by default is called `parent_id`, and a sort column, which is by default called `position`.
5
-
6
- This extension is mostly compatible with [`awesome_nested_set`](https://github.com/collectiveidea/awesome_nested_set/) gem
7
-
8
- ## Requirements
9
- Gem depends on `active_record >= 3`. We test it with `rails-3.0`, `rails-3.1`, `rails-3.2` and with `ruby-1.9.3`, `ruby-1.9.2`, `ruby-1.8.7`, `jruby-1.6.7` and `rubinius-2.0`.
10
-
11
- ## Installation
12
- Install it via rubygems:
13
-
14
- ```bash
15
- gem install acts_as_ordered_tree
16
- ```
17
-
18
- ## Usage
19
-
20
- To make use of `acts_as_ordered_tree`, your model needs to have 2 fields: parent_id and position. You can also have an optional fields: depth and children_count:
21
- ```ruby
22
- class CreateCategories < ActiveRecord::Migration
23
- def self.up
24
- create_table :categories do |t|
25
- t.integer :company_id
26
- t.string :name
27
- t.integer :parent_id # this is mandatory
28
- t.integer :position # this is mandatory
29
- t.integer :depth # this is optional
30
- t.integer :children_count # this is optional
31
- end
32
- end
33
-
34
- def self.down
35
- drop_table :categories
36
- end
37
- end
38
- ```
39
-
40
- Setup your model:
41
-
42
- ```ruby
43
- class Category < ActiveRecord::Base
44
- acts_as_ordered_tree
45
-
46
- # gem introduces new ActiveRecord callbacks:
47
- # *_reorder - fires when position (but not parent node) is changed
48
- # *_move - fires when parent node is changed
49
- before_reorder :do_smth
50
- before_move :do_smth_else
51
- end
52
- ```
53
-
54
- Now you can use `acts_as_ordered_tree` features:
55
-
56
- ```ruby
57
- # root
58
- # \_ child1
59
- # \_ subchild1
60
- # \_ subchild2
61
-
62
-
63
- root = Category.create(:name => "root")
64
- child1 = root.children.create(:name => "child1")
65
- subchild1 = child1.children.create("name" => "subchild1")
66
- subchild2 = child1.children.create("name" => "subchild2")
67
-
68
- Category.roots # => [root]
69
-
70
- root.root? # => true
71
- root.parent # => nil
72
- root.ancestors # => []
73
- root.descendants # => [child1, subchild1, subchild2]
74
-
75
- child1.parent # => root
76
- child1.ancestors # => [root]
77
- child1.children # => [subchild1, subchild2]
78
- child1.descendants # => [subchild1, subchild2]
79
- child1.root? # => false
80
- child1.leaf? # => false
81
-
82
- subchild1.ancestors # => [child1, root]
83
- subchild1.root # => [root]
84
- subchild1.leaf? # => true
85
- subchild1.first? # => true
86
- subchild1.last? # => false
87
- subchild2.last? # => true
88
-
89
- subchild1.move_to_above_of(child1)
90
- subchild1.move_to_bottom_of(child1)
91
- subchild1.move_to_child_of(root)
92
- subchild1.move_lower
93
- subchild1.move_higher
94
- ```
95
-
96
- ## Contributing
97
-
98
- 1. Fork it
99
- 2. Create your feature branch (`git checkout -b my-new-feature`)
100
- 3. Commit your changes (`git commit -am 'Added some feature'`)
101
- 4. Push to the branch (`git push origin my-new-feature`)
102
- 5. Create new Pull Request
103
-
104
- ## TODO
105
- 1. Fix README typos and grammatical errors (english speaking contributors are welcomed)
106
- 2. Add moar examples and docs.
107
- 3. Implement converter from other structures (nested_set, closure_tree)
data/Rakefile DELETED
@@ -1,5 +0,0 @@
1
- require "bundler/gem_tasks"
2
- require "rspec/core/rake_task"
3
- require "appraisal"
4
-
5
- RSpec::Core::RakeTask.new(:spec)
@@ -1,30 +0,0 @@
1
- # -*- encoding: utf-8 -*-
2
- $:.push File.expand_path("../lib", __FILE__)
3
- require "acts_as_ordered_tree/version"
4
-
5
- Gem::Specification.new do |s|
6
- s.name = "acts_as_ordered_tree"
7
- s.version = ActsAsOrderedTree::VERSION
8
- s.authors = ["Alexei Mikhailov", "Vladimir Kuznetsov"]
9
- s.email = %w(amikhailov83@gmail.com kv86@mail.ru)
10
- s.homepage = "https://github.com/take-five/acts_as_ordered_tree"
11
- s.summary = %q{ActiveRecord extension for sorted adjacency lists support}
12
-
13
- s.rubyforge_project = "acts_as_ordered_tree"
14
-
15
- s.files = `git ls-files`.split("\n")
16
- s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
17
- s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
18
- s.require_paths = %w(lib)
19
-
20
- s.add_dependency "activerecord", ">= 3.0.0"
21
-
22
- s.add_development_dependency "bundler", ">= 1.0"
23
- s.add_development_dependency "rails", ">= 3.0.0"
24
- s.add_development_dependency "rspec", ">= 2.11"
25
- s.add_development_dependency "rspec-rails", ">= 2.11"
26
- s.add_development_dependency "shoulda-matchers", ">= 1.2.0"
27
- s.add_development_dependency "factory_girl", "< 3"
28
- s.add_development_dependency "factory_girl_rails", "< 3"
29
- s.add_development_dependency "appraisal", ">= 0.4.0"
30
- end