acts_as_list 0.7.4 → 0.7.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +5 -13
- data/.travis.yml +15 -0
- data/Appraisals +4 -0
- data/CHANGELOG.md +24 -2
- data/gemfiles/rails_5_0.gemfile +23 -0
- data/lib/acts_as_list/active_record/acts/list.rb +73 -69
- data/lib/acts_as_list/version.rb +1 -1
- data/test/helper.rb +2 -2
- data/test/shared.rb +1 -0
- data/test/shared_list.rb +7 -1
- data/test/shared_quoting.rb +21 -0
- data/test/test_joined_list.rb +64 -0
- data/test/test_list.rb +90 -2
- metadata +16 -11
checksums.yaml
CHANGED
@@ -1,15 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
|
5
|
-
data.tar.gz: !binary |-
|
6
|
-
OThlMWNiYjU3MGRmMGQzNjA5NzQ1MDk1MzdiYTg1MGFjODJlNDJmYQ==
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: c73ad553a7510872487e1d9bf560277e02ba3159
|
4
|
+
data.tar.gz: cc8e55f14d3c25aa21b1e2c239077e48a789c338
|
7
5
|
SHA512:
|
8
|
-
metadata.gz:
|
9
|
-
|
10
|
-
NmY4Y2FjY2U4YjczNjliZjFmYzYwYmMzYTNlNTA2MjU4NmVlODFmMzg1NGY0
|
11
|
-
OWNkN2Y4MGU2ZTM4YjM2YjY0MTZkNjcwMjk0NmQ1YzBkMmNjYjE=
|
12
|
-
data.tar.gz: !binary |-
|
13
|
-
Mzg4NGQwNmY2NjdjN2MxZWIzYWE4MWNiOTlkMTc5NGM5NTRiMzRmY2MwNDVh
|
14
|
-
ODI2YTVhZmUwMzE1OTAwNzA1OWZjMjc3ZGNhZmI1Y2ZmNmU4NmYzNGQ3ZTc1
|
15
|
-
OGUyZDE0NjZkZTVjNmQxZTJhOWUyNjdhOWIwMjJiMTg2YzA2NWI=
|
6
|
+
metadata.gz: 4ff90570f627ca4911a842a95e06c0570db69ed3ea2d908eaef1339dea143dbafb17e70d53009dddcb3fcf1ab2a12afe2fe5ceea0c71cd62ca3b1b337b18f947
|
7
|
+
data.tar.gz: e2c8a70ecaaea9b85437feb857a82cb5073eace0a50474fc914461bd19fd7113f27c866591dc291cbabf17342d2c2a98c75d8fd4eaf3d247a98c8eb6a19db968
|
data/.travis.yml
CHANGED
@@ -9,9 +9,24 @@ rvm:
|
|
9
9
|
- 1.9.3
|
10
10
|
- 2.0.0
|
11
11
|
- 2.1.0
|
12
|
+
- 2.2.2
|
12
13
|
- jruby-19mode
|
13
14
|
- rbx-2
|
14
15
|
gemfile:
|
15
16
|
- gemfiles/rails_3_2.gemfile
|
16
17
|
- gemfiles/rails_4_1.gemfile
|
17
18
|
- gemfiles/rails_4_2.gemfile
|
19
|
+
- gemfiles/rails_5_0.gemfile
|
20
|
+
matrix:
|
21
|
+
exclude:
|
22
|
+
- rvm: 1.9.3
|
23
|
+
gemfile: gemfiles/rails_5_0.gemfile
|
24
|
+
- rvm: 2.0.0
|
25
|
+
gemfile: gemfiles/rails_5_0.gemfile
|
26
|
+
- rvm: 2.1.0
|
27
|
+
gemfile: gemfiles/rails_5_0.gemfile
|
28
|
+
- rvm: jruby-19mode
|
29
|
+
gemfile: gemfiles/rails_5_0.gemfile
|
30
|
+
- rvm: rbx-2
|
31
|
+
gemfile: gemfiles/rails_5_0.gemfile
|
32
|
+
|
data/Appraisals
CHANGED
data/CHANGELOG.md
CHANGED
@@ -1,7 +1,29 @@
|
|
1
1
|
# Change Log
|
2
2
|
|
3
|
+
## [Unreleased](https://github.com/swanandp/acts_as_list/tree/HEAD)
|
4
|
+
|
5
|
+
[Full Changelog](https://github.com/swanandp/acts_as_list/compare/v0.7.4...HEAD)
|
6
|
+
|
7
|
+
**Closed issues:**
|
8
|
+
|
9
|
+
- Undefined instance variable @scope\_changed since 0.7.3 [\#199](https://github.com/swanandp/acts_as_list/issues/199)
|
10
|
+
|
11
|
+
## [v0.7.4](https://github.com/swanandp/acts_as_list/tree/v0.7.4) (2016-04-15)
|
12
|
+
[Full Changelog](https://github.com/swanandp/acts_as_list/compare/v0.7.3...v0.7.4)
|
13
|
+
|
14
|
+
**Closed issues:**
|
15
|
+
|
16
|
+
- Releasing a new gem version [\#196](https://github.com/swanandp/acts_as_list/issues/196)
|
17
|
+
|
18
|
+
**Merged pull requests:**
|
19
|
+
|
20
|
+
- Fix scope changed [\#200](https://github.com/swanandp/acts_as_list/pull/200) ([brendon](https://github.com/brendon))
|
21
|
+
|
3
22
|
## [v0.7.3](https://github.com/swanandp/acts_as_list/tree/v0.7.3) (2016-04-14)
|
4
|
-
[Full Changelog](https://github.com/swanandp/acts_as_list/compare/
|
23
|
+
[Full Changelog](https://github.com/swanandp/acts_as_list/compare/v0.7.2...v0.7.3)
|
24
|
+
|
25
|
+
## [v0.7.2](https://github.com/swanandp/acts_as_list/tree/v0.7.2) (2016-04-01)
|
26
|
+
[Full Changelog](https://github.com/swanandp/acts_as_list/compare/0.7.2...v0.7.2)
|
5
27
|
|
6
28
|
**Closed issues:**
|
7
29
|
|
@@ -238,4 +260,4 @@
|
|
238
260
|
|
239
261
|
|
240
262
|
|
241
|
-
\* *This Change Log was automatically generated by [github_changelog_generator](https://github.com/skywinder/Github-Changelog-Generator)*
|
263
|
+
\* *This Change Log was automatically generated by [github_changelog_generator](https://github.com/skywinder/Github-Changelog-Generator)*
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# This file was generated by Appraisal
|
2
|
+
|
3
|
+
source "http://rubygems.org"
|
4
|
+
|
5
|
+
gem "sqlite3", :platforms => [:ruby]
|
6
|
+
gem "activerecord-jdbcsqlite3-adapter", :platforms => [:jruby]
|
7
|
+
gem "rake"
|
8
|
+
gem "appraisal"
|
9
|
+
gem "github_changelog_generator", "1.9.0"
|
10
|
+
gem "activerecord", "~> 5.0.0.beta3"
|
11
|
+
|
12
|
+
group :test do
|
13
|
+
gem "minitest", "~> 5.0"
|
14
|
+
gem "test_after_commit", "~> 0.4.2"
|
15
|
+
end
|
16
|
+
|
17
|
+
platforms :rbx do
|
18
|
+
gem "rubysl", "~> 2.0"
|
19
|
+
gem "rubinius-developer_tools"
|
20
|
+
gem "rubysl-test-unit"
|
21
|
+
end
|
22
|
+
|
23
|
+
gemspec :path => "../"
|
@@ -74,9 +74,9 @@ module ActiveRecord
|
|
74
74
|
)
|
75
75
|
end
|
76
76
|
|
77
|
-
|
78
|
-
include ::ActiveRecord::Acts::List::InstanceMethods
|
77
|
+
quoted_position_column = connection.quote_column_name(configuration[:column])
|
79
78
|
|
79
|
+
class_eval <<-EOV, __FILE__, __LINE__ + 1
|
80
80
|
def acts_as_list_top
|
81
81
|
#{configuration[:top_of_list]}.to_i
|
82
82
|
end
|
@@ -111,23 +111,46 @@ module ActiveRecord
|
|
111
111
|
attr_accessible :#{configuration[:column]}
|
112
112
|
end
|
113
113
|
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
114
|
+
scope :in_list, lambda { where(%q{#{quoted_table_name}.#{quoted_position_column} IS NOT NULL}) }
|
115
|
+
|
116
|
+
def self.decrement_all
|
117
|
+
update_all_with_touch %q(#{quoted_position_column} = (#{quoted_table_name}.#{quoted_position_column} - 1))
|
118
|
+
end
|
119
|
+
|
120
|
+
def self.increment_all
|
121
|
+
update_all_with_touch %q(#{quoted_position_column} = (#{quoted_table_name}.#{quoted_position_column} + 1))
|
122
|
+
end
|
123
|
+
|
124
|
+
def self.update_all_with_touch(updates)
|
125
|
+
record = new
|
126
|
+
attrs = record.send(:timestamp_attributes_for_update_in_model)
|
127
|
+
now = record.send(:current_time_from_proper_timezone)
|
121
128
|
|
122
|
-
|
129
|
+
query = attrs.map { |attr| %(\#{connection.quote_column_name(attr)} = :now) }
|
130
|
+
query.push updates
|
131
|
+
query = query.join(", ")
|
123
132
|
|
124
|
-
|
133
|
+
update_all([query, now: now])
|
134
|
+
end
|
125
135
|
EOV
|
126
136
|
|
137
|
+
attr_reader :position_changed
|
138
|
+
|
139
|
+
before_validation :check_top_position
|
140
|
+
|
141
|
+
before_destroy :lock!
|
142
|
+
after_destroy :decrement_positions_on_lower_items
|
143
|
+
|
144
|
+
before_update :check_scope
|
145
|
+
after_update :update_positions
|
146
|
+
|
147
|
+
after_commit :clear_scope_changed
|
148
|
+
|
127
149
|
if configuration[:add_new_at].present?
|
128
|
-
|
150
|
+
before_create "add_to_list_#{configuration[:add_new_at]}".to_sym
|
129
151
|
end
|
130
152
|
|
153
|
+
include ::ActiveRecord::Acts::List::InstanceMethods
|
131
154
|
end
|
132
155
|
end
|
133
156
|
|
@@ -232,10 +255,10 @@ module ActiveRecord
|
|
232
255
|
limit ||= acts_as_list_list.count
|
233
256
|
position_value = send(position_column)
|
234
257
|
acts_as_list_list.
|
235
|
-
where("#{
|
236
|
-
where("#{
|
258
|
+
where("#{quoted_table_name}.#{quoted_position_column} < ?", position_value).
|
259
|
+
where("#{quoted_table_name}.#{quoted_position_column} >= ?", position_value - limit).
|
237
260
|
limit(limit).
|
238
|
-
order("#{
|
261
|
+
order("#{quoted_table_name}.#{quoted_position_column} ASC")
|
239
262
|
end
|
240
263
|
|
241
264
|
# Return the next lower item in the list.
|
@@ -250,10 +273,10 @@ module ActiveRecord
|
|
250
273
|
limit ||= acts_as_list_list.count
|
251
274
|
position_value = send(position_column)
|
252
275
|
acts_as_list_list.
|
253
|
-
where("#{
|
254
|
-
where("#{
|
276
|
+
where("#{quoted_table_name}.#{quoted_position_column} > ?", position_value).
|
277
|
+
where("#{quoted_table_name}.#{quoted_position_column} <= ?", position_value + limit).
|
255
278
|
limit(limit).
|
256
|
-
order("#{
|
279
|
+
order("#{quoted_table_name}.#{quoted_position_column} ASC")
|
257
280
|
end
|
258
281
|
|
259
282
|
# Test if this record is in a list
|
@@ -298,7 +321,7 @@ module ActiveRecord
|
|
298
321
|
# A poorly named method. It will insert the item at the desired position if the position
|
299
322
|
# has been set manually using position=, not necessarily the bottom of the list
|
300
323
|
def add_to_list_bottom
|
301
|
-
if not_in_list? || internal_scope_changed? &&
|
324
|
+
if not_in_list? || internal_scope_changed? && !position_changed || default_position?
|
302
325
|
self[position_column] = bottom_position_in_list.to_i + 1
|
303
326
|
else
|
304
327
|
increment_positions_on_lower_items(self[position_column], id)
|
@@ -323,12 +346,11 @@ module ActiveRecord
|
|
323
346
|
|
324
347
|
# Returns the bottom item
|
325
348
|
def bottom_item(except = nil)
|
326
|
-
conditions = scope_condition
|
327
349
|
conditions = except ? "#{self.class.primary_key} != #{self.class.connection.quote(except.id)}" : {}
|
328
350
|
acts_as_list_list.in_list.where(
|
329
351
|
conditions
|
330
352
|
).order(
|
331
|
-
"#{
|
353
|
+
"#{quoted_table_name}.#{quoted_position_column} DESC"
|
332
354
|
).first
|
333
355
|
end
|
334
356
|
|
@@ -344,50 +366,32 @@ module ActiveRecord
|
|
344
366
|
|
345
367
|
# This has the effect of moving all the higher items up one.
|
346
368
|
def decrement_positions_on_higher_items(position)
|
347
|
-
acts_as_list_list.where(
|
348
|
-
"#{position_column} <= #{position}"
|
349
|
-
).update_all(
|
350
|
-
"#{position_column} = (#{position_column} - 1)"
|
351
|
-
)
|
369
|
+
acts_as_list_list.where("#{quoted_position_column} <= #{position}").decrement_all
|
352
370
|
end
|
353
371
|
|
354
372
|
# This has the effect of moving all the lower items up one.
|
355
373
|
def decrement_positions_on_lower_items(position=nil)
|
356
374
|
return unless in_list?
|
357
375
|
position ||= send(position_column).to_i
|
358
|
-
acts_as_list_list.where(
|
359
|
-
"#{position_column} > #{position}"
|
360
|
-
).update_all(
|
361
|
-
"#{position_column} = (#{position_column} - 1)"
|
362
|
-
)
|
376
|
+
acts_as_list_list.where("#{quoted_position_column} > #{position}").decrement_all
|
363
377
|
end
|
364
378
|
|
365
379
|
# This has the effect of moving all the higher items down one.
|
366
380
|
def increment_positions_on_higher_items
|
367
381
|
return unless in_list?
|
368
|
-
acts_as_list_list.where(
|
369
|
-
"#{position_column} < #{send(position_column).to_i}"
|
370
|
-
).update_all(
|
371
|
-
"#{position_column} = (#{position_column} + 1)"
|
372
|
-
)
|
382
|
+
acts_as_list_list.where("#{quoted_position_column} < #{send(position_column).to_i}").increment_all
|
373
383
|
end
|
374
384
|
|
375
385
|
# This has the effect of moving all the lower items down one.
|
376
386
|
def increment_positions_on_lower_items(position, avoid_id = nil)
|
377
387
|
avoid_id_condition = avoid_id ? " AND #{self.class.primary_key} != #{self.class.connection.quote(avoid_id)}" : ''
|
378
388
|
|
379
|
-
acts_as_list_list.where(
|
380
|
-
"#{position_column} >= #{position}#{avoid_id_condition}"
|
381
|
-
).update_all(
|
382
|
-
"#{position_column} = (#{position_column} + 1)"
|
383
|
-
)
|
389
|
+
acts_as_list_list.where("#{quoted_position_column} >= #{position}#{avoid_id_condition}").increment_all
|
384
390
|
end
|
385
391
|
|
386
392
|
# Increments position (<tt>position_column</tt>) of all items in the list.
|
387
393
|
def increment_positions_on_all_items
|
388
|
-
acts_as_list_list.
|
389
|
-
"#{position_column} = (#{position_column} + 1)"
|
390
|
-
)
|
394
|
+
acts_as_list_list.increment_all
|
391
395
|
end
|
392
396
|
|
393
397
|
# Reorders intermediate items to support moving an item from old_position to new_position.
|
@@ -401,24 +405,20 @@ module ActiveRecord
|
|
401
405
|
# e.g., if moving an item from 2 to 5,
|
402
406
|
# move [3, 4, 5] to [2, 3, 4]
|
403
407
|
acts_as_list_list.where(
|
404
|
-
"#{
|
408
|
+
"#{quoted_position_column} > #{old_position}"
|
405
409
|
).where(
|
406
|
-
"#{
|
407
|
-
).
|
408
|
-
"#{position_column} = (#{position_column} - 1)"
|
409
|
-
)
|
410
|
+
"#{quoted_position_column} <= #{new_position}#{avoid_id_condition}"
|
411
|
+
).decrement_all
|
410
412
|
else
|
411
413
|
# Increment position of intermediate items
|
412
414
|
#
|
413
415
|
# e.g., if moving an item from 5 to 2,
|
414
416
|
# move [2, 3, 4] to [3, 4, 5]
|
415
417
|
acts_as_list_list.where(
|
416
|
-
"#{
|
418
|
+
"#{quoted_position_column} >= #{new_position}"
|
417
419
|
).where(
|
418
|
-
"#{
|
419
|
-
).
|
420
|
-
"#{position_column} = (#{position_column} + 1)"
|
421
|
-
)
|
420
|
+
"#{quoted_position_column} < #{old_position}#{avoid_id_condition}"
|
421
|
+
).increment_all
|
422
422
|
end
|
423
423
|
end
|
424
424
|
|
@@ -448,39 +448,33 @@ module ActiveRecord
|
|
448
448
|
new_position = send(position_column).to_i
|
449
449
|
|
450
450
|
return unless acts_as_list_list.where(
|
451
|
-
"#{
|
451
|
+
"#{quoted_position_column} = #{new_position}"
|
452
452
|
).count > 1
|
453
453
|
shuffle_positions_on_intermediate_items old_position, new_position, id
|
454
454
|
end
|
455
455
|
|
456
456
|
def internal_scope_changed?
|
457
457
|
return @scope_changed if defined?(@scope_changed)
|
458
|
-
|
458
|
+
|
459
459
|
@scope_changed = scope_changed?
|
460
460
|
end
|
461
461
|
|
462
|
-
|
463
|
-
|
464
|
-
@changed_attributes.each do |k, _|
|
465
|
-
if self.class.column_names.include? k
|
466
|
-
@changed_attributes[k], self[k] = self[k], @changed_attributes[k]
|
467
|
-
end
|
468
|
-
end
|
462
|
+
def clear_scope_changed
|
463
|
+
remove_instance_variable(:@scope_changed) if defined?(@scope_changed)
|
469
464
|
end
|
470
465
|
|
471
466
|
def check_scope
|
472
467
|
if internal_scope_changed?
|
473
|
-
|
468
|
+
cached_changes = changes
|
469
|
+
|
470
|
+
cached_changes.each { |attribute, values| self[attribute] = values[0] }
|
474
471
|
send('decrement_positions_on_lower_items') if lower_item
|
475
|
-
|
472
|
+
cached_changes.each { |attribute, values| self[attribute] = values[1] }
|
473
|
+
|
476
474
|
send("add_to_list_#{add_new_at}")
|
477
475
|
end
|
478
476
|
end
|
479
477
|
|
480
|
-
def reload_position
|
481
|
-
self.reload
|
482
|
-
end
|
483
|
-
|
484
478
|
# This check is skipped if the position is currently the default position from the table
|
485
479
|
# as modifying the default position on creation is handled elsewhere
|
486
480
|
def check_top_position
|
@@ -488,6 +482,16 @@ module ActiveRecord
|
|
488
482
|
self[position_column] = acts_as_list_top
|
489
483
|
end
|
490
484
|
end
|
485
|
+
|
486
|
+
# When using raw column name it must be quoted otherwise it can raise syntax errors with SQL keywords (e.g. order)
|
487
|
+
def quoted_position_column
|
488
|
+
@_quoted_position_column ||= self.class.connection.quote_column_name(position_column)
|
489
|
+
end
|
490
|
+
|
491
|
+
# Used in order clauses
|
492
|
+
def quoted_table_name
|
493
|
+
@_quoted_table_name ||= acts_as_list_class.quoted_table_name
|
494
|
+
end
|
491
495
|
end
|
492
496
|
end
|
493
497
|
end
|
data/lib/acts_as_list/version.rb
CHANGED
data/test/helper.rb
CHANGED
@@ -12,9 +12,9 @@ require "minitest/autorun"
|
|
12
12
|
require "#{File.dirname(__FILE__)}/../init"
|
13
13
|
|
14
14
|
if defined?(ActiveRecord::VERSION) &&
|
15
|
-
ActiveRecord::VERSION::MAJOR
|
16
|
-
(ActiveRecord::VERSION::MAJOR == 4 && ActiveRecord::VERSION::MINOR >= 2)
|
15
|
+
ActiveRecord::VERSION::MAJOR == 4 && ActiveRecord::VERSION::MINOR >= 2
|
17
16
|
|
17
|
+
# Was removed in Rails 5 and is effectively true.
|
18
18
|
ActiveRecord::Base.raise_in_transactional_callbacks = true
|
19
19
|
end
|
20
20
|
|
data/test/shared.rb
CHANGED
data/test/shared_list.rb
CHANGED
@@ -142,7 +142,7 @@ module Shared
|
|
142
142
|
|
143
143
|
def test_update_position_when_scope_changes
|
144
144
|
assert_equal [1, 2, 3, 4], ListMixin.where(parent_id: 5).order('pos').map(&:id)
|
145
|
-
|
145
|
+
ListMixin.create(parent_id: 6)
|
146
146
|
|
147
147
|
ListMixin.where(id: 2).first.move_within_scope(6)
|
148
148
|
|
@@ -246,5 +246,11 @@ module Shared
|
|
246
246
|
|
247
247
|
assert_equal [5, 1, 6, 2, 3, 4], ListMixin.where(parent_id: 5).order('pos').map(&:id)
|
248
248
|
end
|
249
|
+
|
250
|
+
def test_non_persisted_records_dont_get_lock_called
|
251
|
+
new = ListMixin.new(parent_id: 5)
|
252
|
+
|
253
|
+
new.destroy
|
254
|
+
end
|
249
255
|
end
|
250
256
|
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module Shared
|
2
|
+
module Quoting
|
3
|
+
|
4
|
+
def setup
|
5
|
+
3.times { |counter| QuotedList.create! order: counter }
|
6
|
+
end
|
7
|
+
|
8
|
+
def test_create
|
9
|
+
assert_equal QuotedList.in_list.size, 3
|
10
|
+
end
|
11
|
+
|
12
|
+
# This test execute raw queries involving table name
|
13
|
+
def test_moving
|
14
|
+
item = QuotedList.first
|
15
|
+
item.higher_items
|
16
|
+
item.lower_items
|
17
|
+
item.send :bottom_item # Part of private api
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,64 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
ActiveRecord::Base.establish_connection(adapter: "sqlite3", database: ":memory:")
|
4
|
+
ActiveRecord::Schema.verbose = false
|
5
|
+
|
6
|
+
class Section < ActiveRecord::Base
|
7
|
+
has_many :items
|
8
|
+
acts_as_list
|
9
|
+
|
10
|
+
scope :visible, -> { where(visible: true) }
|
11
|
+
end
|
12
|
+
|
13
|
+
class Item < ActiveRecord::Base
|
14
|
+
belongs_to :section
|
15
|
+
acts_as_list scope: :section
|
16
|
+
|
17
|
+
scope :visible, -> { where(visible: true).joins(:section).merge(Section.visible) }
|
18
|
+
end
|
19
|
+
|
20
|
+
class JoinedTestCase < Minitest::Test
|
21
|
+
def setup
|
22
|
+
ActiveRecord::Base.connection.create_table :sections do |t|
|
23
|
+
t.column :position, :integer
|
24
|
+
t.column :visible, :boolean, default: true
|
25
|
+
end
|
26
|
+
|
27
|
+
ActiveRecord::Base.connection.create_table :items do |t|
|
28
|
+
t.column :position, :integer
|
29
|
+
t.column :section_id, :integer
|
30
|
+
t.column :visible, :boolean, default: true
|
31
|
+
end
|
32
|
+
|
33
|
+
ActiveRecord::Base.connection.schema_cache.clear!
|
34
|
+
[Section, Item].each(&:reset_column_information)
|
35
|
+
super
|
36
|
+
end
|
37
|
+
|
38
|
+
def teardown
|
39
|
+
ActiveRecord::Base.connection.tables.each do |table|
|
40
|
+
ActiveRecord::Base.connection.drop_table(table)
|
41
|
+
end
|
42
|
+
super
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
# joining the relation returned by `#higher_items` or `#lower_items` to another table
|
47
|
+
# previously could result in ambiguous column names in the query
|
48
|
+
class TestHigherLowerItems < JoinedTestCase
|
49
|
+
def test_higher_items
|
50
|
+
section = Section.create
|
51
|
+
item1 = Item.create section: section
|
52
|
+
item2 = Item.create section: section
|
53
|
+
item3 = Item.create section: section
|
54
|
+
assert_equal item3.higher_items.visible, [item1, item2]
|
55
|
+
end
|
56
|
+
|
57
|
+
def test_lower_items
|
58
|
+
section = Section.create
|
59
|
+
item1 = Item.create section: section
|
60
|
+
item2 = Item.create section: section
|
61
|
+
item3 = Item.create section: section
|
62
|
+
assert_equal item1.lower_items.visible, [item2, item3]
|
63
|
+
end
|
64
|
+
end
|
data/test/test_list.rb
CHANGED
@@ -16,9 +16,14 @@ def setup_db(position_options = {})
|
|
16
16
|
t.column :state, :integer
|
17
17
|
end
|
18
18
|
|
19
|
+
# This table is used to test table names and column names quoting
|
20
|
+
ActiveRecord::Base.connection.create_table 'table-name' do |t|
|
21
|
+
t.column :order, :integer
|
22
|
+
end
|
23
|
+
|
19
24
|
mixins = [ Mixin, ListMixin, ListMixinSub1, ListMixinSub2, ListWithStringScopeMixin,
|
20
25
|
ArrayScopeListMixin, ZeroBasedMixin, DefaultScopedMixin,
|
21
|
-
DefaultScopedWhereMixin, TopAdditionMixin, NoAdditionMixin ]
|
26
|
+
DefaultScopedWhereMixin, TopAdditionMixin, NoAdditionMixin, QuotedList ]
|
22
27
|
|
23
28
|
mixins << EnumArrayScopeListMixin if rails_4
|
24
29
|
|
@@ -42,7 +47,13 @@ def rails_4
|
|
42
47
|
end
|
43
48
|
|
44
49
|
def teardown_db
|
45
|
-
ActiveRecord::
|
50
|
+
if ActiveRecord::VERSION::MAJOR >= 5
|
51
|
+
tables = ActiveRecord::Base.connection.data_sources
|
52
|
+
else
|
53
|
+
tables = ActiveRecord::Base.connection.tables
|
54
|
+
end
|
55
|
+
|
56
|
+
tables.each do |table|
|
46
57
|
ActiveRecord::Base.connection.drop_table(table)
|
47
58
|
end
|
48
59
|
end
|
@@ -149,6 +160,11 @@ end
|
|
149
160
|
class TheBaseSubclass < TheBaseClass
|
150
161
|
end
|
151
162
|
|
163
|
+
class QuotedList < ActiveRecord::Base
|
164
|
+
self.table_name = 'table-name'
|
165
|
+
acts_as_list column: :order
|
166
|
+
end
|
167
|
+
|
152
168
|
class ActsAsListTestCase < Minitest::Test
|
153
169
|
# No default test required as this class is abstract.
|
154
170
|
# Need for test/unit.
|
@@ -243,6 +259,15 @@ class ArrayScopeListTestWithDefault < ActsAsListTestCase
|
|
243
259
|
end
|
244
260
|
end
|
245
261
|
|
262
|
+
class QuotingTestList < ActsAsListTestCase
|
263
|
+
include Shared::Quoting
|
264
|
+
|
265
|
+
def setup
|
266
|
+
setup_db_with_default
|
267
|
+
super
|
268
|
+
end
|
269
|
+
end
|
270
|
+
|
246
271
|
class DefaultScopedTest < ActsAsListTestCase
|
247
272
|
def setup
|
248
273
|
setup_db
|
@@ -603,3 +628,66 @@ class MultipleListsArrayScopeTest < ActsAsListTestCase
|
|
603
628
|
assert_equal [1], ArrayScopeListMixin.where(:parent_id => 4, :parent_type => 'anything').order(:pos).map(&:pos)
|
604
629
|
end
|
605
630
|
end
|
631
|
+
|
632
|
+
class TouchTest < ActsAsListTestCase
|
633
|
+
def setup
|
634
|
+
setup_db
|
635
|
+
4.times { ListMixin.create! updated_at: yesterday }
|
636
|
+
end
|
637
|
+
|
638
|
+
def now
|
639
|
+
Time.now.utc
|
640
|
+
end
|
641
|
+
|
642
|
+
def yesterday
|
643
|
+
1.day.ago
|
644
|
+
end
|
645
|
+
|
646
|
+
def updated_ats
|
647
|
+
ListMixin.pluck(:updated_at)
|
648
|
+
end
|
649
|
+
|
650
|
+
def test_moving_item_lower_touches_self_and_lower_item
|
651
|
+
ListMixin.first.move_lower
|
652
|
+
updated_ats[0..1].each do |updated_at|
|
653
|
+
assert_in_delta updated_at, now, 1.second
|
654
|
+
end
|
655
|
+
updated_ats[2..3].each do |updated_at|
|
656
|
+
assert_in_delta updated_at, yesterday, 1.second
|
657
|
+
end
|
658
|
+
end
|
659
|
+
|
660
|
+
def test_moving_item_higher_touches_self_and_higher_item
|
661
|
+
ListMixin.all.second.move_higher
|
662
|
+
updated_ats[0..1].each do |updated_at|
|
663
|
+
assert_in_delta updated_at, now, 1.second
|
664
|
+
end
|
665
|
+
updated_ats[2..3].each do |updated_at|
|
666
|
+
assert_in_delta updated_at, yesterday, 1.second
|
667
|
+
end
|
668
|
+
end
|
669
|
+
|
670
|
+
def test_moving_item_to_bottom_touches_all_other_items
|
671
|
+
ListMixin.first.move_to_bottom
|
672
|
+
updated_ats.each do |updated_at|
|
673
|
+
assert_in_delta updated_at, now, 1.second
|
674
|
+
end
|
675
|
+
end
|
676
|
+
|
677
|
+
def test_moving_item_to_top_touches_all_other_items
|
678
|
+
ListMixin.last.move_to_top
|
679
|
+
updated_ats.each do |updated_at|
|
680
|
+
assert_in_delta updated_at, now, 1.second
|
681
|
+
end
|
682
|
+
end
|
683
|
+
|
684
|
+
def test_removing_item_touches_all_lower_items
|
685
|
+
ListMixin.all.third.remove_from_list
|
686
|
+
updated_ats[0..1].each do |updated_at|
|
687
|
+
assert_in_delta updated_at, yesterday, 1.second
|
688
|
+
end
|
689
|
+
updated_ats[2..2].each do |updated_at|
|
690
|
+
assert_in_delta updated_at, now, 1.second
|
691
|
+
end
|
692
|
+
end
|
693
|
+
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.7.
|
4
|
+
version: 0.7.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- David Heinemeier Hansson
|
@@ -10,34 +10,34 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2016-
|
13
|
+
date: 2016-06-30 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
43
|
description: This "acts_as" extension provides the capabilities for sorting and reordering
|
@@ -49,9 +49,9 @@ executables: []
|
|
49
49
|
extensions: []
|
50
50
|
extra_rdoc_files: []
|
51
51
|
files:
|
52
|
-
- .gemtest
|
53
|
-
- .gitignore
|
54
|
-
- .travis.yml
|
52
|
+
- ".gemtest"
|
53
|
+
- ".gitignore"
|
54
|
+
- ".travis.yml"
|
55
55
|
- Appraisals
|
56
56
|
- CHANGELOG.md
|
57
57
|
- Gemfile
|
@@ -62,6 +62,7 @@ files:
|
|
62
62
|
- gemfiles/rails_3_2.gemfile
|
63
63
|
- gemfiles/rails_4_1.gemfile
|
64
64
|
- gemfiles/rails_4_2.gemfile
|
65
|
+
- gemfiles/rails_5_0.gemfile
|
65
66
|
- init.rb
|
66
67
|
- lib/acts_as_list.rb
|
67
68
|
- lib/acts_as_list/active_record/acts/list.rb
|
@@ -72,8 +73,10 @@ files:
|
|
72
73
|
- test/shared_list.rb
|
73
74
|
- test/shared_list_sub.rb
|
74
75
|
- test/shared_no_addition.rb
|
76
|
+
- test/shared_quoting.rb
|
75
77
|
- test/shared_top_addition.rb
|
76
78
|
- test/shared_zero_based.rb
|
79
|
+
- test/test_joined_list.rb
|
77
80
|
- test/test_list.rb
|
78
81
|
homepage: http://github.com/swanandp/acts_as_list
|
79
82
|
licenses:
|
@@ -85,12 +88,12 @@ require_paths:
|
|
85
88
|
- lib
|
86
89
|
required_ruby_version: !ruby/object:Gem::Requirement
|
87
90
|
requirements:
|
88
|
-
- -
|
91
|
+
- - ">="
|
89
92
|
- !ruby/object:Gem::Version
|
90
93
|
version: 1.9.2
|
91
94
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
92
95
|
requirements:
|
93
|
-
- -
|
96
|
+
- - ">="
|
94
97
|
- !ruby/object:Gem::Version
|
95
98
|
version: '0'
|
96
99
|
requirements: []
|
@@ -107,6 +110,8 @@ test_files:
|
|
107
110
|
- test/shared_list.rb
|
108
111
|
- test/shared_list_sub.rb
|
109
112
|
- test/shared_no_addition.rb
|
113
|
+
- test/shared_quoting.rb
|
110
114
|
- test/shared_top_addition.rb
|
111
115
|
- test/shared_zero_based.rb
|
116
|
+
- test/test_joined_list.rb
|
112
117
|
- test/test_list.rb
|