diff options
Diffstat (limited to 'spec/support')
-rw-r--r-- | spec/support/helpers/batch_destroy_dependent_associations_helper.rb | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/spec/support/helpers/batch_destroy_dependent_associations_helper.rb b/spec/support/helpers/batch_destroy_dependent_associations_helper.rb new file mode 100644 index 00000000000..22170de053b --- /dev/null +++ b/spec/support/helpers/batch_destroy_dependent_associations_helper.rb @@ -0,0 +1,13 @@ +# frozen_string_literal: true + +module BatchDestroyDependentAssociationsHelper + private + + def delete_in_batches_regexps(table, column, resource, items, batch_size: 1000) + # rubocop:disable Layout/LineLength + select_query = %r{^SELECT "#{table}".* FROM "#{table}" WHERE.* "#{table}"."#{column}" = #{resource.id}.*ORDER BY "#{table}"."id" ASC LIMIT #{batch_size}} + # rubocop:enable Layout/LineLength + + [select_query] + items.map { |item| %r{^DELETE FROM "#{table}" WHERE "#{table}"."id" = #{item.id}} } + end +end |