Skip to content

Commit

Permalink
feat: ensure latest pact version is returned when searching by pact v…
Browse files Browse the repository at this point in the history
…ersion sha
  • Loading branch information
bethesque committed Jan 11, 2018
1 parent d3b67c3 commit 1d2adc6
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 3 deletions.
11 changes: 9 additions & 2 deletions lib/pact_broker/pacts/repository.rb
Original file line number Diff line number Diff line change
Expand Up @@ -103,13 +103,20 @@ def find_latest_pact(consumer_name, provider_name, tag = nil)
end

def find_pact consumer_name, consumer_version, provider_name, pact_version_sha = nil
query = pact_version_sha ? AllPactPublications.pact_version_sha(pact_version_sha) : LatestPactPublicationsByConsumerVersion
query = if pact_version_sha
AllPactPublications
.pact_version_sha(pact_version_sha)
.reverse_order(:consumer_version_order)
.limit(1)
else
LatestPactPublicationsByConsumerVersion
end
query = query
.eager(:tags)
.consumer(consumer_name)
.provider(provider_name)
query = query.consumer_version_number(consumer_version) if consumer_version
query.limit(1).collect(&:to_domain_with_content)[0]
query.collect(&:to_domain_with_content)[0]
end

def find_all_revisions consumer_name, consumer_version, provider_name
Expand Down
19 changes: 18 additions & 1 deletion spec/lib/pact_broker/pacts/repository_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -347,15 +347,32 @@ module Pacts
context "with a pact_version_sha" do
subject { Repository.new.find_pact "Consumer", nil, "Provider", pact.pact_version_sha }

it "finds the pact with the given version and revision" do
it "finds the pact with the given pact_version_sha" do
expect(subject.pact_version_sha).to eq pact.pact_version_sha
expect(subject.consumer.name).to eq "Consumer"
expect(subject.provider.name).to eq "Provider"
expect(subject.consumer_version_number).to eq "1.2.4"
expect(subject.revision_number).to eq 2

end
context "when there are multiple pact publications for the pact version" do
before do
# Double check the data is set up correctly...
expect(pact_1.pact_version_sha).to eq(pact_2.pact_version_sha)
end

let(:td) { TestDataBuilder.new }
let!(:pact_1) { td.create_pact_with_hierarchy("Foo", "1", "Bar").and_return(:pact) }
let!(:pact_2) { td.create_consumer_version("2").create_pact(json_content: pact_1.json_content).and_return(:pact) }

subject { Repository.new.find_pact "Foo", nil, "Bar", pact_1.pact_version_sha }

it "returns the latest pact, ordered by consumer version order" do
expect(subject.consumer_version_number).to eq "2"
end
end
end

end

describe "find_all_revisions" do
Expand Down

0 comments on commit 1d2adc6

Please sign in to comment.