sortifiable 0.2.4 → 0.2.5

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG CHANGED
@@ -1,3 +1,8 @@
1
+ *0.2.5 (September 11th, 2011)
2
+
3
+ * Don't rely on the current position attribute as it may be stale
4
+
5
+
1
6
  *0.2.4 (June 18th, 2011)
2
7
 
3
8
  * Typecast the list of primary keys return by lock_list! correctly as
data/Rakefile CHANGED
@@ -1,9 +1,6 @@
1
- require 'rake'
2
- require 'rake/rdoctask'
3
1
  require 'rake/testtask'
4
- require 'bundler'
5
-
6
- Bundler::GemHelper.install_tasks
2
+ require 'rdoc/task'
3
+ require "bundler/gem_tasks"
7
4
 
8
5
  desc 'Default: run sortifiable unit tests.'
9
6
  task :default => :test
@@ -16,7 +13,7 @@ Rake::TestTask.new(:test) do |t|
16
13
  end
17
14
 
18
15
  desc 'Generate documentation for the sortifiable gem.'
19
- Rake::RDocTask.new(:rdoc) do |rdoc|
16
+ RDoc::Task.new do |rdoc|
20
17
  rdoc.rdoc_dir = 'rdoc'
21
18
  rdoc.title = 'Sortifiable'
22
19
  rdoc.options << '--line-numbers' << '--inline-source'
data/lib/sortifiable.rb CHANGED
@@ -378,12 +378,17 @@ module Sortifiable
378
378
  end
379
379
 
380
380
  def decrement_position_on_lower_items #:nodoc:
381
- if last?
382
- true
383
- else
384
- update = "#{quoted_position_column} = #{quoted_position_column} - 1"
385
- conditions = "#{quoted_position_column} > #{current_position}"
386
- list_scope.update_all(update, conditions) > 0
381
+ list_class.transaction do
382
+ ids = lock_list!
383
+ current_position, last_position = ids.index(id) + 1, ids.size
384
+
385
+ if current_position == last_position
386
+ true
387
+ else
388
+ update = "#{quoted_position_column} = #{quoted_position_column} - 1"
389
+ conditions = "#{quoted_position_column} > #{current_position}"
390
+ list_scope.update_all(update, conditions) > 0
391
+ end
387
392
  end
388
393
  end
389
394
 
@@ -1,3 +1,3 @@
1
1
  module Sortifiable
2
- VERSION = "0.2.4"
2
+ VERSION = "0.2.5"
3
3
  end
data/sortifiable.gemspec CHANGED
@@ -37,9 +37,9 @@ EOF
37
37
 
38
38
  s.add_dependency "activesupport", ">= 3.0"
39
39
  s.add_dependency "activerecord", ">= 3.0"
40
- s.add_development_dependency "bundler", ">= 1.0.10"
40
+ s.add_development_dependency "bundler", ">= 1.0.18"
41
41
  s.add_development_dependency "mysql", "~> 2.8.1"
42
- s.add_development_dependency "mysql2", "~> 0.2.7"
43
- s.add_development_dependency "pg", "~> 0.9.0"
44
- s.add_development_dependency "sqlite3", "~> 1.3.3"
42
+ s.add_development_dependency "mysql2", ">= 0.2.7"
43
+ s.add_development_dependency "pg", ">= 0.9.0"
44
+ s.add_development_dependency "sqlite3", ">= 1.3.3"
45
45
  end
@@ -155,6 +155,12 @@ class ListTest < ActiveSupport::TestCase
155
155
  assert_equal 2, ListMixin.find(4).pos
156
156
  end
157
157
 
158
+ def test_destroy_all
159
+ assert_equal [1, 2, 3, 4], ListMixin.where(:parent_id => 5).map(&:id)
160
+ ListMixin.destroy_all
161
+ assert_equal [], ListMixin.where(:parent_id => 5).map(&:id)
162
+ end
163
+
158
164
  def test_nil_scope
159
165
  new1, new2, new3 = ListMixin.create, ListMixin.create, ListMixin.create
160
166
  new2.move_higher
@@ -291,6 +297,18 @@ class ListTest < ActiveSupport::TestCase
291
297
  assert_equal true, item.send(:decrement_position_on_lower_items_in_old_list)
292
298
  end
293
299
 
300
+ def test_decrement_callbacks_maintain_list_order
301
+ assert_equal [1, 2, 3, 4], ListMixin.where(:parent_id => 5).map(&:pos)
302
+
303
+ third = ListMixin.where(:parent_id => 5, :pos => 3).first
304
+ first = ListMixin.where(:parent_id => 5, :pos => 1).first
305
+
306
+ first.destroy
307
+ third.destroy
308
+
309
+ assert_equal [1, 2], ListMixin.where(:parent_id => 5).map(&:pos)
310
+ end
311
+
294
312
  end
295
313
 
296
314
  class ListWithStringScopeTest < ActiveSupport::TestCase
