sortifiable 0.2.6 → 0.2.7
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +5 -0
- data/README.md +7 -0
- data/Rakefile +1 -1
- data/lib/sortifiable.rb +4 -4
- data/lib/sortifiable/version.rb +1 -1
- data/sortifiable.gemspec +1 -2
- data/test/sortifiable_test.rb +19 -0
- metadata +48 -23
data/CHANGELOG
CHANGED
data/README.md
CHANGED
@@ -1,6 +1,8 @@
|
|
1
1
|
Sortifiable
|
2
2
|
===========
|
3
3
|
|
4
|
+
[![Build Status][build]][travis] [![Dependency Status][depends]][gemnasium]
|
5
|
+
|
4
6
|
This gem provides an acts_as_list compatible capability for sorting
|
5
7
|
and reordering a number of objects in a list. The class that has this
|
6
8
|
specified needs to have a +position+ column defined as an integer on
|
@@ -41,3 +43,8 @@ Thanks to the following people for their contributions:
|
|
41
43
|
* Reinier de Lange
|
42
44
|
|
43
45
|
Copyright (c) 2011 Andrew White, released under the MIT license
|
46
|
+
|
47
|
+
[build]: https://secure.travis-ci.org/pixeltrix/sortifiable.png
|
48
|
+
[travis]: http://travis-ci.org/pixeltrix/sortifiable
|
49
|
+
[depends]: https://gemnasium.com/pixeltrix/sortifiable.png?travis
|
50
|
+
[gemnasium]: https://gemnasium.com/pixeltrix/sortifiable
|
data/Rakefile
CHANGED
data/lib/sortifiable.rb
CHANGED
@@ -178,7 +178,7 @@ module Sortifiable
|
|
178
178
|
#{quoted_position_column} = CASE
|
179
179
|
WHEN #{quoted_position_column} = #{current_position} THEN #{position}
|
180
180
|
WHEN #{quoted_position_column} > #{current_position}
|
181
|
-
AND #{quoted_position_column}
|
181
|
+
AND #{quoted_position_column} <= #{position} THEN #{quoted_position_column} - 1
|
182
182
|
WHEN #{quoted_position_column} < #{current_position}
|
183
183
|
AND #{quoted_position_column} >= #{position} THEN #{quoted_position_column} + 1
|
184
184
|
ELSE #{quoted_position_column}
|
@@ -242,7 +242,7 @@ module Sortifiable
|
|
242
242
|
if in_list?
|
243
243
|
list_class.transaction do
|
244
244
|
ids = lock_list!
|
245
|
-
current_position
|
245
|
+
current_position = ids.index(id) + 1
|
246
246
|
|
247
247
|
if current_position > 1
|
248
248
|
sql = <<-SQL
|
@@ -327,7 +327,7 @@ module Sortifiable
|
|
327
327
|
if in_list?
|
328
328
|
list_class.transaction do
|
329
329
|
ids = lock_list!
|
330
|
-
current_position
|
330
|
+
current_position = ids.index(id) + 1
|
331
331
|
|
332
332
|
if current_position > 1
|
333
333
|
sql = <<-SQL
|
@@ -354,7 +354,7 @@ module Sortifiable
|
|
354
354
|
if in_list?
|
355
355
|
list_class.transaction do
|
356
356
|
ids = lock_list!
|
357
|
-
current_position
|
357
|
+
current_position = ids.index(id) + 1
|
358
358
|
|
359
359
|
sql = <<-SQL
|
360
360
|
#{quoted_position_column} = CASE
|
data/lib/sortifiable/version.rb
CHANGED
data/sortifiable.gemspec
CHANGED
@@ -37,8 +37,7 @@ EOF
|
|
37
37
|
|
38
38
|
s.add_dependency "activesupport", ">= 3.0"
|
39
39
|
s.add_dependency "activerecord", ">= 3.0"
|
40
|
-
s.add_development_dependency "
|
41
|
-
s.add_development_dependency "mysql", "~> 2.8.1"
|
40
|
+
s.add_development_dependency "mysql", ">= 2.8.1"
|
42
41
|
s.add_development_dependency "mysql2", ">= 0.2.7"
|
43
42
|
s.add_development_dependency "pg", ">= 0.9.0"
|
44
43
|
s.add_development_dependency "sqlite3", ">= 1.3.3"
|
data/test/sortifiable_test.rb
CHANGED
@@ -104,36 +104,55 @@ class ListTest < ActiveSupport::TestCase
|
|
104
104
|
def test_insert_at
|
105
105
|
new = ListMixin.create(:parent_id => 20)
|
106
106
|
assert_equal 1, new.pos
|
107
|
+
assert_equal [1], ListMixin.where(:parent_id => 20).map(&:pos)
|
107
108
|
|
108
109
|
new = ListMixin.create(:parent_id => 20)
|
109
110
|
assert_equal 2, new.pos
|
111
|
+
assert_equal [1, 2], ListMixin.where(:parent_id => 20).map(&:pos)
|
110
112
|
|
111
113
|
new = ListMixin.create(:parent_id => 20)
|
112
114
|
assert_equal 3, new.pos
|
115
|
+
assert_equal [1, 2, 3], ListMixin.where(:parent_id => 20).map(&:pos)
|
113
116
|
|
114
117
|
new4 = ListMixin.create(:parent_id => 20)
|
115
118
|
assert_equal 4, new4.pos
|
119
|
+
assert_equal [1, 2, 3, 4], ListMixin.where(:parent_id => 20).map(&:pos)
|
116
120
|
|
117
121
|
new4.insert_at(3)
|
118
122
|
assert_equal 3, new4.pos
|
123
|
+
assert_equal [1, 2, 3, 4], ListMixin.where(:parent_id => 20).map(&:pos)
|
119
124
|
|
120
125
|
new.reload
|
121
126
|
assert_equal 4, new.pos
|
127
|
+
assert_equal [1, 2, 3, 4], ListMixin.where(:parent_id => 20).map(&:pos)
|
122
128
|
|
123
129
|
new.insert_at(2)
|
124
130
|
assert_equal 2, new.pos
|
131
|
+
assert_equal [1, 2, 3, 4], ListMixin.where(:parent_id => 20).map(&:pos)
|
125
132
|
|
126
133
|
new4.reload
|
127
134
|
assert_equal 4, new4.pos
|
135
|
+
assert_equal [1, 2, 3, 4], ListMixin.where(:parent_id => 20).map(&:pos)
|
128
136
|
|
129
137
|
new5 = ListMixin.create(:parent_id => 20)
|
130
138
|
assert_equal 5, new5.pos
|
139
|
+
assert_equal [1, 2, 3, 4, 5], ListMixin.where(:parent_id => 20).map(&:pos)
|
131
140
|
|
132
141
|
new5.insert_at(1)
|
133
142
|
assert_equal 1, new5.pos
|
143
|
+
assert_equal [1, 2, 3, 4, 5], ListMixin.where(:parent_id => 20).map(&:pos)
|
134
144
|
|
135
145
|
new4.reload
|
136
146
|
assert_equal 5, new4.pos
|
147
|
+
assert_equal [1, 2, 3, 4, 5], ListMixin.where(:parent_id => 20).map(&:pos)
|
148
|
+
|
149
|
+
new.reload
|
150
|
+
assert_equal 3, new.pos
|
151
|
+
assert_equal [1, 2, 3, 4, 5], ListMixin.where(:parent_id => 20).map(&:pos)
|
152
|
+
|
153
|
+
new.insert_at(5)
|
154
|
+
assert_equal 5, new.pos
|
155
|
+
assert_equal [1, 2, 3, 4, 5], ListMixin.where(:parent_id => 20).map(&:pos)
|
137
156
|
end
|
138
157
|
|
139
158
|
def test_delete_middle
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sortifiable
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.7
|
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:
|
12
|
+
date: 2013-02-23 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activesupport
|
16
|
-
requirement:
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,10 +21,15 @@ dependencies:
|
|
21
21
|
version: '3.0'
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements:
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '3.0'
|
25
30
|
- !ruby/object:Gem::Dependency
|
26
31
|
name: activerecord
|
27
|
-
requirement:
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
28
33
|
none: false
|
29
34
|
requirements:
|
30
35
|
- - ! '>='
|
@@ -32,32 +37,31 @@ dependencies:
|
|
32
37
|
version: '3.0'
|
33
38
|
type: :runtime
|
34
39
|
prerelease: false
|
35
|
-
version_requirements:
|
36
|
-
- !ruby/object:Gem::Dependency
|
37
|
-
name: bundler
|
38
|
-
requirement: &2151820980 !ruby/object:Gem::Requirement
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
39
41
|
none: false
|
40
42
|
requirements:
|
41
43
|
- - ! '>='
|
42
44
|
- !ruby/object:Gem::Version
|
43
|
-
version:
|
44
|
-
type: :development
|
45
|
-
prerelease: false
|
46
|
-
version_requirements: *2151820980
|
45
|
+
version: '3.0'
|
47
46
|
- !ruby/object:Gem::Dependency
|
48
47
|
name: mysql
|
49
|
-
requirement:
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
50
49
|
none: false
|
51
50
|
requirements:
|
52
|
-
- -
|
51
|
+
- - ! '>='
|
53
52
|
- !ruby/object:Gem::Version
|
54
53
|
version: 2.8.1
|
55
54
|
type: :development
|
56
55
|
prerelease: false
|
57
|
-
version_requirements:
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 2.8.1
|
58
62
|
- !ruby/object:Gem::Dependency
|
59
63
|
name: mysql2
|
60
|
-
requirement:
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
61
65
|
none: false
|
62
66
|
requirements:
|
63
67
|
- - ! '>='
|
@@ -65,10 +69,15 @@ dependencies:
|
|
65
69
|
version: 0.2.7
|
66
70
|
type: :development
|
67
71
|
prerelease: false
|
68
|
-
version_requirements:
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ! '>='
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: 0.2.7
|
69
78
|
- !ruby/object:Gem::Dependency
|
70
79
|
name: pg
|
71
|
-
requirement:
|
80
|
+
requirement: !ruby/object:Gem::Requirement
|
72
81
|
none: false
|
73
82
|
requirements:
|
74
83
|
- - ! '>='
|
@@ -76,10 +85,15 @@ dependencies:
|
|
76
85
|
version: 0.9.0
|
77
86
|
type: :development
|
78
87
|
prerelease: false
|
79
|
-
version_requirements:
|
88
|
+
version_requirements: !ruby/object:Gem::Requirement
|
89
|
+
none: false
|
90
|
+
requirements:
|
91
|
+
- - ! '>='
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: 0.9.0
|
80
94
|
- !ruby/object:Gem::Dependency
|
81
95
|
name: sqlite3
|
82
|
-
requirement:
|
96
|
+
requirement: !ruby/object:Gem::Requirement
|
83
97
|
none: false
|
84
98
|
requirements:
|
85
99
|
- - ! '>='
|
@@ -87,7 +101,12 @@ dependencies:
|
|
87
101
|
version: 1.3.3
|
88
102
|
type: :development
|
89
103
|
prerelease: false
|
90
|
-
version_requirements:
|
104
|
+
version_requirements: !ruby/object:Gem::Requirement
|
105
|
+
none: false
|
106
|
+
requirements:
|
107
|
+
- - ! '>='
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: 1.3.3
|
91
110
|
description: ! 'This gem provides an acts_as_list compatible capability for sorting
|
92
111
|
|
93
112
|
and reordering a number of objects in a list. The class that has this
|
@@ -129,15 +148,21 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
129
148
|
- - ! '>='
|
130
149
|
- !ruby/object:Gem::Version
|
131
150
|
version: '0'
|
151
|
+
segments:
|
152
|
+
- 0
|
153
|
+
hash: -1709003177613176418
|
132
154
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
133
155
|
none: false
|
134
156
|
requirements:
|
135
157
|
- - ! '>='
|
136
158
|
- !ruby/object:Gem::Version
|
137
159
|
version: '0'
|
160
|
+
segments:
|
161
|
+
- 0
|
162
|
+
hash: -1709003177613176418
|
138
163
|
requirements: []
|
139
164
|
rubyforge_project:
|
140
|
-
rubygems_version: 1.8.
|
165
|
+
rubygems_version: 1.8.25
|
141
166
|
signing_key:
|
142
167
|
specification_version: 3
|
143
168
|
summary: Sort your models
|