diff --git a/lib/pact_broker/pacts/repository.rb b/lib/pact_broker/pacts/repository.rb index 4b1d12577..9e1d1d4c5 100644 --- a/lib/pact_broker/pacts/repository.rb +++ b/lib/pact_broker/pacts/repository.rb @@ -17,6 +17,7 @@ require 'pact_broker/pacts/selected_pact' require 'pact_broker/pacts/selector' require 'pact_broker/pacts/selectors' +require 'pact_broker/feature_toggle' module PactBroker module Pacts @@ -214,14 +215,15 @@ def find_wip_pact_versions_for_provider provider_name, provider_tags_names = [], .where(name: provider_tags_names) .all - wip_pacts.collect do | pact| + provider_version_count = scope_for(PactBroker::Domain::Version).where(pacticipant: provider).count + wip_pacts.collect do | pact| pending_tag_names = find_provider_tags_for_which_pact_publication_id_is_pending(pact, successfully_verified_head_pact_publication_ids_for_each_provider_tag) pre_existing_tag_names = find_provider_tag_names_that_were_first_used_before_pact_published(pact, provider_tag_collection) pre_existing_pending_tags = pending_tag_names & pre_existing_tag_names - if pre_existing_pending_tags.any? + if pre_existing_pending_tags.any? || (PactBroker.feature_enabled?(:experimental_no_provider_versions_makes_all_head_pacts_wip) && provider_version_count == 0) selectors = Selectors.create_for_latest_of_each_tag(pact.head_tag_names) VerifiablePact.new(pact.to_domain, selectors, true, pre_existing_pending_tags, [], true) end diff --git a/spec/lib/pact_broker/pacts/repository_find_wip_pact_versions_for_provider_spec.rb b/spec/lib/pact_broker/pacts/repository_find_wip_pact_versions_for_provider_spec.rb index cb0f33568..6255b3a0f 100644 --- a/spec/lib/pact_broker/pacts/repository_find_wip_pact_versions_for_provider_spec.rb +++ b/spec/lib/pact_broker/pacts/repository_find_wip_pact_versions_for_provider_spec.rb @@ -228,17 +228,30 @@ module Pacts end end - context "when the provider tag does not exist yet" do + context "when the provider tag does not exist yet and there are no provider versions" do before do td.create_pact_with_hierarchy("foo", "1", "bar") .create_consumer_version_tag("feat-x") end + it "is included" do + expect(subject.size).to be 1 + end + end + + context "when the provider tag does not exist yet but there are other provider versions" do + before do + td.create_pact_with_hierarchy("foo", "1", "bar") + .create_consumer_version_tag("feat-x") + .create_provider_version("1") + end + it "doesn't return any pacts" do expect(subject.size).to be 0 end end + context "when a pact was published between the first creation date of two provider tags" do let(:provider_tags) { %w[dev feat-1] }