pact_broker 1.18.0 → 2.0.0.beta.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +12 -9
- data/DEVELOPER_DOCUMENTATION.md +53 -0
- data/README.md +13 -13
- data/db/migrations/23_create_pact_contents_table.rb +19 -0
- data/db/migrations/24_populate_pact_contents.rb +9 -0
- data/db/migrations/25_populate_pact_contents_pacticipants.rb +7 -0
- data/db/migrations/26_make_pc_pacticipants_mandatory.rb +8 -0
- data/db/migrations/27_create_pact_publications.rb +18 -0
- data/db/migrations/28_populate_pact_publications.rb +13 -0
- data/db/migrations/29_recreate_all_pacts.rb +16 -0
- data/db/migrations/30_drop_pacts.rb +8 -0
- data/db/migrations/31_drop_pact_version_contents.rb +5 -0
- data/db/migrations/32_rename_pact_contents.rb +5 -0
- data/db/migrations/33_recreate_all_pacts.rb +52 -0
- data/db/migrations/34_recreate_latest_tagged_pacts.rb +23 -0
- data/db/migrations/35_create_verifications.rb +15 -0
- data/db/migrations/36_create_latest_verifications.rb +14 -0
- data/db/pact_broker_database.sqlite3 +0 -0
- data/lib/pact_broker/api.rb +25 -10
- data/lib/pact_broker/api/contracts/verification_contract.rb +41 -0
- data/lib/pact_broker/api/decorators/pact_decorator.rb +7 -0
- data/lib/pact_broker/api/decorators/pact_version_decorator.rb +0 -1
- data/lib/pact_broker/api/decorators/representable_pact.rb +4 -3
- data/lib/pact_broker/api/decorators/timestamps.rb +1 -1
- data/lib/pact_broker/api/decorators/verification_decorator.rb +30 -0
- data/lib/pact_broker/api/decorators/verifications_decorator.rb +21 -0
- data/lib/pact_broker/api/decorators/version_decorator.rb +14 -0
- data/lib/pact_broker/api/decorators/versions_decorator.rb +1 -1
- data/lib/pact_broker/api/pact_broker_urls.rb +41 -2
- data/lib/pact_broker/api/renderers/html_pact_renderer.rb +1 -1
- data/lib/pact_broker/api/resources/base_resource.rb +11 -2
- data/lib/pact_broker/api/resources/latest_verifications_for_consumer_version.rb +39 -0
- data/lib/pact_broker/api/resources/pacticipants.rb +1 -1
- data/lib/pact_broker/api/resources/previous_distinct_pact_version.rb +1 -1
- data/lib/pact_broker/api/resources/verifications.rb +67 -0
- data/lib/pact_broker/api/resources/versions.rb +1 -1
- data/lib/pact_broker/api/resources/webhooks.rb +1 -1
- data/lib/pact_broker/app.rb +0 -2
- data/lib/pact_broker/configuration.rb +1 -4
- data/lib/pact_broker/doc/views/latest-verifications.markdown +7 -0
- data/lib/pact_broker/doc/views/publish-verification.markdown +14 -0
- data/lib/pact_broker/domain.rb +1 -1
- data/lib/pact_broker/domain/order_versions.rb +5 -15
- data/lib/pact_broker/domain/pact.rb +10 -2
- data/lib/pact_broker/domain/relationship.rb +31 -4
- data/lib/pact_broker/domain/verification.rb +77 -0
- data/lib/pact_broker/domain/version.rb +6 -1
- data/lib/pact_broker/domain/webhook.rb +1 -0
- data/lib/pact_broker/domain/webhook_request.rb +4 -6
- data/lib/pact_broker/locale/en.yml +2 -1
- data/lib/pact_broker/logging.rb +0 -4
- data/lib/pact_broker/pacticipants/repository.rb +1 -2
- data/lib/pact_broker/pacticipants/service.rb +11 -5
- data/lib/pact_broker/pacts/all_pact_publications.rb +96 -0
- data/lib/pact_broker/pacts/all_pacts.rb +4 -89
- data/lib/pact_broker/pacts/diff.rb +2 -2
- data/lib/pact_broker/pacts/latest_pact_publications.rb +11 -0
- data/lib/pact_broker/pacts/latest_pact_publications_by_consumer_version.rb +11 -0
- data/lib/pact_broker/pacts/latest_pacts.rb +1 -0
- data/lib/pact_broker/pacts/latest_tagged_pact_publications.rb +11 -0
- data/lib/pact_broker/pacts/pact_params.rb +11 -1
- data/lib/pact_broker/pacts/pact_publication.rb +50 -0
- data/lib/pact_broker/pacts/pact_version.rb +39 -0
- data/lib/pact_broker/pacts/repository.rb +46 -36
- data/lib/pact_broker/pacts/service.rb +2 -2
- data/lib/pact_broker/repositories.rb +5 -0
- data/lib/pact_broker/services.rb +5 -0
- data/lib/pact_broker/ui/view_models/relationship.rb +38 -0
- data/lib/pact_broker/ui/views/relationships/show.haml +9 -0
- data/lib/pact_broker/verifications/repository.rb +45 -0
- data/lib/pact_broker/verifications/service.rb +40 -0
- data/lib/pact_broker/version.rb +1 -1
- data/lib/pact_broker/versions/parse_semantic_version.rb +9 -6
- data/lib/pact_broker/webhooks/service.rb +8 -9
- data/lib/pact_broker/webhooks/webhook.rb +1 -1
- data/pact_broker.gemspec +3 -4
- data/pact_broker_client-pact_broker.json +4 -4
- data/script/publish.sh +2 -2
- data/script/record_verification.sh +3 -0
- data/spec/features/delete_pact_spec.rb +1 -1
- data/spec/features/get_verifications_for_consumer_version_spec.rb +33 -0
- data/spec/features/publish_verification_spec.rb +28 -0
- data/spec/fixtures/a_consumer-a_provider-2.json +1 -1
- data/spec/fixtures/a_consumer-a_provider-3.json +1 -1
- data/spec/fixtures/a_consumer-a_provider-conflict.json +1 -1
- data/spec/fixtures/a_consumer-a_provider-merged.json +2 -2
- data/spec/fixtures/a_consumer-a_provider.json +1 -1
- data/spec/fixtures/consumer-provider.json +1 -1
- data/spec/fixtures/renderer_pact.json +1 -1
- data/spec/fixtures/verification.json +4 -0
- data/spec/lib/pact_broker/api/contracts/verification_contract_spec.rb +91 -0
- data/spec/lib/pact_broker/api/decorators/latest_pact_decorator_spec.rb +0 -18
- data/spec/lib/pact_broker/api/decorators/pact_decorator_spec.rb +6 -2
- data/spec/lib/pact_broker/api/decorators/pact_version_decorator_spec.rb +0 -3
- data/spec/lib/pact_broker/api/decorators/verification_decorator_spec.rb +61 -0
- data/spec/lib/pact_broker/api/decorators/verifications_decorator_spec.rb +42 -0
- data/spec/lib/pact_broker/api/decorators/version_decorator_spec.rb +4 -0
- data/spec/lib/pact_broker/api/renderers/html_pact_renderer_spec.rb +1 -1
- data/spec/lib/pact_broker/api/resources/latest_verifications_for_consumer_version_spec.rb +68 -0
- data/spec/lib/pact_broker/api/resources/pact_spec.rb +1 -1
- data/spec/lib/pact_broker/api/resources/pacticipants_spec.rb +1 -1
- data/spec/lib/pact_broker/api/resources/verifications_spec.rb +92 -0
- data/spec/lib/pact_broker/api/resources/webhooks_spec.rb +1 -1
- data/spec/lib/pact_broker/domain/order_versions_spec.rb +10 -30
- data/spec/lib/pact_broker/domain/verification_spec.rb +41 -0
- data/spec/lib/pact_broker/domain/version_spec.rb +26 -0
- data/spec/lib/pact_broker/domain/webhook_request_spec.rb +1 -3
- data/spec/lib/pact_broker/pacticipants/repository_spec.rb +0 -16
- data/spec/lib/pact_broker/pacticipants/service_spec.rb +4 -3
- data/spec/lib/pact_broker/pacts/pact_params_spec.rb +14 -1
- data/spec/lib/pact_broker/pacts/pact_version_spec.rb +50 -0
- data/spec/lib/pact_broker/pacts/repository_spec.rb +85 -36
- data/spec/lib/pact_broker/ui/view_models/relationship_spec.rb +48 -2
- data/spec/lib/pact_broker/verifications/repository_spec.rb +92 -0
- data/spec/lib/pact_broker/verifications/service_spec.rb +61 -0
- data/spec/lib/pact_broker/versions/parse_semantic_version_spec.rb +39 -0
- data/spec/lib/pact_broker/webhooks/service_spec.rb +3 -40
- data/spec/migrations/23_pact_versions_spec.rb +95 -0
- data/spec/migrations/24_populate_pact_contents_spec.rb +48 -0
- data/spec/migrations/34_latest_tagged_pacts_spec.rb +108 -0
- data/spec/migrations/34_pact_revisions_spec.rb +106 -0
- data/spec/support/database_cleaner.rb +8 -4
- data/spec/support/provider_state_builder.rb +22 -8
- metadata +81 -36
- data/lib/pact_broker/pacts/database_model.rb +0 -35
- data/lib/pact_broker/pacts/latest_tagged_pacts.rb +0 -11
- data/lib/pact_broker/pacts/pact_version_content.rb +0 -11
- data/lib/pact_broker/webhooks/job.rb +0 -46
- data/script/foo-bar.json +0 -22
- data/script/publish-new.sh +0 -7
- data/script/recreate-pg-db.sh +0 -7
- data/spec/lib/pact_broker/webhooks/job_spec.rb +0 -67
@@ -57,7 +57,7 @@ module PactBroker::Api
|
|
57
57
|
|
58
58
|
|
59
59
|
shared_examples "an update endpoint" do |http_method|
|
60
|
-
subject { self.send http_method, "/pacts/provider/Provider/consumer/Consumer/version/1.2", json, {'CONTENT_TYPE' => "application/json"} ; last_response }
|
60
|
+
subject { self.send http_method, "/pacts/provider/Provider/consumer/Consumer/version/1.2.3", json, {'CONTENT_TYPE' => "application/json"} ; last_response }
|
61
61
|
|
62
62
|
let(:response) { subject; last_response }
|
63
63
|
|
@@ -68,7 +68,7 @@ module PactBroker
|
|
68
68
|
|
69
69
|
it "creates a JSON representation of the new pacticipant" do
|
70
70
|
expect(decorator_class).to receive(:new).with(created_model)
|
71
|
-
expect(decorator).to receive(:to_json).with(
|
71
|
+
expect(decorator).to receive(:to_json).with(instance_of(Decorators::DecoratorContext))
|
72
72
|
subject
|
73
73
|
end
|
74
74
|
|
@@ -0,0 +1,92 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'pact_broker/api/resources/verifications'
|
3
|
+
require 'pact_broker/pacts/service'
|
4
|
+
require 'pact_broker/verifications/service'
|
5
|
+
|
6
|
+
module PactBroker
|
7
|
+
module Api
|
8
|
+
|
9
|
+
module Resources
|
10
|
+
|
11
|
+
describe Verifications do
|
12
|
+
|
13
|
+
describe "post" do
|
14
|
+
|
15
|
+
let(:url) { "/pacts/provider/Provider/consumer/Consumer/pact-version/1234/verifications" }
|
16
|
+
let(:request_body) { {some: 'params'}.to_json }
|
17
|
+
subject { post url, request_body, {'CONTENT_TYPE' => 'application/json' }; last_response }
|
18
|
+
let(:response_body) { JSON.parse(subject.body, {symbolize_names: true}) }
|
19
|
+
let(:verification) { double(PactBroker::Domain::Verification) }
|
20
|
+
let(:errors_empty) { true }
|
21
|
+
|
22
|
+
before do
|
23
|
+
allow(PactBroker::Verifications::Service).to receive(:create).and_return(verification)
|
24
|
+
allow(PactBroker::Verifications::Service).to receive(:errors).and_return(double(:errors, messages: ['errors'], empty?: errors_empty))
|
25
|
+
end
|
26
|
+
|
27
|
+
it "looks up the specified pact" do
|
28
|
+
allow(Pacts::Service).to receive(:find_pact).with(instance_of(PactBroker::Pacts::PactParams))
|
29
|
+
end
|
30
|
+
|
31
|
+
context "when the pact does not exist" do
|
32
|
+
before do
|
33
|
+
allow(Pacts::Service).to receive(:find_pact).and_return(nil)
|
34
|
+
end
|
35
|
+
|
36
|
+
it "returns a 404" do
|
37
|
+
expect(subject.status).to eq 404
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
context "when the pact exists" do
|
42
|
+
let(:pact) { instance_double("PactBroker::Domain::Pact") }
|
43
|
+
let(:next_verification_number) { "2" }
|
44
|
+
let(:serialised_verification) { {some: 'verification'}.to_json }
|
45
|
+
let(:decorator) { instance_double('PactBroker::Api::Decorators::VerificationDecorator', to_json: serialised_verification) }
|
46
|
+
|
47
|
+
before do
|
48
|
+
allow(Pacts::Service).to receive(:find_pact).and_return(pact)
|
49
|
+
allow(PactBroker::Verifications::Service).to receive(:next_number_for).and_return(next_verification_number)
|
50
|
+
allow(PactBroker::Api::Decorators::VerificationDecorator).to receive(:new).and_return(decorator)
|
51
|
+
end
|
52
|
+
|
53
|
+
it "returns a 201" do
|
54
|
+
expect(subject.status).to eq 201
|
55
|
+
end
|
56
|
+
|
57
|
+
it "returns the path of the newly created resource in the headers" do
|
58
|
+
expect(subject.headers['Location']).to end_with("/verifications/2")
|
59
|
+
end
|
60
|
+
|
61
|
+
it "stores the verification in the database" do
|
62
|
+
expect(PactBroker::Verifications::Service).to receive(:create).with(next_verification_number, hash_including('some' => 'params'), pact)
|
63
|
+
subject
|
64
|
+
end
|
65
|
+
|
66
|
+
it "serialises the newly created verification" do
|
67
|
+
expect(PactBroker::Api::Decorators::VerificationDecorator).to receive(:new).with(verification)
|
68
|
+
expect(decorator).to receive(:to_json)
|
69
|
+
subject
|
70
|
+
end
|
71
|
+
|
72
|
+
it "returns the serialised verification in the response body" do
|
73
|
+
expect(subject.body).to eq serialised_verification
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
context "when invalid parameters are used" do
|
78
|
+
let(:errors_empty) { false }
|
79
|
+
|
80
|
+
it "returns a 400 status" do
|
81
|
+
expect(subject.status).to eq 400
|
82
|
+
end
|
83
|
+
|
84
|
+
it "sets errors on the response" do
|
85
|
+
expect(response_body[:errors]).to eq ['errors']
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
@@ -27,7 +27,7 @@ module PactBroker::Api
|
|
27
27
|
|
28
28
|
it "generates a JSON representation of the webhook" do
|
29
29
|
expect(Decorators::WebhooksDecorator).to receive(:new).with(webhooks)
|
30
|
-
expect(decorator).to receive(:to_json).with(
|
30
|
+
expect(decorator).to receive(:to_json).with(instance_of(Decorators::DecoratorContext))
|
31
31
|
subject
|
32
32
|
end
|
33
33
|
|
@@ -4,40 +4,20 @@ require 'pact_broker/domain/order_versions.rb'
|
|
4
4
|
|
5
5
|
describe PactBroker::Domain::OrderVersions do
|
6
6
|
|
7
|
-
context "when order_versions_by_date is false (the default)" do
|
8
|
-
before do
|
9
|
-
ProviderStateBuilder.new
|
10
|
-
.create_condor
|
11
|
-
.create_condor_version('1.3.0')
|
12
|
-
.create_condor_version('1.5.0')
|
13
|
-
.create_condor_version('1.4.0')
|
14
|
-
.create_condor_version('1.6.0')
|
15
|
-
end
|
16
7
|
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
8
|
+
before do
|
9
|
+
ProviderStateBuilder.new
|
10
|
+
.create_condor
|
11
|
+
.create_condor_version('1.3.0')
|
12
|
+
.create_condor_version('1.5.0')
|
13
|
+
.create_condor_version('1.4.0')
|
23
14
|
end
|
24
15
|
|
25
|
-
|
26
|
-
|
27
|
-
allow(PactBroker.configuration).to receive(:order_versions_by_date).and_return(true)
|
28
|
-
end
|
29
|
-
let(:consumer) { ProviderStateBuilder.new.create_consumer.and_return(:consumer) }
|
30
|
-
let!(:version_1) { PactBroker::Domain::Version.create(pacticipant_id: consumer.id, number: '2', created_at: DateTime.new(2017)) }
|
31
|
-
let!(:version_2) { PactBroker::Domain::Version.create(pacticipant_id: consumer.id, number: '1', created_at: DateTime.new(2017)) }
|
32
|
-
let!(:version_3) { PactBroker::Domain::Version.create(pacticipant_id: consumer.id, number: '3', created_at: DateTime.new(2016)) }
|
33
|
-
let!(:version_4) { PactBroker::Domain::Version.create(pacticipant_id: consumer.id, number: '4', created_at: DateTime.new(2018)) }
|
34
|
-
|
35
|
-
let(:ordered_versions) { PactBroker::Domain::Version.order(:order).all.collect(&:number) }
|
36
|
-
|
37
|
-
it "orders by date, then id" do
|
38
|
-
expect(ordered_versions).to eq(['3', '2', '1', '4'])
|
39
|
-
end
|
16
|
+
let(:ordered_versions) { PactBroker::Domain::Version.order(:order).all.collect(&:number) }
|
17
|
+
let(:condor) { PactBroker::Domain::Pacticipant.where(name: 'Condor').single_record }
|
40
18
|
|
19
|
+
it "orders the versions so they can be loaded from the database in order" do
|
20
|
+
expect(ordered_versions).to eq(['1.3.0','1.4.0', '1.5.0'])
|
41
21
|
end
|
42
22
|
|
43
23
|
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
require 'pact_broker/domain/verification'
|
2
|
+
|
3
|
+
module PactBroker
|
4
|
+
|
5
|
+
module Domain
|
6
|
+
describe Verification do
|
7
|
+
|
8
|
+
describe "#consumer" do
|
9
|
+
let!(:consumer) do
|
10
|
+
ProviderStateBuilder.new
|
11
|
+
.create_consumer
|
12
|
+
.create_provider
|
13
|
+
.create_consumer_version
|
14
|
+
.create_pact
|
15
|
+
.create_verification
|
16
|
+
.and_return(:consumer)
|
17
|
+
end
|
18
|
+
|
19
|
+
it "returns the consumer for the verification" do
|
20
|
+
expect(Verification.order(:id).first.consumer).to eq consumer
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
describe "#provider" do
|
25
|
+
let!(:provider) do
|
26
|
+
ProviderStateBuilder.new
|
27
|
+
.create_consumer
|
28
|
+
.create_provider
|
29
|
+
.create_consumer_version
|
30
|
+
.create_pact
|
31
|
+
.create_verification
|
32
|
+
.and_return(:provider)
|
33
|
+
end
|
34
|
+
|
35
|
+
it "returns the provider for the verification" do
|
36
|
+
expect(Verification.order(:id).first.provider).to eq provider
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'pact_broker/domain/version'
|
2
|
+
|
3
|
+
module PactBroker
|
4
|
+
|
5
|
+
module Domain
|
6
|
+
|
7
|
+
describe Version do
|
8
|
+
describe "#latest_pact_publication" do
|
9
|
+
let!(:pact) do
|
10
|
+
ProviderStateBuilder.new
|
11
|
+
.create_consumer
|
12
|
+
.create_provider
|
13
|
+
.create_consumer_version
|
14
|
+
.create_pact
|
15
|
+
.revise_pact
|
16
|
+
.and_return(:pact)
|
17
|
+
end
|
18
|
+
let(:version) { Version.order(:id).last }
|
19
|
+
|
20
|
+
it "returns the latest pact revision for the consumer version" do
|
21
|
+
expect(version.latest_pact_publication.id).to eq pact.id
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -64,9 +64,7 @@ module PactBroker
|
|
64
64
|
|
65
65
|
it "logs the response" do
|
66
66
|
allow(PactBroker.logger).to receive(:info)
|
67
|
-
|
68
|
-
expect(PactBroker.logger).to receive(:info).with(/response.*302/)
|
69
|
-
expect(PactBroker.logger).to receive(:debug).with(/respbod/)
|
67
|
+
expect(PactBroker.logger).to receive(:info).with(/response.*302.*respbod/)
|
70
68
|
subject.execute
|
71
69
|
end
|
72
70
|
|
@@ -53,22 +53,6 @@ module PactBroker
|
|
53
53
|
|
54
54
|
end
|
55
55
|
|
56
|
-
describe "#find_all_pacticipant_versions_in_reverse_order" do
|
57
|
-
before do
|
58
|
-
ProviderStateBuilder.new
|
59
|
-
.create_consumer("Foo")
|
60
|
-
.create_consumer_version("1.2.3")
|
61
|
-
.create_consumer_version("4.5.6")
|
62
|
-
.create_consumer("Bar")
|
63
|
-
.create_consumer_version("8.9.0")
|
64
|
-
end
|
65
|
-
|
66
|
-
subject { Repository.new.find_all_pacticipant_versions_in_reverse_order "Foo" }
|
67
|
-
|
68
|
-
it "returns all the application versions for the given consumer" do
|
69
|
-
expect(subject.collect(&:number)).to eq ["4.5.6", "1.2.3"]
|
70
|
-
end
|
71
|
-
end
|
72
56
|
|
73
57
|
end
|
74
58
|
end
|
@@ -3,7 +3,6 @@ require 'pact_broker/pacticipants/service'
|
|
3
3
|
require 'pact_broker/domain/tag'
|
4
4
|
require 'pact_broker/domain/pact'
|
5
5
|
|
6
|
-
|
7
6
|
module PactBroker
|
8
7
|
|
9
8
|
module Pacticipants
|
@@ -101,14 +100,16 @@ module PactBroker
|
|
101
100
|
let(:consumer) { instance_double("PactBroker::Domain::Pacticipant")}
|
102
101
|
let(:provider) { instance_double("PactBroker::Domain::Pacticipant")}
|
103
102
|
let(:pact) { instance_double("PactBroker::Domain::Pact", consumer: consumer, provider: provider)}
|
103
|
+
let(:verification) { instance_double("PactBroker::Domain::Verification")}
|
104
104
|
let(:pacts) { [pact]}
|
105
105
|
|
106
106
|
before do
|
107
107
|
allow_any_instance_of(PactBroker::Pacts::Repository).to receive(:find_latest_pacts).and_return(pacts)
|
108
|
+
allow(PactBroker::Verifications::Service).to receive(:find_latest_verification_for).and_return(verification)
|
108
109
|
end
|
109
110
|
|
110
111
|
it "returns a list of relationships" do
|
111
|
-
expect(subject.find_relationships).to eq([PactBroker::Domain::Relationship.create(consumer, provider)])
|
112
|
+
expect(subject.find_relationships).to eq([PactBroker::Domain::Relationship.create(consumer, provider, pact, verification)])
|
112
113
|
end
|
113
114
|
|
114
115
|
end
|
@@ -155,7 +156,7 @@ module PactBroker
|
|
155
156
|
|
156
157
|
it "deletes the child pacts" do
|
157
158
|
expect{ delete_pacticipant }.to change{
|
158
|
-
PactBroker::Pacts::
|
159
|
+
PactBroker::Pacts::PactPublication.count
|
159
160
|
}.by(-2)
|
160
161
|
end
|
161
162
|
end
|
@@ -8,6 +8,7 @@ module PactBroker
|
|
8
8
|
let(:body) { load_fixture('a_consumer-a_provider.json') }
|
9
9
|
let(:consumer_version_number) { '1.2.3' }
|
10
10
|
let(:headers) { { 'X-Pact-Consumer-Version' => consumer_version_number, 'Host' => 'example.org' } }
|
11
|
+
let(:revision_number) { '1' }
|
11
12
|
|
12
13
|
describe "from_request" do
|
13
14
|
|
@@ -17,7 +18,8 @@ module PactBroker
|
|
17
18
|
{
|
18
19
|
consumer_name: 'Consumer',
|
19
20
|
provider_name: 'Provider',
|
20
|
-
consumer_version_number: '1.2.3'
|
21
|
+
consumer_version_number: '1.2.3',
|
22
|
+
revision_number: revision_number
|
21
23
|
}
|
22
24
|
end
|
23
25
|
|
@@ -35,6 +37,10 @@ module PactBroker
|
|
35
37
|
expect(subject.consumer_version_number).to eq "1.2.3"
|
36
38
|
end
|
37
39
|
|
40
|
+
it "extracts the revision_number from the path" do
|
41
|
+
expect(subject.revision_number).to eq "1"
|
42
|
+
end
|
43
|
+
|
38
44
|
it "extracts the json_content" do
|
39
45
|
expect(subject.json_content).to eq body
|
40
46
|
end
|
@@ -47,6 +53,13 @@ module PactBroker
|
|
47
53
|
expect(subject.provider_name_in_pact).to eq "A Provider"
|
48
54
|
end
|
49
55
|
|
56
|
+
context "with no revision_number" do
|
57
|
+
let(:revision_number) { nil }
|
58
|
+
it "the revision_number is null" do
|
59
|
+
expect(subject.revision_number).to be nil
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
50
63
|
context "with missing data" do
|
51
64
|
let(:body){ '' }
|
52
65
|
|
@@ -0,0 +1,50 @@
|
|
1
|
+
require 'pact_broker/pacts/pact_version'
|
2
|
+
|
3
|
+
module PactBroker
|
4
|
+
module Pacts
|
5
|
+
describe PactVersion do
|
6
|
+
|
7
|
+
describe "pacticipant names" do
|
8
|
+
subject(:pact_version) do
|
9
|
+
ProviderStateBuilder.new
|
10
|
+
.create_consumer("consumer")
|
11
|
+
.create_provider("provider")
|
12
|
+
.create_consumer_version("1.0.1")
|
13
|
+
.create_pact
|
14
|
+
PactVersion.order(:id).last
|
15
|
+
end
|
16
|
+
|
17
|
+
its(:consumer_name) { is_expected.to eq("consumer") }
|
18
|
+
its(:provider_name) { is_expected.to eq("provider") }
|
19
|
+
end
|
20
|
+
|
21
|
+
describe "#latest_pact_publication" do
|
22
|
+
|
23
|
+
end
|
24
|
+
|
25
|
+
describe "#latest_consumer_version_number" do
|
26
|
+
before do
|
27
|
+
builder = ProviderStateBuilder.new
|
28
|
+
builder
|
29
|
+
.create_consumer
|
30
|
+
.create_provider
|
31
|
+
.create_consumer_version("1.0.1")
|
32
|
+
.create_pact
|
33
|
+
.create_consumer_version("1.0.0")
|
34
|
+
second_consumer_version = builder.and_return(:consumer_version)
|
35
|
+
pact_publication = PactBroker::Pacts::PactPublication.order(:id).last
|
36
|
+
new_params = pact_publication.to_hash
|
37
|
+
new_params.delete(:id)
|
38
|
+
new_params[:revision_number] = 2
|
39
|
+
new_params[:consumer_version_id] = second_consumer_version.id
|
40
|
+
|
41
|
+
PactBroker::Pacts::PactPublication.create(new_params)
|
42
|
+
end
|
43
|
+
|
44
|
+
it "returns the latest consumer version that has a pact that has this content" do
|
45
|
+
expect(PactVersion.first.latest_consumer_version_number).to eq "1.0.1"
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
@@ -3,6 +3,8 @@
|
|
3
3
|
require 'pact_broker/pacts/repository'
|
4
4
|
require 'spec/support/provider_state_builder'
|
5
5
|
require 'pact_broker/pacts/pact_params'
|
6
|
+
require 'pact_broker/versions/repository'
|
7
|
+
require 'pact_broker/pacticipants/repository'
|
6
8
|
|
7
9
|
module PactBroker
|
8
10
|
module Pacts
|
@@ -14,13 +16,13 @@ module PactBroker
|
|
14
16
|
describe "create" do
|
15
17
|
let(:consumer) { Pacticipants::Repository.new.create name: 'Consumer' }
|
16
18
|
let(:provider) { Pacticipants::Repository.new.create name: 'Provider' }
|
17
|
-
let(:version) { Versions::Repository.new.create number: '1.2.3', pacticipant_id: consumer.id }
|
19
|
+
let(:version) { PactBroker::Versions::Repository.new.create number: '1.2.3', pacticipant_id: consumer.id }
|
18
20
|
let(:json_content) { {some: 'json'}.to_json }
|
19
21
|
|
20
|
-
subject { Repository.new.create version_id: version.id, provider_id: provider.id, json_content: json_content }
|
22
|
+
subject { Repository.new.create version_id: version.id, consumer_id: consumer.id, provider_id: provider.id, json_content: json_content }
|
21
23
|
|
22
24
|
it "saves the pact" do
|
23
|
-
expect{subject}.to change{
|
25
|
+
expect{subject}.to change{ PactPublication.count }.by(1)
|
24
26
|
end
|
25
27
|
|
26
28
|
it "returns a Pact::Model" do
|
@@ -34,22 +36,37 @@ module PactBroker
|
|
34
36
|
expect(subject.consumer_version.number).to eq '1.2.3'
|
35
37
|
expect(subject.json_content).to eq json_content
|
36
38
|
expect(subject.created_at).to be_instance_of(DateTime)
|
37
|
-
expect(subject.updated_at).to be_instance_of(DateTime)
|
38
39
|
end
|
39
40
|
|
40
41
|
context "when a pact already exists with the same content" do
|
41
42
|
let(:another_version) { Versions::Repository.new.create number: '2.0.0', pacticipant_id: consumer.id }
|
42
43
|
|
43
44
|
before do
|
44
|
-
Repository.new.create version_id: version.id, provider_id: provider.id, json_content: json_content
|
45
|
+
Repository.new.create version_id: version.id, consumer_id: consumer.id, provider_id: provider.id, json_content: json_content
|
45
46
|
end
|
46
47
|
|
47
48
|
subject do
|
48
|
-
Repository.new.create version_id: another_version.id, provider_id: provider.id, json_content: json_content
|
49
|
+
Repository.new.create version_id: another_version.id, consumer_id: consumer.id, provider_id: provider.id, json_content: json_content
|
49
50
|
end
|
50
51
|
|
51
|
-
it "reuses the same
|
52
|
-
expect { subject }.to change{
|
52
|
+
it "reuses the same PactVersion to save room" do
|
53
|
+
expect { subject }.to change{ PactVersion.count }.by(0)
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
context "when a pact already exists with the same content but with a different consumer/provider" do
|
58
|
+
let(:another_version) { Versions::Repository.new.create number: '2.0.0', pacticipant_id: consumer.id }
|
59
|
+
let(:another_provider) { Pacticipants::Repository.new.create name: 'Provider2' }
|
60
|
+
before do
|
61
|
+
Repository.new.create version_id: version.id, consumer_id: consumer.id, provider_id: another_provider.id, json_content: json_content
|
62
|
+
end
|
63
|
+
|
64
|
+
subject do
|
65
|
+
Repository.new.create version_id: another_version.id, consumer_id: consumer.id, provider_id: provider.id, json_content: json_content
|
66
|
+
end
|
67
|
+
|
68
|
+
it "does not reuse the same PactVersion to save room" do
|
69
|
+
expect { subject }.to change{ PactVersion.count }.by(1)
|
53
70
|
end
|
54
71
|
end
|
55
72
|
|
@@ -57,15 +74,15 @@ module PactBroker
|
|
57
74
|
let(:another_version) { Versions::Repository.new.create number: '2.0.0', pacticipant_id: consumer.id }
|
58
75
|
|
59
76
|
before do
|
60
|
-
Repository.new.create version_id: version.id, provider_id: provider.id, json_content: {some_other: 'json_content'}.to_json
|
77
|
+
Repository.new.create version_id: version.id, consumer_id: consumer.id, provider_id: provider.id, json_content: {some_other: 'json_content'}.to_json
|
61
78
|
end
|
62
79
|
|
63
80
|
subject do
|
64
|
-
Repository.new.create version_id: another_version.id, provider_id: provider.id, json_content: json_content
|
81
|
+
Repository.new.create version_id: another_version.id, consumer_id: consumer.id, provider_id: provider.id, json_content: json_content
|
65
82
|
end
|
66
83
|
|
67
|
-
it "creates a new
|
68
|
-
expect { subject }.to change{
|
84
|
+
it "creates a new PactVersion" do
|
85
|
+
expect { subject }.to change{ PactVersion.count }.by(1)
|
69
86
|
end
|
70
87
|
end
|
71
88
|
end
|
@@ -77,19 +94,16 @@ module PactBroker
|
|
77
94
|
end
|
78
95
|
|
79
96
|
before do
|
80
|
-
::DB::PACT_BROKER_DB[:
|
97
|
+
::DB::PACT_BROKER_DB[:pact_publications]
|
81
98
|
.where(id: existing_pact.id)
|
82
99
|
.update(
|
83
|
-
created_at: created_at
|
84
|
-
|
85
|
-
::DB::PACT_BROKER_DB[:pact_version_contents]
|
100
|
+
created_at: created_at)
|
101
|
+
::DB::PACT_BROKER_DB[:pact_versions]
|
86
102
|
.update(
|
87
|
-
created_at: created_at
|
88
|
-
updated_at: updated_at)
|
103
|
+
created_at: created_at)
|
89
104
|
end
|
90
105
|
|
91
106
|
let(:created_at) { DateTime.new(2014, 3, 2) }
|
92
|
-
let(:updated_at) { DateTime.new(2014, 3, 4) }
|
93
107
|
|
94
108
|
let(:original_json_content) { {some: 'json'}.to_json }
|
95
109
|
let(:json_content) { {some_other: 'json'}.to_json }
|
@@ -99,30 +113,48 @@ module PactBroker
|
|
99
113
|
|
100
114
|
subject { Repository.new.update existing_pact.id, json_content: json_content }
|
101
115
|
|
102
|
-
it "
|
103
|
-
expect
|
116
|
+
it "creates a new PactVersion" do
|
117
|
+
expect { subject }.to change{ PactBroker::Pacts::PactPublication.count }.by(1)
|
104
118
|
end
|
105
119
|
|
106
|
-
it "
|
107
|
-
expect
|
120
|
+
it "creates a new PactVersion" do
|
121
|
+
expect { subject }.to change{ PactBroker::Pacts::PactVersion.count }.by(1)
|
108
122
|
end
|
109
123
|
|
110
|
-
it "does not
|
111
|
-
|
124
|
+
it "does not change the existing PactVersion" do
|
125
|
+
existing_pvc = PactBroker::Pacts::PactVersion.order(:id).last
|
126
|
+
subject
|
127
|
+
existing_pvc_reloaded = PactBroker::Pacts::PactVersion.find(id: existing_pvc[:id])
|
128
|
+
expect(existing_pvc_reloaded).to eq(existing_pvc)
|
129
|
+
end
|
130
|
+
|
131
|
+
it "updates the existing content on the returned model" do
|
132
|
+
expect(subject.json_content).to eq json_content
|
112
133
|
end
|
113
134
|
|
135
|
+
it "sets the created_at timestamp" do
|
136
|
+
expect(subject.created_at).to_not eq created_at
|
137
|
+
end
|
138
|
+
|
139
|
+
it "increments the revision_number by 1" do
|
140
|
+
expect(subject.revision_number).to eq 2
|
141
|
+
end
|
114
142
|
end
|
115
143
|
|
116
144
|
context "when the content has not changed" do
|
117
145
|
|
118
146
|
subject { Repository.new.update existing_pact.id, json_content: original_json_content }
|
119
147
|
|
120
|
-
it "
|
121
|
-
expect
|
148
|
+
it "does not create a new PactVersion" do
|
149
|
+
expect { subject }.to_not change{ PactBroker::Pacts::PactPublication.count }
|
150
|
+
end
|
151
|
+
|
152
|
+
it "does not create a new PactVersion" do
|
153
|
+
expect { subject }.to_not change{ PactBroker::Pacts::PactVersion.count }
|
122
154
|
end
|
123
155
|
|
124
|
-
it "
|
125
|
-
expect(subject.
|
156
|
+
it "the json_content is the same" do
|
157
|
+
expect(subject.json_content).to eq original_json_content
|
126
158
|
end
|
127
159
|
|
128
160
|
it "does not update the created_at timestamp" do
|
@@ -138,6 +170,7 @@ module PactBroker
|
|
138
170
|
.create_consumer_version("1.2.3")
|
139
171
|
.create_provider(provider_name)
|
140
172
|
.create_pact
|
173
|
+
.revise_pact
|
141
174
|
.create_consumer_version("2.3.4")
|
142
175
|
.create_pact
|
143
176
|
.create_provider("Another Provider")
|
@@ -148,12 +181,12 @@ module PactBroker
|
|
148
181
|
|
149
182
|
subject { Repository.new.delete pact_params }
|
150
183
|
|
151
|
-
it "deletes the
|
152
|
-
expect { subject }.to change {
|
184
|
+
it "deletes all PactPublication for the specified consumer version" do
|
185
|
+
expect { subject }.to change { PactPublication.count }.by(-2)
|
153
186
|
end
|
154
187
|
|
155
188
|
it "does not delete the content because it may be used by another pact" do
|
156
|
-
expect { subject }.to change {
|
189
|
+
expect { subject }.to change { PactVersion.count }.by(0)
|
157
190
|
end
|
158
191
|
|
159
192
|
end
|
@@ -256,8 +289,9 @@ module PactBroker
|
|
256
289
|
end
|
257
290
|
|
258
291
|
describe "find_pact" do
|
259
|
-
|
260
|
-
ProviderStateBuilder.new
|
292
|
+
let!(:pact) do
|
293
|
+
builder = ProviderStateBuilder.new
|
294
|
+
pact = builder
|
261
295
|
.create_consumer("Consumer")
|
262
296
|
.create_consumer_version("1.2.2")
|
263
297
|
.create_provider("Provider")
|
@@ -265,11 +299,15 @@ module PactBroker
|
|
265
299
|
.create_consumer_version("1.2.4")
|
266
300
|
.create_consumer_version_tag("prod")
|
267
301
|
.create_pact
|
302
|
+
.revise_pact
|
303
|
+
.and_return(:pact)
|
304
|
+
builder
|
268
305
|
.create_consumer_version("1.2.6")
|
269
306
|
.create_pact
|
270
307
|
.create_provider("Another Provider")
|
271
308
|
.create_consumer_version("1.2.5")
|
272
309
|
.create_pact
|
310
|
+
pact
|
273
311
|
end
|
274
312
|
|
275
313
|
subject { Repository.new.find_pact "Consumer", "1.2.4", "Provider" }
|
@@ -282,6 +320,19 @@ module PactBroker
|
|
282
320
|
expect(subject.consumer_version.tags.first.name).to eq "prod"
|
283
321
|
expect(subject.json_content).to_not be_nil
|
284
322
|
end
|
323
|
+
|
324
|
+
context "with a pact_version_sha" do
|
325
|
+
subject { Repository.new.find_pact "Consumer", nil, "Provider", pact.pact_version_sha }
|
326
|
+
|
327
|
+
it "finds the pact with the given version and revision" do
|
328
|
+
expect(subject.pact_version_sha).to eq pact.pact_version_sha
|
329
|
+
expect(subject.consumer.name).to eq "Consumer"
|
330
|
+
expect(subject.provider.name).to eq "Provider"
|
331
|
+
expect(subject.consumer_version_number).to eq "1.2.4"
|
332
|
+
expect(subject.revision_number).to eq 2
|
333
|
+
|
334
|
+
end
|
335
|
+
end
|
285
336
|
end
|
286
337
|
|
287
338
|
describe "find_previous_pact" do
|
@@ -425,7 +476,6 @@ module PactBroker
|
|
425
476
|
|
426
477
|
it "has timestamps" do
|
427
478
|
expect(latest_prod_pact.created_at).to be_instance_of(DateTime)
|
428
|
-
expect(latest_prod_pact.updated_at).to be_instance_of(DateTime)
|
429
479
|
end
|
430
480
|
end
|
431
481
|
|
@@ -470,7 +520,6 @@ module PactBroker
|
|
470
520
|
it "includes the timestamps - need to update view" do
|
471
521
|
pacts = Repository.new.find_latest_pacts
|
472
522
|
|
473
|
-
expect(pacts[0].updated_at).to be_instance_of DateTime
|
474
523
|
expect(pacts[0].created_at).to be_instance_of DateTime
|
475
524
|
end
|
476
525
|
end
|