diff --git a/lib/pact_broker/matrix/resolved_selector.rb b/lib/pact_broker/matrix/resolved_selector.rb index 207c47e86..3ebb17ccf 100644 --- a/lib/pact_broker/matrix/resolved_selector.rb +++ b/lib/pact_broker/matrix/resolved_selector.rb @@ -1,12 +1,17 @@ +require "pact_broker/hash_refinements" + # A selector with the pacticipant id, name, version number, and version id set # This is created from either specified or inferred data, based on the user's query # eg. # can-i-deploy --pacticipant Foo --version 1 (this is a specified selector) # --to prod (this is used to create inferred selectors) + module PactBroker module Matrix class ResolvedSelector < Hash + using PactBroker::HashRefinements + # A version ID of -1 will not match any rows, which is what we want to ensure that # no matrix rows are returned for a version that does not exist. NULL_VERSION_ID = -1 @@ -124,7 +129,7 @@ def most_specific_criterion end def only_pacticipant_name_specified? - !!pacticipant_name && !branch && !tag && !latest? && !pacticipant_version_number && !main_branch? + !!pacticipant_name && self[:original_selector].without(:pacticipant_name).none?{ |_key, value| value } end def latest_tagged? diff --git a/spec/lib/pact_broker/matrix/deployment_status_summary_spec.rb b/spec/lib/pact_broker/matrix/deployment_status_summary_spec.rb index 59d920f73..f270b651c 100644 --- a/spec/lib/pact_broker/matrix/deployment_status_summary_spec.rb +++ b/spec/lib/pact_broker/matrix/deployment_status_summary_spec.rb @@ -323,14 +323,16 @@ module Matrix pacticipant_name: foo.name, pacticipant_version_number: foo_version.number, pacticipant_version_id: foo_version.id, - type: :specified + type: :specified, + original_selector: {} ), ResolvedSelector.new( pacticipant_id: bar.id, pacticipant_name: bar.name, pacticipant_version_number: bar_version.number, pacticipant_version_id: bar_version.id, - type: :inferred + type: :inferred, + original_selector: {} ) ] end @@ -347,14 +349,16 @@ module Matrix pacticipant_name: foo.name, pacticipant_version_number: foo_version.number, pacticipant_version_id: foo_version.id, - type: :specified + type: :specified, + original_selector: {} ), ResolvedSelector.new( pacticipant_id: bar.id, pacticipant_name: bar.name, pacticipant_version_number: bar_version.number, pacticipant_version_id: bar_version.id, - type: :specified + type: :specified, + original_selector: {} ) ] end diff --git a/spec/lib/pact_broker/matrix/resolved_selector_spec.rb b/spec/lib/pact_broker/matrix/resolved_selector_spec.rb index 3449f5432..53f93f244 100644 --- a/spec/lib/pact_broker/matrix/resolved_selector_spec.rb +++ b/spec/lib/pact_broker/matrix/resolved_selector_spec.rb @@ -34,12 +34,18 @@ module Matrix let(:one_of_many) { false } let(:version_values) { {} } - its(:description) { is_expected.to eq "version 123 of Foo" } + context "when it was specified by version number" do + let(:pacticipant_version_number) { "123" } + + its(:description) { is_expected.to eq "version 123 of Foo" } + its(:only_pacticipant_name_specified?) { is_expected.to be false } + end context "when it was specified by tag" do let(:tag) { "dev" } its(:description) { is_expected.to eq "a version of Foo with tag dev (123)" } + its(:only_pacticipant_name_specified?) { is_expected.to be false } end context "when it was specified by tag and latest" do @@ -47,6 +53,7 @@ module Matrix let(:latest) { true } its(:description) { is_expected.to eq "the latest version of Foo with tag dev (123)" } + its(:only_pacticipant_name_specified?) { is_expected.to be false } end context "when it was specified by branch" do @@ -58,6 +65,7 @@ module Matrix let(:one_of_many) { true } its(:description) { is_expected.to eq "one of the versions of Foo from branch main (123)" } + its(:only_pacticipant_name_specified?) { is_expected.to be false } end end @@ -66,18 +74,21 @@ module Matrix let(:latest) { true } its(:description) { is_expected.to eq "the latest version of Foo from branch main (123)" } + its(:only_pacticipant_name_specified?) { is_expected.to be false } end context "when it was specified by environment" do let(:environment_name) { "test" } its(:description) { is_expected.to eq "the version of Foo currently in test (123)" } + its(:only_pacticipant_name_specified?) { is_expected.to be false } end context "when it was specified by version number" do let(:pacticipant_version_number) { "123" } its(:description) { is_expected.to eq "version 123 of Foo" } + its(:only_pacticipant_name_specified?) { is_expected.to be false } end context "when specified by main_branch" do @@ -91,6 +102,7 @@ module Matrix let(:one_of_many) { true } its(:description) { is_expected.to eq "one of the versions of Foo from branch develop (123)" } + its(:only_pacticipant_name_specified?) { is_expected.to be false } end end @@ -100,6 +112,16 @@ module Matrix let(:version_values) { { branch_name: "develop" } } its(:description) { is_expected.to eq "the latest version of Foo from branch develop (123)" } + its(:only_pacticipant_name_specified?) { is_expected.to be false } + end + + context "when it was specified by pacticipant name only" do + let(:subject) do + PactBroker::Matrix::ResolvedSelector.for_pacticipant(pacticipant, original_selector, :specified, false) + end + + its(:description) { is_expected.to eq "any version of Foo" } + its(:only_pacticipant_name_specified?) { is_expected.to be true } end end