positionable 1.0.3 → 1.0.4

Sign up to get free protection for your applications and to get access to all the features.
data/lib/positionable.rb CHANGED
@@ -244,7 +244,8 @@ module Positionable
244
244
 
245
245
  # All the records that belong to same scope (if any) of this record (including itself).
246
246
  def scoped_all
247
- self.class.where(scoped_condition)
247
+ # The range is shared among all subclasses of the base class, which directly extends ActiveRecord::Base
248
+ self.class.base_class.where(scoped_condition)
248
249
  end
249
250
 
250
251
  # Reorders records between provided positions, unless the destination position is out of range.
@@ -1,3 +1,3 @@
1
1
  module Positionable
2
- VERSION = "1.0.3"
2
+ VERSION = "1.0.4"
3
3
  end
data/spec/factories.rb CHANGED
@@ -19,6 +19,14 @@ FactoryGirl.define do
19
19
  sequence(:title) { |n| "Default Item #{n}" }
20
20
  end
21
21
 
22
+ factory :sub_item_1 do
23
+ sequence(:title) { |n| "Sub-Item-1 #{n}" }
24
+ end
25
+
26
+ factory :sub_item_2 do
27
+ sequence(:title) { |n| "Sub-Item-2 #{n}" }
28
+ end
29
+
22
30
  factory :starting_at_one_item do
23
31
  sequence(:title) { |n| "Starting At One Item #{n}" }
24
32
  end
@@ -15,12 +15,14 @@ describe Positionable do
15
15
  dummy = Dummy.new
16
16
  dummy.respond_to?(:previous).should be_false
17
17
  dummy.respond_to?(:next).should be_false
18
+ dummy.respond_to?(:position=).should be_false
18
19
  end
19
20
 
20
21
  it "extends positionable models" do
21
22
  item = DefaultItem.new
22
23
  item.respond_to?(:previous).should be_true
23
24
  item.respond_to?(:next).should be_true
25
+ item.respond_to?(:position=).should be_true
24
26
  end
25
27
 
26
28
  it "prepends the table name in SQL 'order by' clause" do
@@ -29,6 +31,17 @@ describe Positionable do
29
31
  sql.should include("ORDER BY \"#{table}\".\"position\"")
30
32
  end
31
33
 
34
+ context "inheritance" do
35
+
36
+ it "extends positionable sub-models" do
37
+ item = SubItem1.new
38
+ item.respond_to?(:previous).should be_true
39
+ item.respond_to?(:next).should be_true
40
+ item.respond_to?(:position=).should be_true
41
+ end
42
+
43
+ end
44
+
32
45
  end
33
46
 
34
47
  context "ordering" do
@@ -151,6 +164,16 @@ describe Positionable do
151
164
  neXt.reload.position.should == position
152
165
  end
153
166
 
167
+ context "inheritance" do
168
+
169
+ it "inserts contiguously records of all subclasses" do
170
+ Factory.create(:sub_item_1).position.should == items.count
171
+ Factory.create(:sub_item_2).position.should == items.count + 1
172
+ Factory.create(:sub_item_1).position.should == items.count + 2
173
+ end
174
+
175
+ end
176
+
154
177
  describe "moving" do
155
178
 
156
179
  context "mass-assignement" do
@@ -15,6 +15,12 @@ class DefaultItem < Item
15
15
  is_positionable
16
16
  end
17
17
 
18
+ class SubItem1 < DefaultItem
19
+ end
20
+
21
+ class SubItem2 < DefaultItem
22
+ end
23
+
18
24
  class StartingAtOneItem < Item
19
25
  is_positionable :start => 1
20
26
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: positionable
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:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-03-06 00:00:00.000000000 Z
12
+ date: 2012-03-14 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler
16
- requirement: &70099336314860 !ruby/object:Gem::Requirement
16
+ requirement: !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,15 @@ dependencies:
21
21
  version: 1.0.0
22
22
  type: :development
23
23
  prerelease: false
24
- version_requirements: *70099336314860
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: 1.0.0
25
30
  - !ruby/object:Gem::Dependency
26
31
  name: rspec
27
- requirement: &70099336314240 !ruby/object:Gem::Requirement
32
+ requirement: !ruby/object:Gem::Requirement
28
33
  none: false
29
34
  requirements:
30
35
  - - ~>
@@ -32,10 +37,15 @@ dependencies:
32
37
  version: '2.3'
33
38
  type: :development
34
39
  prerelease: false
35
- version_requirements: *70099336314240
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ~>
44
+ - !ruby/object:Gem::Version
45
+ version: '2.3'
36
46
  - !ruby/object:Gem::Dependency
37
47
  name: sqlite3-ruby
38
- requirement: &70099336313540 !ruby/object:Gem::Requirement
48
+ requirement: !ruby/object:Gem::Requirement
39
49
  none: false
40
50
  requirements:
41
51
  - - ! '>='
@@ -43,10 +53,15 @@ dependencies:
43
53
  version: '0'
44
54
  type: :development
45
55
  prerelease: false
46
- version_requirements: *70099336313540
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
47
62
  - !ruby/object:Gem::Dependency
48
63
  name: simplecov
49
- requirement: &70099336312400 !ruby/object:Gem::Requirement
64
+ requirement: !ruby/object:Gem::Requirement
50
65
  none: false
51
66
  requirements:
52
67
  - - ! '>='
@@ -54,10 +69,15 @@ dependencies:
54
69
  version: '0'
55
70
  type: :development
56
71
  prerelease: false
57
- version_requirements: *70099336312400
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
58
78
  - !ruby/object:Gem::Dependency
59
79
  name: factory_girl
60
- requirement: &70099336311600 !ruby/object:Gem::Requirement
80
+ requirement: !ruby/object:Gem::Requirement
61
81
  none: false
62
82
  requirements:
63
83
  - - ! '>='
@@ -65,10 +85,15 @@ dependencies:
65
85
  version: '0'
66
86
  type: :development
67
87
  prerelease: false
68
- version_requirements: *70099336311600
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ! '>='
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
69
94
  - !ruby/object:Gem::Dependency
70
95
  name: activerecord
71
- requirement: &70099336310240 !ruby/object:Gem::Requirement
96
+ requirement: !ruby/object:Gem::Requirement
72
97
  none: false
73
98
  requirements:
74
99
  - - ~>
@@ -76,7 +101,12 @@ dependencies:
76
101
  version: '3.1'
77
102
  type: :runtime
78
103
  prerelease: false
79
- version_requirements: *70099336310240
104
+ version_requirements: !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - ~>
108
+ - !ruby/object:Gem::Version
109
+ version: '3.1'
80
110
  description: This extension provides contiguous positionning capabilities to you ActiveRecord
81
111
  models.
82
112
  email:
@@ -120,7 +150,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
120
150
  version: '0'
121
151
  requirements: []
122
152
  rubyforge_project: positionable
123
- rubygems_version: 1.8.17
153
+ rubygems_version: 1.8.18
124
154
  signing_key:
125
155
  specification_version: 3
126
156
  summary: A gem for positionning your ActiveRecord models.