Skip to content

Commit 5456eda

Browse files
committed
fix: delete overwritten pact publications when deleting all pact publications between a consumer and provider
1 parent 718f021 commit 5456eda

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

lib/pact_broker/pacts/repository.rb

+8-3
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,12 @@ def find_all_pact_versions_between consumer_name, options
9292
end
9393

9494
def delete_all_pact_publications_between consumer_name, options
95-
ids = find_all_database_versions_between(consumer_name, options).select_for_subquery(:id)
95+
consumer = pacticipant_repository.find_by_name(consumer_name)
96+
provider = pacticipant_repository.find_by_name(options.fetch(:and))
97+
query = PactPublication.where(consumer: consumer, provider: provider)
98+
query = query.tag(options[:tag]) if options[:tag]
99+
100+
ids = query.select_for_subquery(:id)
96101
webhook_repository.delete_triggered_webhooks_by_pact_publication_ids(ids)
97102
PactPublication.where(id: ids).delete
98103
end
@@ -283,10 +288,10 @@ def create_pact_version consumer_id, provider_id, sha, json_content
283288
pact_version.save
284289
end
285290

286-
def find_all_database_versions_between(consumer_name, options)
291+
def find_all_database_versions_between(consumer_name, options, base_class = LatestPactPublicationsByConsumerVersion)
287292
provider_name = options.fetch(:and)
288293

289-
query = LatestPactPublicationsByConsumerVersion
294+
query = base_class
290295
.consumer(consumer_name)
291296
.provider(provider_name)
292297

spec/lib/pact_broker/pacts/repository_spec.rb

+4-1
Original file line numberDiff line numberDiff line change
@@ -321,6 +321,8 @@ module Pacts
321321
.create_consumer_version("1.2.3")
322322
.create_provider(provider_name)
323323
.create_pact
324+
.revise_pact
325+
.comment("The overwritten pact needs to be deleted too")
324326
.create_webhook
325327
.create_triggered_webhook
326328
.create_webhook_execution
@@ -330,12 +332,13 @@ module Pacts
330332
.create_pact
331333
.create_provider("Another Provider")
332334
.create_pact
335+
.comment("This one won't be deleted")
333336
end
334337

335338
subject { Repository.new.delete_all_pact_publications_between(consumer_name, :and => provider_name) }
336339

337340
it "deletes the pacts between the specified consumer and provider" do
338-
expect { subject }.to change { PactPublication.count }.by(-2)
341+
expect { subject }.to change { PactPublication.count }.by(-3)
339342
end
340343

341344
context "with a tag" do

0 commit comments

Comments
 (0)