acts_as_list 0.7.2 → 0.7.7

Sign up to get free protection for your applications and to get access to all the features.
data/test/test_list.rb CHANGED
@@ -1,7 +1,10 @@
1
1
  # NOTE: following now done in helper.rb (better Readability)
2
2
  require 'helper'
3
3
 
4
- ActiveRecord::Base.establish_connection(adapter: "sqlite3", database: ":memory:")
4
+ ActiveRecord::Base.establish_connection(
5
+ adapter: "sqlite3",
6
+ database: 'file:memdb1?mode=memory&cache=shared'
7
+ )
5
8
  ActiveRecord::Schema.verbose = false
6
9
 
7
10
  def setup_db(position_options = {})
@@ -16,9 +19,14 @@ def setup_db(position_options = {})
16
19
  t.column :state, :integer
17
20
  end
18
21
 
22
+ # This table is used to test table names and column names quoting
23
+ ActiveRecord::Base.connection.create_table 'table-name' do |t|
24
+ t.column :order, :integer
25
+ end
26
+
19
27
  mixins = [ Mixin, ListMixin, ListMixinSub1, ListMixinSub2, ListWithStringScopeMixin,
20
28
  ArrayScopeListMixin, ZeroBasedMixin, DefaultScopedMixin,
21
- DefaultScopedWhereMixin, TopAdditionMixin, NoAdditionMixin ]
29
+ DefaultScopedWhereMixin, TopAdditionMixin, NoAdditionMixin, QuotedList ]
22
30
 
23
31
  mixins << EnumArrayScopeListMixin if rails_4
24
32
 
@@ -42,7 +50,13 @@ def rails_4
42
50
  end
43
51
 
44
52
  def teardown_db
45
- ActiveRecord::Base.connection.tables.each do |table|
53
+ if ActiveRecord::VERSION::MAJOR >= 5
54
+ tables = ActiveRecord::Base.connection.data_sources
55
+ else
56
+ tables = ActiveRecord::Base.connection.tables
57
+ end
58
+
59
+ tables.each do |table|
46
60
  ActiveRecord::Base.connection.drop_table(table)
47
61
  end
48
62
  end
@@ -109,6 +123,29 @@ class NoAdditionMixin < Mixin
109
123
  acts_as_list column: "pos", add_new_at: nil, scope: :parent_id
110
124
  end
111
125
 
126
+ ##
127
+ # The way we track changes to
128
+ # scope and position can get tripped up
129
+ # by someone using update_attributes within
130
+ # a callback because it causes multiple passes
131
+ # through the callback chain
132
+ module CallbackMixin
133
+
134
+ def self.included(base)
135
+ base.send :include, InstanceMethods
136
+ base.after_create :change_field
137
+ end
138
+
139
+ module InstanceMethods
140
+ def change_field
141
+ # doesn't matter what column changes, just
142
+ # need to change something
143
+
144
+ self.update_attributes(active: !self.active)
145
+ end
146
+ end
147
+ end
148
+
112
149
  class TheAbstractClass < ActiveRecord::Base
113
150
  self.abstract_class = true
114
151
  self.table_name = 'mixins'
@@ -126,6 +163,18 @@ end
126
163
  class TheBaseSubclass < TheBaseClass
127
164
  end
128
165
 
166
+ class DBConfigTest < Minitest::Test
167
+ def test_db_config
168
+ # make sure sqlite3 accepts multi threaded access
169
+ assert_equal "file:memdb1?mode=memory&cache=shared", ActiveRecord::Base.connection.pool.spec.config[:database]
170
+ end
171
+ end
172
+
173
+ class QuotedList < ActiveRecord::Base
174
+ self.table_name = 'table-name'
175
+ acts_as_list column: :order
176
+ end
177
+
129
178
  class ActsAsListTestCase < Minitest::Test
130
179
  # No default test required as this class is abstract.
131
180
  # Need for test/unit.
