diff --git a/db/migrations/000050_create_latest_matrix.rb b/db/migrations/000050_create_latest_matrix.rb index 700e87021..b07739a82 100644 --- a/db/migrations/000050_create_latest_matrix.rb +++ b/db/migrations/000050_create_latest_matrix.rb @@ -14,7 +14,14 @@ UNION - select * from matrix where verification_id is null" + select matrix.* from matrix + inner join latest_pact_publication_revision_numbers lr + on matrix.consumer_id = lr.consumer_id + and matrix.provider_id = lr.provider_id + and matrix.consumer_version_order = lr.consumer_version_order + and matrix.pact_revision_number = lr.latest_revision_number + where verification_id is null + " ) end end diff --git a/spec/lib/pact_broker/matrix/repository_spec.rb b/spec/lib/pact_broker/matrix/repository_spec.rb index 227ad6bbc..5a21c543b 100644 --- a/spec/lib/pact_broker/matrix/repository_spec.rb +++ b/spec/lib/pact_broker/matrix/repository_spec.rb @@ -249,11 +249,27 @@ def shorten_rows rows end describe "find" do - let(:options) { { scope: scope} } - let(:scope) { 'latest' } + let(:options) { {} } subject { Repository.new.find(selectors, options) } + context "when a pact is revised, then verified" do + before do + td.create_pact_with_hierarchy("A", "1", "B") + .revise_pact + .create_verification(provider_version: "1") + end + + context "when latestby=cvpv" do + let(:selectors) { build_selectors('A' => '1', 'B' => '1')} + let(:options) { { latestby: 'cvpv' } } + + it "returns one row" do + expect(shorten_rows(subject)).to eq ['A1 B1 n1'] + end + end + end + context "when the provider version resource exists but there is no verification for that version" do before do # A/1.2.3 -> B diff --git a/spec/migrations/50_create_latest_matrix_spec.rb b/spec/migrations/50_create_latest_matrix_spec.rb index d5f700d4d..1c0d33511 100644 --- a/spec/migrations/50_create_latest_matrix_spec.rb +++ b/spec/migrations/50_create_latest_matrix_spec.rb @@ -103,7 +103,6 @@ def shorten_row row # C2 P? (r1/n?) it "only includes the latest pact revisions and latest verifications" do - puts database[:matrix].order(:consumer_version_order, :provider_version_order, :pact_revision_number, :verification_id).all.collect{ |r| shorten_row(r) } rows = database[:latest_matrix].order(:verification_id).all.collect{|row| shorten_row(row) } expect(rows).to include "C1 P1 (r2/n2)" expect(rows).to include "C1 P2 (r2/n3)" diff --git a/spec/service_consumers/provider_states_for_pact_broker_client.rb b/spec/service_consumers/provider_states_for_pact_broker_client.rb index e1849a096..bcec8df1f 100644 --- a/spec/service_consumers/provider_states_for_pact_broker_client.rb +++ b/spec/service_consumers/provider_states_for_pact_broker_client.rb @@ -6,10 +6,12 @@ set_up do TestDataBuilder.new .create_pact_with_hierarchy("Foo Thing", "1.2.3", "Bar") + .revise_pact .create_verification(provider_version: "4.5.6") .create_verification(provider_version: "7.8.9", number: 2) .create_consumer_version("2.0.0") .create_pact + .revise_pact .create_verification(provider_version: "4.5.6") end end @@ -18,10 +20,12 @@ set_up do TestDataBuilder.new .create_pact_with_hierarchy("Foo", "1.2.3", "Bar") + .revise_pact .create_verification(provider_version: "4.5.6") .create_verification(provider_version: "7.8.9", number: 2) .create_consumer_version("2.0.0") .create_pact + .revise_pact .create_verification(provider_version: "4.5.6") end end @@ -30,9 +34,11 @@ set_up do TestDataBuilder.new .create_pact_with_hierarchy("Foo", "1.2.3", "Bar") + .revise_pact .create_verification(provider_version: "4.5.6") .create_consumer_version("1.2.4") .create_pact + .revise_pact .create_verification(provider_version: "4.5.6") end end @@ -41,9 +47,11 @@ set_up do TestDataBuilder.new .create_pact_with_hierarchy("Foo", "1.2.3", "Bar") + .revise_pact .create_verification(provider_version: "4.5.6") .create_consumer_version("1.2.4") .create_pact + .revise_pact .create_verification(provider_version: "9.9.9", success: false) end end @@ -52,12 +60,14 @@ set_up do TestDataBuilder.new .create_pact_with_hierarchy("Foo", "1.2.3", "Bar") + .revise_pact .create_verification(provider_version: "4.5.6") .use_provider("Bar") .use_provider_version("4.5.6") .create_provider_version_tag("prod") .create_consumer_version("1.2.4") .create_pact + .revise_pact .create_verification(provider_version: "9.9.9", success: false) end end