Use around block to set and restore the DatabaseCleaner strategy

parent 7fddfa0b
......@@ -61,8 +61,14 @@ describe Groups::DestroyService, services: true do
context 'potential race conditions' do
context "when the `GroupDestroyWorker` task runs immediately" do
before do
DatabaseCleaner.strategy = :deletion
around(:each) do |example|
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
it "deletes the group" do
......@@ -98,10 +104,6 @@ describe Groups::DestroyService, services: true do
expect(group_record).to be_nil
end
after do
DatabaseCleaner.strategy = :transaction
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