acts_as_list 0.2.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,15 @@
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=
@@ -1,6 +1,14 @@
1
1
  language: ruby
2
2
  rvm:
3
- - 1.8.7
4
3
  - 1.9.2
5
4
  - 1.9.3
6
5
  - 2.0.0
6
+ gemfile:
7
+ - gemfiles/rails3/Gemfile
8
+ - gemfiles/rails4/Gemfile
9
+ matrix:
10
+ allow_failures:
11
+ - rvm: 1.8.7
12
+ gemfile: gemfiles/rails4/Gemfile
13
+ - rvm: 1.9.2
14
+ gemfile: gemfiles/rails4/Gemfile
@@ -0,0 +1,8 @@
1
+ source "https://rubygems.org"
2
+
3
+ gem 'activerecord', '>= 3.0', '< 4'
4
+
5
+ # Specify your gem's dependencies in acts_as_list.gemspec
6
+ gemspec :path => File.join('..', '..')
7
+
8
+ gem 'rake'
@@ -0,0 +1,8 @@
1
+ source "https://rubygems.org"
2
+
3
+ gem 'activerecord', '>= 4.0.0', '< 5'
4
+
5
+ # Specify your gem's dependencies in acts_as_list.gemspec
6
+ gemspec :path => File.join('..', '..')
7
+
8
+ gem 'rake'
@@ -12,12 +12,12 @@ module ActiveRecord
12
12
  # Todo list example:
13
13
  #
14
14
  # class TodoList < ActiveRecord::Base
15
- # has_many :todo_items, :order => "position"
15
+ # has_many :todo_items, order: "position"
16
16
  # end
17
17
  #
18
18
  # class TodoItem < ActiveRecord::Base
19
19
  # belongs_to :todo_list
20
- # acts_as_list :scope => :todo_list
20
+ # acts_as_list scope: :todo_list
21
21
  # end
22
22
  #
23
23
  # todo_list.first.move_to_bottom
@@ -29,33 +29,51 @@ module ActiveRecord
29
29
  # * +scope+ - restricts what is to be considered a list. Given a symbol, it'll attach <tt>_id</tt>
30
30
  # (if it hasn't already been added) and use that as the foreign key restriction. It's also possible
31
31
  # to give it an entire string that is interpolated if you need a tighter scope than just a foreign key.
32
- # Example: <tt>acts_as_list :scope => 'todo_list_id = #{todo_list_id} AND completed = 0'</tt>
32
+ # Example: <tt>acts_as_list scope: 'todo_list_id = #{todo_list_id} AND completed = 0'</tt>
33
33
  # * +top_of_list+ - defines the integer used for the top of the list. Defaults to 1. Use 0 to make the collection
34
34
  # act more like an array in its indexing.
35
35
  # * +add_new_at+ - specifies whether objects get added to the :top or :bottom of the list. (default: +bottom+)
36
+ # `nil` will result in new items not being added to the list on create
36
37
  def acts_as_list(options = {})
37
- configuration = { :column => "position", :scope => "1 = 1", :top_of_list => 1, :add_new_at => :bottom}
38
+ configuration = { column: "position", scope: "1 = 1", top_of_list: 1, add_new_at: :bottom}
38
39
  configuration.update(options) if options.is_a?(Hash)
39
40
 
40
41
  configuration[:scope] = "#{configuration[:scope]}_id".intern if configuration[:scope].is_a?(Symbol) && configuration[:scope].to_s !~ /_id$/
41
42
 
42
43
  if configuration[:scope].is_a?(Symbol)