@@ -475,6 +493,12 @@ class ListSubTest < ActiveSupport::TestCase
475
493
  assert_equal 2, ListMixin.find(4).pos
476
494
  end
477
495
 
496
+ def test_destroy_all
497
+ assert_equal [1, 2, 3, 4], ListMixin.where(:parent_id => 5000).map(&:id)
498
+ ListMixin.destroy_all
499
+ assert_equal [], ListMixin.where(:parent_id => 5000).map(&:id)
500
+ end
501
+
478
502
  def test_higher_items
479
503
  ListMixin.find(2).remove_from_list
480
504
  assert_equal [1], ListMixin.find(3).higher_items.map(&:id)
@@ -640,6 +664,12 @@ class ArrayScopeListTest < ActiveSupport::TestCase
640
664
  assert_equal 2, ArrayScopeListMixin.find(4).pos
641
665
  end
642
666
 
667
+ def test_destroy_all
668
+ assert_equal [1, 2, 3, 4], ArrayScopeListMixin.where(conditions).map(&:id)
669
+ ArrayScopeListMixin.destroy_all
670
+ assert_equal [], ArrayScopeListMixin.where(conditions).map(&:id)
671
+ end
672
+
643
673
  def test_remove_from_list_by_updating_scope_part_1_should_shift_lower_items
644
674
  assert_equal [1, 2, 3, 4], ArrayScopeListMixin.where(conditions).map(&:id)
645
675
 
metadata CHANGED
@@ -1,151 +1,114 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: sortifiable
3
- version: !ruby/object:Gem::Version
4
- hash: 31
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.5
5
5
  prerelease:
6
- segments:
7
- - 0
8
- - 2
9
- - 4
10
- version: 0.2.4
11
6
  platform: ruby
12
- authors:
7
+ authors:
13
8
  - Andrew White
14
9
  autorequire:
15
10
  bindir: bin
16
11
  cert_chain: []
17
-
18
- date: 2011-06-18 00:00:00 +01:00
12
+ date: 2011-09-11 00:00:00.000000000 +01:00
19
13
  default_executable:
20
- dependencies:
21
- - !ruby/object:Gem::Dependency
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
22
16
  name: activesupport
23
- prerelease: false
24
- requirement: &id001 !ruby/object:Gem::Requirement
17
+ requirement: &2161594080 !ruby/object:Gem::Requirement
25
18
  none: false
26
- requirements:
27
- - - ">="
28
- - !ruby/object:Gem::Version
29
- hash: 7
30
- segments:
31
- - 3
32
- - 0
33
- version: "3.0"
19
+ requirements:
20
+ - - ! '>='
21
+ - !ruby/object:Gem::Version
22
+ version: '3.0'
34
23
  type: :runtime
35
- version_requirements: *id001
36
- - !ruby/object:Gem::Dependency
37
- name: activerecord
38
24
  prerelease: false
39
- requirement: &id002 !ruby/object:Gem::Requirement
25
+ version_requirements: *2161594080
26
+ - !ruby/object:Gem::Dependency
27
+ name: activerecord
28
+ requirement: &2161593620 !ruby/object:Gem::Requirement
40
29
  none: false
41
- requirements:
42
- - - ">="
43
- - !ruby/object:Gem::Version
44
- hash: 7
45
- segments:
46
- - 3
47
- - 0
48
- version: "3.0"
30
+ requirements:
31
+ - - ! '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '3.0'
49
34
  type: :runtime
50
- version_requirements: *id002
51
- - !ruby/object:Gem::Dependency
52
- name: bundler
53
35
  prerelease: false
54
- requirement: &id003 !ruby/object:Gem::Requirement
36
+ version_requirements: *2161593620
37
+ - !ruby/object:Gem::Dependency
38
+ name: bundler
39
+ requirement: &2161593160 !ruby/object:Gem::Requirement
55
40
  none: false
56
- requirements:
57
- - - ">="
58
- - !ruby/object:Gem::Version
59
- hash: 3
60
- segments:
61
- - 1
62
- - 0
63
- - 10
64
- version: 1.0.10
41
+ requirements:
42
+ - - ! '>='
43
+ - !ruby/object:Gem::Version
44
+ version: 1.0.18
65
45
  type: :development
66
- version_requirements: *id003
67
- - !ruby/object:Gem::Dependency
68
- name: mysql
69
46
  prerelease: false
70
- requirement: &id004 !ruby/object:Gem::Requirement
47
+ version_requirements: *2161593160
48
+ - !ruby/object:Gem::Dependency
49
+ name: mysql
50
+ requirement: &2161592700 !ruby/object:Gem::Requirement
71
51
  none: false
72
- requirements:
52
+ requirements:
73
53
  - - ~>
74
- - !ruby/object:Gem::Version
75
- hash: 45
76
- segments:
77
- - 2
78
- - 8
79
- - 1
54
+ - !ruby/object:Gem::Version
80
55
  version: 2.8.1
