sortifiable 0.2.1 → 0.2.2

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG CHANGED
@@ -1,3 +1,12 @@
1
+ *0.2.2 (May 3rd, 2011)
2
+
3
+ * Ensure that callbacks return true when no updates take place
4
+
5
+ * Moving first and last items should return true even when no update takes place
6
+
7
+ * Loosen gem dependencies so that it will work with Rails edge
8
+
9
+
1
10
  *0.2.1 (April 20th, 2011)
2
11
 
3
12
  * Add checking for scope changes so items are moved between lists correctly [Manuel Meurer]
@@ -1,4 +1,5 @@
1
- == Sortifiable
1
+ Sortifiable
2
+ ===========
2
3
 
3
4
  This gem provides an acts_as_list compatible capability for sorting
4
5
  and reordering a number of objects in a list. The class that has this
@@ -8,23 +9,25 @@ the mapped database table.
8
9
  This gem requires ActiveRecord 3.0 as it has been refactored to use
9
10
  the scope methods and query interface introduced with Ruby on Rails 3.0
10
11
 
12
+ Example
13
+ -------
11
14
 
12
- === Example
15
+ ``` ruby
16
+ class TodoList < ActiveRecord::Base
17
+ has_many :todo_items, :order => "position"
18
+ end
13
19
 
14
- class TodoList < ActiveRecord::Base
15
- has_many :todo_items, :order => "position"
16
- end
20
+ class TodoItem < ActiveRecord::Base
21
+ belongs_to :todo_list
22
+ acts_as_list :scope => :todo_list
23
+ end
17
24
 
18
- class TodoItem < ActiveRecord::Base
19
- belongs_to :todo_list
20
- acts_as_list :scope => :todo_list
21
- end
25
+ todo_list.first.move_to_bottom
26
+ todo_list.last.move_higher
27
+ ```
22
28
 
23
- todo_list.first.move_to_bottom
24
- todo_list.last.move_higher
25
-
26
-
27
- === Contributions
29
+ Contributions
30
+ -------------
28
31
 
29
32
  Bug fixes and new feature patches are welcome. Please provide tests and
30
33
  documentation wherever possible - without them it is unlikely your patch
@@ -36,5 +39,4 @@ Thanks to the following people for their contributions:
36
39
 
37
40
  * Manuel Meurer
38
41
 
39
-
40
42
  Copyright (c) 2011 Andrew White, released under the MIT license
data/Rakefile CHANGED
@@ -20,6 +20,5 @@ Rake::RDocTask.new(:rdoc) do |rdoc|
20
20
  rdoc.rdoc_dir = 'rdoc'
21
21
  rdoc.title = 'Sortifiable'
22
22
  rdoc.options << '--line-numbers' << '--inline-source'
23
- rdoc.rdoc_files.include('README')
24
23
  rdoc.rdoc_files.include('lib/**/*.rb')
25
24
  end
data/lib/sortifiable.rb CHANGED
@@ -243,6 +243,8 @@ module Sortifiable
243
243
 
244
244
  set_position current_position - 1
245
245
  list_scope.update_all(sql) > 0
246
+ else
247
+ true
246
248
  end
247
249
  end
248
250
  else
@@ -269,6 +271,8 @@ module Sortifiable
269
271
 
270
272
  set_position current_position + 1
271
273
  list_scope.update_all(sql) > 0
274
+ else
275
+ true
272
276
  end
273
277
  end
274
278
  else
@@ -296,6 +300,8 @@ module Sortifiable
296
300
 
297
301
  set_position last_position
298
302
  list_scope.update_all(sql) > 0
303
+ else
304
+ true
299
305
  end
300
306
  end
301
307
  else
@@ -322,6 +328,8 @@ module Sortifiable
322
328
 
323
329
  set_position 1
324
330
  list_scope.update_all(sql) > 0
331
+ else
332
+ true
325
333
  end
326
334
  end
327
335
  else
@@ -358,9 +366,13 @@ module Sortifiable
358
366
  end
359
367
 
360
368
  def decrement_position_on_lower_items #:nodoc:
361
- update = "#{quoted_position_column} = #{quoted_position_column} - 1"
362
- conditions = "#{quoted_position_column} > #{current_position}"
363
- list_scope.update_all(update, conditions) > 0
369
+ if last?
370
+ true
371
+ else
372
+ update = "#{quoted_position_column} = #{quoted_position_column} - 1"
373
+ conditions = "#{quoted_position_column} > #{current_position}"
374
+ list_scope.update_all(update, conditions) > 0
375
+ end
364
376
  end
365
377
 
366
378
  def decrement_position_on_lower_items_in_old_list #:nodoc:
@@ -376,10 +388,12 @@ module Sortifiable
376
388
  # Set old scope
377
389
  scope_parts.each { |scope_part| send "#{scope_part}=", send("#{scope_part}_was") }
378
390
 
379
- yield
391
+ retval = yield
380
392
 
381
393
  # Set new scope
382
394
  scope_parts.each_with_index { |scope_part, i| send "#{scope_part}=", new_scope[i] }
395
+
396
+ retval
383
397
  end
384
398
 
385
399
  def scope_parts_from_string(string) #:nodoc:
@@ -401,6 +415,7 @@ module Sortifiable
401
415
 
402
416
  def set_position(position) #:nodoc:
403
417
  send "#{position_column}=", position
418
+ true
404
419
  end
405
420
 
406
421
  def list_class #:nodoc:
@@ -1,3 +1,3 @@
1
1
  module Sortifiable
2
- VERSION = "0.2.1"
2
+ VERSION = "0.2.2"
3
3
  end
data/sortifiable.gemspec CHANGED
@@ -24,7 +24,7 @@ EOF
24
24
  ".gemtest",