43
- scope_condition_method = %(
44
+ scope_methods = %(
44
45
  def scope_condition
45
46
  self.class.send(:sanitize_sql_hash_for_conditions, { :#{configuration[:scope].to_s} => send(:#{configuration[:scope].to_s}) })
46
47
  end
48
+
49
+ def scope_changed?
50
+ changes.include?(scope_name.to_s)
51
+ end
47
52
  )
48
53
  elsif configuration[:scope].is_a?(Array)
49
- scope_condition_method = %(
50
- def scope_condition
51
- attrs = %w(#{configuration[:scope].join(" ")}).inject({}) do |memo,column|
54
+ scope_methods = %(
55
+ def attrs
56
+ %w(#{configuration[:scope].join(" ")}).inject({}) do |memo,column|
52
57
  memo[column.intern] = send(column.intern); memo
53
58
  end
59
+ end
60
+
61
+ def scope_changed?
62
+ (attrs.keys & changes.keys.map(&:to_sym)).any?
63
+ end
64
+
65
+ def scope_condition
54
66
  self.class.send(:sanitize_sql_hash_for_conditions, attrs)
55
67
  end
56
68
  )
57
69
  else
58
- scope_condition_method = "def scope_condition() \"#{configuration[:scope]}\" end"
70
+ scope_methods = %(
71
+ def scope_condition
72
+ "#{configuration[:scope]}"
73
+ end
74
+
75
+ def scope_changed?() false end
76
+ )
59
77
  end
60
78
 
61
79
  class_eval <<-EOV
@@ -81,7 +99,7 @@ module ActiveRecord
81
99
  '#{configuration[:add_new_at]}'
82
100
  end
83
101
 
84
- #{scope_condition_method}
102
+ #{scope_methods}
85
103
 
86
104
  # only add to attr_accessible
87
105
  # if the class has some mass_assignment_protection
@@ -92,10 +110,16 @@ module ActiveRecord
92
110
 
93
111
  before_destroy :reload_position
94
112
  after_destroy :decrement_positions_on_lower_items
95
- before_create :add_to_list_#{configuration[:add_new_at]}
96
- after_update :update_positions
97
113
  before_update :check_scope
114
+ after_update :update_positions
115
+
116
+ scope :in_list, lambda { where("#{table_name}.#{configuration[:column]} IS NOT NULL") }
98
117
  EOV
118
+
119
+ if configuration[:add_new_at].present?
120
+ self.send(:before_create, "add_to_list_#{configuration[:add_new_at]}")
121
+ end
122
+
99
123
  end
100
124
  end
101
125
 
@@ -157,6 +181,12 @@ module ActiveRecord
157
181
  end
158
182
  end
159
183
 
184
+ # Move the item within scope
185
+ def move_within_scope(scope_id)
186
+ send("#{scope_name}=", scope_id)
187
+ save!
188
+ end
189
+
160
190
  # Increase the position of this item without adjusting the rest of the list.
161
191
  def increment_position
162
192
  return unless in_list?
@@ -184,10 +214,9 @@ module ActiveRecord
184
214
  # Return the next higher item in the list.
185
215
  def higher_item
186
216
  return nil unless in_list?
187
- acts_as_list_class.unscoped.find(:first, :conditions =>
188
- "#{scope_condition} AND #{position_column} < #{(send(position_column).to_i).to_s}",
189
- :order => "#{acts_as_list_class.table_name}.#{position_column} DESC"
190
- )
217
+ acts_as_list_class.unscoped.
218
+ where("#{scope_condition} AND #{position_column} < #{(send(position_column).to_i).to_s}").
219
+ order("#{acts_as_list_class.table_name}.#{position_column} DESC").first
191
220
  end
192
221
 
193
222
  # Return the next n higher items in the list
@@ -205,10 +234,9 @@ module ActiveRecord
205
234
  # Return the next lower item in the list.
206
235
  def lower_item
207
236
  return nil unless in_list?
208
- acts_as_list_class.unscoped.find(:first, :conditions =>
209
- "#{scope_condition} AND #{position_column} > #{(send(position_column).to_i).to_s}",
210
- :order => "#{acts_as_list_class.table_name}.#{position_column} ASC"
211
- )
237
+ acts_as_list_class.unscoped.
238
+ where("#{scope_condition} AND #{position_column} > #{(send(position_column).to_i).to_s}").
239
+ order("#{acts_as_list_class.table_name}.#{position_column} ASC").first
212
240
  end
213
241
 
214
242
  # Return the next n lower items in the list
@@ -279,7 +307,7 @@ module ActiveRecord
279
307
  def bottom_item(except = nil)
280
308
  conditions = scope_condition
281
309
  conditions = "#{conditions} AND #{self.class.primary_key} != #{except.id}" if except
282
- acts_as_list_class.unscoped.where(conditions).order("#{acts_as_list_class.table_name}.#{position_column} DESC").first
310
+ acts_as_list_class.unscoped.in_list.where(conditions).order("#{acts_as_list_class.table_name}.#{position_column} DESC").first
283
311
  end
284
312
 
285
313
  # Forces item to assume the bottom position in the list.
@@ -390,17 +418,22 @@ module ActiveRecord
390
418
  def update_positions
391
419
  old_position = send("#{position_column}_was").to_i
392
420
  new_position = send(position_column).to_i
421
+
393
422
  return unless acts_as_list_class.unscoped.where("#{scope_condition} AND #{position_column} = #{new_position}").count > 1
394
423
  shuffle_positions_on_intermediate_items old_position, new_position, id
395
424
  end
396
425
 
426
+ # Temporarily swap changes attributes with current attributes
427
+ def swap_changed_attributes
428
+ @changed_attributes.each { |k, _| @changed_attributes[k], self[k] =
429
+ self[k], @changed_attributes[k] }
430
+ end
431
+
397
432
  def check_scope
398
- if changes.include?("#{scope_name}")
399
- old_scope_id = changes["#{scope_name}"].first
400
- new_scope_id = changes["#{scope_name}"].last
401
- self["#{scope_name}"] = old_scope_id
402
- send("decrement_positions_on_lower_items")
403
- self["#{scope_name}"] = new_scope_id
433
+ if scope_changed?
434
+ swap_changed_attributes
435
+ send('decrement_positions_on_lower_items') if lower_item
436
+ swap_changed_attributes
404
437
  send("add_to_list_#{add_new_at}")
405
438
  end
406
439
  end
@@ -1,7 +1,7 @@
1
1
  module ActiveRecord
2
2
  module Acts
3
3
  module List
4
- VERSION = "0.2.0"
4
+ VERSION = "0.3.0"
5
5
  end
6
6
  end
7
7
  end
@@ -5,4 +5,5 @@ module Shared
5
5
  autoload :ZeroBased, 'shared_zero_based'
6
6
  autoload :ArrayScopeList, 'shared_array_scope_list'
7
7
  autoload :TopAddition, 'shared_top_addition'
8
+ autoload :NoAddition, 'shared_no_addition'
8
9
  end
@@ -1,87 +1,87 @@
1
1
  module Shared
2
2
  module ArrayScopeList
3
3
  def setup
4
- (1..4).each { |counter| ArrayScopeListMixin.create! :pos => counter, :parent_id => 5, :parent_type => 'ParentClass' }
5
- (1..4).each { |counter| ArrayScopeListMixin.create! :pos => counter, :parent_id => 6, :parent_type => 'ParentClass' }
4
+ (1..4).each { |counter| ArrayScopeListMixin.create! pos: counter, parent_id: 5, parent_type: 'ParentClass' }
5
+ (1..4).each { |counter| ArrayScopeListMixin.create! pos: counter, parent_id: 6, parent_type: 'ParentClass' }
6
6
  end
7
7
 
8
8
  def test_reordering
9
- assert_equal [1, 2, 3, 4], ArrayScopeListMixin.find(:all, :conditions => "parent_id = 5 AND parent_type = 'ParentClass'", :order => 'pos').map(&:id)
9
+ assert_equal [1, 2, 3, 4], ArrayScopeListMixin.where(parent_id: 5, parent_type: 'ParentClass').order('pos').map(&:id)
10
10
 
11
- ArrayScopeListMixin.find(2).move_lower
12
- assert_equal [1, 3, 2, 4], ArrayScopeListMixin.find(:all, :conditions => "parent_id = 5 AND parent_type = 'ParentClass'", :order => 'pos').map(&:id)
11
+ ArrayScopeListMixin.where(id: 2).first.move_lower
12
+ assert_equal [1, 3, 2, 4], ArrayScopeListMixin.where(parent_id: 5, parent_type: 'ParentClass').order('pos').map(&:id)
13
13
 
14
- ArrayScopeListMixin.find(2).move_higher
15
- assert_equal [1, 2, 3, 4], ArrayScopeListMixin.find(:all, :conditions => "parent_id = 5 AND parent_type = 'ParentClass'", :order => 'pos').map(&:id)
14
+ ArrayScopeListMixin.where(id: 2).first.move_higher
15
+ assert_equal [1, 2, 3, 4], ArrayScopeListMixin.where(parent_id: 5, parent_type: 'ParentClass').order('pos').map(&:id)
16
16
 
17
- ArrayScopeListMixin.find(1).move_to_bottom
18
- assert_equal [2, 3, 4, 1], ArrayScopeListMixin.find(:all, :conditions => "parent_id = 5 AND parent_type = 'ParentClass'", :order => 'pos').map(&:id)
17
+ ArrayScopeListMixin.where(id: 1).first.move_to_bottom
18
+ assert_equal [2, 3, 4, 1], ArrayScopeListMixin.where(parent_id: 5, parent_type: 'ParentClass').order('pos').map(&:id)
19
19
 
20
- ArrayScopeListMixin.find(1).move_to_top
21
- assert_equal [1, 2, 3, 4], ArrayScopeListMixin.find(:all, :conditions => "parent_id = 5 AND parent_type = 'ParentClass'", :order => 'pos').map(&:id)
20
+ ArrayScopeListMixin.where(id: 1).first.move_to_top
21
+ assert_equal [1, 2, 3, 4], ArrayScopeListMixin.where(parent_id: 5, parent_type: 'ParentClass').order('pos').map(&:id)
22
22
 
23
- ArrayScopeListMixin.find(2).move_to_bottom
24
- assert_equal [1, 3, 4, 2], ArrayScopeListMixin.find(:all, :conditions => "parent_id = 5 AND parent_type = 'ParentClass'", :order => 'pos').map(&:id)
23
+ ArrayScopeListMixin.where(id: 2).first.move_to_bottom
24
+ assert_equal [1, 3, 4, 2], ArrayScopeListMixin.where(parent_id: 5, parent_type: 'ParentClass').order('pos').map(&:id)
25
25
 
26
- ArrayScopeListMixin.find(4).move_to_top
27
- assert_equal [4, 1, 3, 2], ArrayScopeListMixin.find(:all, :conditions => "parent_id = 5 AND parent_type = 'ParentClass'", :order => 'pos').map(&:id)
26
+ ArrayScopeListMixin.where(id: 4).first.move_to_top
27
+ assert_equal [4, 1, 3, 2], ArrayScopeListMixin.where(parent_id: 5, parent_type: 'ParentClass').order('pos').map(&:id)
28
28
 
29
- ArrayScopeListMixin.find(4).insert_at(4)
30
- assert_equal [1, 3, 2, 4], ArrayScopeListMixin.find(:all, :conditions => "parent_id = 5 AND parent_type = 'ParentClass'", :order => 'pos').map(&:id)
31
- assert_equal [1, 2, 3, 4], ArrayScopeListMixin.find(:all, :conditions => "parent_id = 5 AND parent_type = 'ParentClass'", :order => 'pos').map(&:pos)
29
+ ArrayScopeListMixin.where(id: 4).first.insert_at(4)
30
+ assert_equal [1, 3, 2, 4], ArrayScopeListMixin.where(parent_id: 5, parent_type: 'ParentClass').order('pos').map(&:id)
31
+ assert_equal [1, 2, 3, 4], ArrayScopeListMixin.where(parent_id: 5, parent_type: 'ParentClass').order('pos').map(&:pos)
32
32
  end
33
33
 
34
34
  def test_move_to_bottom_with_next_to_last_item
35
- assert_equal [1, 2, 3, 4], ArrayScopeListMixin.find(:all, :conditions => "parent_id = 5 AND parent_type = 'ParentClass'", :order => 'pos').map(&:id)
36
- ArrayScopeListMixin.find(3).move_to_bottom
37
- assert_equal [1, 2, 4, 3], ArrayScopeListMixin.find(:all, :conditions => "parent_id = 5 AND parent_type = 'ParentClass'", :order => 'pos').map(&:id)
35
+ assert_equal [1, 2, 3, 4], ArrayScopeListMixin.where(parent_id: 5, parent_type: 'ParentClass').order('pos').map(&:id)
36
+ ArrayScopeListMixin.where(id: 3).first.move_to_bottom
37
+ assert_equal [1, 2, 4, 3], ArrayScopeListMixin.where(parent_id: 5, parent_type: 'ParentClass').order('pos').map(&:id)
38
38
  end
39
39
 
40
40
  def test_next_prev
41
- assert_equal ArrayScopeListMixin.find(2), ArrayScopeListMixin.find(1).lower_item
42
- assert_nil ArrayScopeListMixin.find(1).higher_item
43
- assert_equal ArrayScopeListMixin.find(3), ArrayScopeListMixin.find(4).higher_item
44
- assert_nil ArrayScopeListMixin.find(4).lower_item
41
+ assert_equal ArrayScopeListMixin.where(id: 2).first, ArrayScopeListMixin.where(id: 1).first.lower_item
42
+ assert_nil ArrayScopeListMixin.where(id: 1).first.higher_item
43
+ assert_equal ArrayScopeListMixin.where(id: 3).first, ArrayScopeListMixin.where(id: 4).first.higher_item
44
+ assert_nil ArrayScopeListMixin.where(id: 4).first.lower_item
45
45
  end
46
46
 
47
47
  def test_injection
48
- item = ArrayScopeListMixin.new(:parent_id => 1, :parent_type => 'ParentClass')
48
+ item = ArrayScopeListMixin.new(parent_id: 1, parent_type: 'ParentClass')
49
49
  assert_equal "pos", item.position_column
50
50
  end
51
51
 
52
52
  def test_insert
53
- new = ArrayScopeListMixin.create(:parent_id => 20, :parent_type => 'ParentClass')
53
+ new = ArrayScopeListMixin.create(parent_id: 20, parent_type: 'ParentClass')
54
54
  assert_equal 1, new.pos
55
55
  assert new.first?
56
56
  assert new.last?
57
57
 
58
- new = ArrayScopeListMixin.create(:parent_id => 20, :parent_type => 'ParentClass')
58
+ new = ArrayScopeListMixin.create(parent_id: 20, parent_type: 'ParentClass')
59
59
  assert_equal 2, new.pos
60
60
  assert !new.first?
61
61
  assert new.last?
62
62
 
63
- new = ArrayScopeListMixin.create(:parent_id => 20, :parent_type => 'ParentClass')
63
+ new = ArrayScopeListMixin.create(parent_id: 20, parent_type: 'ParentClass')
64
64
  assert_equal 3, new.pos
65
65
  assert !new.first?
66
66
  assert new.last?
67
67
 
68
- new = ArrayScopeListMixin.create(:parent_id => 0, :parent_type => 'ParentClass')
68
+ new = ArrayScopeListMixin.create(parent_id: 0, parent_type: 'ParentClass')
69
69
  assert_equal 1, new.pos
70
70
  assert new.first?
71
71
  assert new.last?
72
72
  end
73
73
 
74
74
  def test_insert_at
75
- new = ArrayScopeListMixin.create(:parent_id => 20, :parent_type => 'ParentClass')
75
+ new = ArrayScopeListMixin.create(parent_id: 20, parent_type: 'ParentClass')
76
76
  assert_equal 1, new.pos
77
77
 
78
- new = ArrayScopeListMixin.create(:parent_id => 20, :parent_type => 'ParentClass')
78
+ new = ArrayScopeListMixin.create(parent_id: 20, parent_type: 'ParentClass')
79
79
  assert_equal 2, new.pos
80
80
 
81
- new = ArrayScopeListMixin.create(:parent_id => 20, :parent_type => 'ParentClass')
81
+ new = ArrayScopeListMixin.create(parent_id: 20, parent_type: 'ParentClass')
82
82
  assert_equal 3, new.pos
83
83
 
84
- new4 = ArrayScopeListMixin.create(:parent_id => 20, :parent_type => 'ParentClass')
84
+ new4 = ArrayScopeListMixin.create(parent_id: 20, parent_type: 'ParentClass')
85
85
  assert_equal 4, new4.pos
86
86
 
87
87
  new4.insert_at(3)
@@ -96,7 +96,7 @@ module Shared
96
96
  new4.reload
97
97
  assert_equal 4, new4.pos
98
98
 
99
- new5 = ArrayScopeListMixin.create(:parent_id => 20, :parent_type => 'ParentClass')
99
+ new5 = ArrayScopeListMixin.create(parent_id: 20, parent_type: 'ParentClass')
100
100
  assert_equal 5, new5.pos
101
101
 
102
102
  new5.insert_at(1)
@@ -107,54 +107,54 @@ module Shared
107
107
  end
108
108
 
109
109
  def test_delete_middle
110
- assert_equal [1, 2, 3, 4], ArrayScopeListMixin.find(:all, :conditions => "parent_id = 5 AND parent_type = 'ParentClass'", :order => 'pos').map(&:id)
110
+ assert_equal [1, 2, 3, 4], ArrayScopeListMixin.where(parent_id: 5, parent_type: 'ParentClass').order('pos').map(&:id)
111
111
 
112
- ArrayScopeListMixin.find(2).destroy
112
+ ArrayScopeListMixin.where(id: 2).first.destroy
113
113
 
114
- assert_equal [1, 3, 4], ArrayScopeListMixin.find(:all, :conditions => "parent_id = 5 AND parent_type = 'ParentClass'", :order => 'pos').map(&:id)
114
+ assert_equal [1, 3, 4], ArrayScopeListMixin.where(parent_id: 5, parent_type: 'ParentClass').order('pos').map(&:id)
115
115
 
116
- assert_equal 1, ArrayScopeListMixin.find(1).pos
117
- assert_equal 2, ArrayScopeListMixin.find(3).pos
118
- assert_equal 3, ArrayScopeListMixin.find(4).pos
116
+ assert_equal 1, ArrayScopeListMixin.where(id: 1).first.pos
117
+ assert_equal 2, ArrayScopeListMixin.where(id: 3).first.pos
118
+ assert_equal 3, ArrayScopeListMixin.where(id: 4).first.pos
119
119
 
120
- ArrayScopeListMixin.find(1).destroy
120
+ ArrayScopeListMixin.where(id: 1).first.destroy
121
121
 
122
- assert_equal [3, 4], ArrayScopeListMixin.find(:all, :conditions => "parent_id = 5 AND parent_type = 'ParentClass'", :order => 'pos').map(&:id)
122
+ assert_equal [3, 4], ArrayScopeListMixin.where(parent_id: 5, parent_type: 'ParentClass').order('pos').map(&:id)
123
123
 
124
- assert_equal 1, ArrayScopeListMixin.find(3).pos
125
- assert_equal 2, ArrayScopeListMixin.find(4).pos
124
+ assert_equal 1, ArrayScopeListMixin.where(id: 3).first.pos
125
+ assert_equal 2, ArrayScopeListMixin.where(id: 4).first.pos
126
126
  end
127
127
 
128
128
  def test_remove_from_list_should_then_fail_in_list?
129
- assert_equal true, ArrayScopeListMixin.find(1).in_list?
130
- ArrayScopeListMixin.find(1).remove_from_list
131
- assert_equal false, ArrayScopeListMixin.find(1).in_list?
129
+ assert_equal true, ArrayScopeListMixin.where(id: 1).first.in_list?
130
+ ArrayScopeListMixin.where(id: 1).first.remove_from_list
131
+ assert_equal false, ArrayScopeListMixin.where(id: 1).first.in_list?
132
132
  end
133
133
 
134
134
  def test_remove_from_list_should_set_position_to_nil
135
- assert_equal [1, 2, 3, 4], ArrayScopeListMixin.find(:all, :conditions => "parent_id = 5 AND parent_type = 'ParentClass'", :order => 'pos').map(&:id)
135
+ assert_equal [1, 2, 3, 4], ArrayScopeListMixin.where(parent_id: 5, parent_type: 'ParentClass').order('pos').map(&:id)
136
136
 
137
- ArrayScopeListMixin.find(2).remove_from_list
137
+ ArrayScopeListMixin.where(id: 2).first.remove_from_list
138
138
 
139
- assert_equal [2, 1, 3, 4], ArrayScopeListMixin.find(:all, :conditions => "parent_id = 5 AND parent_type = 'ParentClass'", :order => 'pos').map(&:id)
139
+ assert_equal [2, 1, 3, 4], ArrayScopeListMixin.where(parent_id: 5, parent_type: 'ParentClass').order('pos').map(&:id)
140
140
 
141
- assert_equal 1, ArrayScopeListMixin.find(1).pos
142
- assert_equal nil, ArrayScopeListMixin.find(2).pos
143
- assert_equal 2, ArrayScopeListMixin.find(3).pos
144
- assert_equal 3, ArrayScopeListMixin.find(4).pos
141
+ assert_equal 1, ArrayScopeListMixin.where(id: 1).first.pos
142
+ assert_equal nil, ArrayScopeListMixin.where(id: 2).first.pos
143
+ assert_equal 2, ArrayScopeListMixin.where(id: 3).first.pos
144
+ assert_equal 3, ArrayScopeListMixin.where(id: 4).first.pos
145
145
  end
146
146
 
147
147
  def test_remove_before_destroy_does_not_shift_lower_items_twice
148
- assert_equal [1, 2, 3, 4], ArrayScopeListMixin.find(:all, :conditions => "parent_id = 5 AND parent_type = 'ParentClass'", :order => 'pos').map(&:id)
148
+ assert_equal [1, 2, 3, 4], ArrayScopeListMixin.where(parent_id: 5, parent_type: 'ParentClass').order('pos').map(&:id)
149
149
 
150
- ArrayScopeListMixin.find(2).remove_from_list
151
- ArrayScopeListMixin.find(2).destroy
150
+ ArrayScopeListMixin.where(id: 2).first.remove_from_list
151
+ ArrayScopeListMixin.where(id: 2).first.destroy
152
152
 
153
- assert_equal [1, 3, 4], ArrayScopeListMixin.find(:all, :conditions => "parent_id = 5 AND parent_type = 'ParentClass'", :order => 'pos').map(&:id)
153
+ assert_equal [1, 3, 4], ArrayScopeListMixin.where(parent_id: 5, parent_type: 'ParentClass').order('pos').map(&:id)
154
154
 
155
- assert_equal 1, ArrayScopeListMixin.find(1).pos
156
- assert_equal 2, ArrayScopeListMixin.find(3).pos
157
- assert_equal 3, ArrayScopeListMixin.find(4).pos
155
+ assert_equal 1, ArrayScopeListMixin.where(id: 1).first.pos
156
+ assert_equal 2, ArrayScopeListMixin.where(id: 3).first.pos
157
+ assert_equal 3, ArrayScopeListMixin.where(id: 4).first.pos
158
158
  end
159
159
  end
160
160
  end