File tree 3 files changed +29
-3
lines changed
3 files changed +29
-3
lines changed Original file line number Diff line number Diff line change @@ -27,6 +27,9 @@ def initialize(model_class, options)
27
27
:numeric_order => false
28
28
} . merge ( options )
29
29
raise ArgumentError , "name_column can't be 'path'" if options [ :name_column ] == 'path'
30
+ if !options [ :with_advisory_lock ] && options [ :advisory_lock_timeout_seconds ] . present?
31
+ raise ArgumentError , "advisory_lock_timeout_seconds cannot be provided when advisory lock is disabled"
32
+ end
30
33
if order_is_numeric?
31
34
extend NumericOrderSupport . adapter_for_connection ( connection )
32
35
end
Original file line number Diff line number Diff line change @@ -103,7 +103,7 @@ def run_workers(worker_class = FindOrCreateWorker)
103
103
104
104
it 'creates dupe roots without advisory locks' do
105
105
# disable with_advisory_lock:
106
- allow ( Tag ) . to receive ( :with_advisory_lock ) { |_lock_name , &block | block . call }
106
+ allow ( Tag ) . to receive ( :with_advisory_lock! ) { |_lock_name , &block | block . call }
107
107
run_workers
108
108
# duplication from at least one iteration:
109
109
expect ( Tag . where ( name : @names ) . size ) . to be > @iterations
Original file line number Diff line number Diff line change 1
1
require 'spec_helper'
2
2
3
3
RSpec . describe ClosureTree ::Support do
4
- let ( :sut ) { Tag . _ct }
4
+ let ( :mock_model ) { double ( 'TagModel' ) }
5
+ let ( :sut ) { described_class . new ( mock_model , options ) }
6
+
5
7
it 'passes through table names without prefix and suffix' do
6
8
expected = 'some_random_table_name'
7
9
expect ( sut . remove_prefix_and_suffix ( expected ) ) . to eq ( expected )
8
10
end
11
+
9
12
it 'extracts through table name with prefix and suffix' do
10
13
expected = 'some_random_table_name'
11
14
tn = ActiveRecord ::Base . table_name_prefix + expected + ActiveRecord ::Base . table_name_suffix
12
15
expect ( sut . remove_prefix_and_suffix ( tn ) ) . to eq ( expected )
13
16
end
14
- end
17
+
18
+ [
19
+ [ true , 10 , { timeout_seconds : 10 } ] ,
20
+ [ true , nil , { } ] ,
21
+ [ false , nil , { } ]
22
+ ] . each do |with_lock , timeout , expected_options |
23
+ context "when with_advisory_lock is #{ with_lock } and timeout is #{ timeout } " do
24
+ let ( :options ) { { with_advisory_lock : with_lock , advisory_lock_timeout_seconds : timeout } }
25
+
26
+ it "uses advisory lock with timeout options: #{ expected_options } " do
27
+ if with_lock
28
+ expect ( mock_model ) . to receive ( :with_advisory_lock! ) . with ( anything , expected_options ) . and_yield
29
+ else
30
+ expect ( mock_model ) . not_to receive ( :with_advisory_lock! )
31
+ end
32
+
33
+ expect { |b | sut . with_advisory_lock! ( &b ) } . to yield_control
34
+ end
35
+ end
36
+ end
37
+ end
You can’t perform that action at this time.
0 commit comments