diff --git a/lib/pact_broker/api/decorators/pacticipant_decorator.rb b/lib/pact_broker/api/decorators/pacticipant_decorator.rb index f881417f3..cf2dca748 100644 --- a/lib/pact_broker/api/decorators/pacticipant_decorator.rb +++ b/lib/pact_broker/api/decorators/pacticipant_decorator.rb @@ -25,6 +25,14 @@ class PacticipantDecorator < BaseDecorator versions_url(options[:base_url], represented) end + link :'pb:version-tag' do | options | + { + title: "Get, create or delete a tag for a version of #{represented.name}", + href: templated_tag_url_for_pacticipant(represented.name, options[:base_url]), + templated: true + } + end + # TODO deprecate in v3 # URL isn't implemented # link 'latest-version' do | options | diff --git a/lib/pact_broker/api/pact_broker_urls.rb b/lib/pact_broker/api/pact_broker_urls.rb index 0637dce8e..23dc99db5 100644 --- a/lib/pact_broker/api/pact_broker_urls.rb +++ b/lib/pact_broker/api/pact_broker_urls.rb @@ -128,6 +128,10 @@ def tag_url base_url, tag "#{tags_url(base_url, tag.version)}/#{tag.name}" end + def templated_tag_url_for_pacticipant pacticipant_name, base_url = "" + pacticipant_url_from_params({pacticipant_name: pacticipant_name}, base_url) + "/versions/{version}/tags/{tag}" + end + def label_url label, base_url "#{labels_url(label.pacticipant, base_url)}/#{label.name}" end diff --git a/spec/lib/pact_broker/api/decorators/pacticipant_decorator_spec.rb b/spec/lib/pact_broker/api/decorators/pacticipant_decorator_spec.rb index 521f4c16c..60f08b2ef 100644 --- a/spec/lib/pact_broker/api/decorators/pacticipant_decorator_spec.rb +++ b/spec/lib/pact_broker/api/decorators/pacticipant_decorator_spec.rb @@ -20,13 +20,15 @@ module Decorators let(:created_at) { Time.new(2014, 3, 4) } let(:updated_at) { Time.new(2014, 3, 5) } + let(:base_url) { 'http://example.org' } before do pacticipant.created_at = created_at pacticipant.updated_at = updated_at + allow_any_instance_of(PacticipantDecorator).to receive(:templated_tag_url_for_pacticipant).and_return('version_tag_url') end - subject { JSON.parse PacticipantDecorator.new(pacticipant).to_json(user_options: {base_url: 'http://example.org'}), symbolize_names: true } + subject { JSON.parse PacticipantDecorator.new(pacticipant).to_json(user_options: {base_url: base_url}), symbolize_names: true } it "includes timestamps" do expect(subject[:createdAt]).to eq created_at.xmlschema @@ -38,6 +40,15 @@ module Decorators expect(subject[:_embedded][:labels].first[:_links][:self][:href]).to match %r{http://example.org/.*foo} end + it "creates the URL for a version tag" do + expect_any_instance_of(PacticipantDecorator).to receive(:templated_tag_url_for_pacticipant).with("Name", base_url) + subject + end + + it "includes a relation for a version tag" do + expect(subject[:_links][:'pb:version-tag'][:href]).to eq "version_tag_url" + end + context "when there is a latest_version" do before { test_data_builder.create_version("1.2.107") } it "includes an embedded latestVersion" do diff --git a/spec/lib/pact_broker/api/pact_broker_urls_spec.rb b/spec/lib/pact_broker/api/pact_broker_urls_spec.rb new file mode 100644 index 000000000..10d93debb --- /dev/null +++ b/spec/lib/pact_broker/api/pact_broker_urls_spec.rb @@ -0,0 +1,16 @@ +require 'pact_broker/api/pact_broker_urls' + +module PactBroker + module Api + describe PactBrokerUrls do + + let(:base_url) { "http://example.org" } + + describe "templated_tag_url_for_pacticipant" do + subject { PactBrokerUrls.templated_tag_url_for_pacticipant("Bar", base_url) } + + it { is_expected.to eq "http://example.org/pacticipants/Bar/versions/{version}/tags/{tag}" } + end + end + end +end