Skip to content

Commit

Permalink
feat(badge markdown): show message about enabling public badge access…
Browse files Browse the repository at this point in the history
… when disabled
  • Loading branch information
bethesque committed Sep 17, 2017
1 parent cb6cb8e commit 6fc78ff
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 8 deletions.
27 changes: 19 additions & 8 deletions lib/pact_broker/api/renderers/html_pact_renderer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ def head
def pact_metadata
"<div class='pact-metadata'>
<ul>
#{badge_list_items}
#{badge_list_item}
#{badge_markdown_item}
<li>
<span class='name'>#{@pact.consumer.name} version:</span>
<span class='value'>#{@pact.consumer_version_number}#{tags}</span>
Expand All @@ -69,20 +70,30 @@ def pact_metadata
</div>"
end

def badge_list_items
if PactBroker.configuration.enable_public_badge_access
def badge_list_item
"<li class='badge'>
<img src='#{badge_url}'/>
</li>
<li class='badge-markdown' style='display:none'>
<textarea rows='3' cols='100'>#{badge_markdown}</textarea>
</li>
"
end
end

def badge_markdown_item
"<li class='badge-markdown' style='display:none'>
<textarea rows='3' cols='100'>#{badge_markdown}</textarea>
</li>"
end

def badge_markdown
"[![#{@pact.consumer.name}/#{@pact.provider.name} Pact Status](#{badge_url})](#{badge_target_url})"
warning = if badges_protected?
"If the broker is protected by authentication, set `enable_public_badge_access` to true in the configuration to enable badges to be embedded in a markdown file.\n"
else
""
end
"#{warning}[![#{@pact.consumer.name}/#{@pact.provider.name} Pact Status](#{badge_url})](#{badge_target_url})"
end

def badges_protected?
!PactBroker.configuration.enable_public_badge_access
end

def base_url
Expand Down
10 changes: 10 additions & 0 deletions spec/lib/pact_broker/api/renderers/html_pact_renderer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,16 @@ module Renderers
expect(subject).to include "[![Consumer/Provider Pact Status](http://badge)](http://base)"
end

context "when enable_public_badge_access is false" do
before do
PactBroker.configuration.enable_public_badge_access = false
end

it "renders a message instructing the user to turn public access on" do
expect(subject).to include "set `enable_public_badge_access` to true in the configuration"
end
end

context "when the content is not a valid pact, but is still JSON" do
before do
allow(pact).to receive(:content_hash).and_return(content_hash)
Expand Down

0 comments on commit 6fc78ff

Please sign in to comment.