@@ -161,6 +210,49 @@ class ListTest < ActsAsListTestCase
161
210
  setup_db
162
211
  super
163
212
  end
213
+
214
+ def test_insert_race_condition
215
+ # the bigger n is the more likely we will have a race condition
216
+ n = 1000
217
+ (1..n).each do |counter|
218
+ node = ListMixin.new parent_id: 1
219
+ node.pos = counter
220
+ node.save!
221
+ end
222
+
223
+ wait_for_it = true
224
+ threads = []
225
+ 4.times do |i|
226
+ threads << Thread.new do
227
+ true while wait_for_it
228
+ ActiveRecord::Base.connection_pool.with_connection do |c|
229
+ n.times do
230
+ begin
231
+ ListMixin.where(parent_id: 1).order(:pos).last.insert_at(1)
232
+ rescue Exception
233
+ # ignore SQLite3::SQLException due to table locking
234
+ end
235
+ end
236
+ end
237
+ end
238
+ end
239
+ wait_for_it = false
240
+ threads.each(&:join)
241
+
242
+ assert_equal (1..n).to_a, ListMixin.where(parent_id: 1).order('pos').map(&:pos)
243
+ end
244
+ end
245
+
246
+ class ListWithCallbackTest < ActsAsListTestCase
247
+
248
+ include Shared::List
249
+
250
+ def setup
251
+ ListMixin.send(:include, CallbackMixin)
252
+ setup_db
253
+ super
254
+ end
255
+
164
256
  end
165
257
 
166
258
  class ListTestWithDefault < ActsAsListTestCase
@@ -208,6 +300,15 @@ class ArrayScopeListTestWithDefault < ActsAsListTestCase
208
300
  end
209
301
  end
210
302
 
303
+ class QuotingTestList < ActsAsListTestCase
304
+ include Shared::Quoting
305
+
306
+ def setup
307
+ setup_db_with_default
308
+ super
309
+ end
310
+ end
311
+
211
312
  class DefaultScopedTest < ActsAsListTestCase
212
313
  def setup
213
314
  setup_db
@@ -568,3 +669,82 @@ class MultipleListsArrayScopeTest < ActsAsListTestCase
568
669
  assert_equal [1], ArrayScopeListMixin.where(:parent_id => 4, :parent_type => 'anything').order(:pos).map(&:pos)
569
670
  end
570
671
  end
672
+
673
+ class TouchTest < ActsAsListTestCase
674
+ def setup
675
+ setup_db
676
+ 4.times { ListMixin.create! updated_at: yesterday }
677
+ end
678
+
679
+ def now
680
+ Time.now.utc
681
+ end
682
+
683
+ def yesterday
684
+ 1.day.ago
685
+ end
686
+
687
+ def updated_ats
688
+ ListMixin.pluck(:updated_at)
689
+ end
690
+
691
+ def test_moving_item_lower_touches_self_and_lower_item
692
+ ListMixin.first.move_lower
693
+ updated_ats[0..1].each do |updated_at|
694
+ assert_in_delta updated_at, now, 1.second
695
+ end
696
+ updated_ats[2..3].each do |updated_at|
697
+ assert_in_delta updated_at, yesterday, 1.second
698
+ end
699
+ end
700
+
701
+ def test_moving_item_higher_touches_self_and_higher_item
702
+ ListMixin.all.second.move_higher
703
+ updated_ats[0..1].each do |updated_at|
704
+ assert_in_delta updated_at, now, 1.second
705
+ end
706
+ updated_ats[2..3].each do |updated_at|
707
+ assert_in_delta updated_at, yesterday, 1.second
708
+ end
709
+ end
710
+
711
+ def test_moving_item_to_bottom_touches_all_other_items
712
+ ListMixin.first.move_to_bottom
713
+ updated_ats.each do |updated_at|
714
+ assert_in_delta updated_at, now, 1.second
715
+ end
716
+ end
717
+
718
+ def test_moving_item_to_top_touches_all_other_items
719
+ ListMixin.last.move_to_top
720
+ updated_ats.each do |updated_at|
721
+ assert_in_delta updated_at, now, 1.second
722
+ end
723
+ end
724
+
725
+ def test_removing_item_touches_all_lower_items
726
+ ListMixin.all.third.remove_from_list
727
+ updated_ats[0..1].each do |updated_at|
728
+ assert_in_delta updated_at, yesterday, 1.second
729
+ end
730
+ updated_ats[2..2].each do |updated_at|
731
+ assert_in_delta updated_at, now, 1.second
732
+ end
733
+ end
734
+ end
735
+
736
+ class ActsAsListTopTest < ActsAsListTestCase
737
+ def setup
738
+ setup_db
739
+ end
740
+
741
+ def test_acts_as_list_top
742
+ assert_equal 1, TheBaseSubclass.new.acts_as_list_top
743
+ assert_equal 0, ZeroBasedMixin.new.acts_as_list_top
744
+ end
745
+
746
+ def test_class_acts_as_list_top
747
+ assert_equal 1, TheBaseSubclass.acts_as_list_top
748
+ assert_equal 0, ZeroBasedMixin.acts_as_list_top
749
+ end
750
+ 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.2
4
+ version: 0.7.7
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: 2015-05-06 00:00:00.000000000 Z
13
+ date: 2016-08-18 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,21 +49,20 @@ 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
+ - CHANGELOG.md
56
57
  - Gemfile
