Skip to content

Commit

Permalink
fix: return overwritten pact publication as latest if non exists as a…
Browse files Browse the repository at this point in the history
… latest version when rendering verification

Closes: #189
  • Loading branch information
bethesque committed Feb 15, 2018
1 parent 3f74e7e commit 8217209
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 22 deletions.
8 changes: 7 additions & 1 deletion lib/pact_broker/pacts/pact_version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,13 @@ def latest_consumer_version
end

def latest_pact_publication
PactBroker::Pacts::LatestPactPublicationsByConsumerVersion.where(pact_version_id: id).order(:consumer_version_order).last
PactBroker::Pacts::LatestPactPublicationsByConsumerVersion
.where(pact_version_id: id)
.order(:consumer_version_order)
.last || PactBroker::Pacts::AllPactPublications
.where(pact_version_id: id)
.order(:consumer_version_order)
.last
end

def consumer_versions
Expand Down
65 changes: 44 additions & 21 deletions spec/lib/pact_broker/pacts/pact_version_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,29 +19,52 @@ module Pacts
end

describe "#latest_pact_publication" do
before do
TestDataBuilder.new
.create_provider("Bar")
.create_consumer("Foo")
.create_consumer_version("1.2.100")
.create_pact
.revise_pact
.create_consumer_version("1.2.101")
.create_pact
.create_consumer_version("1.2.102")
.create_pact
.revise_pact
.create_provider("Animals")
.create_pact
.create_provider("Wiffles")
.create_pact

context "when the latest pact publication is not an overwritten one" do
before do
TestDataBuilder.new
.create_provider("Bar")
.create_consumer("Foo")
.create_consumer_version("1.2.100")
.create_pact
.revise_pact
.create_consumer_version("1.2.101")
.create_pact
.create_consumer_version("1.2.102")
.create_pact
.revise_pact
.create_provider("Animals")
.create_pact
.create_provider("Wiffles")
.create_pact
end

it "returns the latest pact publication for the given pact version" do
pact = PactBroker::Pacts::Repository.new.find_pact("Foo", "1.2.102", "Animals")
pact_version = PactBroker::Pacts::PactVersion.find(sha: pact.pact_version_sha)
latest_pact_publication = pact_version.latest_pact_publication
expect(latest_pact_publication.id).to eq pact.id
end
end

it "returns the latest pact publication for the given pact version" do
pact = PactBroker::Pacts::Repository.new.find_pact("Foo", "1.2.102", "Animals")
pact_version = PactBroker::Pacts::PactVersion.find(sha: pact.pact_version_sha)
latest_pact_publication = pact_version.latest_pact_publication
expect(latest_pact_publication.id).to eq pact.id
context "when the only pact publication with the given sha is an overwritten one" do
let(:td) { TestDataBuilder.new }
let!(:first_version) do
td.create_provider("Bar")
.create_consumer("Foo")
.create_consumer_version("1")
.create_pact
.and_return(:pact)
end
let!(:second_revision) do
td.revise_pact
end

it "returns the overwritten pact publication" do
pact_version = PactBroker::Pacts::PactVersion.find(sha: first_version.pact_version_sha)
latest_pact_publication = pact_version.latest_pact_publication
expect(latest_pact_publication.revision_number).to eq 1
end
end
end

Expand Down

0 comments on commit 8217209

Please sign in to comment.