Commit cc244160 authored by Grzegorz Bizon's avatar Grzegorz Bizon

Extract the abstract base class of badge metadata

parent 7b840c84
...@@ -4,22 +4,14 @@ module Gitlab ...@@ -4,22 +4,14 @@ module Gitlab
## ##
# Class that describes build badge metadata # Class that describes build badge metadata
# #
class Metadata class Metadata < Badge::Metadata
include Gitlab::Application.routes.url_helpers
include ActionView::Helpers::AssetTagHelper
include ActionView::Helpers::UrlHelper
def initialize(badge) def initialize(badge)
@project = badge.project @project = badge.project
@ref = badge.ref @ref = badge.ref
end end
def to_html def title
link_to(image_tag(image_url, alt: 'build status'), link_url) 'build status'
end
def to_markdown
"[![build status](#{image_url})](#{link_url})"
end end
def image_url def image_url
......
...@@ -4,23 +4,15 @@ module Gitlab ...@@ -4,23 +4,15 @@ module Gitlab
## ##
# Class that describes coverage badge metadata # Class that describes coverage badge metadata
# #
class Metadata class Metadata < Badge::Metadata
include Gitlab::Application.routes.url_helpers
include ActionView::Helpers::AssetTagHelper
include ActionView::Helpers::UrlHelper
def initialize(badge) def initialize(badge)
@project = badge.project @project = badge.project
@ref = badge.ref @ref = badge.ref
@job = badge.job @job = badge.job
end end
def to_html def title
link_to(image_tag(image_url, alt: 'coverage report'), link_url) 'coverage report'
end
def to_markdown
"[![coverage report](#{image_url})](#{link_url})"
end end
def image_url def image_url
......
module Gitlab
module Badge
##
# Abstract class for badge metadata
#
class Metadata
include Gitlab::Application.routes.url_helpers
include ActionView::Helpers::AssetTagHelper
include ActionView::Helpers::UrlHelper
def initialize(badge)
@badge = badge
end
def to_html
link_to(image_tag(image_url, alt: title), link_url)
end
def to_markdown
"[![#{title}](#{image_url})](#{link_url})"
end
def title
raise NotImplementedError
end
def image_url
raise NotImplementedError
end
def link_url
raise NotImplementedError
end
end
end
end
...@@ -7,6 +7,12 @@ describe Gitlab::Badge::Build::Metadata do ...@@ -7,6 +7,12 @@ describe Gitlab::Badge::Build::Metadata do
it_behaves_like 'badge metadata' it_behaves_like 'badge metadata'
describe '#title' do
it 'returns build status title' do
expect(metadata.title).to eq 'build status'
end
end
describe '#image_url' do describe '#image_url' do
it 'returns valid url' do it 'returns valid url' do
expect(metadata.image_url).to include 'badges/feature/build.svg' expect(metadata.image_url).to include 'badges/feature/build.svg'
......
...@@ -10,6 +10,12 @@ describe Gitlab::Badge::Coverage::Metadata do ...@@ -10,6 +10,12 @@ describe Gitlab::Badge::Coverage::Metadata do
it_behaves_like 'badge metadata' it_behaves_like 'badge metadata'
describe '#title' do
it 'returns coverage report title' do
expect(metadata.title).to eq 'coverage report'
end
end
describe '#image_url' do describe '#image_url' do
it 'returns valid url' do it 'returns valid url' do
expect(metadata.image_url).to include 'badges/feature/coverage.svg' expect(metadata.image_url).to include 'badges/feature/coverage.svg'
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment