File tree Expand file tree Collapse file tree 2 files changed +8
-24
lines changed Expand file tree Collapse file tree 2 files changed +8
-24
lines changed Original file line number Diff line number Diff line change @@ -23,12 +23,12 @@ def initialize(model_class, options)
2323 :dependent => :nullify , # or :destroy or :delete_all -- see the README
2424 :name_column => 'name' ,
2525 :with_advisory_lock => true ,
26- :advisory_lock_timeout_seconds => nil ,
26+ :advisory_lock_timeout_seconds => 0 ,
2727 :numeric_order => false
2828 } . merge ( options )
2929 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 "
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 "
3232 end
3333 if order_is_numeric?
3434 extend NumericOrderSupport . adapter_for_connection ( connection )
@@ -114,8 +114,7 @@ def where_eq(column_name, value)
114114
115115 def with_advisory_lock! ( &block )
116116 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
117+ model_class . with_advisory_lock! ( advisory_lock_name , timeout_seconds : options [ :advisory_lock_timeout_seconds ] ) do
119118 transaction { yield }
120119 end
121120 else
Original file line number Diff line number Diff line change 22
33RSpec . describe ClosureTree ::Support do
44 let ( :model ) { Tag }
5- let ( :options ) { { } }
5+ let ( :options ) { { with_advisory_lock : true , advisory_lock_timeout_seconds : 10 } }
66 let ( :sut ) { described_class . new ( model , options ) }
77
88 it 'passes through table names without prefix and suffix' do
1616 expect ( sut . remove_prefix_and_suffix ( tn ) ) . to eq ( expected )
1717 end
1818
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
3722 end
3823end
You can’t perform that action at this time.
0 commit comments