Skip to content

Commit

Permalink
feat: add self relation to tags in extended pact and verification res…
Browse files Browse the repository at this point in the history
…ources
  • Loading branch information
bethesque committed Dec 7, 2020
1 parent e972efa commit a560ce6
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 4 deletions.
10 changes: 9 additions & 1 deletion lib/pact_broker/api/decorators/extended_pact_decorator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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}",
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 0 additions & 3 deletions lib/pact_broker/api/decorators/tag_decorator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,8 @@
require_relative 'timestamps'

module PactBroker

module Api

module Decorators

class TagDecorator < BaseDecorator

property :name
Expand Down
2 changes: 2 additions & 0 deletions lib/pact_broker/tags/tag_with_latest_flag.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit a560ce6

Please sign in to comment.