Skip to content

Commit

Permalink
feat: add pb:version-tag relation to pacticipant resource
Browse files Browse the repository at this point in the history
  • Loading branch information
bethesque committed May 1, 2018
1 parent 38a8e06 commit 0704772
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 1 deletion.
8 changes: 8 additions & 0 deletions lib/pact_broker/api/decorators/pacticipant_decorator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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 |
Expand Down
4 changes: 4 additions & 0 deletions lib/pact_broker/api/pact_broker_urls.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
16 changes: 16 additions & 0 deletions spec/lib/pact_broker/api/pact_broker_urls_spec.rb
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 0704772

Please sign in to comment.