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
##
# Class that describes build badge metadata
#
class Metadata
include Gitlab::Application.routes.url_helpers
include ActionView::Helpers::AssetTagHelper
include ActionView::Helpers::UrlHelper
class Metadata < Badge::Metadata
def initialize(badge)
@project = badge.project
@ref = badge.ref
end
def to_html
link_to(image_tag(image_url, alt: 'build status'), link_url)
end
def to_markdown
"[![build status](#{image_url})](#{link_url})"
def title
'build status'
end
def image_url
......
......@@ -4,23 +4,15 @@ module Gitlab
##
# Class that describes coverage badge metadata
#
class Metadata
include Gitlab::Application.routes.url_helpers
include ActionView::Helpers::AssetTagHelper
include ActionView::Helpers::UrlHelper
class Metadata < Badge::Metadata
def initialize(badge)
@project = badge.project
@ref = badge.ref
@job = badge.job
end
def to_html
link_to(image_tag(image_url, alt: 'coverage report'), link_url)
end
def to_markdown
"[![coverage report](#{image_url})](#{link_url})"
def title
'coverage report'
end
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
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
it 'returns valid url' do
expect(metadata.image_url).to include 'badges/feature/build.svg'
......
......@@ -10,6 +10,12 @@ describe Gitlab::Badge::Coverage::Metadata do
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
it 'returns valid url' do
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