diff --git a/lib/pact_broker/metrics/service.rb b/lib/pact_broker/metrics/service.rb index 0e70ffff7..c0c94461b 100644 --- a/lib/pact_broker/metrics/service.rb +++ b/lib/pact_broker/metrics/service.rb @@ -101,8 +101,8 @@ def interactions_counts end def pact_revision_counts - query = "select revision_count as number_of_revisions, count(consumer_version_id) as consumer_version_count - from (select consumer_version_id, count(*) as revision_count from pact_publications group by consumer_version_id) foo + query = "select revision_count as number_of_revisions, count(*) as consumer_version_count + from (select count(*) as revision_count from pact_publications group by consumer_version_id, provider_id) foo group by revision_count order by 1" PactBroker::Pacts::PactPublication.db[query].all.each_with_object({}) { |row, hash| hash[row[:number_of_revisions]] = row[:consumer_version_count] } diff --git a/spec/lib/pact_broker/metrics/service_spec.rb b/spec/lib/pact_broker/metrics/service_spec.rb index 7fa07f43f..0bdac2994 100644 --- a/spec/lib/pact_broker/metrics/service_spec.rb +++ b/spec/lib/pact_broker/metrics/service_spec.rb @@ -121,7 +121,7 @@ module Service describe "pactRevisionsPerPactPublication" do before do - td.create_pact_with_hierarchy + td.create_pact_with_hierarchy("Foo", "1", "Bar") .comment("this consumer version will have 3 revisions") .revise_pact .revise_pact @@ -129,12 +129,15 @@ module Service .create_pact .comment("this consumer version will have 1 revision") .revise_pact + .create_pact_with_hierarchy("Foo", "1", "Bar2", td.random_json_content("Foo", "Bar2")) + .create_pact_with_hierarchy("Foo", "2", "Bar", td.random_json_content("Foo", "Bar")) end let(:distribution) { subject[:pactRevisionsPerConsumerVersion][:distribution] } it "returns a distribution of pact revisions per consumer version" do - expect(distribution).to eq(2 => 1, 3 => 1) + # numberOfRevisions => countOfPactsWithThisNumberOfRevisions + expect(distribution).to eq({ 1 => 2, 2 => 1, 3 => 1 }) end end end