Use around block to set and restore the DatabaseCleaner strategy

parent 7fddfa0b
...@@ -61,8 +61,14 @@ describe Groups::DestroyService, services: true do ...@@ -61,8 +61,14 @@ describe Groups::DestroyService, services: true do
context 'potential race conditions' do context 'potential race conditions' do
context "when the `GroupDestroyWorker` task runs immediately" do context "when the `GroupDestroyWorker` task runs immediately" do
before do around(:each) do |example|
DatabaseCleaner.strategy = :deletion old_strategy = DatabaseCleaner[:active_record, { connection: ActiveRecord::Base }].strategy
DatabaseCleaner[:active_record, { connection: ActiveRecord::Base }].strategy = :deletion
begin
example.run
ensure
DatabaseCleaner[:active_record, { connection: ActiveRecord::Base }].strategy = old_strategy
end
end end
it "deletes the group" do it "deletes the group" do
...@@ -98,10 +104,6 @@ describe Groups::DestroyService, services: true do ...@@ -98,10 +104,6 @@ describe Groups::DestroyService, services: true do
expect(group_record).to be_nil expect(group_record).to be_nil
end end
after do
DatabaseCleaner.strategy = :transaction
end
end end
end end
end end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment