acts_as_list 0.3.0 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,7 @@
1
1
  ---
2
- !binary "U0hBMQ==":
3
- metadata.gz: !binary |-
4
- NzM4YWNhZmE0NzViMmFhNDI0OGM0ZDFkM2RkYzAxMDIxODY2M2E2Mg==
5
- data.tar.gz: !binary |-
6
- MWYwZDU4MzgwNzhjMGQwYmU2YTJmOGZlZTUwODViOTc4NjBmZTlkYQ==
7
- !binary "U0hBNTEy":
8
- metadata.gz: !binary |-
9
- MzFmMjljMTNmMjY1ZGU5YTJjMzgzYjc2NjQ1ZjMyOWYyOWUwMmExMmJjMGQ5
10
- OGEwYjlhNjQ4YTdiM2RlZmQ3M2IxMzA1N2E3Y2I1MjE0NDE0OWZhNWU1Y2I5
11
- NzI1ZjgwZWNiOTE1MGNiZDE5NDBmNDZkNDA3ZjdlMGZjMThmYmM=
12
- data.tar.gz: !binary |-
13
- YTk3YjgxYThlYzE3MmQxY2QzNGNiN2QyNGZkYjY1ZGVmNzVkM2ZkM2QyNGI4
14
- MjI5OTUzZTNhNjY2Nzk1ZWMxYmI4NmZlNTFiMjgyMTI1MWY5ZTk1NzBlYTMz
15
- YzljYmY3MzMyZTUxZDk3M2QzNTEyNDJjNmVhODE1YzM0MTNlNTM=
2
+ SHA1:
3
+ metadata.gz: d5cbf688ac985c43f61b4c0669030f5b6f6c6caa
4
+ data.tar.gz: aef8fc0d40ed0ee55bf73ff2b7989e14e9c6572e
5
+ SHA512:
6
+ metadata.gz: de7f8dd3123cb1bf1fd5837517c221d8a6682207c3a75ac99a7457782b5ebf6d3fa995ee12664674cc7dfacaca6bd7e5ffaa484407502856aa8e9932ff066746
7
+ data.tar.gz: 20d069cc6a4420dd3dd6073f12ab8940cf2bb3c1003bd71faca489ddefe780349159696cd12ef37e65578ac796c0d4686af3c231cff832f3eb2b2a3306f2da62
@@ -3,12 +3,13 @@ rvm:
3
3
  - 1.9.2
4
4
  - 1.9.3
5
5
  - 2.0.0
6
+ - 2.1.0
7
+ - jruby-19mode
8
+ - rbx
6
9
  gemfile:
7
10
  - gemfiles/rails3/Gemfile
8
11
  - gemfiles/rails4/Gemfile
9
12
  matrix:
10
13
  allow_failures:
11
- - rvm: 1.8.7
12
- gemfile: gemfiles/rails4/Gemfile
13
14
  - rvm: 1.9.2
14
15
  gemfile: gemfiles/rails4/Gemfile
data/Gemfile CHANGED
@@ -1,5 +1,14 @@
1
1
  source "http://rubygems.org"
2
2
 
3
+ gem 'sqlite3', :platforms => [:ruby]
4
+ gem 'activerecord-jdbcsqlite3-adapter', :platforms => [:jruby]
5
+
6
+ platforms :rbx do
7
+ gem 'rubysl', '~> 2.0'
8
+ gem 'rubinius-developer_tools'
9
+ gem 'rubysl-test-unit'
10
+ end
11
+
3
12
  # Specify your gem's dependencies in acts_as_list-rails3.gemspec
4
13
  gemspec
5
14
 
@@ -0,0 +1,19 @@
1
+ Copyright (c) 2007 David Heinemeier Hansson
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ of this software and associated documentation files (the "Software"), to deal
5
+ in the Software without restriction, including without limitation the rights
6
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+ copies of the Software, and to permit persons to whom the Software is
8
+ furnished to do so, subject to the following conditions:
9
+
10
+ The above copyright notice and this permission notice shall be included in
11
+ all copies or substantial portions of the Software.
12
+
13
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
+ THE SOFTWARE.
data/README.md CHANGED
@@ -25,7 +25,7 @@ After that you can use `acts_as_list` method in the model:
25
25
 
