acts_as_list 0.9.17 → 0.9.18

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: fab8be3ea9754103e60311aaa592f0ab4b7c84e3
4
- data.tar.gz: 166a2aff0b3f6cbb6cfc67709de71fda2f4b3960
3
+ metadata.gz: c7f90b8a37019ae091449a79440aca7cb8862960
4
+ data.tar.gz: db75dccae8c652a84e9dfaaffb2f195ca238b442
5
5
  SHA512:
6
- metadata.gz: 5afeff2ad86a92fb1261062596b2646508dee23473242686bf20ccf809623834705e467c3ad701963eba9a46c839f29fc2f3aba4adbce62dbe49d91e810f628d
7
- data.tar.gz: 037aa8e4d42c306040f7e2da8c9f9615e1c1a1c123df08edb7d1cb511fadb63a388f65567a45e20ea58a3444905f024f38da10fa54b0e55cdd3c610587539af4
6
+ metadata.gz: 65c7f4c2b1ee583aeb3f2ddc8a9c9c07b5428ad6b0d4b3f5d45e0ad9f1e2a55b7ac98c1f0f1ea7a4ee79969bf2bd343b748f1b9463c65a6635120a3235ad02c1
7
+ data.tar.gz: 8bd08749b808b25f33e9f8f398731973625ff0ee42dc76080944a94ab88ca6e817412609af0897d69db7e2c7a8843a36a5a90177fffee17d2cadbfa483a87df8
data/Appraisals CHANGED
@@ -3,6 +3,7 @@ appraise "rails-3-2" do
3
3
  gem "mysql2", "~> 0.3.21", platforms: [:ruby]
4
4
  end
5
5
  gem "activerecord", "~> 3.2.22.2"
6
+ gem "rake", "~> 12.2.0", platforms: [:ruby_19]
6
7
  group :test do
7
8
  gem "after_commit_exception_notification"
8
9
  end
@@ -13,6 +14,7 @@ appraise "rails-4-1" do
13
14
  gem "mysql2", "~> 0.3.21", platforms: [:ruby]
14
15
  end
15
16
  gem "activerecord", "~> 4.1.16"
17
+ gem "rake", "~> 12.2.0", platforms: [:ruby_19]
16
18
  group :test do
17
19
  gem "after_commit_exception_notification"
18
20
  end
@@ -23,6 +25,7 @@ appraise "rails-4-2" do
23
25
  gem "mysql2", "~> 0.4.10", platforms: [:ruby]
24
26
  end
25
27
  gem "activerecord", "~> 4.2.10"
28
+ gem "rake", "~> 12.2.0", platforms: [:ruby_19]
26
29
  end
27
30
 
28
31
  appraise "rails-5-0" do