81
56
  type: :development
82
- version_requirements: *id004
83
- - !ruby/object:Gem::Dependency
84
- name: mysql2
85
57
  prerelease: false
86
- requirement: &id005 !ruby/object:Gem::Requirement
58
+ version_requirements: *2161592700
59
+ - !ruby/object:Gem::Dependency
60
+ name: mysql2
61
+ requirement: &2161592240 !ruby/object:Gem::Requirement
87
62
  none: false
88
- requirements:
89
- - - ~>
90
- - !ruby/object:Gem::Version
91
- hash: 25
92
- segments:
93
- - 0
94
- - 2
95
- - 7
63
+ requirements:
64
+ - - ! '>='
65
+ - !ruby/object:Gem::Version
96
66
  version: 0.2.7
97
67
  type: :development
98
- version_requirements: *id005
99
- - !ruby/object:Gem::Dependency
100
- name: pg
101
68
  prerelease: false
102
- requirement: &id006 !ruby/object:Gem::Requirement
69
+ version_requirements: *2161592240
70
+ - !ruby/object:Gem::Dependency
71
+ name: pg
72
+ requirement: &2161591780 !ruby/object:Gem::Requirement
103
73
  none: false
104
- requirements:
105
- - - ~>
106
- - !ruby/object:Gem::Version
107
- hash: 59
108
- segments:
109
- - 0
110
- - 9
111
- - 0
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
112
77
  version: 0.9.0
113
78
  type: :development
114
- version_requirements: *id006
115
- - !ruby/object:Gem::Dependency
116
- name: sqlite3
117
79
  prerelease: false
118
- requirement: &id007 !ruby/object:Gem::Requirement
80
+ version_requirements: *2161591780
81
+ - !ruby/object:Gem::Dependency
82
+ name: sqlite3
83
+ requirement: &2161591320 !ruby/object:Gem::Requirement
119
84
  none: false
120
- requirements:
121
- - - ~>
122
- - !ruby/object:Gem::Version
123
- hash: 29
124
- segments:
125
- - 1
126
- - 3
127
- - 3
85
+ requirements:
86
+ - - ! '>='
87
+ - !ruby/object:Gem::Version
128
88
  version: 1.3.3
129
89
  type: :development
130
- version_requirements: *id007
131
- description: |
132
- This gem provides an acts_as_list compatible capability for sorting
90
+ prerelease: false
91
+ version_requirements: *2161591320
92
+ description: ! 'This gem provides an acts_as_list compatible capability for sorting
93
+
133
94
  and reordering a number of objects in a list. The class that has this
95
+
134
96
  specified needs to have a +position+ column defined as an integer on
97
+
135
98
  the mapped database table.
136
-
99
+
100
+
137
101
  This gem requires ActiveRecord 3.0 as it has been refactored to use
102
+
138
103
  the scope methods and query interface introduced with Ruby on Rails 3.0
139
104
 
140
- email:
105
+ '
106
+ email:
141
107
  - andyw@pixeltrix.co.uk
142
108
  executables: []
143
-
144
109
  extensions: []
145
-
146
110
  extra_rdoc_files: []
147
-
148
- files:
111
+ files:
149
112
  - .gemtest
150
113
  - CHANGELOG
151
114
  - LICENSE
@@ -158,36 +121,27 @@ files:
158
121
  has_rdoc: true
159
122
  homepage: http://github.com/pixeltrix/sortifiable/
160
123
  licenses: []
161
-
162
124
  post_install_message:
163
125
  rdoc_options: []
164
-
165
- require_paths:
126
+ require_paths:
166
127
  - lib
167
- required_ruby_version: !ruby/object:Gem::Requirement
128
+ required_ruby_version: !ruby/object:Gem::Requirement
168
129
  none: false
169
- requirements:
170
- - - ">="
171
- - !ruby/object:Gem::Version
172
- hash: 3
173
- segments:
174
- - 0
175
- version: "0"
176
- required_rubygems_version: !ruby/object:Gem::Requirement
130
+ requirements:
131
+ - - ! '>='
132
+ - !ruby/object:Gem::Version
133
+ version: '0'
134
+ required_rubygems_version: !ruby/object:Gem::Requirement
177
135
  none: false
178
- requirements:
179
- - - ">="
180
- - !ruby/object:Gem::Version
181
- hash: 3
182
- segments:
183
- - 0
184
- version: "0"
136
+ requirements:
137
+ - - ! '>='
138
+ - !ruby/object:Gem::Version
139
+ version: '0'
185
140
  requirements: []
186
-
187
141
  rubyforge_project:
188
- rubygems_version: 1.5.2
142
+ rubygems_version: 1.6.2
189
143
  signing_key:
190
144
  specification_version: 3
191
145
  summary: Sort your models
192
- test_files:
146
+ test_files:
193
147
  - test/sortifiable_test.rb