|
3 | 3 | require 'test_helper' |
4 | 4 |
|
5 | 5 | describe ClosureTree::Support do |
6 | | - let(:sut) { Tag._ct } |
| 6 | + let(:model) { Tag } |
| 7 | + let(:sut) { model._ct } |
7 | 8 |
|
8 | 9 | it 'passes through table names without prefix and suffix' do |
9 | 10 | expected = 'some_random_table_name' |
|
15 | 16 | tn = ActiveRecord::Base.table_name_prefix + expected + ActiveRecord::Base.table_name_suffix |
16 | 17 | assert_equal expected, sut.remove_prefix_and_suffix(tn) |
17 | 18 | end |
| 19 | + |
| 20 | + it 'initializes without error when with_advisory_lock is false' do |
| 21 | + assert ClosureTree::Support.new(model, { with_advisory_lock: false }) |
| 22 | + end |
| 23 | + |
| 24 | + it 'initializes without error when with_advisory_lock is true and advisory_lock_timeout_seconds is set' do |
| 25 | + assert ClosureTree::Support.new(model, { with_advisory_lock: true, advisory_lock_timeout_seconds: 10 }) |
| 26 | + end |
| 27 | + |
| 28 | + it 'calls :with_advisory_lock! when with_advisory_lock is true and timeout is 10' do |
| 29 | + options = sut.options.merge(with_advisory_lock: true, advisory_lock_timeout_seconds: 10) |
| 30 | + called = false |
| 31 | + sut.stub(:options, options) do |
| 32 | + model.stub(:with_advisory_lock!, ->(_lock_name, _options, &block) { block.call }) do |
| 33 | + sut.with_advisory_lock { called = true } |
| 34 | + end |
| 35 | + end |
| 36 | + assert called, 'block should have been called' |
| 37 | + end |
| 38 | + |
| 39 | + it 'calls :with_advisory_lock when with_advisory_lock is true and timeout is nil' do |
| 40 | + called = false |
| 41 | + model.stub(:with_advisory_lock, ->(_lock_name, _options, &block) { block.call }) do |
| 42 | + sut.with_advisory_lock { called = true } |
| 43 | + end |
| 44 | + assert called, 'block should have been called' |
| 45 | + end |
| 46 | + |
| 47 | + it 'does not call advisory lock methods when with_advisory_lock is false' do |
| 48 | + options = sut.options.merge(with_advisory_lock: false, advisory_lock_timeout_seconds: nil) |
| 49 | + called = false |
| 50 | + sut.stub(:options, options) do |
| 51 | + sut.with_advisory_lock { called = true } |
| 52 | + end |
| 53 | + assert called, 'block should have been called' |
| 54 | + end |
18 | 55 | end |
0 commit comments