57
58
  - MIT-LICENSE
58
59
  - README.md
59
60
  - Rakefile
60
61
  - acts_as_list.gemspec
61
62
  - gemfiles/rails_3_2.gemfile
62
- - gemfiles/rails_3_2.gemfile.lock
63
63
  - gemfiles/rails_4_1.gemfile
64
- - gemfiles/rails_4_1.gemfile.lock
65
64
  - gemfiles/rails_4_2.gemfile
66
- - gemfiles/rails_4_2.gemfile.lock
65
+ - gemfiles/rails_5_0.gemfile
67
66
  - init.rb
68
67
  - lib/acts_as_list.rb
69
68
  - lib/acts_as_list/active_record/acts/list.rb
@@ -74,8 +73,10 @@ files:
74
73
  - test/shared_list.rb
75
74
  - test/shared_list_sub.rb
76
75
  - test/shared_no_addition.rb
76
+ - test/shared_quoting.rb
77
77
  - test/shared_top_addition.rb
78
78
  - test/shared_zero_based.rb
79
+ - test/test_joined_list.rb
79
80
  - test/test_list.rb
80
81
  homepage: http://github.com/swanandp/acts_as_list
81
82
  licenses:
@@ -87,12 +88,12 @@ require_paths:
87
88
  - lib
88
89
  required_ruby_version: !ruby/object:Gem::Requirement
89
90
  requirements:
90
- - - ! '>='
91
+ - - ">="
91
92
  - !ruby/object:Gem::Version
92
93
  version: 1.9.2
93
94
  required_rubygems_version: !ruby/object:Gem::Requirement
94
95
  requirements:
95
- - - ! '>='
96
+ - - ">="
96
97
  - !ruby/object:Gem::Version
97
98
  version: '0'
98
99
  requirements: []
@@ -109,6 +110,8 @@ test_files:
109
110
  - test/shared_list.rb
110
111
  - test/shared_list_sub.rb
111
112
  - test/shared_no_addition.rb
113
+ - test/shared_quoting.rb
112
114
  - test/shared_top_addition.rb
113
115
  - test/shared_zero_based.rb
116
+ - test/test_joined_list.rb
114
117
  - test/test_list.rb
