diff --git a/lib/pact_broker/api/decorators/extended_pact_decorator.rb b/lib/pact_broker/api/decorators/extended_pact_decorator.rb index c284a9a23..98b5d304f 100644 --- a/lib/pact_broker/api/decorators/extended_pact_decorator.rb +++ b/lib/pact_broker/api/decorators/extended_pact_decorator.rb @@ -11,6 +11,14 @@ class TagDecorator < BaseDecorator property :name property :latest, getter: ->(_) { true } + link :self do | options | + { + title: 'Tag', + name: represented.name, + href: tag_url(options[:base_url], represented) + } + end + link "pb:latest-pact" do | opts | { name: "The latest pact with the tag #{represented.name}", @@ -33,7 +41,7 @@ def to_hash(options = {}) def head_tags represented.head_tag_names.collect do | tag_name | - OpenStruct.new(name: tag_name, pact: represented) + OpenStruct.new(name: tag_name, pact: represented, version: represented.consumer_version) end end end diff --git a/lib/pact_broker/api/decorators/extended_verification_decorator.rb b/lib/pact_broker/api/decorators/extended_verification_decorator.rb index 3a09e3b50..8cc11c7e8 100644 --- a/lib/pact_broker/api/decorators/extended_verification_decorator.rb +++ b/lib/pact_broker/api/decorators/extended_verification_decorator.rb @@ -7,6 +7,14 @@ class ExtendedVerificationDecorator < VerificationDecorator class TagDecorator < BaseDecorator property :name property :latest?, as: :latest + + link :self do | options | + { + title: 'Tag', + name: represented.name, + href: tag_url(options[:base_url], represented) + } + end end collection :provider_version_tags, as: :tags, embedded: true, extend: TagDecorator diff --git a/lib/pact_broker/api/decorators/tag_decorator.rb b/lib/pact_broker/api/decorators/tag_decorator.rb index f973e6c4a..ad1a3a8a4 100644 --- a/lib/pact_broker/api/decorators/tag_decorator.rb +++ b/lib/pact_broker/api/decorators/tag_decorator.rb @@ -3,11 +3,8 @@ require_relative 'timestamps' module PactBroker - module Api - module Decorators - class TagDecorator < BaseDecorator property :name diff --git a/lib/pact_broker/tags/tag_with_latest_flag.rb b/lib/pact_broker/tags/tag_with_latest_flag.rb index 3d9b3e1f9..e76dcef6f 100644 --- a/lib/pact_broker/tags/tag_with_latest_flag.rb +++ b/lib/pact_broker/tags/tag_with_latest_flag.rb @@ -5,6 +5,8 @@ module PactBroker module Tags # The tag associated with the latest verification for a given tag class TagWithLatestFlag < Sequel::Model(:tags_with_latest_flag) + associate(:many_to_one, :version, :class => "PactBroker::Domain::Version", :key => :version_id, :primary_key => :id) + dataset_module do include PactBroker::Repositories::Helpers end diff --git a/spec/lib/pact_broker/api/decorators/extended_pact_decorator_spec.rb b/spec/lib/pact_broker/api/decorators/extended_pact_decorator_spec.rb index 0b56e9fbc..5fa611993 100644 --- a/spec/lib/pact_broker/api/decorators/extended_pact_decorator_spec.rb +++ b/spec/lib/pact_broker/api/decorators/extended_pact_decorator_spec.rb @@ -46,6 +46,7 @@ module Decorators expect(subject[:_embedded][:tags].first).to include name: 'prod', latest: true # Can't seem to stub the verification_publication_url method on the TagDecorator expect(subject[:_embedded][:tags].first[:_links][:'pb:latest-pact'][:href]).to eq "http://example.org/pacts/provider/A%20Provider/consumer/A%20Consumer/latest/prod" + expect(subject[:_embedded][:tags].first[:_links][:self][:href]).to eq "http://example.org/pacticipants/A%20Consumer/versions/1234/tags/prod" end it "includes the pact contents under the contract key" do