Skip to content

Commit

Permalink
feat(matrix): ensure correct row is returned when a pact is revised, …
Browse files Browse the repository at this point in the history
…then verified
  • Loading branch information
bethesque committed Nov 6, 2017
1 parent bdc5ac0 commit 7f37644
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 4 deletions.
9 changes: 8 additions & 1 deletion db/migrations/000050_create_latest_matrix.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
20 changes: 18 additions & 2 deletions spec/lib/pact_broker/matrix/repository_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion spec/migrations/50_create_latest_matrix_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)"
Expand Down
10 changes: 10 additions & 0 deletions spec/service_consumers/provider_states_for_pact_broker_client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down

0 comments on commit 7f37644

Please sign in to comment.