File tree Expand file tree Collapse file tree 2 files changed +9
-23
lines changed Expand file tree Collapse file tree 2 files changed +9
-23
lines changed Original file line number Diff line number Diff line change @@ -23,11 +23,13 @@ def initialize(model_class, options)
23
23
:dependent => :nullify , # or :destroy or :delete_all -- see the README
24
24
:name_column => 'name' ,
25
25
:with_advisory_lock => true ,
26
- :advisory_lock_timeout_seconds => nil ,
26
+ :advisory_lock_timeout_seconds => 0 ,
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?
30
+ if options [ :with_advisory_lock ] && options [ :advisory_lock_timeout_seconds ] . nil?
31
+ raise ArgumentError , "advisory_lock_timeout_seconds must be provided when advisory lock is enabled"
32
+ elsif !options [ :with_advisory_lock ] && options [ :advisory_lock_timeout_seconds ] . present?
31
33
raise ArgumentError , "advisory_lock_timeout_seconds cannot be provided when advisory lock is disabled"
32
34
end
33
35
if order_is_numeric?
@@ -114,8 +116,7 @@ def where_eq(column_name, value)
114
116
115
117
def with_advisory_lock! ( &block )
116
118
if options [ :with_advisory_lock ]
117
- lock_options = { timeout_seconds : options [ :advisory_lock_timeout_seconds ] } . compact
118
- model_class . with_advisory_lock! ( advisory_lock_name , lock_options ) do
119
+ model_class . with_advisory_lock! ( advisory_lock_name , timeout_seconds : options [ :advisory_lock_timeout_seconds ] ) do
119
120
transaction { yield }
120
121
end
121
122
else
Original file line number Diff line number Diff line change 2
2
3
3
RSpec . describe ClosureTree ::Support do
4
4
let ( :model ) { Tag }
5
- let ( :options ) { { } }
5
+ let ( :options ) { { with_advisory_lock : true , advisory_lock_timeout_seconds : 10 } }
6
6
let ( :sut ) { described_class . new ( model , options ) }
7
7
8
8
it 'passes through table names without prefix and suffix' do
16
16
expect ( sut . remove_prefix_and_suffix ( tn ) ) . to eq ( expected )
17
17
end
18
18
19
- [
20
- [ true , 10 , { timeout_seconds : 10 } ] ,
21
- [ true , nil , { } ] ,
22
- [ false , nil , { } ]
23
- ] . each do |with_lock , timeout , expected_options |
24
- context "when with_advisory_lock is #{ with_lock } and timeout is #{ timeout } " do
25
- let ( :options ) { { with_advisory_lock : with_lock , advisory_lock_timeout_seconds : timeout } }
26
-
27
- it "uses advisory lock with timeout options: #{ expected_options } " do
28
- if with_lock
29
- expect ( model ) . to receive ( :with_advisory_lock! ) . with ( anything , expected_options ) . and_yield
30
- else
31
- expect ( model ) . not_to receive ( :with_advisory_lock! )
32
- end
33
-
34
- expect { |b | sut . with_advisory_lock! ( &b ) } . to yield_control
35
- end
36
- end
19
+ it 'calls with_advisory_lock! with timeout options' do
20
+ expect ( model ) . to receive ( :with_advisory_lock! ) . with ( anything , { timeout_seconds : 10 } ) . and_yield
21
+ expect { |b | sut . with_advisory_lock! ( &b ) } . to yield_control
37
22
end
38
23
end
You can’t perform that action at this time.
0 commit comments