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 CHANGED
@@ -1 +1 @@
1
- 0.1.4
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).where(scope_condition).order(self.ordered_tree_config[:order])
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
- self.class.send(:sanitize_sql_hash_for_conditions, {self.class.ordered_tree_config[:scope].to_sym => send(self.class.ordered_tree_config[:scope].to_sym)})
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(true).each do |root|
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
@@ -15,7 +15,7 @@ module OrderedTree
15
15
 
16
16
  # Overwrite this method to define the scope of the list changes
17
17
  def scope_condition
18
- "1 = 1"
18
+ "1"
19
19
  end
20
20
  end
21
21
  end
data/ordered_tree.gemspec CHANGED
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{ordered_tree}
8
- s.version = "0.1.4"
8
+ s.version = "0.1.5"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Ramon Tayag"]
@@ -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").position.should == 1
35
- Page.create(:person => @people[3], :name => "steiners").position.should == 1
36
- Page.create(:person => @people[3], :name => "frankenstein").position.should == 2
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: 19
4
+ hash: 17
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 1
9
- - 4
10
- version: 0.1.4
9
+ - 5
10
+ version: 0.1.5
11
11
  platform: ruby
12
12
  authors:
13
13
  - Ramon Tayag