Skip to content

Commit

Permalink
fix(pacts for verification): ensure a separate pact URL is returned f…
Browse files Browse the repository at this point in the history
…or each consumer when multiple consumers share the same pact json content
  • Loading branch information
bethesque committed May 12, 2020
1 parent 439a36b commit 13e7b64
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
3 changes: 1 addition & 2 deletions lib/pact_broker/pacts/repository.rb
Original file line number Diff line number Diff line change
Expand Up @@ -357,12 +357,11 @@ def find_for_verification(provider_name, consumer_version_selectors)
selected_pacts = selected_pacts + find_pacts_for_fallback_tags(selected_pacts, provider_name, consumer_version_selectors)

selected_pacts
.group_by(&:pact_version_sha)
.group_by{ |p| [p.consumer_name, p.pact_version_sha] }
.values
.collect do | selected_pacts_for_pact_version_id |
SelectedPact.merge(selected_pacts_for_pact_version_id)
end

end

private
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ module Pacts
let(:td) { TestDataBuilder.new }

describe "#find_for_verification" do

def find_by_consumer_version_number(consumer_version_number)
subject.find{ |pact| pact.consumer_version_number == consumer_version_number }
end
Expand Down Expand Up @@ -189,6 +188,24 @@ def find_by_consumer_name_and_consumer_version_number(consumer_name, consumer_ve
expect(find_by_consumer_version_number("foo-latest-dev-version").overall_latest?).to be true
end
end

context "when two consumers have exactly the same json content" do
before do
td.create_consumer
.create_provider("Bar")
.create_consumer_version
.create_pact(json_content: { interactions: ['foo'] }.to_json )
.create_consumer
.create_consumer_version
.create_pact(json_content: { interactions: ['foo'] }.to_json )
end

let(:consumer_version_selectors) { Selectors.new }

it "returns a pact for each consumer" do
expect(subject.size).to eq 2
end
end
end
end
end
Expand Down

0 comments on commit 13e7b64

Please sign in to comment.