@@ -1,4 +1,35 @@
1
- # Change Log
1
+ # Changelog
2
+ All notable changes to this project will be documented in this file.
3
+
4
+ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
5
+ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
6
+
7
+ ## [Unreleased]
8
+
9
+ ## [0.9.18] - 2019-03-08
10
+ ### Added
11
+ - Added additional gemspec metadata [@boone](https://github.com/boone)
12
+ - Add gem version badge to README [@joshuapinter](https://github.com/joshuapinter)
13
+ - Add touch on update configuration [@mgbatchelor](https://github.com/mgbatchelor)
14
+
15
+ ### Changed
16
+ - Let's start a new direction with the CHANGELOG file [@mainameiz](https://github.com/mainameiz)
17
+
18
+ ### Fixed
19
+ - Fix sqlite3 gem pinning breaking tests
20
+
21
+ ## [v0.9.17](https://github.com/swanandp/acts_as_list/tree/v0.9.17) (2018-10-29)
22
+ [Full Changelog](https://github.com/swanandp/acts_as_list/compare/v0.9.16...v0.9.17)
23
+
24
+ **Closed issues:**
25
+
26
+ - Inconsistent behavior [\#330](https://github.com/swanandp/acts_as_list/issues/330)
27
+ - Using `top\_of\_list` set to 1 and setting a record to index 0 triggers a `PG::UniqueViolation` [\#322](https://github.com/swanandp/acts_as_list/issues/322)
28
+
29
+ **Merged pull requests:**
30
+
31
+ - Feature/add exception to wrong position [\#323](https://github.com/swanandp/acts_as_list/pull/323) ([TheNeikos](https://github.com/TheNeikos))
32
+ - Methods move\_to\_bottom and move\_to\_top should not fail when there are unique constraints [\#320](https://github.com/swanandp/acts_as_list/pull/320) ([faucct](https://github.com/faucct))
2
33
 
3
34
  ## [v0.9.16](https://github.com/swanandp/acts_as_list/tree/v0.9.16) (2018-08-30)
4
35
  [Full Changelog](https://github.com/swanandp/acts_as_list/compare/v0.9.15...v0.9.16)
@@ -572,7 +603,3 @@
572
603
  - Fixed test issue for test\_injection: expected SQL was reversed. [\#3](https://github.com/swanandp/acts_as_list/pull/3) ([afriqs](https://github.com/afriqs))
573
604
  - Added an option to set the top of the position [\#2](https://github.com/swanandp/acts_as_list/pull/2) ([danielcooper](https://github.com/danielcooper))
574
605
  - minor change to acts\_as\_list's callbacks [\#1](https://github.com/swanandp/acts_as_list/pull/1) ([tiegz](https://github.com/tiegz))
575
-
576
-
577
-
578
- \* *This Change Log was automatically generated by [github_changelog_generator](https://github.com/skywinder/Github-Changelog-Generator)*
data/Gemfile CHANGED
@@ -19,7 +19,7 @@ group :test do
19
19
  end
20
20
 
21
21
  group :sqlite do
22
- gem "sqlite3", platforms: [:ruby]
22
+ gem "sqlite3", "~> 1.3.13", platforms: [:ruby]
23
23
  end
24
24
 
25
25
  group :postgresql do
data/README.md CHANGED
@@ -2,6 +2,7 @@
2
2
 
3
3
  ## Build Status
4
4
  [![Build Status](https://secure.travis-ci.org/swanandp/acts_as_list.png)](https://secure.travis-ci.org/swanandp/acts_as_list)
5
+ [![Gem Version](https://badge.fury.io/rb/acts_as_list.svg)](https://badge.fury.io/rb/acts_as_list)
5
6
 
6
7
  ## Description
7
8
 
@@ -16,6 +16,12 @@ Gem::Specification.new do |s|
16
16
  s.rubyforge_project = "acts_as_list"
17
17
  s.required_ruby_version = ">= 1.9.2"
18
18
 
19
+ if s.respond_to?(:metadata)
20
+ s.metadata['changelog_uri'] = 'https://github.com/swanandp/acts_as_list/blob/master/CHANGELOG.md'
21
+ s.metadata['source_code_uri'] = 'https://github.com/swanandp/acts_as_list'
22
+ s.metadata['bug_tracker_uri'] = 'https://github.com/swanandp/acts_as_list/issues'
23
+ end
24
+
19
25
  # Load Paths...
20
26
  s.files = `git ls-files`.split("\n")
21
27
  s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
@@ -3,7 +3,7 @@
3
3
  source "http://rubygems.org"
4
4
 
5
5
  gem "rack", "~> 1", platforms: [:ruby_19, :ruby_20, :ruby_21]
6
- gem "rake"
6
+ gem "rake", "~> 12.2.0", platforms: [:ruby_19]
7
7
  gem "appraisal"
8
8
  gem "activerecord", "~> 3.2.22.2"
9
9
 
@@ -20,7 +20,7 @@ group :test do
20
20
  end
21
21
 
22
22
  group :sqlite do
23
- gem "sqlite3", platforms: [:ruby]
23
+ gem "sqlite3", "~> 1.3.13", platforms: [:ruby]
24
24
  end
25
25
 
26
26
  group :postgresql do
@@ -3,7 +3,7 @@
3
3
  source "http://rubygems.org"
4
4
 
5
5
  gem "rack", "~> 1", platforms: [:ruby_19, :ruby_20, :ruby_21]
6
- gem "rake"
6
+ gem "rake", "~> 12.2.0", platforms: [:ruby_19]
7
7
  gem "appraisal"
8
8
  gem "activerecord", "~> 4.1.16"
9
9
 
@@ -20,7 +20,7 @@ group :test do
20
20
  end
21
21
 
22
22
  group :sqlite do
23
- gem "sqlite3", platforms: [:ruby]
23
+ gem "sqlite3", "~> 1.3.13", platforms: [:ruby]
24
24
  end
25
25
 
26
26
  group :postgresql do
@@ -3,7 +3,7 @@
3
3
  source "http://rubygems.org"
4
4
 
5
5
  gem "rack", "~> 1", platforms: [:ruby_19, :ruby_20, :ruby_21]
6
- gem "rake"
6
+ gem "rake", "~> 12.2.0", platforms: [:ruby_19]
7
7
  gem "appraisal"
8
8
  gem "activerecord", "~> 4.2.10"
9
9
 
@@ -19,7 +19,7 @@ group :test do
19
19
  end
20
20
 
21
21
  group :sqlite do
22
- gem "sqlite3", platforms: [:ruby]
22
+ gem "sqlite3", "~> 1.3.13", platforms: [:ruby]
23
23
  end
24
24
 
25
25
  group :postgresql do
@@ -19,7 +19,7 @@ group :test do
19
19
  end
20
20
 
21
21
  group :sqlite do
22
- gem "sqlite3", platforms: [:ruby]
22
+ gem "sqlite3", "~> 1.3.13", platforms: [:ruby]
23
23
  end
24
24
 
25
25
  group :postgresql do
@@ -19,7 +19,7 @@ group :test do
19
19
  end
20
20
 
21
21
  group :sqlite do
22
- gem "sqlite3", platforms: [:ruby]
22
+ gem "sqlite3", "~> 1.3.13", platforms: [:ruby]
23
23
  end
24
24
 
25
25
  group :postgresql do
@@ -5,7 +5,7 @@ source "http://rubygems.org"
5
5
  gem "rack", "~> 1", platforms: [:ruby_19, :ruby_20, :ruby_21]
6
6
  gem "rake"
7
7
  gem "appraisal"
8
- gem "activerecord", "~> 5.2.0.rc1"
8
+ gem "activerecord", "~> 5.2.1"
9
9
 
10
10
  group :development do
11
11
  gem "github_changelog_generator", "1.9.0"
@@ -19,7 +19,7 @@ group :test do
19
19
  end
20
20
 
21
21
  group :sqlite do
22
- gem "sqlite3", platforms: [:ruby]
22
+ gem "sqlite3", "~> 1.3.13", platforms: [:ruby]
23
23
  end
24
24
 
25
25
  group :postgresql do
@@ -20,13 +20,14 @@ module ActiveRecord
20
20
  # one by one to respect position column unique not null constraint.
21
21
  # Defaults to true if position column has unique index, otherwise false.
22
22
  # If constraint is <tt>deferrable initially deferred<tt>, overriding it with false will speed up insert_at.
23
+ # * +touch_on_update+ - configuration to disable the update of the model timestamps when the positions are updated.
23
24
  def acts_as_list(options = {})
24
- configuration = { column: "position", scope: "1 = 1", top_of_list: 1, add_new_at: :bottom }
25
+ configuration = { column: "position", scope: "1 = 1", top_of_list: 1, add_new_at: :bottom, touch_on_update: true }
25
26
  configuration.update(options) if options.is_a?(Hash)
26
27
 
27
28
  caller_class = self
28
29
 
29
- ActiveRecord::Acts::List::PositionColumnMethodDefiner.call(caller_class, configuration[:column])
30
+ ActiveRecord::Acts::List::PositionColumnMethodDefiner.call(caller_class, configuration[:column], configuration[:touch_on_update])
30
31
  ActiveRecord::Acts::List::ScopeMethodDefiner.call(caller_class, configuration[:scope])
31
32
  ActiveRecord::Acts::List::TopOfListMethodDefiner.call(caller_class, configuration[:top_of_list])
32
33
  ActiveRecord::Acts::List::AddNewAtMethodDefiner.call(caller_class, configuration[:add_new_at])
@@ -327,9 +328,7 @@ module ActiveRecord
327
328
  position ||= send(position_column).to_i
328
329
 
329
330
  if sequential_updates?
330
- acts_as_list_list.where("#{quoted_position_column_with_table_name} > ?", position).reorder(acts_as_list_order_argument(:asc)).each do |item|
331
- item.decrement!(position_column)
332
- end
331
+ acts_as_list_list.where("#{quoted_position_column_with_table_name} > ?", position).reorder(acts_as_list_order_argument(:asc)).decrement_sequentially
333
332
  else
334
333
  acts_as_list_list.where("#{quoted_position_column_with_table_name} > ?", position).decrement_all
335
334
  end
@@ -365,9 +364,7 @@ module ActiveRecord
365
364
  )
366
365
 
367
366
  if sequential_updates?
368
- items.reorder(acts_as_list_order_argument(:asc)).each do |item|
369
- item.decrement!(position_column)
370
- end
367
+ items.reorder(acts_as_list_order_argument(:asc)).decrement_sequentially
371
368
  else
372
369
  items.decrement_all
373
370
  end
@@ -383,9 +380,7 @@ module ActiveRecord
383
380
  )
384
381
 
385
382
  if sequential_updates?
386
- items.reorder(acts_as_list_order_argument(:desc)).each do |item|
387
- item.increment!(position_column)
388
- end
383
+ items.reorder(acts_as_list_order_argument(:desc)).increment_sequentially
389
384
  else
390
385
  items.increment_all
391
386
  end
@@ -1,8 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ActiveRecord::Acts::List::PositionColumnMethodDefiner #:nodoc:
4
- def self.call(caller_class, position_column)
5
- define_class_methods(caller_class, position_column)
4
+ def self.call(caller_class, position_column, touch_on_update)
5
+ define_class_methods(caller_class, position_column, touch_on_update)
6
6
  define_instance_methods(caller_class, position_column)
7
7
 
8
8
  if mass_assignment_protection_was_used_by_user?(caller_class)
@@ -12,7 +12,7 @@ module ActiveRecord::Acts::List::PositionColumnMethodDefiner #:nodoc:
12
12
 
13
13
  private
14
14
 
15
- def self.define_class_methods(caller_class, position_column)
15
+ def self.define_class_methods(caller_class, position_column, touch_on_update)
16
16
  caller_class.class_eval do
17
17
  define_singleton_method :quoted_position_column do
18
18
  @_quoted_position_column ||= connection.quote_column_name(position_column)
@@ -22,6 +22,18 @@ module ActiveRecord::Acts::List::PositionColumnMethodDefiner #:nodoc:
22
22
  @_quoted_position_column_with_table_name ||= "#{caller_class.quoted_table_name}.#{quoted_position_column}"
23
23
  end
24
24
 
25
+ define_singleton_method :decrement_sequentially do
26
+ pluck(primary_key).each do |id|
27
+ where(primary_key => id).decrement_all
28
+ end
29
+ end
30
+
31
+ define_singleton_method :increment_sequentially do
32
+ pluck(primary_key).each do |id|
33
+ where(primary_key => id).increment_all
34
+ end
35
+ end
36
+
25
37
  define_singleton_method :decrement_all do
26
38
  update_all_with_touch "#{quoted_position_column} = (#{quoted_position_column_with_table_name} - 1)"
27
39
  end
@@ -31,7 +43,8 @@ module ActiveRecord::Acts::List::PositionColumnMethodDefiner #:nodoc:
31
43
  end
32
44
 
33
45
  define_singleton_method :update_all_with_touch do |updates|
34
- update_all(updates + touch_record_sql)
46
+ updates += touch_record_sql if touch_on_update
47
+ update_all(updates)
35
48
  end
36
49
 
37
50
  private
@@ -3,7 +3,7 @@
3
3
  module ActiveRecord
4
4
  module Acts
5
5
  module List
6
- VERSION = '0.9.17'
6
+ VERSION = '0.9.18'
7
7
  end
8
8
  end
9
9
  end
@@ -39,9 +39,18 @@ def setup_db(position_options = {})
39
39
  t.column :order, :integer
40
40
  end
41
41
 
42
+ # This table is used to test table names with different primary_key columns
43
+ ActiveRecord::Base.connection.create_table 'altid-table', primary_key: 'altid' do |t|
44
+ t.column :pos, :integer
45
+ t.column :created_at, :datetime
46
+ t.column :updated_at, :datetime
47
+ end
48
+
49
+ ActiveRecord::Base.connection.add_index 'altid-table', :pos, unique: true
50
+
42
51
  mixins = [ Mixin, ListMixin, ListMixinSub1, ListMixinSub2, ListWithStringScopeMixin,
43
52
  ArrayScopeListMixin, ZeroBasedMixin, DefaultScopedMixin,
44
- DefaultScopedWhereMixin, TopAdditionMixin, NoAdditionMixin, QuotedList ]
53
+ DefaultScopedWhereMixin, TopAdditionMixin, NoAdditionMixin, QuotedList, TouchDisabledMixin ]
45
54
 
46
55
  mixins << EnumArrayScopeListMixin if rails_4
47
56
 
@@ -63,6 +72,10 @@ class ListMixin < Mixin
63
72
  acts_as_list column: "pos", scope: :parent
64
73
  end
65
74
 
75
+ class TouchDisabledMixin < Mixin
76
+ acts_as_list column: "pos", touch_on_update: false
77
+ end
78
+
66
79
  class ListMixinSub1 < ListMixin
67
80
  end
68
81
 
@@ -131,6 +144,17 @@ class SequentialUpdatesDefault < Mixin
131
144
  acts_as_list column: "pos"
132
145
  end
133
146
 
147
+ class SequentialUpdatesAltId < ActiveRecord::Base
148
+ self.table_name = "altid-table"
149
+ self.primary_key = "altid"
150
+
151
+ acts_as_list column: "pos"
152
+ end
153
+
154
+ class SequentialUpdatesAltIdTouchDisabled < SequentialUpdatesAltId
155
+ acts_as_list column: "pos", touch_on_update: false
156
+ end
157
+
134
158
  class SequentialUpdatesFalseMixin < Mixin
135
159
  acts_as_list column: "pos", sequential_updates: false
136
160
  end
@@ -812,6 +836,41 @@ class TouchTest < ActsAsListTestCase
812
836
  end
813
837
  end
814
838
 
839
+ class TouchDisabledTest < ActsAsListTestCase
840
+ def setup
841
+ setup_db
842
+ Timecop.freeze(yesterday) do
843
+ 4.times { TouchDisabledMixin.create! }
844
+ end
845
+ end
846
+
847
+ def now
848
+ @now ||= Time.current.change(usec: 0)
849
+ end
850
+
851
+ def yesterday
852
+ @yesterday ||= 1.day.ago
853
+ end
854
+
855
+ def updated_ats
856
+ TouchDisabledMixin.order(:id).pluck(:updated_at)
857
+ end
858
+
859
+ def positions
860
+ ListMixin.order(:id).pluck(:pos)
861
+ end
862
+
863
+ def test_deleting_item_does_not_touch_higher_items
864
+ Timecop.freeze(now) do
865
+ TouchDisabledMixin.first.destroy
866
+ updated_ats.each do |updated_at|
867
+ assert_equal updated_at.to_i, yesterday.to_i
868
+ end
869
+ assert_equal positions, [1, 2, 3]
870
+ end
871
+ end
872
+ end
873
+
815
874
  class ActsAsListTopTest < ActsAsListTestCase
816
875
  def setup
817
876
  setup_db
@@ -930,4 +989,95 @@ class SequentialUpdatesMixinNotNullUniquePositiveConstraintsTest < ActsAsListTes
930
989
  new_item.insert_at(0)
931
990
  end
932
991
  end
992
+
993
+
994
+ class SequentialUpdatesMixinNotNullUniquePositiveConstraintsTest < ActsAsListTestCase
995
+ def setup
996
+ setup_db null: false, unique: true, positive: true
997
+ (1..4).each { |counter| SequentialUpdatesAltId.create!({pos: counter}) }
998
+ end
999
+
1000
+ def test_sequential_updates_default_to_true_with_unique_index
1001
+ assert_equal true, SequentialUpdatesAltId.new.send(:sequential_updates?)
1002
+ end
1003
+
1004
+ def test_insert_at
1005
+ new = SequentialUpdatesAltId.create
1006
+ assert_equal 5, new.pos
1007
+
1008
+ new.insert_at(1)
1009
+ assert_equal 1, new.pos
1010
+
1011
+ new.insert_at(5)
1012
+ assert_equal 5, new.pos
1013
+
1014
+ new.insert_at(3)
1015
+ assert_equal 3, new.pos
1016
+ end
1017
+
1018
+ def test_move_to_bottom
1019
+ item = SequentialUpdatesAltId.order(:pos).first
1020
+ item.move_to_bottom
1021
+ assert_equal 4, item.pos
1022
+ end
1023
+
1024
+ def test_move_to_top
1025
+ new_item = SequentialUpdatesAltId.create!
1026
+ assert_equal 5, new_item.pos
1027
+
1028
+ new_item.move_to_top
1029
+ assert_equal 1, new_item.pos
1030
+ end
1031
+
1032
+ def test_destroy
1033
+ new_item = SequentialUpdatesAltId.create
1034
+ assert_equal 5, new_item.pos
1035
+
1036
+ new_item.insert_at(2)
1037
+ assert_equal 2, new_item.pos
1038
+
1039
+ new_item.destroy
1040
+ assert_equal [1,2,3,4], SequentialUpdatesAltId.all.map(&:pos).sort
1041
+
1042
+ end
1043
+ end
1044
+
1045
+ class SequentialUpdatesAltIdTouchDisabledTest < ActsAsListTestCase
1046
+ def setup
1047
+ setup_db
1048
+ Timecop.freeze(yesterday) do
1049
+ 4.times { SequentialUpdatesAltIdTouchDisabled.create! }
1050
+ end
1051
+ end
1052
+
1053
+ def now
1054
+ @now ||= Time.current.change(usec: 0)
1055
+ end
1056
+
1057
+ def yesterday
1058
+ @yesterday ||= 1.day.ago
1059
+ end
1060
+
1061
+ def updated_ats
1062
+ SequentialUpdatesAltIdTouchDisabled.order(:altid).pluck(:updated_at)
1063
+ end
1064
+
1065
+ def positions
1066
+ SequentialUpdatesAltIdTouchDisabled.order(:altid).pluck(:pos)
1067
+ end
1068
+
1069
+ def test_sequential_updates_default_to_true_with_unique_index
1070
+ assert_equal true, SequentialUpdatesAltIdTouchDisabled.new.send(:sequential_updates?)
1071
+ end
1072
+
1073
+ def test_deleting_item_does_not_touch_higher_items
1074
+ Timecop.freeze(now) do
1075
+ SequentialUpdatesAltIdTouchDisabled.first.destroy
1076
+ updated_ats.each do |updated_at|
1077
+ assert_equal updated_at.to_i, yesterday.to_i
1078
+ end
1079
+ assert_equal positions, [1, 2, 3]
1080
+ end
1081
+ end
1082
+ end
933
1083
  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.17
4
+ version: 0.9.18
5
5
  platform: ruby
6
6
  authors:
7
7
  - David Heinemeier Hansson
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2018-10-29 00:00:00.000000000 Z
13
+ date: 2019-03-07 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: activerecord
@@ -97,7 +97,10 @@ files:
97
97
  homepage: http://github.com/swanandp/acts_as_list
98
98
  licenses:
99
99
  - MIT
100
- metadata: {}
100
+ metadata:
101
+ changelog_uri: https://github.com/swanandp/acts_as_list/blob/master/CHANGELOG.md
102
+ source_code_uri: https://github.com/swanandp/acts_as_list
103
+ bug_tracker_uri: https://github.com/swanandp/acts_as_list/issues
101
104
  post_install_message:
102
105
  rdoc_options: []
103
106
  require_paths: