ordered_tree 0.1.4 → 0.1.5
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/lib/ordered_tree.rb +3 -2
- data/lib/ordered_tree/instance_methods/list.rb +1 -1
- data/lib/ordered_tree/instance_methods/misc.rb +1 -1
- data/ordered_tree.gemspec +1 -1
- data/spec/ordered_tree_spec.rb +12 -3
- metadata +3 -3
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.5
|
data/lib/ordered_tree.rb
CHANGED
@@ -30,7 +30,7 @@ module OrderedTree #:nodoc:
|
|
30
30
|
has_many :child_nodes, :class_name => self.name, :foreign_key => ordered_tree_config[:foreign_key], :order => ordered_tree_config[:order]
|
31
31
|
scope :roots, lambda { |*args|
|
32
32
|
scope_condition = args[0]
|
33
|
-
where(self.ordered_tree_config[:foreign_key].to_sym => 0).
|
33
|
+
where(scope_condition).where(self.ordered_tree_config[:foreign_key].to_sym => 0).order(self.ordered_tree_config[:order])
|
34
34
|
}
|
35
35
|
|
36
36
|
# If the scope is something like :person, then turn it into :person_id
|
@@ -40,7 +40,8 @@ module OrderedTree #:nodoc:
|
|
40
40
|
|
41
41
|
if self.ordered_tree_config[:scope].is_a?(Symbol) # ie :person_id
|
42
42
|
define_method "scope_condition" do
|
43
|
-
|
43
|
+
hash = {self.class.ordered_tree_config[:scope].to_sym => send(self.class.ordered_tree_config[:scope].to_sym)}
|
44
|
+
self.class.send(:sanitize_sql_hash_for_conditions, hash)
|
44
45
|
end
|
45
46
|
end
|
46
47
|
|
@@ -140,7 +140,7 @@ module OrderedTree
|
|
140
140
|
|
141
141
|
def reorder_roots
|
142
142
|
self.class.transaction do
|
143
|
-
self.class.roots(
|
143
|
+
self.class.roots(scope_condition).each do |root|
|
144
144
|
new_position = self.class.roots.index(root) + 1
|
145
145
|
root.update_attribute(order_column, new_position) if (root.position_in_list != new_position)
|
146
146
|
end
|
data/ordered_tree.gemspec
CHANGED
data/spec/ordered_tree_spec.rb
CHANGED
@@ -31,9 +31,18 @@ describe OrderedTree do
|
|
31
31
|
"person_id = #{person_id} AND name = '#{name}'"
|
32
32
|
end
|
33
33
|
end
|
34
|
-
Page.create(:person => @people[3], :name => "frankenstein")
|
35
|
-
|
36
|
-
Page.create(:person => @people[3], :name => "
|
34
|
+
page_1 = Page.create(:person => @people[3], :name => "frankenstein")
|
35
|
+
page_1.position.should == 1
|
36
|
+
page_2 = Page.create(:person => @people[3], :name => "steiners")
|
37
|
+
page_2.position.should == 1
|
38
|
+
page_3 = Page.create(:person => @people[3], :name => "frankenstein")
|
39
|
+
page_3.position.should == 2
|
40
|
+
|
41
|
+
# when moving a root to be a child of another
|
42
|
+
page_1.children << page_3
|
43
|
+
page_1.position.should == 1
|
44
|
+
page_2.position.should == 1
|
45
|
+
page_3.position.should == 1
|
37
46
|
end
|
38
47
|
end
|
39
48
|
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ordered_tree
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 17
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 1
|
9
|
-
-
|
10
|
-
version: 0.1.
|
9
|
+
- 5
|
10
|
+
version: 0.1.5
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Ramon Tayag
|