@@ -1,258 +0,0 @@
1
- PATH
2
- remote: ../
3
- specs:
4
- acts_as_list (0.7.2)
5
- activerecord (>= 3.0)
6
-
7
- GEM
8
- remote: http://rubygems.org/
9
- specs:
10
- activemodel (3.2.21)
11
- activesupport (= 3.2.21)
12
- builder (~> 3.0.0)
13
- activerecord (3.2.21)
14
- activemodel (= 3.2.21)
15
- activesupport (= 3.2.21)
16
- arel (~> 3.0.2)
17
- tzinfo (~> 0.3.29)
18
- activesupport (3.2.21)
19
- i18n (~> 0.6, >= 0.6.4)
20
- multi_json (~> 1.0)
21
- appraisal (1.0.2)
22
- bundler
23
- rake
24
- thor (>= 0.14.0)
25
- arel (3.0.3)
26
- builder (3.0.4)
27
- ffi2-generators (0.1.1)
28
- i18n (0.7.0)
29
- minitest (5.5.1)
30
- multi_json (1.10.1)
31
- rake (10.4.2)
32
- rubinius-coverage (2.0.3)
33
- rubinius-debugger (2.2.1)
34
- rubinius-developer_tools (2.0.0)
35
- rubinius-coverage (~> 2.0)
36
- rubinius-debugger (~> 2.0)
37
- rubinius-profiler (~> 2.0)
38
- rubinius-profiler (2.0.1)
39
- rubysl (2.1.0)
40
- rubysl-abbrev (~> 2.0)
41
- rubysl-base64 (~> 2.0)
42
- rubysl-benchmark (~> 2.0)
43
- rubysl-bigdecimal (~> 2.0)
44
- rubysl-cgi (~> 2.0)
45
- rubysl-cgi-session (~> 2.0)
46
- rubysl-cmath (~> 2.0)
47
- rubysl-complex (~> 2.0)
48
- rubysl-continuation (~> 2.0)
49
- rubysl-coverage (~> 2.0)
50
- rubysl-csv (~> 2.0)
51
- rubysl-curses (~> 2.0)
52
- rubysl-date (~> 2.0)
53
- rubysl-delegate (~> 2.0)
54
- rubysl-digest (~> 2.0)
55
- rubysl-drb (~> 2.0)
56
- rubysl-e2mmap (~> 2.0)
57
- rubysl-english (~> 2.0)
58
- rubysl-enumerator (~> 2.0)
59
- rubysl-erb (~> 2.0)
60
- rubysl-etc (~> 2.0)
61
- rubysl-expect (~> 2.0)
62
- rubysl-fcntl (~> 2.0)
63
- rubysl-fiber (~> 2.0)
64
- rubysl-fileutils (~> 2.0)
65
- rubysl-find (~> 2.0)
66
- rubysl-forwardable (~> 2.0)
67
- rubysl-getoptlong (~> 2.0)
68
- rubysl-gserver (~> 2.0)
69
- rubysl-io-console (~> 2.0)
70
- rubysl-io-nonblock (~> 2.0)
71
- rubysl-io-wait (~> 2.0)
72
- rubysl-ipaddr (~> 2.0)
73
- rubysl-irb (~> 2.1)
74
- rubysl-logger (~> 2.0)
75
- rubysl-mathn (~> 2.0)
76
- rubysl-matrix (~> 2.0)
77
- rubysl-mkmf (~> 2.0)
78
- rubysl-monitor (~> 2.0)
79
- rubysl-mutex_m (~> 2.0)
80
- rubysl-net-ftp (~> 2.0)
81
- rubysl-net-http (~> 2.0)
82
- rubysl-net-imap (~> 2.0)
83
- rubysl-net-pop (~> 2.0)
84
- rubysl-net-protocol (~> 2.0)
85
- rubysl-net-smtp (~> 2.0)
86
- rubysl-net-telnet (~> 2.0)
87
- rubysl-nkf (~> 2.0)
88
- rubysl-observer (~> 2.0)
89
- rubysl-open-uri (~> 2.0)
90
- rubysl-open3 (~> 2.0)
91
- rubysl-openssl (~> 2.0)
92
- rubysl-optparse (~> 2.0)
93
- rubysl-ostruct (~> 2.0)
94
- rubysl-pathname (~> 2.0)
95
- rubysl-prettyprint (~> 2.0)
96
- rubysl-prime (~> 2.0)
97
- rubysl-profile (~> 2.0)
98
- rubysl-profiler (~> 2.0)
99
- rubysl-pstore (~> 2.0)
100
- rubysl-pty (~> 2.0)
101
- rubysl-rational (~> 2.0)
102
- rubysl-resolv (~> 2.0)
103
- rubysl-rexml (~> 2.0)
104
- rubysl-rinda (~> 2.0)
105
- rubysl-rss (~> 2.0)
106
- rubysl-scanf (~> 2.0)
107
- rubysl-securerandom (~> 2.0)
108
- rubysl-set (~> 2.0)
109
- rubysl-shellwords (~> 2.0)
110
- rubysl-singleton (~> 2.0)
111
- rubysl-socket (~> 2.0)
112
- rubysl-stringio (~> 2.0)
113
- rubysl-strscan (~> 2.0)
114
- rubysl-sync (~> 2.0)
115
- rubysl-syslog (~> 2.0)
116
- rubysl-tempfile (~> 2.0)
117
- rubysl-thread (~> 2.0)
118
- rubysl-thwait (~> 2.0)
119
- rubysl-time (~> 2.0)
120
- rubysl-timeout (~> 2.0)
121
- rubysl-tmpdir (~> 2.0)
122
- rubysl-tsort (~> 2.0)
123
- rubysl-un (~> 2.0)
124
- rubysl-uri (~> 2.0)
125
- rubysl-weakref (~> 2.0)
126
- rubysl-webrick (~> 2.0)
127
- rubysl-xmlrpc (~> 2.0)
128
- rubysl-yaml (~> 2.0)
129
- rubysl-zlib (~> 2.0)
130
- rubysl-abbrev (2.0.4)
131
- rubysl-base64 (2.0.0)
132
- rubysl-benchmark (2.0.1)
133
- rubysl-bigdecimal (2.0.2)
134
- rubysl-cgi (2.0.1)
135
- rubysl-cgi-session (2.0.1)
136
- rubysl-cmath (2.0.0)
137
- rubysl-complex (2.0.0)
138
- rubysl-continuation (2.0.0)
139
- rubysl-coverage (2.0.3)
140
- rubysl-csv (2.0.2)
141
- rubysl-english (~> 2.0)
142
- rubysl-curses (2.0.1)
143
- rubysl-date (2.0.9)
144
- rubysl-delegate (2.0.1)
145
- rubysl-digest (2.0.3)
146
- rubysl-drb (2.0.1)
147
- rubysl-e2mmap (2.0.0)
148
- rubysl-english (2.0.0)
149
- rubysl-enumerator (2.0.0)
150
- rubysl-erb (2.0.2)
151
- rubysl-etc (2.0.3)
152
- ffi2-generators (~> 0.1)
153
- rubysl-expect (2.0.0)
154
- rubysl-fcntl (2.0.4)
155
- ffi2-generators (~> 0.1)
156
- rubysl-fiber (2.0.0)
157
- rubysl-fileutils (2.0.3)
158
- rubysl-find (2.0.1)
159
- rubysl-forwardable (2.0.1)
160
- rubysl-getoptlong (2.0.0)
161
- rubysl-gserver (2.0.0)
162
- rubysl-socket (~> 2.0)
163
- rubysl-thread (~> 2.0)
164
- rubysl-io-console (2.0.0)
165
- rubysl-io-nonblock (2.0.0)
166
- rubysl-io-wait (2.0.0)
167
- rubysl-ipaddr (2.0.0)
168
- rubysl-irb (2.1.1)
169
- rubysl-e2mmap (~> 2.0)
170
- rubysl-mathn (~> 2.0)
171
- rubysl-thread (~> 2.0)
172
- rubysl-logger (2.1.0)
173
- rubysl-mathn (2.0.0)
174
- rubysl-matrix (2.1.0)
175
- rubysl-e2mmap (~> 2.0)
176
- rubysl-mkmf (2.0.1)
177
- rubysl-fileutils (~> 2.0)
178
- rubysl-shellwords (~> 2.0)
179
- rubysl-monitor (2.0.0)
180
- rubysl-mutex_m (2.0.0)
181
- rubysl-net-ftp (2.0.1)
182
- rubysl-net-http (2.0.4)
183
- rubysl-cgi (~> 2.0)
184
- rubysl-erb (~> 2.0)
185
- rubysl-singleton (~> 2.0)
186
- rubysl-net-imap (2.0.1)
187
- rubysl-net-pop (2.0.1)
188
- rubysl-net-protocol (2.0.1)
189
- rubysl-net-smtp (2.0.1)
190
- rubysl-net-telnet (2.0.0)
191
- rubysl-nkf (2.0.1)
192
- rubysl-observer (2.0.0)
193
- rubysl-open-uri (2.0.0)
194
- rubysl-open3 (2.0.0)
195
- rubysl-openssl (2.2.1)
196
- rubysl-optparse (2.0.1)
197
- rubysl-shellwords (~> 2.0)
198
- rubysl-ostruct (2.0.4)
199
- rubysl-pathname (2.1.0)
200
- rubysl-prettyprint (2.0.3)
201
- rubysl-prime (2.0.1)
202
- rubysl-profile (2.0.0)
203
- rubysl-profiler (2.0.1)
204
- rubysl-pstore (2.0.0)
205
- rubysl-pty (2.0.3)
206
- rubysl-rational (2.0.1)
207
- rubysl-resolv (2.1.2)
208
- rubysl-rexml (2.0.4)
209
- rubysl-rinda (2.0.1)
210
- rubysl-rss (2.0.0)
211
- rubysl-scanf (2.0.0)
212
- rubysl-securerandom (2.0.0)
213
- rubysl-set (2.0.1)
214
- rubysl-shellwords (2.0.0)
215
- rubysl-singleton (2.0.0)
216
- rubysl-socket (2.0.1)
217
- rubysl-stringio (2.0.0)
218
- rubysl-strscan (2.0.0)
219
- rubysl-sync (2.0.0)
220
- rubysl-syslog (2.1.0)
221
- ffi2-generators (~> 0.1)
222
- rubysl-tempfile (2.0.1)
223
- rubysl-test-unit (2.0.2)
224
- minitest
225
- rubysl-thread (2.0.3)
226
- rubysl-thwait (2.0.0)
227
- rubysl-time (2.0.3)
228
- rubysl-timeout (2.0.0)
229
- rubysl-tmpdir (2.0.1)
230
- rubysl-tsort (2.0.1)
231
- rubysl-un (2.0.0)
232
- rubysl-fileutils (~> 2.0)
233
- rubysl-optparse (~> 2.0)
234
- rubysl-uri (2.0.0)
235
- rubysl-weakref (2.0.0)
236
- rubysl-webrick (2.0.0)
237
- rubysl-xmlrpc (2.0.0)
238
- rubysl-yaml (2.1.0)
239
- rubysl-zlib (2.0.1)
240
- sqlite3 (1.3.10)
241
- thor (0.19.1)
242
- tzinfo (0.3.42)
243
-
244
- PLATFORMS
245
- ruby
246
-
247
- DEPENDENCIES
248
- activerecord (= 3.2.21)
249
- activerecord-jdbcsqlite3-adapter
250
- acts_as_list!
251
- appraisal
252
- bundler (>= 1.0.0)
253
- minitest
254
- rake
255
- rubinius-developer_tools
256
- rubysl (~> 2.0)
257
- rubysl-test-unit
258
- sqlite3