From 6a46ebbe13438f6ab9a1234a602edbb9a3163cd2 Mon Sep 17 00:00:00 2001 From: Beth Skurrie Date: Tue, 14 Aug 2018 08:17:37 +1000 Subject: [PATCH] feat: rename 'wip pacts' to 'pending pacts' --- lib/pact/hal/entity.rb | 4 +++- lib/pact/pact_broker.rb | 6 ++--- ...ch_wip_pacts.rb => fetch_pending_pacts.rb} | 11 +++++----- ...ts_spec.rb => fetch_pending_pacts_spec.rb} | 8 +++---- spec/lib/pact/pact_broker_spec.rb | 10 ++++----- .../pact_ruby_fetch_wip_pacts_test.rb | 22 +++++++++---------- 6 files changed, 32 insertions(+), 29 deletions(-) rename lib/pact/pact_broker/{fetch_wip_pacts.rb => fetch_pending_pacts.rb} (81%) rename spec/lib/pact/pact_broker/{fetch_wip_pacts_spec.rb => fetch_pending_pacts_spec.rb} (85%) diff --git a/lib/pact/hal/entity.rb b/lib/pact/hal/entity.rb index 399af85c..1bee4f69 100644 --- a/lib/pact/hal/entity.rb +++ b/lib/pact/hal/entity.rb @@ -36,9 +36,11 @@ def follow(key, http_method, *args) Link.new(@links[key].merge(method: http_method), @client).run(*args) end - def _link(key) + def _link(key, fallback_key = nil) if @links[key] Link.new(@links[key], @client) + elsif fallback_key && @links[fallback_key] + Link.new(@links[fallback_key], @client) else nil end diff --git a/lib/pact/pact_broker.rb b/lib/pact/pact_broker.rb index d9d2e54a..45293c07 100644 --- a/lib/pact/pact_broker.rb +++ b/lib/pact/pact_broker.rb @@ -1,5 +1,5 @@ require 'pact/pact_broker/fetch_pacts' -require 'pact/pact_broker/fetch_wip_pacts' +require 'pact/pact_broker/fetch_pending_pacts' # # @public Use by Pact Provider Verifier @@ -12,8 +12,8 @@ def fetch_pact_uris *args Pact::PactBroker::FetchPacts.call(*args).collect(&:uri) end - def fetch_wip_pact_uris *args - Pact::PactBroker::FetchWipPacts.call(*args).collect(&:uri) + def fetch_pending_pact_uris *args + Pact::PactBroker::FetchPendingPacts.call(*args).collect(&:uri) end end end diff --git a/lib/pact/pact_broker/fetch_wip_pacts.rb b/lib/pact/pact_broker/fetch_pending_pacts.rb similarity index 81% rename from lib/pact/pact_broker/fetch_wip_pacts.rb rename to lib/pact/pact_broker/fetch_pending_pacts.rb index 6d410df3..dd3459b3 100644 --- a/lib/pact/pact_broker/fetch_wip_pacts.rb +++ b/lib/pact/pact_broker/fetch_pending_pacts.rb @@ -4,10 +4,11 @@ module Pact module PactBroker - class FetchWipPacts + class FetchPendingPacts attr_reader :provider, :tags, :broker_base_url, :http_client_options, :http_client, :index_entity - WIP_PROVIDER_RELATION = 'beta:wip-provider-pacts'.freeze + PENDING_PROVIDER_RELATION = 'beta:pending-provider-pacts'.freeze + WIP_PROVIDER_RELATION = 'beta:wip-provider-pacts'.freeze # deprecated PACTS = 'pacts'.freeze PB_PACTS = 'pb:pacts'.freeze HREF = 'href'.freeze @@ -25,7 +26,7 @@ def self.call(provider, broker_base_url, http_client_options) def call if index.success? - wip_pacts_for_provider + pending_pacts_for_provider else raise Pact::Error.new("Error retrieving #{broker_base_url} status=#{index_entity.response.code} #{index_entity.response.raw_body}") end @@ -37,8 +38,8 @@ def index @index_entity ||= Pact::Hal::Link.new({ "href" => broker_base_url }, http_client).get end - def wip_pacts_for_provider - link = index_entity._link(WIP_PROVIDER_RELATION) + def pending_pacts_for_provider + link = index_entity._link(WIP_PROVIDER_RELATION, PENDING_PROVIDER_RELATION) if link get_pact_urls(link.expand(provider: provider).get) else diff --git a/spec/lib/pact/pact_broker/fetch_wip_pacts_spec.rb b/spec/lib/pact/pact_broker/fetch_pending_pacts_spec.rb similarity index 85% rename from spec/lib/pact/pact_broker/fetch_wip_pacts_spec.rb rename to spec/lib/pact/pact_broker/fetch_pending_pacts_spec.rb index 7acc3b28..ea16ae4b 100644 --- a/spec/lib/pact/pact_broker/fetch_wip_pacts_spec.rb +++ b/spec/lib/pact/pact_broker/fetch_pending_pacts_spec.rb @@ -1,8 +1,8 @@ -require 'pact/pact_broker/fetch_wip_pacts' +require 'pact/pact_broker/fetch_pending_pacts' module Pact module PactBroker - describe FetchWipPacts do + describe FetchPendingPacts do describe "call" do before do allow(Pact.configuration).to receive(:output_stream).and_return(double('output stream').as_null_object) @@ -11,7 +11,7 @@ module PactBroker let(:provider) { "Foo"} let(:broker_base_url) { "http://broker.org" } let(:http_client_options) { {} } - subject { FetchWipPacts.call(provider, broker_base_url, http_client_options)} + subject { FetchPendingPacts.call(provider, broker_base_url, http_client_options)} context "when there is an error retrieving the index resource" do before do @@ -32,7 +32,7 @@ module PactBroker end end - context "when the pb:wip-provider-pacts relation does not exist" do + context "when the pb:pending-provider-pacts relation does not exist" do before do stub_request(:get, "http://broker.org/").to_return(status: 200, body: response_body, headers: response_headers) end diff --git a/spec/lib/pact/pact_broker_spec.rb b/spec/lib/pact/pact_broker_spec.rb index d3cb5c39..f47a5c23 100644 --- a/spec/lib/pact/pact_broker_spec.rb +++ b/spec/lib/pact/pact_broker_spec.rb @@ -22,17 +22,17 @@ module PactBroker end end - describe ".fetch_wip_pact_uris" do + describe ".fetch_pending_pact_uris" do before do - allow(Pact::PactBroker::FetchWipPacts).to receive(:call).and_return([pact_uri]) + allow(Pact::PactBroker::FetchPendingPacts).to receive(:call).and_return([pact_uri]) end let(:pact_uri) { Pact::Provider::PactURI.new("http://pact") } - subject { Pact::PactBroker.fetch_wip_pact_uris("foo") } + subject { Pact::PactBroker.fetch_pending_pact_uris("foo") } - it "calls Pact::PactBroker::FetchWipPacts" do - expect(Pact::PactBroker::FetchWipPacts).to receive(:call).with("foo") + it "calls Pact::PactBroker::FetchPendingPacts" do + expect(Pact::PactBroker::FetchPendingPacts).to receive(:call).with("foo") subject end diff --git a/spec/service_providers/pact_ruby_fetch_wip_pacts_test.rb b/spec/service_providers/pact_ruby_fetch_wip_pacts_test.rb index 6ead66bf..baa5a47f 100644 --- a/spec/service_providers/pact_ruby_fetch_wip_pacts_test.rb +++ b/spec/service_providers/pact_ruby_fetch_wip_pacts_test.rb @@ -1,7 +1,7 @@ require_relative 'helper' -require 'pact/pact_broker/fetch_wip_pacts' +require 'pact/pact_broker/fetch_pending_pacts' -describe Pact::PactBroker::FetchWipPacts, pact: true do +describe Pact::PactBroker::FetchPendingPacts, pact: true do before do allow($stdout).to receive(:puts) end @@ -15,7 +15,7 @@ before do pact_broker - .given('the relation for retrieving WIP pacts exists in the index resource') + .given('the relation for retrieving pending pacts exists in the index resource') .upon_receiving('a request for the index resource') .with( method: :get, @@ -26,10 +26,10 @@ status: 200, body: { _links: { - 'beta:wip-provider-pacts' => { + 'beta:pending-provider-pacts' => { href: Pact.term( - generate: broker_base_url + 'pacts/provider/{provider}/wip', - matcher: %r{/pacts/provider/{provider}/wip$} + generate: broker_base_url + 'pacts/provider/{provider}/pending', + matcher: %r{/pacts/provider/{provider}/pending$} ) } } @@ -37,14 +37,14 @@ ) end - context 'retrieving WIP pacts by provider' do + context 'retrieving pending pacts by provider' do before do pact_broker - .given('consumer-1 has a WIP pact with provider provider-1') - .upon_receiving('a request to retrieve the WIP pacts for provider') + .given('consumer-1 has a pending pact with provider provider-1') + .upon_receiving('a request to retrieve the pending pacts for provider') .with( method: :get, - path: '/pacts/provider/provider-1/wip', + path: '/pacts/provider/provider-1/pending', headers: get_headers ) .will_respond_with( @@ -62,7 +62,7 @@ end it 'returns the array of pact urls' do - pacts = Pact::PactBroker::FetchWipPacts.call(provider, broker_base_url, basic_auth_options) + pacts = Pact::PactBroker::FetchPendingPacts.call(provider, broker_base_url, basic_auth_options) expect(pacts).to eq( [ Pact::Provider::PactURI.new('http://pact-broker-url-for-consumer-1', basic_auth_options)