diff options
Diffstat (limited to 'spec/workers/concerns/worker_attributes_spec.rb')
-rw-r--r-- | spec/workers/concerns/worker_attributes_spec.rb | 68 |
1 files changed, 68 insertions, 0 deletions
diff --git a/spec/workers/concerns/worker_attributes_spec.rb b/spec/workers/concerns/worker_attributes_spec.rb index a654ecbd3e2..d4b17c65f46 100644 --- a/spec/workers/concerns/worker_attributes_spec.rb +++ b/spec/workers/concerns/worker_attributes_spec.rb @@ -62,6 +62,12 @@ RSpec.describe WorkerAttributes do end describe '.idempotent!' do + it 'sets `idempotent` attribute of the worker class to true' do + worker.idempotent! + + expect(worker.send(:class_attributes)[:idempotent]).to eq(true) + end + context 'when data consistency is not :always' do it 'raise exception' do worker.data_consistency(:sticky) @@ -71,4 +77,66 @@ RSpec.describe WorkerAttributes do end end end + + describe '.idempotent?' do + subject(:idempotent?) { worker.idempotent? } + + context 'when the worker is idempotent' do + before do + worker.idempotent! + end + + it { is_expected.to be_truthy } + end + + context 'when the worker is not idempotent' do + it { is_expected.to be_falsey } + end + end + + describe '.deduplicate' do + it 'sets deduplication_strategy and deduplication_options' do + worker.deduplicate(:until_executing, including_scheduled: true) + + expect(worker.send(:class_attributes)[:deduplication_strategy]).to eq(:until_executing) + expect(worker.send(:class_attributes)[:deduplication_options]).to eq(including_scheduled: true) + end + end + + describe '#deduplication_enabled?' do + subject(:deduplication_enabled?) { worker.deduplication_enabled? } + + context 'when no feature flag is set' do + before do + worker.deduplicate(:until_executing) + end + + it { is_expected.to eq(true) } + end + + context 'when feature flag is set' do + before do + skip_feature_flags_yaml_validation + skip_default_enabled_yaml_check + + worker.deduplicate(:until_executing, feature_flag: :my_feature_flag) + end + + context 'when the FF is enabled' do + before do + stub_feature_flags(my_feature_flag: true) + end + + it { is_expected.to eq(true) } + end + + context 'when the FF is disabled' do + before do + stub_feature_flags(my_feature_flag: false) + end + + it { is_expected.to eq(false) } + end + end + end end |