From d5ea068fe81587e5e8a1b3f4ca0515bd37f5dee1 Mon Sep 17 00:00:00 2001 From: Beth Skurrie Date: Fri, 15 Sep 2017 08:36:11 +1000 Subject: [PATCH 1/3] feat(pact resource): add link relation for all pact versions --- lib/pact_broker/api/decorators/pact_decorator.rb | 7 +++++++ spec/lib/pact_broker/api/decorators/pact_decorator_spec.rb | 5 +++++ 2 files changed, 12 insertions(+) diff --git a/lib/pact_broker/api/decorators/pact_decorator.rb b/lib/pact_broker/api/decorators/pact_decorator.rb index 00b4c8f0c..6530706dc 100644 --- a/lib/pact_broker/api/decorators/pact_decorator.rb +++ b/lib/pact_broker/api/decorators/pact_decorator.rb @@ -63,6 +63,13 @@ def to_hash(options = {}) } end + link :'pb:all-pact-versions' do | options | + { + title: "All versions of this pact", + href: pact_versions_url(represented.consumer.name, represented.provider.name, options.fetch(:base_url)) + } + end + link :'pb:latest-untagged-pact-version' do | options | { title: "Pact", diff --git a/spec/lib/pact_broker/api/decorators/pact_decorator_spec.rb b/spec/lib/pact_broker/api/decorators/pact_decorator_spec.rb index 0a17e2819..26c317839 100644 --- a/spec/lib/pact_broker/api/decorators/pact_decorator_spec.rb +++ b/spec/lib/pact_broker/api/decorators/pact_decorator_spec.rb @@ -85,6 +85,11 @@ module Decorators expect(subject[:_links][:'pb:latest-pact-version'][:href]).to eq "http://example.org/pacts/provider/A%20Provider/consumer/A%20Consumer/latest" end + it "includes a link to all pact versions" do + expect(subject[:_links][:'pb:all-pact-versions'][:title]).to eq "All versions of this pact" + expect(subject[:_links][:'pb:all-pact-versions'][:href]).to eq "http://example.org/pacts/provider/A%20Provider/consumer/A%20Consumer/versions" + end + it "includes a link to the pact version" do expect(subject[:_links][:'pb:consumer-version'][:title]).to eq "Consumer version" expect(subject[:_links][:'pb:consumer-version'][:name]).to eq "1234" From 3a9a1784f8c3cfa7881d12216c4d57eb249b3736 Mon Sep 17 00:00:00 2001 From: Beth Skurrie Date: Fri, 15 Sep 2017 08:39:31 +1000 Subject: [PATCH 2/3] feat(pact resource): improve usage of name and title fields --- lib/pact_broker/api/decorators/pact_decorator.rb | 15 +++++---------- .../api/decorators/pact_decorator_spec.rb | 9 +++------ 2 files changed, 8 insertions(+), 16 deletions(-) diff --git a/lib/pact_broker/api/decorators/pact_decorator.rb b/lib/pact_broker/api/decorators/pact_decorator.rb index 6530706dc..06bbbbde5 100644 --- a/lib/pact_broker/api/decorators/pact_decorator.rb +++ b/lib/pact_broker/api/decorators/pact_decorator.rb @@ -56,8 +56,7 @@ def to_hash(options = {}) link :'pb:latest-pact-version' do | options | { - title: "Pact", - name: "Latest version of this pact", + title: "Latest version of this pact", href: latest_pact_url(options.fetch(:base_url), represented) } @@ -72,16 +71,14 @@ def to_hash(options = {}) link :'pb:latest-untagged-pact-version' do | options | { - title: "Pact", - name: "Latest untagged version of this pact", + title: "Latest untagged version of this pact", href: latest_untagged_pact_url(represented, options.fetch(:base_url)) } end link :'pb:latest-tagged-pact-version' do | options | { - title: "Pact", - name: "Latest tagged version of this pact", + title: "Latest tagged version of this pact", href: "#{latest_pact_url(options.fetch(:base_url), represented)}/{tag}", templated: true } @@ -89,16 +86,14 @@ def to_hash(options = {}) link :'pb:previous-distinct' do | options | { - title: "Pact", - name: "Previous distinct version of this pact", + title: "Previous distinct version of this pact", href: previous_distinct_pact_version_url(represented, options.fetch(:base_url)) } end link :'pb:diff-previous-distinct' do | options | { - title: "Diff", - name: "Diff with previous distinct version of this pact", + title: "Diff with previous distinct version of this pact", href: previous_distinct_diff_url(represented, options.fetch(:base_url)) } diff --git a/spec/lib/pact_broker/api/decorators/pact_decorator_spec.rb b/spec/lib/pact_broker/api/decorators/pact_decorator_spec.rb index 26c317839..57534f514 100644 --- a/spec/lib/pact_broker/api/decorators/pact_decorator_spec.rb +++ b/spec/lib/pact_broker/api/decorators/pact_decorator_spec.rb @@ -53,14 +53,12 @@ module Decorators it "includes a link to the diff with the previous distinct version" do expect(subject[:_links][:'pb:diff-previous-distinct']).to eq({href: 'http://example.org/pacts/provider/A%20Provider/consumer/A%20Consumer/version/1234/diff/previous-distinct', - title: 'Diff', - name: 'Diff with previous distinct version of this pact'}) + title: 'Diff with previous distinct version of this pact'}) end it "includes a link to the previous distinct pact version" do expect(subject[:_links][:'pb:previous-distinct']).to eq({href: 'http://example.org/pacts/provider/A%20Provider/consumer/A%20Consumer/version/1234/previous-distinct', - title: 'Pact', - name: 'Previous distinct version of this pact'}) + title: 'Previous distinct version of this pact'}) end it "includes a link to tag this version" do @@ -80,8 +78,7 @@ module Decorators end it "includes a link to the latest pact" do - expect(subject[:_links][:'pb:latest-pact-version'][:title]).to eq "Pact" - expect(subject[:_links][:'pb:latest-pact-version'][:name]).to eq "Latest version of this pact" + expect(subject[:_links][:'pb:latest-pact-version'][:title]).to eq "Latest version of this pact" expect(subject[:_links][:'pb:latest-pact-version'][:href]).to eq "http://example.org/pacts/provider/A%20Provider/consumer/A%20Consumer/latest" end From 915a7eeaf06d5f906c07c7c1b69b4d1ec5e5bb48 Mon Sep 17 00:00:00 2001 From: Beth Skurrie Date: Fri, 15 Sep 2017 08:44:42 +1000 Subject: [PATCH 3/3] feat(resources): improve usage of title and name attributes --- lib/pact_broker/api/decorators/pact_collection_decorator.rb | 3 +-- lib/pact_broker/api/decorators/pact_versions_decorator.rb | 3 +-- lib/pact_broker/api/decorators/webhook_decorator.rb | 2 -- lib/pact_broker/api/decorators/webhooks_decorator.rb | 1 - 4 files changed, 2 insertions(+), 7 deletions(-) diff --git a/lib/pact_broker/api/decorators/pact_collection_decorator.rb b/lib/pact_broker/api/decorators/pact_collection_decorator.rb index bacc0ee7f..e4f6bc3e9 100644 --- a/lib/pact_broker/api/decorators/pact_collection_decorator.rb +++ b/lib/pact_broker/api/decorators/pact_collection_decorator.rb @@ -29,8 +29,7 @@ def create_representable_pact pact represented.collect do | pact | { :href => latest_pact_url(options[:base_url], pact), - :name => "Latest pact between #{pact.consumer.name} and #{pact.provider.name}", - :title => "Pact" + :title => "Latest pact between #{pact.consumer.name} and #{pact.provider.name}", } end end diff --git a/lib/pact_broker/api/decorators/pact_versions_decorator.rb b/lib/pact_broker/api/decorators/pact_versions_decorator.rb index 1b0b29fd1..037b9dad3 100644 --- a/lib/pact_broker/api/decorators/pact_versions_decorator.rb +++ b/lib/pact_broker/api/decorators/pact_versions_decorator.rb @@ -11,8 +11,7 @@ class PactVersionsDecorator < BaseDecorator link :self do | context | { href: context[:resource_url], - title: "Pact versions", - name: "All versions of the pact between #{context[:consumer_name]} and #{context[:provider_name]}" + title: "All versions of the pact between #{context[:consumer_name]} and #{context[:provider_name]}" } end diff --git a/lib/pact_broker/api/decorators/webhook_decorator.rb b/lib/pact_broker/api/decorators/webhook_decorator.rb index 00f1d5ea2..7e2093777 100644 --- a/lib/pact_broker/api/decorators/webhook_decorator.rb +++ b/lib/pact_broker/api/decorators/webhook_decorator.rb @@ -43,9 +43,7 @@ class WebhookDecorator < BaseDecorator title: "Test the execution of the webhook by sending a POST request to this URL", href: webhook_execution_url(represented, options[:base_url]) } - end - end end end diff --git a/lib/pact_broker/api/decorators/webhooks_decorator.rb b/lib/pact_broker/api/decorators/webhooks_decorator.rb index 3517bbce3..3b5cb2ae0 100644 --- a/lib/pact_broker/api/decorators/webhooks_decorator.rb +++ b/lib/pact_broker/api/decorators/webhooks_decorator.rb @@ -38,7 +38,6 @@ class WebhooksDecorator < BaseDecorator templated: true }] end - end end end