pact_broker 1.5.0 → 1.6.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 +5 -1
- data/README.md +1 -1
- data/lib/pact_broker/api/decorators/pact_decorator.rb +6 -1
- data/lib/pact_broker/api/renderers/html_pact_renderer.rb +9 -0
- data/lib/pact_broker/pacts/pact_params.rb +6 -3
- data/lib/pact_broker/version.rb +1 -1
- data/script/publish-2.sh +1 -1
- data/script/publish-not-a-pact.sh +3 -0
- data/script/publish.sh +1 -1
- data/spec/features/publish_not_a_pact_spec.rb +37 -0
- data/spec/features/publish_pact_spec.rb +0 -9
- data/spec/lib/pact_broker/api/decorators/pact_decorator_spec.rb +10 -3
- data/spec/lib/pact_broker/api/renderers/html_pact_renderer_spec.rb +22 -1
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e750616e35159ab4915a82899463fb4726c3f1a0
|
4
|
+
data.tar.gz: 194233d951cfa4bc3b4039efbaac97f19ecf88f7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fe4b4e81c2224d8ef238c3ddc8f5539b435dcadf5c87add833e9992d4e5ca79ad8463aff7a337601826be1fccd148cc709a6ca9b43c922a618ddf259b0b35eeb
|
7
|
+
data.tar.gz: 3a3b9df99e3e07546c2088297e6baf3b15d6928d0190642de12ed86bcd627b56412c40f486793954600f1c1aa368cd178fbea307f85d9f04e1db65be669b016e
|
data/CHANGELOG.md
CHANGED
@@ -1,6 +1,10 @@
|
|
1
1
|
Do this to generate your change history
|
2
2
|
|
3
|
-
$ git log --pretty=format:' * %h - %s (%an, %ad)'
|
3
|
+
$ git log --pretty=format:' * %h - %s (%an, %ad)' vX.Y.Z..HEAD
|
4
|
+
|
5
|
+
#### 1.6.0 (2015-03-20)
|
6
|
+
|
7
|
+
* e20e657 - Added support for JSON contracts that are not in the Pact format (e.g. top level is an array) (Beth Skurrie, Fri Mar 20 19:12:46 2015 +1100)
|
4
8
|
|
5
9
|
#### 1.5.0 (2015-02-20)
|
6
10
|
|
data/README.md
CHANGED
@@ -94,7 +94,7 @@ Use the HAL browser to view documentation as you browse.
|
|
94
94
|
* Copy the [example](/example) directory to the location you want to install the application.
|
95
95
|
* Modify the config.ru and Gemfile as desired (eg. choose database driver gem, set your database credentials. Use the "pg" gem if using Postgres.)
|
96
96
|
* Please ensure you use `encoding: 'utf8'` in your Sequel options to avoid encoding issues.
|
97
|
-
* For production usage, use a web application server like [Phusion Passenger](https://www.phusionpassenger.com) or [Nginx]
|
97
|
+
* For production usage, use a web application server like [Phusion Passenger](https://www.phusionpassenger.com) or [Nginx](http://nginx.org/) to serve the Pact Broker application.
|
98
98
|
* Deploy to your location of choice.
|
99
99
|
|
100
100
|
[decouple]: http://techblog.realestate.com.au/enter-the-pact-matrix-or-how-to-decouple-the-release-cycles-of-your-microservices/
|
@@ -13,7 +13,12 @@ module PactBroker
|
|
13
13
|
include Timestamps
|
14
14
|
|
15
15
|
def to_hash(options = {})
|
16
|
-
|
16
|
+
parsed_content = represented.content_hash
|
17
|
+
if parsed_content.is_a?(::Hash)
|
18
|
+
parsed_content.merge super
|
19
|
+
else
|
20
|
+
parsed_content
|
21
|
+
end
|
17
22
|
end
|
18
23
|
|
19
24
|
link :self do | options |
|
@@ -9,6 +9,8 @@ module PactBroker
|
|
9
9
|
module Renderers
|
10
10
|
class HtmlPactRenderer
|
11
11
|
|
12
|
+
class NotAPactError < StandardError; end
|
13
|
+
|
12
14
|
def self.call pact
|
13
15
|
new(pact).call
|
14
16
|
end
|
@@ -69,6 +71,11 @@ module PactBroker
|
|
69
71
|
|
70
72
|
def markdown
|
71
73
|
Pact::Doc::Markdown::ConsumerContractRenderer.call consumer_contract
|
74
|
+
rescue NotAPactError
|
75
|
+
heading = "### A contract between #{@pact.consumer.name} and #{@pact.provider.name}"
|
76
|
+
warning = "_Note: this contract could not be parsed to a Pact, showing raw content instead._"
|
77
|
+
pretty_json = JSON.pretty_generate(@pact.content_hash)
|
78
|
+
"#{heading}\n#{warning}\n```json\n#{pretty_json}\n```\n"
|
72
79
|
end
|
73
80
|
|
74
81
|
def html
|
@@ -77,6 +84,8 @@ module PactBroker
|
|
77
84
|
|
78
85
|
def consumer_contract
|
79
86
|
Pact::ConsumerContract.from_json(@json_content)
|
87
|
+
rescue
|
88
|
+
raise NotAPactError
|
80
89
|
end
|
81
90
|
|
82
91
|
end
|
@@ -12,18 +12,21 @@ module PactBroker
|
|
12
12
|
|
13
13
|
def self.from_request request, path_info
|
14
14
|
json_content = request.body.to_s
|
15
|
-
|
15
|
+
parsed_content = begin
|
16
16
|
JSON.parse(json_content, PACT_PARSING_OPTIONS)
|
17
17
|
rescue
|
18
18
|
{}
|
19
19
|
end
|
20
20
|
|
21
|
+
consumer_name_in_pact = parsed_content.is_a?(Hash) ? parsed_content.fetch('consumer',{})['name'] : nil
|
22
|
+
provider_name_in_pact = parsed_content.is_a?(Hash) ? parsed_content.fetch('provider',{})['name'] : nil
|
23
|
+
|
21
24
|
new(
|
22
25
|
consumer_name: path_info.fetch(:consumer_name),
|
23
26
|
provider_name: path_info.fetch(:provider_name),
|
24
27
|
consumer_version_number: path_info.fetch(:consumer_version_number),
|
25
|
-
consumer_name_in_pact:
|
26
|
-
provider_name_in_pact:
|
28
|
+
consumer_name_in_pact: consumer_name_in_pact,
|
29
|
+
provider_name_in_pact: provider_name_in_pact,
|
27
30
|
json_content: json_content
|
28
31
|
)
|
29
32
|
end
|
data/lib/pact_broker/version.rb
CHANGED
data/script/publish-2.sh
CHANGED
@@ -1,3 +1,3 @@
|
|
1
1
|
curl -v -XPUT \-H "Content-Type: application/json" \
|
2
2
|
-d@spec/fixtures/a_consumer-a_provider-2.json \
|
3
|
-
http://localhost:9292/pacts/provider/A%20Provider/consumer/A%20Consumer/version/1.0.1
|
3
|
+
http://localhost:9292/pacts/provider/A%20Provider/consumer/A%20Consumer/version/1.0.1
|
data/script/publish.sh
CHANGED
@@ -1,3 +1,3 @@
|
|
1
1
|
curl -v -XPUT \-H "Content-Type: application/json" \
|
2
2
|
-d@spec/fixtures/a_consumer-a_provider.json \
|
3
|
-
http://localhost:9292/pacts/provider/A%20Provider/consumer/A%20Consumer/version/1.0.0
|
3
|
+
http://localhost:9292/pacts/provider/A%20Provider/consumer/A%20Consumer/version/1.0.0
|
@@ -0,0 +1,37 @@
|
|
1
|
+
describe "Publishing a contract that is not a pact" do
|
2
|
+
|
3
|
+
let(:path) { "/pacts/provider/A%20Provider/consumer/A%20Consumer/version/1.2.3" }
|
4
|
+
let(:parsed_response_body) { JSON.parse(subject.body) }
|
5
|
+
|
6
|
+
subject { put path, pact_content, {'CONTENT_TYPE' => 'application/json' }; last_response }
|
7
|
+
|
8
|
+
context "when the pact is another type of CDC that doesn't have the Consumer or Provider names in the expected places" do
|
9
|
+
let(:pact_content) { {a: 'not pact'}.to_json }
|
10
|
+
|
11
|
+
it "accepts the un-pact Pact" do
|
12
|
+
expect(subject.status).to be 201
|
13
|
+
end
|
14
|
+
|
15
|
+
it "returns the content" do
|
16
|
+
expect(parsed_response_body).to include 'a' => 'not pact'
|
17
|
+
end
|
18
|
+
|
19
|
+
it "returns _links" do
|
20
|
+
expect(parsed_response_body).to have_key '_links'
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
context "when the content is an array" do
|
25
|
+
|
26
|
+
let(:pact_content) { '[1]' }
|
27
|
+
|
28
|
+
it "accepts the un-pact Pact" do
|
29
|
+
expect(subject.status).to be 201
|
30
|
+
end
|
31
|
+
|
32
|
+
it "returns the content" do
|
33
|
+
expect(parsed_response_body).to eq [1]
|
34
|
+
end
|
35
|
+
|
36
|
+
end
|
37
|
+
end
|
@@ -46,13 +46,4 @@ describe "Publishing a pact" do
|
|
46
46
|
expect(subject).to be_a_json_error_response "does not match"
|
47
47
|
end
|
48
48
|
end
|
49
|
-
|
50
|
-
context "when the pact is another type of CDC that doesn't have the Consumer or Provider names in the expected places" do
|
51
|
-
let(:pact_content) { {}.to_json }
|
52
|
-
|
53
|
-
it "accepts the un-pact Pact" do
|
54
|
-
expect(subject.status).to be 201
|
55
|
-
end
|
56
|
-
end
|
57
|
-
|
58
49
|
end
|
@@ -9,20 +9,20 @@ module PactBroker
|
|
9
9
|
|
10
10
|
describe PactDecorator do
|
11
11
|
|
12
|
-
let(:
|
12
|
+
let(:content_hash) {
|
13
13
|
{
|
14
14
|
'consumer' => {'name' => 'Consumer'},
|
15
15
|
'provider' => {'name' => 'Provider'},
|
16
16
|
'interactions' => [],
|
17
17
|
'metadata' => {}
|
18
|
-
}
|
18
|
+
}
|
19
19
|
}
|
20
20
|
|
21
21
|
let(:base_url) { 'http://example.org' }
|
22
22
|
let(:created_at) { Time.new(2014, 3, 4) }
|
23
23
|
let(:updated_at) { Time.new(2014, 3, 5) }
|
24
24
|
let(:pact) { double('pact',
|
25
|
-
|
25
|
+
content_hash: content_hash,
|
26
26
|
created_at: created_at,
|
27
27
|
updated_at: updated_at,
|
28
28
|
consumer: consumer,
|
@@ -93,6 +93,13 @@ module PactBroker
|
|
93
93
|
it "includes a curie" do
|
94
94
|
expect(subject[:_links][:curies]).to eq [{ name: "pb", href: "http://example.org/doc/{rel}", templated: true }]
|
95
95
|
end
|
96
|
+
|
97
|
+
context "when the json_content is not a Hash" do
|
98
|
+
let(:content_hash) { [1] }
|
99
|
+
it "returns the plain JSON without any links" do
|
100
|
+
expect(subject).to eq content_hash
|
101
|
+
end
|
102
|
+
end
|
96
103
|
end
|
97
104
|
|
98
105
|
end
|
@@ -16,9 +16,10 @@ module PactBroker
|
|
16
16
|
end
|
17
17
|
|
18
18
|
let(:consumer) { double('consumer', name: 'Consumer')}
|
19
|
+
let(:provider) { double('provider', name: 'Provider')}
|
19
20
|
let(:created_at) { DateTime.new(2014, 02, 27) }
|
20
21
|
let(:json_content) { load_fixture('renderer_pact.json') }
|
21
|
-
let(:pact) { double('pact', json_content: json_content, updated_at: created_at, consumer_version_number: '1.2.3', consumer: consumer)}
|
22
|
+
let(:pact) { double('pact', json_content: json_content, updated_at: created_at, consumer_version_number: '1.2.3', consumer: consumer, provider: provider)}
|
22
23
|
let(:pact_url) { '/pact/url' }
|
23
24
|
|
24
25
|
before do
|
@@ -40,6 +41,26 @@ module PactBroker
|
|
40
41
|
expect(subject).to include("Date published:")
|
41
42
|
expect(subject).to include("Thu 27 Feb 2014, 11:00am +11:00")
|
42
43
|
end
|
44
|
+
|
45
|
+
context "when the content is not a valid pact, but is still JSON" do
|
46
|
+
before do
|
47
|
+
allow(pact).to receive(:content_hash).and_return(content_hash)
|
48
|
+
end
|
49
|
+
let(:json_content) { '[1]' }
|
50
|
+
let(:content_hash) { [1] }
|
51
|
+
|
52
|
+
it "includes a dismissive title" do
|
53
|
+
expect(subject).to include "A contract between Consumer and Provider"
|
54
|
+
end
|
55
|
+
|
56
|
+
it "includes a warning" do
|
57
|
+
expect(subject).to include "Note:"
|
58
|
+
end
|
59
|
+
|
60
|
+
it "renders the JSON in HTML" do
|
61
|
+
expect(subject).to match /\[\s+1\s+\]/m
|
62
|
+
end
|
63
|
+
end
|
43
64
|
end
|
44
65
|
|
45
66
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pact_broker
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.6.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Bethany Skurrie
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2015-
|
13
|
+
date: 2015-03-20 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: httparty
|
@@ -552,6 +552,7 @@ files:
|
|
552
552
|
- public/stylesheets/pact.css
|
553
553
|
- public/stylesheets/relationships.css
|
554
554
|
- script/publish-2.sh
|
555
|
+
- script/publish-not-a-pact.sh
|
555
556
|
- script/publish.sh
|
556
557
|
- script/update-hal-browser
|
557
558
|
- spec/features/create_webhook_spec.rb
|
@@ -559,6 +560,7 @@ files:
|
|
559
560
|
- spec/features/get_diff.rb
|
560
561
|
- spec/features/get_previous_distinct_version.rb
|
561
562
|
- spec/features/get_version.rb
|
563
|
+
- spec/features/publish_not_a_pact_spec.rb
|
562
564
|
- spec/features/publish_pact_spec.rb
|
563
565
|
- spec/features/update_pacticipant_spec.rb
|
564
566
|
- spec/fixtures/a_consumer-a_provider-2.json
|
@@ -709,6 +711,7 @@ test_files:
|
|
709
711
|
- spec/features/get_diff.rb
|
710
712
|
- spec/features/get_previous_distinct_version.rb
|
711
713
|
- spec/features/get_version.rb
|
714
|
+
- spec/features/publish_not_a_pact_spec.rb
|
712
715
|
- spec/features/publish_pact_spec.rb
|
713
716
|
- spec/features/update_pacticipant_spec.rb
|
714
717
|
- spec/fixtures/a_consumer-a_provider-2.json
|