diff --git a/lib/pact_broker/api/decorators/pact_decorator.rb b/lib/pact_broker/api/decorators/pact_decorator.rb index affffe15b..ce552e976 100644 --- a/lib/pact_broker/api/decorators/pact_decorator.rb +++ b/lib/pact_broker/api/decorators/pact_decorator.rb @@ -159,6 +159,13 @@ def to_hash(options = {}) } end + link :'pb:matrix-for-consumer-version' do | options | + { + title: "View matrix rows for the consumer version to which this pact belongs", + href: matrix_for_pacticipant_version_url(represented.consumer_version, options.fetch(:base_url)) + } + end + curies do | options | [{ name: :pb, diff --git a/lib/pact_broker/api/pact_broker_urls.rb b/lib/pact_broker/api/pact_broker_urls.rb index 1824ac941..3d3827e08 100644 --- a/lib/pact_broker/api/pact_broker_urls.rb +++ b/lib/pact_broker/api/pact_broker_urls.rb @@ -250,6 +250,14 @@ def matrix_url consumer_name, provider_name, base_url = '' "/matrix/provider/#{url_encode(provider_name)}/consumer/#{url_encode(consumer_name)}" end + def matrix_for_pacticipant_version_url(version, base_url = '') + query = { + q: [{ pacticipant: version.pacticipant.name, version: version.number }], + latestby: 'cvpv' + } + "#{base_url}/matrix?#{Rack::Utils.build_nested_query(query)}" + end + def matrix_url_from_params params, base_url = '' matrix_url(params.fetch(:consumer_name), params.fetch(:provider_name), base_url) end diff --git a/lib/pact_broker/api/renderers/html_pact_renderer.rb b/lib/pact_broker/api/renderers/html_pact_renderer.rb index dda1ec975..929597020 100644 --- a/lib/pact_broker/api/renderers/html_pact_renderer.rb +++ b/lib/pact_broker/api/renderers/html_pact_renderer.rb @@ -137,7 +137,7 @@ def pact_url end def matrix_url - PactBroker::Api::PactBrokerUrls.matrix_url_from_params({ consumer_name: @pact.consumer.name, provider_name: @pact.provider.name }, base_url) + PactBroker::Api::PactBrokerUrls.matrix_for_pacticipant_version_url(@pact.consumer_version, base_url) end def latest_pact_url diff --git a/lib/pact_broker/doc/views/pact/all-pact-versions.markdown b/lib/pact_broker/doc/views/pact/all-pact-versions.markdown index 86fa8d723..e329bf7aa 100644 --- a/lib/pact_broker/doc/views/pact/all-pact-versions.markdown +++ b/lib/pact_broker/doc/views/pact/all-pact-versions.markdown @@ -1,6 +1,7 @@ # All versions of a pact between a given consumer and provider Allowed methods: `GET`, `DELETE` + Path: `/pacts/provider/{provider}/consumer/{consumer}/versions` This resource returns a history of all the versions of the given pact between a consumer and provider. diff --git a/lib/pact_broker/doc/views/pact/latest-pact-version.markdown b/lib/pact_broker/doc/views/pact/latest-pact-version.markdown index 1a746038f..0bf340d3d 100644 --- a/lib/pact_broker/doc/views/pact/latest-pact-version.markdown +++ b/lib/pact_broker/doc/views/pact/latest-pact-version.markdown @@ -1,6 +1,6 @@ # Latest pact version -Allowed methods: GET +Allowed methods: `GET` The latest pact between this consumer and provider. diff --git a/spec/lib/pact_broker/api/pact_broker_urls_spec.rb b/spec/lib/pact_broker/api/pact_broker_urls_spec.rb index fe9d42d3d..5aaac9d62 100644 --- a/spec/lib/pact_broker/api/pact_broker_urls_spec.rb +++ b/spec/lib/pact_broker/api/pact_broker_urls_spec.rb @@ -27,6 +27,11 @@ module Api pact_version_sha: "1234", number: "1") end + let(:version) do + double('version', + pacticipant: consumer, + number: "2") + end matcher :match_route_in_api do |api| match do |url| @@ -127,6 +132,12 @@ module Api it { is_expected.to eq "http://example.org/pacts/provider/Bar%2FBar/consumer/Foo%2FFoo/version/123%2F456/verification-results/latest" } end end + + describe "matrix_for_pacticipant_version_url" do + subject { PactBrokerUrls.matrix_for_pacticipant_version_url(version, base_url) } + + it { is_expected.to eq "http://example.org/matrix?q[][pacticipant]=Foo%2FFoo&q[][version]=2&latestby=cvpv" } + end end end end diff --git a/spec/lib/pact_broker/api/renderers/html_pact_renderer_spec.rb b/spec/lib/pact_broker/api/renderers/html_pact_renderer_spec.rb index be2d88689..a9b9cfccb 100644 --- a/spec/lib/pact_broker/api/renderers/html_pact_renderer_spec.rb +++ b/spec/lib/pact_broker/api/renderers/html_pact_renderer_spec.rb @@ -12,6 +12,7 @@ module Renderers ENV['TZ'] = "Australia/Melbourne" PactBroker.configuration.enable_public_badge_access = true allow(PactBroker::Api::PactBrokerUrls).to receive(:pact_url).with('http://base', pact).and_return(pact_url) + allow(PactBroker::Api::PactBrokerUrls).to receive(:matrix_for_pacticipant_version_url).with(consumer_version, 'http://base').and_return(matrix_url) allow_any_instance_of(HtmlPactRenderer).to receive(:logger).and_return(logger) Timecop.freeze(created_at + 3) @@ -24,10 +25,22 @@ module Renderers let(:consumer) { double('consumer', name: 'Consumer')} let(:provider) { double('provider', name: 'Provider')} + let(:consumer_version) { double('consumer version') } let(:created_at) { DateTime.new(2014, 02, 27) } let(:json_content) { load_fixture('renderer_pact.json') } - let(:pact) { double('pact', json_content: json_content, consumer_version_number: '1.2.3', consumer: consumer, provider: provider, consumer_version_tag_names: ['prod', 'master'], created_at: created_at)} + let(:pact) do + double('pact', + json_content: json_content, + consumer_version_number: '1.2.3', + consumer: consumer, + provider: provider, + consumer_version_tag_names: ['prod', 'master'], + created_at: created_at, + consumer_version: consumer_version + ) + end let(:pact_url) { '/pact/url' } + let(:matrix_url) { '/matrix/url' } let(:options) do { base_url: 'http://base', @@ -64,6 +77,10 @@ module Renderers expect(subject).to include "[![Consumer/Provider Pact Status](http://badge)](http://base)" end + it "includes the matrix URL" do + expect(subject).to include matrix_url + end + context "when enable_public_badge_access is false" do before do PactBroker.configuration.enable_public_badge_access = false @@ -99,7 +116,6 @@ module Renderers end end end - end end end