26
26
  ```ruby
27
27
  class TodoList < ActiveRecord::Base
28
- has_many :todo_items, order: :position
28
+ has_many :todo_items, -> { order("position ASC") }
29
29
  end
30
30
 
31
31
  class TodoItem < ActiveRecord::Base
@@ -82,6 +82,9 @@ All versions `0.1.5` onwards require Rails 3.0.x and higher.
82
82
  ## Build Status
83
83
  [![Build Status](https://secure.travis-ci.org/swanandp/acts_as_list.png)](https://secure.travis-ci.org/swanandp/acts_as_list)
84
84
 
85
+ ## Workflow Status
86
+ [![WIP Issues](https://badge.waffle.io/swanandp/acts_as_list.png)](http://waffle.io/swanandp/acts_as_list)
87
+
85
88
  ## Roadmap
86
89
 
87
90
  1. Sort based feature
data/Rakefile CHANGED
@@ -15,15 +15,21 @@ Rake::TestTask.new(:test) do |t|
15
15
  t.verbose = false
16
16
  end
17
17
 
18
- # Run the rdoc task to generate rdocs for this gem
19
- require 'rdoc/task'
20
- RDoc::Task.new do |rdoc|
21
- require "acts_as_list/version"
22
- version = ActiveRecord::Acts::List::VERSION
18
+ begin
19
+ # Run the rdoc task to generate rdocs for this gem
20
+ require 'rdoc/task'
21
+ RDoc::Task.new do |rdoc|
22
+ require "acts_as_list/version"
23
+ version = ActiveRecord::Acts::List::VERSION
23
24
 
24
- rdoc.rdoc_dir = 'rdoc'
25
- rdoc.title = "acts_as_list-rails3 #{version}"
26
- rdoc.rdoc_files.include('README*')
27
- rdoc.rdoc_files.include('lib/**/*.rb')
25
+ rdoc.rdoc_dir = 'rdoc'
26
+ rdoc.title = "acts_as_list-rails3 #{version}"
27
+ rdoc.rdoc_files.include('README*')
28
+ rdoc.rdoc_files.include('lib/**/*.rb')
29
+ end
30
+ rescue LoadError
31
+ puts 'RDocTask is not supported on this platform.'
32
+ rescue StandardError
33
+ puts 'RDocTask is not supported on this platform.'
28
34
  end
29
35
 
@@ -13,8 +13,9 @@ Gem::Specification.new do |s|
13
13
  s.homepage = 'http://github.com/swanandp/acts_as_list'
14
14
  s.summary = %q{A gem allowing a active_record model to act_as_list.}
15
15
  s.description = %q{This "acts_as" extension provides the capabilities for sorting and reordering a number of objects in a list. The class that has this specified needs to have a "position" column defined as an integer on the mapped database table.}
16
+ s.license = 'MIT'
16
17
  s.rubyforge_project = 'acts_as_list'
17
-
18
+ s.required_ruby_version = '>= 1.9.2'
18
19
 
19
20
  # Load Paths...
20
21
  s.files = `git ls-files`.split("\n")
@@ -26,6 +27,4 @@ Gem::Specification.new do |s|
26
27
  # Dependencies (installed via 'bundle install')...
27
28
  s.add_dependency("activerecord", [">= 3.0"])
28
29
  s.add_development_dependency("bundler", [">= 1.0.0"])
29
- s.add_development_dependency("rdoc")
30
- s.add_development_dependency("sqlite3")
31
30
  end
@@ -1,5 +1,14 @@
1
1
  source "https://rubygems.org"
2
2
 
3
+ gem 'sqlite3', :platforms => [:ruby]
4
+ gem 'activerecord-jdbcsqlite3-adapter', :platforms => [:jruby]
5
+
6
+ platforms :rbx do
7
+ gem 'rubysl', '~> 2.0'
8
+ gem 'rubinius-developer_tools'
9
+ gem 'rubysl-test-unit'
10
+ end
11
+
3
12
  gem 'activerecord', '>= 3.0', '< 4'
4
13
 
5
14
  # Specify your gem's dependencies in acts_as_list.gemspec
@@ -1,5 +1,15 @@
1
1
  source "https://rubygems.org"
2
2
 
3
+ gem 'sqlite3', :platforms => [:ruby]
4
+ gem 'activerecord-jdbcsqlite3-adapter', :platforms => [:jruby]
5
+
6
+ platforms :rbx do
7
+ gem 'rubysl', '~> 2.0'
8
+ gem 'rubinius-developer_tools'
9
+ gem 'rubysl-test-unit'
10
+ end
11
+
12
+
3
13
  gem 'activerecord', '>= 4.0.0', '< 5'
4
14
 
5
15
  # Specify your gem's dependencies in acts_as_list.gemspec
@@ -112,6 +112,7 @@ module ActiveRecord
112
112
  after_destroy :decrement_positions_on_lower_items
113
113
  before_update :check_scope
114
114
  after_update :update_positions
115
+ before_validation :check_top_position
115
116
 
116
117
  scope :in_list, lambda { where("#{table_name}.#{configuration[:column]} IS NOT NULL") }
117
118
  EOV
@@ -306,7 +307,7 @@ module ActiveRecord
306
307
  # Returns the bottom item
307
308
  def bottom_item(except = nil)
308
309
  conditions = scope_condition
309
- conditions = "#{conditions} AND #{self.class.primary_key} != #{except.id}" if except
310
+ conditions = "#{conditions} AND #{self.class.primary_key} != '#{except.id}'" if except
310
311
  acts_as_list_class.unscoped.in_list.where(conditions).order("#{acts_as_list_class.table_name}.#{position_column} DESC").first
311
312
  end
312
313
 
@@ -371,7 +372,7 @@ module ActiveRecord
371
372
  # Reorders intermediate items to support moving an item from old_position to new_position.
372
373
  def shuffle_positions_on_intermediate_items(old_position, new_position, avoid_id = nil)
373
374
  return if old_position == new_position
374
- avoid_id_condition = avoid_id ? " AND #{self.class.primary_key} != #{avoid_id}" : ''
375
+ avoid_id_condition = avoid_id ? " AND #{self.class.primary_key} != '#{avoid_id}'" : ''
375
376
  if old_position < new_position
376
377
  # Decrement position of intermediate items
377
378
  #
@@ -396,6 +397,7 @@ module ActiveRecord
396
397
  end
397
398
 
398
399
  def insert_at_position(position)
400
+ return set_list_position(position) if new_record?
399
401
  if in_list?
400
402
  old_position = send(position_column).to_i
401
403
  return if position == old_position
@@ -441,6 +443,12 @@ module ActiveRecord
441
443
  def reload_position
442
444
  self.reload
443
445
  end
446
+
447
+ def check_top_position
448
+ if send(position_column) && send(position_column) < acts_as_list_top
449
+ self[position_column] = acts_as_list_top
450
+ end
451
+ end
444
452
  end
445
453
  end
446
454
  end
@@ -1,7 +1,7 @@
1
1
  module ActiveRecord
2
2
  module Acts
3
3
  module List
4
- VERSION = "0.3.0"
4
+ VERSION = '0.4.0'
5
5
  end
6
6
  end
7
7
  end
@@ -7,8 +7,8 @@ rescue Bundler::BundlerError => e
7
7
  $stderr.puts "Run `bundle install` to install missing gems"
8
8
  exit e.status_code
9
9
  end
10
- require 'test/unit'
11
10
  require 'active_record'
11
+ require 'minitest/autorun'
12
12
  require "#{File.dirname(__FILE__)}/../init"
13
13
 
14
14
  require 'shared'
@@ -24,6 +24,11 @@ module Shared
24
24
  assert_equal 0, new.pos
25
25
  assert new.first?
26
26
  assert new.last?
27
+
28
+ new = ZeroBasedMixin.create(parent_id: 1, pos: -500)
29
+ assert_equal 0, new.pos
30
+ assert new.first?
31
+ assert new.last?
27
32
  end
28
33
 
29
34
  def test_reordering
@@ -73,6 +73,10 @@ end
73
73
  class DefaultScopedWhereMixin < Mixin
74
74
  acts_as_list column: "pos"
75
75
  default_scope { order('pos ASC').where(active: true) }
76
+
77
+ def self.for_active_false_tests
78
+ unscoped.order('pos ASC').where(active: false)
79
+ end
76
80
  end
77
81
 
78
82
  class TopAdditionMixin < Mixin
@@ -83,7 +87,7 @@ class NoAdditionMixin < Mixin
83
87
  acts_as_list column: "pos", add_new_at: nil, scope: :parent_id
84
88
  end
85
89
 
86
- class ActsAsListTestCase < Test::Unit::TestCase
90
+ class ActsAsListTestCase < MiniTest::Unit::TestCase
87
91
  # No default test required a this class is abstract.
88
92
  # Need for test/unit.
89
93
  undef_method :default_test if method_defined?(:default_test)
@@ -282,25 +286,25 @@ class DefaultScopedWhereTest < ActsAsListTestCase
282
286
  end
283
287
 
284
288
  def test_reordering
285
- assert_equal [1, 2, 3, 4], DefaultScopedWhereMixin.where(active: false).map(&:id)
289
+ assert_equal [1, 2, 3, 4], DefaultScopedWhereMixin.for_active_false_tests.map(&:id)
286
290
 
287
- DefaultScopedWhereMixin.where(active: false).where(id: 2).first.move_lower
288
- assert_equal [1, 3, 2, 4], DefaultScopedWhereMixin.where(active: false).map(&:id)
291
+ DefaultScopedWhereMixin.for_active_false_tests.where(id: 2).first.move_lower
292
+ assert_equal [1, 3, 2, 4], DefaultScopedWhereMixin.for_active_false_tests.map(&:id)
289
293
 
290
- DefaultScopedWhereMixin.where(active: false).where(id: 2).first.move_higher
291
- assert_equal [1, 2, 3, 4], DefaultScopedWhereMixin.where(active: false).map(&:id)
294
+ DefaultScopedWhereMixin.for_active_false_tests.where(id: 2).first.move_higher
295
+ assert_equal [1, 2, 3, 4], DefaultScopedWhereMixin.for_active_false_tests.map(&:id)
292
296
 
293
- DefaultScopedWhereMixin.where(active: false).where(id: 1).first.move_to_bottom
294
- assert_equal [2, 3, 4, 1], DefaultScopedWhereMixin.where(active: false).map(&:id)
297
+ DefaultScopedWhereMixin.for_active_false_tests.where(id: 1).first.move_to_bottom
298
+ assert_equal [2, 3, 4, 1], DefaultScopedWhereMixin.for_active_false_tests.map(&:id)
295
299
 
296
- DefaultScopedWhereMixin.where(active: false).where(id: 1).first.move_to_top
297
- assert_equal [1, 2, 3, 4], DefaultScopedWhereMixin.where(active: false).map(&:id)
300
+ DefaultScopedWhereMixin.for_active_false_tests.where(id: 1).first.move_to_top
301
+ assert_equal [1, 2, 3, 4], DefaultScopedWhereMixin.for_active_false_tests.map(&:id)
298
302
 
299
- DefaultScopedWhereMixin.where(active: false).where(id: 2).first.move_to_bottom
300
- assert_equal [1, 3, 4, 2], DefaultScopedWhereMixin.where(active: false).map(&:id)
303
+ DefaultScopedWhereMixin.for_active_false_tests.where(id: 2).first.move_to_bottom
304
+ assert_equal [1, 3, 4, 2], DefaultScopedWhereMixin.for_active_false_tests.map(&:id)
301
305
 
302
- DefaultScopedWhereMixin.where(active: false).where(id: 4).first.move_to_top
303
- assert_equal [4, 1, 3, 2], DefaultScopedWhereMixin.where(active: false).map(&:id)
306
+ DefaultScopedWhereMixin.for_active_false_tests.where(id: 4).first.move_to_top
307
+ assert_equal [4, 1, 3, 2], DefaultScopedWhereMixin.for_active_false_tests.map(&:id)
304
308
  end
305
309
 
306
310
  def test_insert_at
@@ -339,15 +343,15 @@ class DefaultScopedWhereTest < ActsAsListTestCase
339
343
  end
340
344
 
341
345
  def test_update_position
342
- assert_equal [1, 2, 3, 4], DefaultScopedWhereMixin.where(active: false).map(&:id)
343
- DefaultScopedWhereMixin.where(active: false).where(id: 2).first.set_list_position(4)
344
- assert_equal [1, 3, 4, 2], DefaultScopedWhereMixin.where(active: false).map(&:id)
345
- DefaultScopedWhereMixin.where(active: false).where(id: 2).first.set_list_position(2)
346
- assert_equal [1, 2, 3, 4], DefaultScopedWhereMixin.where(active: false).map(&:id)
347
- DefaultScopedWhereMixin.where(active: false).where(id: 1).first.set_list_position(4)
348
- assert_equal [2, 3, 4, 1], DefaultScopedWhereMixin.where(active: false).map(&:id)
349
- DefaultScopedWhereMixin.where(active: false).where(id: 1).first.set_list_position(1)
350
- assert_equal [1, 2, 3, 4], DefaultScopedWhereMixin.where(active: false).map(&:id)
346
+ assert_equal [1, 2, 3, 4], DefaultScopedWhereMixin.for_active_false_tests.map(&:id)
347
+ DefaultScopedWhereMixin.for_active_false_tests.where(id: 2).first.set_list_position(4)
348
+ assert_equal [1, 3, 4, 2], DefaultScopedWhereMixin.for_active_false_tests.map(&:id)
349
+ DefaultScopedWhereMixin.for_active_false_tests.where(id: 2).first.set_list_position(2)
350
+ assert_equal [1, 2, 3, 4], DefaultScopedWhereMixin.for_active_false_tests.map(&:id)
351
+ DefaultScopedWhereMixin.for_active_false_tests.where(id: 1).first.set_list_position(4)
352
+ assert_equal [2, 3, 4, 1], DefaultScopedWhereMixin.for_active_false_tests.map(&:id)
353
+ DefaultScopedWhereMixin.for_active_false_tests.where(id: 1).first.set_list_position(1)
354
+ assert_equal [1, 2, 3, 4], DefaultScopedWhereMixin.for_active_false_tests.map(&:id)
351
355
  end
352
356
 
353
357
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: acts_as_list
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - David Heinemeier Hansson
@@ -10,64 +10,36 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2013-08-06 00:00:00.000000000 Z
13
+ date: 2014-02-22 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: activerecord
17
17
  requirement: !ruby/object:Gem::Requirement
18
18
  requirements:
19
- - - ! '>='
19
+ - - '>='
20
20
  - !ruby/object:Gem::Version
21
21
  version: '3.0'
22
22
  type: :runtime
23
23
  prerelease: false
24
24
  version_requirements: !ruby/object:Gem::Requirement
25
25
  requirements:
26
- - - ! '>='
26
+ - - '>='
27
27
  - !ruby/object:Gem::Version
28
28
  version: '3.0'
29
29
  - !ruby/object:Gem::Dependency
30
30
  name: bundler
31
31
  requirement: !ruby/object:Gem::Requirement
32
32
  requirements:
33
- - - ! '>='
33
+ - - '>='
34
34
  - !ruby/object:Gem::Version
35
35
  version: 1.0.0
36
36
  type: :development
37
37
  prerelease: false
38
38
  version_requirements: !ruby/object:Gem::Requirement
39
39
  requirements:
40
- - - ! '>='
40
+ - - '>='
41
41
  - !ruby/object:Gem::Version
42
42
  version: 1.0.0
43
- - !ruby/object:Gem::Dependency
44
- name: rdoc
45
- requirement: !ruby/object:Gem::Requirement
46
- requirements:
47
- - - ! '>='
48
- - !ruby/object:Gem::Version
49
- version: '0'
50
- type: :development
51
- prerelease: false
52
- version_requirements: !ruby/object:Gem::Requirement
53
- requirements:
54
- - - ! '>='
55
- - !ruby/object:Gem::Version
56
- version: '0'
57
- - !ruby/object:Gem::Dependency
58
- name: sqlite3
59
- requirement: !ruby/object:Gem::Requirement
60
- requirements:
61
- - - ! '>='
62
- - !ruby/object:Gem::Version
63
- version: '0'
64
- type: :development
65
- prerelease: false
66
- version_requirements: !ruby/object:Gem::Requirement
67
- requirements:
68
- - - ! '>='
69
- - !ruby/object:Gem::Version
70
- version: '0'
71
43
  description: This "acts_as" extension provides the capabilities for sorting and reordering
72
44
  a number of objects in a list. The class that has this specified needs to have a
73
45
  "position" column defined as an integer on the mapped database table.
@@ -81,6 +53,7 @@ files:
81
53
  - .gitignore
82
54
  - .travis.yml
83
55
  - Gemfile
56
+ - MIT-LICENSE
84
57
  - README.md
85
58
  - Rakefile
86
59
  - acts_as_list.gemspec
@@ -100,7 +73,8 @@ files:
100
73
  - test/shared_zero_based.rb
101
74
  - test/test_list.rb
102
75
  homepage: http://github.com/swanandp/acts_as_list
103
- licenses: []
76
+ licenses:
77
+ - MIT
104
78
  metadata: {}
105
79
  post_install_message:
106
80
  rdoc_options: []
@@ -108,17 +82,17 @@ require_paths:
108
82
  - lib
109
83
  required_ruby_version: !ruby/object:Gem::Requirement
110
84
  requirements:
111
- - - ! '>='
85
+ - - '>='
112
86
  - !ruby/object:Gem::Version
113
- version: '0'
87
+ version: 1.9.2
114
88
  required_rubygems_version: !ruby/object:Gem::Requirement
115
89
  requirements:
116
- - - ! '>='
90
+ - - '>='
117
91
  - !ruby/object:Gem::Version
118
92
  version: '0'
119
93
  requirements: []
120
94
  rubyforge_project: acts_as_list
121
- rubygems_version: 2.0.6
95
+ rubygems_version: 2.2.2
122
96
  signing_key:
123
97
  specification_version: 4
124
98
  summary: A gem allowing a active_record model to act_as_list.