Skip to content
Browse files

The range is shared among all subclasses of the base class, which dir…

…ectly extends ActiveRecord::Base
  • Loading branch information...
1 parent cedccdd commit ff41362420d82d0ba2197a83f0b569f021b3c1b7 @pguegan committed Mar 14, 2012
Showing with 26 additions and 4 deletions.
  1. +2 −1 lib/positionable.rb
  2. +1 −1 lib/positionable/version.rb
  3. +8 −0 spec/factories.rb
  4. +11 −1 spec/lib/positionable_spec.rb
  5. +4 −1 spec/support/models.rb
View
3 lib/positionable.rb
@@ -244,7 +244,8 @@ def swap_with(other)
# All the records that belong to same scope (if any) of this record (including itself).
def scoped_all
- self.class.where(scoped_condition)
+ # The range is shared among all subclasses of the base class, which directly extends ActiveRecord::Base
+ self.class.base_class.where(scoped_condition)
end
# Reorders records between provided positions, unless the destination position is out of range.
View
2 lib/positionable/version.rb
@@ -1,3 +1,3 @@
module Positionable
- VERSION = "1.0.3"
+ VERSION = "1.0.4"
end
View
8 spec/factories.rb
@@ -19,6 +19,14 @@
sequence(:title) { |n| "Default Item #{n}" }
end
+ factory :sub_item_1 do
+ sequence(:title) { |n| "Sub-Item-1 #{n}" }
+ end
+
+ factory :sub_item_2 do
+ sequence(:title) { |n| "Sub-Item-2 #{n}" }
+ end
+
factory :starting_at_one_item do
sequence(:title) { |n| "Starting At One Item #{n}" }
end
View
12 spec/lib/positionable_spec.rb
@@ -34,7 +34,7 @@
context "inheritance" do
it "extends positionable sub-models" do
- item = SubItem.new
+ item = SubItem1.new
item.respond_to?(:previous).should be_true
item.respond_to?(:next).should be_true
item.respond_to?(:position=).should be_true
@@ -164,6 +164,16 @@
neXt.reload.position.should == position
end
+ context "inheritance" do
+
+ it "inserts contiguously records of all subclasses" do
+ Factory.create(:sub_item_1).position.should == items.count
+ Factory.create(:sub_item_2).position.should == items.count + 1
+ Factory.create(:sub_item_1).position.should == items.count + 2
+ end
+
+ end
+
describe "moving" do
context "mass-assignement" do
View
5 spec/support/models.rb
@@ -15,7 +15,10 @@ class DefaultItem < Item
is_positionable
end
-class SubItem < DefaultItem
+class SubItem1 < DefaultItem
+end
+
+class SubItem2 < DefaultItem
end
class StartingAtOneItem < Item

0 comments on commit ff41362

Please sign in to comment.
Something went wrong with that request. Please try again.