diff --git a/lib/pact_broker/integrations/integration.rb b/lib/pact_broker/integrations/integration.rb index aef67971c..2d62c878a 100644 --- a/lib/pact_broker/integrations/integration.rb +++ b/lib/pact_broker/integrations/integration.rb @@ -8,6 +8,7 @@ class Integration < Sequel::Model associate(:many_to_one, :consumer, :class => "PactBroker::Domain::Pacticipant", :key => :consumer_id, :primary_key => :id) associate(:many_to_one, :provider, :class => "PactBroker::Domain::Pacticipant", :key => :provider_id, :primary_key => :id) associate(:one_to_one, :latest_pact, :class => "PactBroker::Pacts::LatestPactPublications", key: [:consumer_id, :provider_id], primary_key: [:consumer_id, :provider_id]) + associate(:one_to_one, :latest_verification, :class => "PactBroker::Verifications::LatestVerificationForConsumerAndProvider", key: [:consumer_id, :provider_id], primary_key: [:consumer_id, :provider_id]) def verification_status_for_latest_pact @verification_status_for_latest_pact ||= PactBroker::Verifications::PseudoBranchStatus.new(latest_pact, latest_pact&.latest_verification) @@ -18,7 +19,7 @@ def latest_pact_or_verification_publication_date end def latest_verification_publication_date - PactBroker::Domain::Verification.where(consumer_id: consumer_id, provider_id: provider_id).order(:id).last&.execution_date + latest_verification&.execution_date end end end diff --git a/lib/pact_broker/integrations/service.rb b/lib/pact_broker/integrations/service.rb index 4f6a83004..cc2a92d5f 100644 --- a/lib/pact_broker/integrations/service.rb +++ b/lib/pact_broker/integrations/service.rb @@ -11,10 +11,19 @@ class Service include PactBroker::Logging def self.find_all + # The only reason the pact_version needs to be loaded is that + # the Verification::PseudoBranchStatus uses it to determine if + # the pseudo branch is 'stale'. + # Because this is the status for a pact, and not a pseudo branch, + # the status can never be 'stale', + # so it would be better to create a Verification::PactStatus class + # that doesn't have the 'stale' logic in it. + # Then we can remove the eager loading of the pact_version PactBroker::Integrations::Integration .eager(:consumer) .eager(:provider) - .eager(latest_pact: :latest_verification) + .eager(latest_pact: [:latest_verification, :pact_version]) + .eager(:latest_verification) .all .sort { | a, b| b.latest_pact_or_verification_publication_date <=> a.latest_pact_or_verification_publication_date } end diff --git a/spec/lib/pact_broker/integrations/integration_spec.rb b/spec/lib/pact_broker/integrations/integration_spec.rb index 663773bd4..0885eaba8 100644 --- a/spec/lib/pact_broker/integrations/integration_spec.rb +++ b/spec/lib/pact_broker/integrations/integration_spec.rb @@ -29,6 +29,11 @@ module Integrations expect(Integration.first.verification_status_for_latest_pact).to be_instance_of(PactBroker::Verifications::PseudoBranchStatus) end + it "has a latest verification - this may not be the same as the latest verification for the latest pact" do + integration = Integration.eager(:latest_verification).all.first + expect(integration.latest_verification.provider_version_number).to eq "4" + end + describe "latest_pact_or_verification_publication_date" do context "when the last publication is a verification" do it "returns the verification execution date" do