25
25
  "CHANGELOG",
26
26
  "LICENSE",
27
- "README",
27
+ "README.md",
28
28
  "Rakefile",
29
29
  "lib/sortifiable.rb",
30
30
  "lib/sortifiable/version.rb",
@@ -35,8 +35,8 @@ EOF
35
35
  s.test_files = ["test/sortifiable_test.rb"]
36
36
  s.require_paths = ["lib"]
37
37
 
38
- s.add_dependency "activesupport", "~> 3.0.3"
39
- s.add_dependency "activerecord", "~> 3.0.3"
40
- s.add_development_dependency "bundler", "~> 1.0.10"
41
- s.add_development_dependency "sqlite3", "~> 1.3.3"
38
+ s.add_dependency "activesupport", ">= 3.0"
39
+ s.add_dependency "activerecord", ">= 3.0"
40
+ s.add_development_dependency "bundler", ">= 1.0.10"
41
+ s.add_development_dependency "sqlite3", ">= 1.3.3"
42
42
  end
@@ -336,6 +336,46 @@ class ListTest < Test::Unit::TestCase
336
336
  assert_equal [], ListMixin.find(4).lower_items.map(&:id)
337
337
  end
338
338
 
339
+ def test_moving_first_and_last_items_return_true
340
+ assert_equal [1, 2, 3, 4], ListMixin.where(:parent_id => 5).map(&:id)
341
+ assert_equal true, ListMixin.find(1).move_to_top
342
+ assert_equal true, ListMixin.find(1).move_higher
343
+ assert_equal true, ListMixin.find(4).move_to_bottom
344
+ assert_equal true, ListMixin.find(4).move_lower
345
+ end
346
+
347
+ def test_add_to_list_should_return_true
348
+ assert_equal [1, 2, 3, 4], ListMixin.where(:parent_id => 5).map(&:id)
349
+
350
+ item = ListMixin.new(:parent_id => 5)
351
+ assert_equal true, item.new_record?
352
+ assert_equal false, item.in_list?
353
+ assert_equal true, item.add_to_list
354
+
355
+ item = ListMixin.create(:parent_id => 5)
356
+ item.remove_from_list
357
+ assert_equal false, item.new_record?
358
+ assert_equal false, item.in_list?
359
+ assert_equal true, item.add_to_list
360
+ end
361
+
362
+ def test_decrement_callbacks_should_return_true
363
+ assert_equal [1, 2, 3, 4], ListMixin.where(:parent_id => 5).map(&:id)
364
+
365
+ item = ListMixin.find(4)
366
+ assert_equal 4, item.pos
367
+ assert_equal true, item.send(:decrement_position_on_lower_items)
368
+
369
+ assert_equal [1, 2, 3, 4], ListMixin.where(:parent_id => 5).map(&:id)
370
+
371
+ item = ListMixin.find(4)
372
+ item.parent_id = 6
373
+
374
+ assert_equal 4, item.pos
375
+ assert_equal true, item.will_leave_list?
376
+ assert_equal true, item.send(:decrement_position_on_lower_items_in_old_list)
377
+ end
378
+
339
379
  end
340
380
 
341
381
  class ListWithStringScopeTest < Test::Unit::TestCase
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sortifiable
3
3
  version: !ruby/object:Gem::Version
4
- hash: 21
4
+ hash: 19
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 2
9
- - 1
10
- version: 0.2.1
9
+ - 2
10
+ version: 0.2.2
11
11
  platform: ruby
12
12
  authors:
13
13
  - Andrew White
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-04-20 00:00:00 +01:00
18
+ date: 2011-05-03 00:00:00 +01:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -24,14 +24,13 @@ dependencies:
24
24
  requirement: &id001 !ruby/object:Gem::Requirement
25
25
  none: false
26
26
  requirements:
27
- - - ~>
27
+ - - ">="
28
28
  - !ruby/object:Gem::Version
29
- hash: 1
29
+ hash: 7
30
30
  segments:
31
31
  - 3
32
32
  - 0
33
- - 3
34
- version: 3.0.3
33
+ version: "3.0"
35
34
  type: :runtime
36
35
  version_requirements: *id001
37
36
  - !ruby/object:Gem::Dependency
@@ -40,14 +39,13 @@ dependencies:
40
39
  requirement: &id002 !ruby/object:Gem::Requirement
41
40
  none: false
42
41
  requirements:
43
- - - ~>
42
+ - - ">="
44
43
  - !ruby/object:Gem::Version
45
- hash: 1
44
+ hash: 7
46
45
  segments:
47
46
  - 3
48
47
  - 0
49
- - 3
50
- version: 3.0.3
48
+ version: "3.0"
51
49
  type: :runtime
52
50
  version_requirements: *id002
53
51
  - !ruby/object:Gem::Dependency
@@ -56,7 +54,7 @@ dependencies:
56
54
  requirement: &id003 !ruby/object:Gem::Requirement
57
55
  none: false
58
56
  requirements:
59
- - - ~>
57
+ - - ">="
60
58
  - !ruby/object:Gem::Version
61
59
  hash: 3
62
60
  segments:
@@ -72,7 +70,7 @@ dependencies:
72
70
  requirement: &id004 !ruby/object:Gem::Requirement
73
71
  none: false
74
72
  requirements:
75
- - - ~>
73
+ - - ">="
76
74
  - !ruby/object:Gem::Version
77
75
  hash: 29
78
76
  segments:
@@ -103,7 +101,7 @@ files:
103
101
  - .gemtest
104
102
  - CHANGELOG
105
103
  - LICENSE
106
- - README
104
+ - README.md
107
105
  - Rakefile
108
106
  - lib/sortifiable.rb
109
107
  - lib/sortifiable/version.rb