pact_broker 2.24.0 → 2.25.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +38 -0
- data/CONTRIBUTING.md +2 -2
- data/DEVELOPER_DOCUMENTATION.md +31 -27
- data/DEVELOPER_SETUP.md +3 -2
- data/config/database.yml +10 -0
- data/db/ddl_statements.rb +3 -0
- data/db/ddl_statements/head_matrix_v001.rb +31 -0
- data/db/ddl_statements/head_matrix_v002.rb +31 -0
- data/db/ddl_statements/latest_verification_ids_for_pact_versions_v001.rb +4 -0
- data/db/migrations/000028_create_all_pact_publications.rb +4 -1
- data/db/migrations/20180311_optimise_head_matrix.rb +5 -34
- data/db/migrations/20180523_create_latest_verifications_for_consumer_version_tags.rb +2 -0
- data/db/migrations/20180612_add_pacticipant_ids_to_verifications.rb +17 -0
- data/db/migrations/20180613_migrate_pacticipant_ids_for_verifications.rb +7 -0
- data/db/migrations/20180614_update_latest_verification_ids_for_consumer_and_provider.rb +27 -0
- data/db/migrations/20180615_add_consumer_id_to_pact_publications.rb +13 -0
- data/db/migrations/20180616_migrate_consumer_ids_for_pact_publications.rb +11 -0
- data/db/migrations/20180720_create_latest_pact_publication_ids.rb +25 -0
- data/db/migrations/20180721_migrate_latest_pact_publication_ids.rb +11 -0
- data/db/migrations/20180722_recreate_views.rb +43 -0
- data/db/migrations/20180723_create_latest_verification_ids.rb +23 -0
- data/db/migrations/20180724_migrate_latest_verification_ids.rb +18 -0
- data/db/migrations/20180726_recreate_views.rb +29 -0
- data/db/migrations/20180727_recreate_latest_verification_ids_for_consumer_version_tags.rb +34 -0
- data/db/migrations/20180728_truncate_materialized_matrix_tables.rb +20 -0
- data/db/migrations/20180729_create_latest_verification_ids_for_provider_versions.rb +8 -0
- data/db/migrations/20180730_create_latest_verifications_for_provider_versions.rb +33 -0
- data/db/migrations/20180731_update_head_matrix.rb +11 -0
- data/db/pact_broker_database.sqlite3 +0 -0
- data/lib/pact_broker/api.rb +3 -3
- data/lib/pact_broker/api/decorators/dashboard_text_decorator.rb +2 -2
- data/lib/pact_broker/api/pact_broker_urls.rb +1 -1
- data/lib/pact_broker/api/resources/base_resource.rb +0 -7
- data/lib/pact_broker/api/resources/index.rb +11 -9
- data/lib/pact_broker/api/resources/pact.rb +1 -3
- data/lib/pact_broker/api/resources/pacticipant.rb +1 -3
- data/lib/pact_broker/api/resources/tag.rb +1 -4
- data/lib/pact_broker/api/resources/verification.rb +2 -0
- data/lib/pact_broker/api/resources/version.rb +1 -3
- data/lib/pact_broker/app.rb +8 -0
- data/lib/pact_broker/certificates/certificate.rb +12 -0
- data/lib/pact_broker/config/setting.rb +12 -0
- data/lib/pact_broker/configuration.rb +2 -1
- data/lib/pact_broker/db.rb +6 -0
- data/lib/pact_broker/db/clean.rb +2 -7
- data/lib/pact_broker/db/data_migrations/set_consumer_ids_for_pact_publications.rb +29 -0
- data/lib/pact_broker/db/data_migrations/set_pacticipant_ids_for_verifications.rb +35 -0
- data/lib/pact_broker/db/migrate_data.rb +14 -0
- data/lib/pact_broker/doc/views/wip-provider-pacts.markdown +3 -0
- data/lib/pact_broker/domain/label.rb +12 -0
- data/lib/pact_broker/domain/pacticipant.rb +32 -1
- data/lib/pact_broker/domain/tag.rb +14 -1
- data/lib/pact_broker/domain/verification.rb +29 -0
- data/lib/pact_broker/domain/version.rb +25 -1
- data/lib/pact_broker/feature_toggle.rb +23 -0
- data/lib/pact_broker/index/service.rb +1 -0
- data/lib/pact_broker/matrix/head_row.rb +25 -20
- data/lib/pact_broker/matrix/repository.rb +0 -18
- data/lib/pact_broker/matrix/row.rb +24 -27
- data/lib/pact_broker/matrix/service.rb +0 -8
- data/lib/pact_broker/pacts/all_pact_publications.rb +15 -0
- data/lib/pact_broker/pacts/latest_pact_publication_id_by_consumer_version.rb +34 -0
- data/lib/pact_broker/pacts/latest_pact_publications.rb +15 -0
- data/lib/pact_broker/pacts/latest_pact_publications_by_consumer_version.rb +15 -0
- data/lib/pact_broker/pacts/latest_tagged_pact_publications.rb +16 -0
- data/lib/pact_broker/pacts/pact_publication.rb +24 -0
- data/lib/pact_broker/pacts/pact_version.rb +20 -0
- data/lib/pact_broker/pacts/repository.rb +37 -11
- data/lib/pact_broker/pacts/service.rb +9 -2
- data/lib/pact_broker/repositories/helpers.rb +20 -0
- data/lib/pact_broker/tags/tag_with_latest_flag.rb +8 -0
- data/lib/pact_broker/ui/view_models/index_item.rb +5 -1
- data/lib/pact_broker/ui/views/index/show.haml +1 -1
- data/lib/pact_broker/verifications/all_verifications.rb +13 -0
- data/lib/pact_broker/verifications/latest_verification_for_consumer_and_provider.rb +18 -0
- data/lib/pact_broker/verifications/latest_verification_for_consumer_version_tag.rb +19 -0
- data/lib/pact_broker/verifications/latest_verification_for_pact_version.rb +22 -0
- data/lib/pact_broker/verifications/latest_verification_id_for_pact_version_and_provider_version.rb +36 -0
- data/lib/pact_broker/verifications/repository.rb +23 -5
- data/lib/pact_broker/verifications/sequence.rb +4 -0
- data/lib/pact_broker/version.rb +1 -1
- data/lib/pact_broker/webhooks/execution.rb +16 -0
- data/lib/pact_broker/webhooks/latest_triggered_webhook.rb +14 -0
- data/lib/pact_broker/webhooks/triggered_webhook.rb +27 -0
- data/lib/pact_broker/webhooks/webhook.rb +26 -0
- data/lib/pact_broker/webhooks/webhook_event.rb +13 -0
- data/pact_broker.gemspec +1 -0
- data/script/recreate-docker-pg-db.sh +20 -0
- data/script/recreate-mysql-db.sh +1 -0
- data/spec/integration/webhooks/certificate_spec.rb +1 -1
- data/spec/lib/pact_broker/db/clean_spec.rb +1 -1
- data/spec/lib/pact_broker/db/data_migrations/set_consumer_ids_for_pact_publications_spec.rb +40 -0
- data/spec/lib/pact_broker/feature_toggle_spec.rb +74 -0
- data/spec/lib/pact_broker/matrix/head_row_spec.rb +0 -44
- data/spec/lib/pact_broker/matrix/repository_spec.rb +0 -20
- data/spec/lib/pact_broker/matrix/row_spec.rb +0 -56
- data/spec/lib/pact_broker/pacts/repository_spec.rb +61 -9
- data/spec/lib/pact_broker/pacts/service_spec.rb +65 -17
- data/spec/lib/pact_broker/ui/view_models/index_item_spec.rb +3 -2
- data/spec/migrations/44_add_provider_version_to_verification_spec.rb +0 -1
- data/spec/service_consumers/provider_states_for_pact_ruby.rb +14 -0
- data/spec/support/test_data_builder.rb +0 -18
- data/tasks/database/annotate.rb +40 -0
- data/tasks/db.rake +12 -0
- metadata +50 -3
- data/lib/pact_broker/verifications/latest_verifications_by_consumer_version.rb +0 -15
@@ -19,26 +19,6 @@ module PactBroker
|
|
19
19
|
rows.collect{ |r| shorten_row(r) }
|
20
20
|
end
|
21
21
|
|
22
|
-
describe "refresh" do
|
23
|
-
before do
|
24
|
-
td.create_pact_with_hierarchy("Foo", "1", "Bar")
|
25
|
-
Row.refresh(pacticipant_id: td.provider.id)
|
26
|
-
end
|
27
|
-
|
28
|
-
context "when deleting an object in the block" do
|
29
|
-
it "removes the relevant lines from the matrix" do
|
30
|
-
expect(Row.count).to_not eq 0
|
31
|
-
Repository.new.refresh(pacticipant_name: "Bar") { PactBroker::Pacticipants::Service.delete("Bar") }
|
32
|
-
expect(Row.count).to eq 0
|
33
|
-
end
|
34
|
-
|
35
|
-
it "yields the block" do
|
36
|
-
Repository.new.refresh(pacticipant_name: "Bar") { PactBroker::Pacticipants::Service.delete("Bar") }
|
37
|
-
expect(PactBroker::Domain::Pacticipant.where(name: "Bar").count).to eq 0
|
38
|
-
end
|
39
|
-
end
|
40
|
-
end
|
41
|
-
|
42
22
|
describe "find" do
|
43
23
|
before do
|
44
24
|
# A1 - B1
|
@@ -26,62 +26,6 @@ module PactBroker
|
|
26
26
|
end
|
27
27
|
end
|
28
28
|
|
29
|
-
describe "refresh", migration: true do
|
30
|
-
let(:td) { TestDataBuilder.new(auto_refresh_matrix: false) }
|
31
|
-
|
32
|
-
before do
|
33
|
-
PactBroker::Database.migrate
|
34
|
-
td.create_pact_with_hierarchy("Foo", "1", "Bar")
|
35
|
-
end
|
36
|
-
|
37
|
-
context "with only a consumer_id" do
|
38
|
-
subject { Row.refresh(consumer_id: td.consumer.id) }
|
39
|
-
|
40
|
-
it "refreshes the data for the consumer" do
|
41
|
-
subject
|
42
|
-
expect(Row.all.collect(&:values)).to contain_hash(provider_name: "Bar", consumer_name: "Foo")
|
43
|
-
end
|
44
|
-
end
|
45
|
-
|
46
|
-
context "with only a provider_id" do
|
47
|
-
subject { Row.refresh(provider_id: td.provider.id) }
|
48
|
-
|
49
|
-
it "refreshes the data for the provider" do
|
50
|
-
subject
|
51
|
-
expect(Row.all.collect(&:values)).to contain_hash(provider_name: "Bar", consumer_name: "Foo")
|
52
|
-
end
|
53
|
-
end
|
54
|
-
|
55
|
-
context "with both consumer_id and provider_id" do
|
56
|
-
subject { Row.refresh(provider_id: td.provider.id, consumer_id: td.consumer.id) }
|
57
|
-
|
58
|
-
it "refreshes the data for the consumer and provider" do
|
59
|
-
subject
|
60
|
-
expect(Row.all.collect(&:values)).to contain_hash(provider_name: "Bar", consumer_name: "Foo")
|
61
|
-
end
|
62
|
-
end
|
63
|
-
|
64
|
-
context "when there was existing data" do
|
65
|
-
it "deletes the existing data before inserting the new data" do
|
66
|
-
Row.refresh(provider_id: td.provider.id, consumer_id: td.consumer.id)
|
67
|
-
expect(Row.count).to eq 1
|
68
|
-
td.create_consumer_version("2")
|
69
|
-
.create_pact
|
70
|
-
Row.refresh(provider_id: td.provider.id, consumer_id: td.consumer.id)
|
71
|
-
expect(Row.count).to eq 2
|
72
|
-
end
|
73
|
-
end
|
74
|
-
|
75
|
-
context "with a pacticipant_id" do
|
76
|
-
subject { Row.refresh(pacticipant_id: td.provider.id) }
|
77
|
-
|
78
|
-
it "refreshes the data for both consumer and provider roles" do
|
79
|
-
subject
|
80
|
-
expect(Row.all.collect(&:values)).to contain_hash(provider_name: "Bar", consumer_name: "Foo")
|
81
|
-
end
|
82
|
-
end
|
83
|
-
end
|
84
|
-
|
85
29
|
describe "<=>" do
|
86
30
|
let(:row_1) do
|
87
31
|
Row.new(
|
@@ -24,6 +24,11 @@ module PactBroker
|
|
24
24
|
expect{subject}.to change{ PactPublication.count }.by(1)
|
25
25
|
end
|
26
26
|
|
27
|
+
it "sets the consumer_id" do
|
28
|
+
subject
|
29
|
+
expect(PactPublication.first.consumer_id).to eq consumer.id
|
30
|
+
end
|
31
|
+
|
27
32
|
it "returns a Pact::Model" do
|
28
33
|
expect(subject).to be_instance_of(PactBroker::Domain::Pact)
|
29
34
|
end
|
@@ -508,27 +513,74 @@ module PactBroker
|
|
508
513
|
.create_consumer("Consumer")
|
509
514
|
.create_consumer_version("1.2.2")
|
510
515
|
.create_provider("Provider")
|
516
|
+
.create_consumer_version_tag("a_tag")
|
517
|
+
.create_pact
|
518
|
+
.create_consumer_version("1.2.3")
|
511
519
|
.create_pact
|
512
520
|
.create_consumer_version("1.2.4")
|
521
|
+
.create_consumer_version_tag("another_tag")
|
513
522
|
.create_pact
|
514
|
-
.create_consumer_version("1.2.
|
523
|
+
.create_consumer_version("1.2.5")
|
524
|
+
.create_consumer_version_tag("a_tag")
|
525
|
+
.create_pact
|
526
|
+
.create_consumer_version("1.2.7")
|
527
|
+
.create_consumer_version_tag("another_tag")
|
515
528
|
.create_pact
|
516
529
|
.create_provider("Another Provider")
|
517
|
-
.create_consumer_version("1.2.
|
530
|
+
.create_consumer_version("1.2.6")
|
531
|
+
.create_consumer_version_tag("a_tag")
|
518
532
|
.create_pact
|
519
533
|
end
|
520
534
|
|
521
|
-
|
535
|
+
context "regardless of tag" do
|
536
|
+
context "when a previous version with a pact exists" do
|
522
537
|
|
523
|
-
|
538
|
+
let(:pact) { Repository.new.find_latest_pact "Consumer", "Provider", "another_tag" }
|
524
539
|
|
525
|
-
|
526
|
-
|
527
|
-
|
540
|
+
subject { Repository.new.find_previous_pact pact }
|
541
|
+
|
542
|
+
it "finds the previous pact" do
|
543
|
+
expect(subject.consumer_version_number).to eq "1.2.5"
|
544
|
+
end
|
545
|
+
|
546
|
+
it "sets the json_content" do
|
547
|
+
expect(subject.json_content).to_not be nil
|
548
|
+
end
|
549
|
+
end
|
528
550
|
end
|
529
551
|
|
530
|
-
|
531
|
-
|
552
|
+
context "by tag" do
|
553
|
+
context "when a previous version with a pact with a specific tag exists" do
|
554
|
+
|
555
|
+
let(:pact) { Repository.new.find_latest_pact "Consumer", "Provider", "a_tag" }
|
556
|
+
|
557
|
+
subject { Repository.new.find_previous_pact pact, "a_tag" }
|
558
|
+
|
559
|
+
it "finds the previous pact" do
|
560
|
+
expect(subject.consumer_version_number).to eq "1.2.2"
|
561
|
+
end
|
562
|
+
|
563
|
+
it "sets the json_content" do
|
564
|
+
expect(subject.json_content).to_not be nil
|
565
|
+
end
|
566
|
+
end
|
567
|
+
end
|
568
|
+
|
569
|
+
context "that is untagged" do
|
570
|
+
context "when a previous version with a an untagged pact exists" do
|
571
|
+
|
572
|
+
let(:pact) { Repository.new.find_latest_pact "Consumer", "Provider" }
|
573
|
+
|
574
|
+
subject { Repository.new.find_previous_pact pact, :untagged }
|
575
|
+
|
576
|
+
it "finds the previous pact" do
|
577
|
+
expect(subject.consumer_version_number).to eq "1.2.3"
|
578
|
+
end
|
579
|
+
|
580
|
+
it "sets the json_content" do
|
581
|
+
expect(subject.json_content).to_not be nil
|
582
|
+
end
|
583
|
+
end
|
532
584
|
end
|
533
585
|
end
|
534
586
|
|
@@ -34,35 +34,83 @@ module PactBroker
|
|
34
34
|
let(:json_content) { { 'some' => 'json'}.to_json }
|
35
35
|
let(:pact) { instance_double(PactBroker::Domain::Pact, json_content: json_content)}
|
36
36
|
|
37
|
-
before do
|
38
|
-
allow_any_instance_of(Pacts::Repository).to receive(:find_previous_pact).and_return(previous_pact)
|
39
|
-
end
|
40
|
-
|
41
37
|
subject { Service.pact_is_new_or_pact_has_changed_since_previous_version? pact }
|
42
38
|
|
43
|
-
context "when
|
44
|
-
|
45
|
-
|
39
|
+
context "when consumer version is untagged" do
|
40
|
+
before do
|
41
|
+
allow(pact).to receive(:consumer_version_tag_names).and_return([]);
|
42
|
+
allow_any_instance_of(Pacts::Repository).to receive(:find_previous_pact).with(pact, :untagged).and_return(previous_pact)
|
43
|
+
end
|
44
|
+
|
45
|
+
context "when a previous pact is found" do
|
46
|
+
let(:previous_pact) { instance_double(PactBroker::Domain::Pact, json_content: previous_json_content)}
|
47
|
+
let(:previous_json_content) { {'some' => 'json'}.to_json }
|
46
48
|
|
47
|
-
|
48
|
-
|
49
|
-
|
49
|
+
context "when the json_content is the same" do
|
50
|
+
it "returns false" do
|
51
|
+
expect(subject).to be_falsey
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
context "when the json_content is not the same" do
|
56
|
+
let(:previous_json_content) { {'some-other' => 'json'}.to_json }
|
57
|
+
it "returns truthy" do
|
58
|
+
expect(subject).to be_truthy
|
59
|
+
end
|
50
60
|
end
|
51
61
|
end
|
52
62
|
|
53
|
-
context "when
|
54
|
-
let(:
|
55
|
-
|
63
|
+
context "when a previous pact is not found" do
|
64
|
+
let(:previous_pact) { nil }
|
65
|
+
|
66
|
+
it "returns true" do
|
56
67
|
expect(subject).to be_truthy
|
57
68
|
end
|
58
69
|
end
|
59
70
|
end
|
60
71
|
|
61
|
-
context "when
|
62
|
-
|
72
|
+
context "when consumer version has two tags" do
|
73
|
+
before do
|
74
|
+
allow(pact).to receive(:consumer_version_tag_names).and_return(['tag_1', 'tag_2']);
|
75
|
+
allow_any_instance_of(Pacts::Repository).to receive(:find_previous_pact).with(pact, 'tag_1').and_return(previous_pact_tag_1)
|
76
|
+
allow_any_instance_of(Pacts::Repository).to receive(:find_previous_pact).with(pact, 'tag_2').and_return(previous_pact_tag_2)
|
77
|
+
end
|
78
|
+
|
79
|
+
context "when a previous pact is found for both tags" do
|
80
|
+
let(:previous_pact_tag_1) { instance_double(PactBroker::Domain::Pact, json_content: previous_json_content_tag_1)}
|
81
|
+
let(:previous_json_content_tag_1) { {'some' => 'json'}.to_json }
|
82
|
+
|
83
|
+
let(:previous_pact_tag_2) { instance_double(PactBroker::Domain::Pact, json_content: previous_json_content_tag_2)}
|
84
|
+
let(:previous_json_content_tag_2) { {'some' => 'json'}.to_json }
|
63
85
|
|
64
|
-
|
65
|
-
|
86
|
+
context "when the json_content of both previous pacts and new pact is the same" do
|
87
|
+
it "returns false" do
|
88
|
+
expect(subject).to be_falsey
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
context "when the json_content of first previous pact is not the same" do
|
93
|
+
let(:previous_json_content_tag_1) { {'some-other' => 'json'}.to_json }
|
94
|
+
it "returns truthy" do
|
95
|
+
expect(subject).to be_truthy
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
context "when the json_content of second previous pact not the same" do
|
100
|
+
let(:previous_json_content_tag_2) { {'some-other' => 'json'}.to_json }
|
101
|
+
it "returns truthy" do
|
102
|
+
expect(subject).to be_truthy
|
103
|
+
end
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
context "when no previous pacts are found" do
|
108
|
+
let(:previous_pact_tag_1) { nil }
|
109
|
+
let(:previous_pact_tag_2) { nil }
|
110
|
+
|
111
|
+
it "returns true" do
|
112
|
+
expect(subject).to be_truthy
|
113
|
+
end
|
66
114
|
end
|
67
115
|
end
|
68
116
|
end
|
@@ -9,7 +9,7 @@ module PactBroker
|
|
9
9
|
|
10
10
|
let(:consumer) { instance_double("PactBroker::Domain::Pacticipant", name: 'Consumer Name')}
|
11
11
|
let(:provider) { instance_double("PactBroker::Domain::Pacticipant", name: 'Provider Name')}
|
12
|
-
let(:latest_pact) { instance_double("PactBroker::Domain::Pact") }
|
12
|
+
let(:latest_pact) { instance_double("PactBroker::Domain::Pact", consumer_version_number: "1.2.3") }
|
13
13
|
let(:latest_verification) { instance_double("PactBroker::Domain::Verification") }
|
14
14
|
let(:domain_relationship) { PactBroker::Domain::IndexItem.new(consumer, provider, latest_pact, latest, latest_verification, [], [], tags, latest_verification_latest_tags)}
|
15
15
|
let(:tags) { [] }
|
@@ -22,7 +22,8 @@ module PactBroker
|
|
22
22
|
|
23
23
|
its(:consumer_name) { should eq 'Consumer Name'}
|
24
24
|
its(:provider_name) { should eq 'Provider Name'}
|
25
|
-
its(:
|
25
|
+
its(:latest_pact_url) { should eq "/pacts/provider/Provider%20Name/consumer/Consumer%20Name/latest" }
|
26
|
+
its(:pact_url) { should eq "/pacts/provider/Provider%20Name/consumer/Consumer%20Name/version/1.2.3" }
|
26
27
|
its(:pact_matrix_url) { should eq "/matrix/provider/Provider%20Name/consumer/Consumer%20Name" }
|
27
28
|
its(:consumer_group_url) { should eq "/groups/Consumer%20Name" }
|
28
29
|
its(:provider_group_url) { should eq "/groups/Provider%20Name" }
|
@@ -6,7 +6,6 @@ describe 'add provider version relationship to verification (migrate 42-44)', mi
|
|
6
6
|
let(:now) { DateTime.new(2018, 2, 2) }
|
7
7
|
let!(:consumer) { create(:pacticipants, {name: 'Consumer', created_at: now, updated_at: now}) }
|
8
8
|
let!(:provider) { create(:pacticipants, {name: 'Provider', created_at: now, updated_at: now}) }
|
9
|
-
let!(:provider) { create(:pacticipants, {name: 'Provider', created_at: now, updated_at: now}) }
|
10
9
|
let!(:consumer_version) { create(:versions, {number: '1.2.3', order: 1, pacticipant_id: consumer[:id], created_at: now, updated_at: now}) }
|
11
10
|
let!(:pact_version) { create(:pact_versions, {content: {some: 'json'}.to_json, sha: '1234', consumer_id: consumer[:id], provider_id: provider[:id], created_at: now}) }
|
12
11
|
let!(:pact_publication) do
|
@@ -6,6 +6,20 @@ Pact.provider_states_for "Pact Ruby" do
|
|
6
6
|
no_op
|
7
7
|
end
|
8
8
|
|
9
|
+
provider_state "the relation for retrieving WIP pacts exists in the index resource" do
|
10
|
+
no_op
|
11
|
+
end
|
12
|
+
|
13
|
+
provider_state "consumer-1 has a WIP pact with provider provider-1" do
|
14
|
+
set_up do
|
15
|
+
TestDataBuilder.new
|
16
|
+
.create_provider('provider-1')
|
17
|
+
.create_consumer('consumer-1')
|
18
|
+
.create_consumer_version('1.3.0')
|
19
|
+
.create_pact
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
9
23
|
provider_state 'consumer-1 and consumer-2 have pacts with provider provider-1' do
|
10
24
|
set_up do
|
11
25
|
TestDataBuilder.new
|
@@ -40,28 +40,14 @@ class TestDataBuilder
|
|
40
40
|
attr_reader :webhook
|
41
41
|
attr_reader :webhook_execution
|
42
42
|
attr_reader :triggered_webhook
|
43
|
-
attr_accessor :auto_refresh_matrix
|
44
43
|
|
45
44
|
def initialize(params = {})
|
46
|
-
@auto_refresh_matrix = params.fetch(:auto_refresh_matrix, true)
|
47
45
|
end
|
48
46
|
|
49
47
|
def comment *args
|
50
48
|
self
|
51
49
|
end
|
52
50
|
|
53
|
-
def refresh_matrix
|
54
|
-
if auto_refresh_matrix
|
55
|
-
params = {}
|
56
|
-
params[:consumer_name] = consumer.name if consumer
|
57
|
-
params[:provider_name] = provider.name if provider
|
58
|
-
matrix_service.refresh(params)
|
59
|
-
# Row is not used in production code, but the tests depend on it
|
60
|
-
# Technically this code is expecting ids, but it will work with names too
|
61
|
-
PactBroker::Matrix::Row.refresh(params)
|
62
|
-
end
|
63
|
-
end
|
64
|
-
|
65
51
|
def create_pricing_service
|
66
52
|
@pricing_service_id = pacticipant_repository.create(:name => 'Pricing Service', :repository_url => 'git@git.realestate.com.au:business-systems/pricing-service').save(raise_on_save_failure: true).id
|
67
53
|
self
|
@@ -206,7 +192,6 @@ class TestDataBuilder
|
|
206
192
|
def create_consumer_version_tag tag_name, params = {}
|
207
193
|
params.delete(:comment)
|
208
194
|
@tag = PactBroker::Domain::Tag.create(name: tag_name, version: @consumer_version)
|
209
|
-
refresh_matrix
|
210
195
|
self
|
211
196
|
end
|
212
197
|
|
@@ -227,7 +212,6 @@ class TestDataBuilder
|
|
227
212
|
set_created_at_if_set params[:created_at], :pact_publications, {id: @pact.id}
|
228
213
|
set_created_at_if_set params[:created_at], :pact_versions, {sha: @pact.pact_version_sha}
|
229
214
|
@pact = PactBroker::Pacts::PactPublication.find(id: @pact.id).to_domain
|
230
|
-
refresh_matrix
|
231
215
|
self
|
232
216
|
end
|
233
217
|
|
@@ -241,7 +225,6 @@ class TestDataBuilder
|
|
241
225
|
def revise_pact json_content = nil
|
242
226
|
json_content = json_content ? json_content : {random: rand}.to_json
|
243
227
|
@pact = PactBroker::Pacts::Repository.new.update(@pact.id, json_content: json_content)
|
244
|
-
refresh_matrix
|
245
228
|
self
|
246
229
|
end
|
247
230
|
|
@@ -328,7 +311,6 @@ class TestDataBuilder
|
|
328
311
|
PactBroker::Domain::Tag.create(name: tag_name, version: @provider_version)
|
329
312
|
end
|
330
313
|
end
|
331
|
-
refresh_matrix
|
332
314
|
self
|
333
315
|
end
|
334
316
|
|
@@ -0,0 +1,40 @@
|
|
1
|
+
require 'sequel/annotate'
|
2
|
+
|
3
|
+
module PactBroker
|
4
|
+
class Annotate
|
5
|
+
def self.call
|
6
|
+
annotation_configuration.each_pair do | klass, path |
|
7
|
+
puts "Annotating #{klass}"
|
8
|
+
sa = Sequel::Annotate.new(klass)
|
9
|
+
sa.annotate(path)
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.annotation_configuration
|
14
|
+
sequel_domain_classes.each_with_object({}) do | klass, configs |
|
15
|
+
file_path = file_path_for_class(klass)
|
16
|
+
if File.exist?(file_path)
|
17
|
+
configs[klass] = file_path
|
18
|
+
else
|
19
|
+
puts "Skipping annotation for #{klass} as the generated file path #{file_path} does not exist"
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def self.sequel_domain_classes
|
25
|
+
|
26
|
+
Dir.chdir("lib") { Dir.glob("**/*.rb") }.sort.each do | path |
|
27
|
+
require path
|
28
|
+
end
|
29
|
+
|
30
|
+
ObjectSpace
|
31
|
+
.each_object(::Class).select {|klass| klass < ::Sequel::Model }
|
32
|
+
.select{ |klass| klass.name && klass.name.start_with?("PactBroker::") }
|
33
|
+
.sort{ | c1, c2| c1.name <=> c2.name }
|
34
|
+
end
|
35
|
+
|
36
|
+
def self.file_path_for_class klass
|
37
|
+
"lib/" + klass.name.gsub('::', '/').gsub(/([a-z])([A-Z])/) {|match| match[0] + "_" + match[1].downcase }.downcase + ".rb"
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
data/tasks/db.rake
CHANGED
@@ -96,6 +96,14 @@ namespace :db do
|
|
96
96
|
PactBroker::Database.ensure_database_dir_exists
|
97
97
|
end
|
98
98
|
|
99
|
+
desc 'Annotate the Sequel domain classes with schema information'
|
100
|
+
task :annotate =>['db:set_postgres_database_adapter', 'db:migrate'] do
|
101
|
+
load 'tasks/database/annotate.rb'
|
102
|
+
require 'pact_broker/db'
|
103
|
+
PactBroker::DB.connection = PactBroker::Database.database
|
104
|
+
PactBroker::Annotate.call
|
105
|
+
end
|
106
|
+
|
99
107
|
# task :create => 'db:env' do
|
100
108
|
# PactBroker::Database.create
|
101
109
|
# end
|
@@ -105,6 +113,10 @@ namespace :db do
|
|
105
113
|
ENV['RACK_ENV'] = 'test'
|
106
114
|
end
|
107
115
|
|
116
|
+
task :set_postgres_database_adapter do
|
117
|
+
ENV['DATABASE_ADAPTER'] = 'postgres'
|
118
|
+
end
|
119
|
+
|
108
120
|
# Private
|
109
121
|
task 'env:nonprod' => ['bundler:setup'] do
|
110
122
|
# Allow default RACK_ENV to be set when not in production
|