From 0fa33f154f562a6f95302e8e659a0540959d287b Mon Sep 17 00:00:00 2001 From: Beth Skurrie Date: Wed, 1 Nov 2017 10:22:05 +1100 Subject: [PATCH] feat(matrix): update validation of selectors to allow tag and latest flag to be specified --- lib/pact_broker/matrix/service.rb | 14 +++++++----- spec/lib/pact_broker/matrix/service_spec.rb | 24 +++++++++++++++++---- 2 files changed, 29 insertions(+), 9 deletions(-) diff --git a/lib/pact_broker/matrix/service.rb b/lib/pact_broker/matrix/service.rb index dcf0dc339..e6502c805 100644 --- a/lib/pact_broker/matrix/service.rb +++ b/lib/pact_broker/matrix/service.rb @@ -29,8 +29,12 @@ def validate_selectors selectors elsif s[:pacticipant_name].nil? error_messages << "Please specify the pacticipant name" else - if s.key?(:pacticipant_version_number) && s.key?(:latest_tag) - error_messages << "A version and a latest tag cannot both be specified for #{s[:pacticipant_name]}" + if s.key?(:pacticipant_version_number) && s.key?(:latest) + error_messages << "A version and latest flag cannot both be specified for #{s[:pacticipant_name]}" + end + + if s.key?(:tag) && !s.key?(:latest) + error_messages << "Querying for all versions with a tag is not currently supported. The latest=true flag must be specified when a tag is given." end end end @@ -46,9 +50,9 @@ def validate_selectors selectors if s[:pacticipant_version_number] version = version_service.find_by_pacticipant_name_and_number(pacticipant_name: s[:pacticipant_name], pacticipant_version_number: s[:pacticipant_version_number]) error_messages << "No pact or verification found for #{s[:pacticipant_name]} version #{s[:pacticipant_version_number]}" if version.nil? - elsif s[:latest_tag] - version = version_service.find_by_pacticpant_name_and_latest_tag(s[:pacticipant_name], s[:latest_tag]) - error_messages << "No version of #{s[:pacticipant_name]} found with tag #{s[:latest_tag]}" if version.nil? + elsif s[:tag] + version = version_service.find_by_pacticpant_name_and_latest_tag(s[:pacticipant_name], s[:tag]) + error_messages << "No version of #{s[:pacticipant_name]} found with tag #{s[:tag]}" if version.nil? end end end diff --git a/spec/lib/pact_broker/matrix/service_spec.rb b/spec/lib/pact_broker/matrix/service_spec.rb index b28d675a9..bb080dba3 100644 --- a/spec/lib/pact_broker/matrix/service_spec.rb +++ b/spec/lib/pact_broker/matrix/service_spec.rb @@ -90,7 +90,7 @@ module Matrix context "when there is not a version for the tag" do - let(:selectors) { [{ pacticipant_name: "Foo", latest_tag: "wiffle" }, { pacticipant_name: "Bar", pacticipant_version_number: "2" }] } + let(:selectors) { [{ pacticipant_name: "Foo", latest: true, tag: "wiffle" }, { pacticipant_name: "Bar", pacticipant_version_number: "2" }] } it "returns an error message" do expect(subject).to eq ["No version of Foo found with tag wiffle"] @@ -98,7 +98,7 @@ module Matrix end end - context "when the latest_tag is used as well as a version" do + context "when the latest is used as well as a version" do before do td.create_pacticipant("Foo") .create_version("1") @@ -107,10 +107,26 @@ module Matrix .create_version("2") end - let(:selectors) { [{ pacticipant_name: "Foo", pacticipant_version_number: "1", latest_tag: "prod" }, { pacticipant_name: "Bar", pacticipant_version_number: "2" }] } + let(:selectors) { [{ pacticipant_name: "Foo", pacticipant_version_number: "1", latest: true }, { pacticipant_name: "Bar", pacticipant_version_number: "2" }] } it "returns an error message" do - expect(subject).to eq ["A version and a latest tag cannot both be specified for Foo"] + expect(subject).to eq ["A version and latest flag cannot both be specified for Foo"] + end + end + + context "when a tag is specified without latest=true" do + before do + td.create_pacticipant("Foo") + .create_version("1") + .create_tag("prod") + .create_pacticipant("Bar") + .create_version("2") + end + + let(:selectors) { [{ pacticipant_name: "Foo", tag: "1"}] } + + it "returns an error message" do + expect(subject).to eq ["Querying for all versions with a tag is not currently supported. The latest=true flag must be specified when a tag is given."] end end end