acts_as_list 0.9.13 → 0.9.14
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 +4 -4
- data/CHANGELOG.md +7 -0
- data/lib/acts_as_list/active_record/acts/list.rb +10 -6
- data/lib/acts_as_list/version.rb +1 -1
- data/test/shared_list.rb +15 -1
- data/test/test_list.rb +8 -0
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9c9b9604fc6198654f18e08d86d1d9b036fa2430
|
4
|
+
data.tar.gz: 9a3bd7ece52927226cfdd073f9071525189f0f07
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e9ba06d872a758fc9a0f7e32cb7439b6db5f59742a6c0b407a8be43915309f84df7e4c740ca56f0be99e78937bfb1522104ee6a90b025598497c952eaeba3e52
|
7
|
+
data.tar.gz: 14581f4471d860d9619e9a84a1762b785f83b3d1b4856dfd1439ff72f680a73000ab68f87fb1e9b9629394f49d730e26d447b67af474d4e0f085b6f5642b0903
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,12 @@
|
|
1
1
|
# Change Log
|
2
2
|
|
3
|
+
## [v0.9.13](https://github.com/swanandp/acts_as_list/tree/v0.9.13) (2018-06-05)
|
4
|
+
[Full Changelog](https://github.com/swanandp/acts_as_list/compare/v0.9.12...v0.9.13)
|
5
|
+
|
6
|
+
**Merged pull requests:**
|
7
|
+
|
8
|
+
- Fix unique index constraint failure on item destroy [\#313](https://github.com/swanandp/acts_as_list/pull/313) ([yjukaku](https://github.com/yjukaku))
|
9
|
+
|
3
10
|
## [v0.9.12](https://github.com/swanandp/acts_as_list/tree/v0.9.12) (2018-05-02)
|
4
11
|
[Full Changelog](https://github.com/swanandp/acts_as_list/compare/v0.9.11...v0.9.12)
|
5
12
|
|
@@ -69,6 +69,10 @@ module ActiveRecord
|
|
69
69
|
insert_at_position(position)
|
70
70
|
end
|
71
71
|
|
72
|
+
def insert_at!(position = acts_as_list_top)
|
73
|
+
insert_at_position(position, true)
|
74
|
+
end
|
75
|
+
|
72
76
|
# Swap positions with the next lower item, if one exists.
|
73
77
|
def move_lower
|
74
78
|
return unless lower_item
|
@@ -208,9 +212,9 @@ module ActiveRecord
|
|
208
212
|
end
|
209
213
|
|
210
214
|
# Sets the new position and saves it
|
211
|
-
def set_list_position(new_position)
|
215
|
+
def set_list_position(new_position, raise_exception_if_save_fails=false)
|
212
216
|
write_attribute position_column, new_position
|
213
|
-
save
|
217
|
+
raise_exception_if_save_fails ? save! : save
|
214
218
|
end
|
215
219
|
|
216
220
|
private
|
@@ -394,8 +398,8 @@ module ActiveRecord
|
|
394
398
|
end
|
395
399
|
end
|
396
400
|
|
397
|
-
def insert_at_position(position)
|
398
|
-
return set_list_position(position) if new_record?
|
401
|
+
def insert_at_position(position, raise_exception_if_save_fails=false)
|
402
|
+
return set_list_position(position, raise_exception_if_save_fails) if new_record?
|
399
403
|
with_lock do
|
400
404
|
if in_list?
|
401
405
|
old_position = send(position_column).to_i
|
@@ -404,12 +408,12 @@ module ActiveRecord
|
|
404
408
|
# gap is required to leave room for position increments
|
405
409
|
# positive number will be valid with unique not null check (>= 0) db constraint
|
406
410
|
temporary_position = bottom_position_in_list + 2
|
407
|
-
set_list_position(temporary_position)
|
411
|
+
set_list_position(temporary_position, raise_exception_if_save_fails)
|
408
412
|
shuffle_positions_on_intermediate_items(old_position, position, id)
|
409
413
|
else
|
410
414
|
increment_positions_on_lower_items(position)
|
411
415
|
end
|
412
|
-
set_list_position(position)
|
416
|
+
set_list_position(position, raise_exception_if_save_fails)
|
413
417
|
end
|
414
418
|
end
|
415
419
|
|
data/lib/acts_as_list/version.rb
CHANGED
data/test/shared_list.rb
CHANGED
@@ -293,8 +293,22 @@ module Shared
|
|
293
293
|
|
294
294
|
def test_non_persisted_records_dont_get_lock_called
|
295
295
|
new = ListMixin.new(parent_id: 5)
|
296
|
-
|
297
296
|
new.destroy
|
298
297
|
end
|
298
|
+
|
299
|
+
def test_invalid_records_dont_get_inserted
|
300
|
+
new = ListMixinError.new(parent_id: 5, state: nil)
|
301
|
+
assert !new.valid?
|
302
|
+
new.insert_at(1)
|
303
|
+
assert !new.persisted?
|
304
|
+
end
|
305
|
+
|
306
|
+
def test_invalid_records_raise_error_with_insert_at!
|
307
|
+
new = ListMixinError.new(parent_id: 5, state: nil)
|
308
|
+
assert !new.valid?
|
309
|
+
assert_raises ActiveRecord::RecordInvalid do
|
310
|
+
new.insert_at!(1)
|
311
|
+
end
|
312
|
+
end
|
299
313
|
end
|
300
314
|
end
|
data/test/test_list.rb
CHANGED
@@ -74,6 +74,14 @@ class ListMixinSub2 < ListMixin
|
|
74
74
|
end
|
75
75
|
end
|
76
76
|
|
77
|
+
class ListMixinError < ListMixin
|
78
|
+
if rails_3
|
79
|
+
validates :state, presence: true
|
80
|
+
else
|
81
|
+
validates_presence_of :state
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
77
85
|
class ListWithStringScopeMixin < Mixin
|
78
86
|
acts_as_list column: "pos", scope: 'parent_id = #{parent_id}'
|
79
87
|
end
|