Skip to content

Commit

Permalink
feat(matrix): update validation of selectors to allow tag and latest …
Browse files Browse the repository at this point in the history
…flag to be specified
  • Loading branch information
bethesque committed Oct 31, 2017
1 parent abcab9e commit 0fa33f1
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 9 deletions.
14 changes: 9 additions & 5 deletions lib/pact_broker/matrix/service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
24 changes: 20 additions & 4 deletions spec/lib/pact_broker/matrix/service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -90,15 +90,15 @@ 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"]
end
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")
Expand All @@ -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
Expand Down

0 comments on commit 0fa33f1

Please sign in to comment.