acts_as_list 0.9.13 → 0.9.14

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: bb0226cb2a1505d4baf4dce3e6987ac31f4468b4
4
- data.tar.gz: d418ae9ae5b4db5c20dcdc5d056f5458c5823a92
3
+ metadata.gz: 9c9b9604fc6198654f18e08d86d1d9b036fa2430
4
+ data.tar.gz: 9a3bd7ece52927226cfdd073f9071525189f0f07
5
5
  SHA512:
6
- metadata.gz: 3819051f4dcdad3e3d88968138194d9c2572bb26738b06eb615746f8456d03954b822c0bc443e9f50da46b4b6d297516a286d02980c3f191827bea31666b3f6e
7
- data.tar.gz: cd2c5e384d77e2c287905451d49bd7594a2562b41fd0e6334ed62a2ea38a543114f9798078f090aca5505247aec523acdf28d440b13d3dcdcb32580f466719d4
6
+ metadata.gz: e9ba06d872a758fc9a0f7e32cb7439b6db5f59742a6c0b407a8be43915309f84df7e4c740ca56f0be99e78937bfb1522104ee6a90b025598497c952eaeba3e52
7
+ data.tar.gz: 14581f4471d860d9619e9a84a1762b785f83b3d1b4856dfd1439ff72f680a73000ab68f87fb1e9b9629394f49d730e26d447b67af474d4e0f085b6f5642b0903
@@ -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(validate: false)
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
 
@@ -3,7 +3,7 @@
3
3
  module ActiveRecord
4
4
  module Acts
5
5
  module List
6
- VERSION = '0.9.13'
6
+ VERSION = '0.9.14'
7
7
  end
8
8
  end
9
9
  end
@@ -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
@@ -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
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.9.13
4
+ version: 0.9.14
5
5
  platform: ruby
6
6
  authors:
7
7
  - David Heinemeier Hansson