2019-04-15 06:17:05 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-07-19 07:08:47 -04:00
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
describe Projects::BadgesController do
|
|
|
|
let(:project) { pipeline.project }
|
|
|
|
let!(:pipeline) { create(:ci_empty_pipeline) }
|
|
|
|
let(:user) { create(:user) }
|
|
|
|
|
|
|
|
before do
|
2018-07-11 10:36:08 -04:00
|
|
|
project.add_maintainer(user)
|
2017-07-19 07:08:47 -04:00
|
|
|
sign_in(user)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'requests the pipeline badge successfully' do
|
|
|
|
get_badge(:pipeline)
|
|
|
|
|
2017-10-19 14:28:19 -04:00
|
|
|
expect(response).to have_gitlab_http_status(:ok)
|
2017-07-19 07:08:47 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'requests the coverage badge successfully' do
|
|
|
|
get_badge(:coverage)
|
|
|
|
|
2017-10-19 14:28:19 -04:00
|
|
|
expect(response).to have_gitlab_http_status(:ok)
|
2017-07-19 07:08:47 -04:00
|
|
|
end
|
|
|
|
|
2019-01-18 08:39:35 -05:00
|
|
|
it 'renders the `flat` badge layout by default' do
|
|
|
|
get_badge(:coverage)
|
|
|
|
|
|
|
|
expect(response).to render_template('projects/badges/badge')
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when style param is set to `flat`' do
|
|
|
|
it 'renders the `flat` badge layout' do
|
|
|
|
get_badge(:coverage, 'flat')
|
|
|
|
|
|
|
|
expect(response).to render_template('projects/badges/badge')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when style param is set to an invalid type' do
|
|
|
|
it 'renders the `flat` (default) badge layout' do
|
|
|
|
get_badge(:coverage, 'xxx')
|
|
|
|
|
|
|
|
expect(response).to render_template('projects/badges/badge')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when style param is set to `flat-square`' do
|
|
|
|
it 'renders the `flat-square` badge layout' do
|
|
|
|
get_badge(:coverage, 'flat-square')
|
|
|
|
|
|
|
|
expect(response).to render_template('projects/badges/badge_flat-square')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def get_badge(badge, style = nil)
|
|
|
|
params = {
|
|
|
|
namespace_id: project.namespace.to_param,
|
|
|
|
project_id: project,
|
|
|
|
ref: pipeline.ref,
|
|
|
|
style: style
|
|
|
|
}
|
|
|
|
|
|
|
|
get badge, params: params, format: :svg
|
2017-07-19 07:08:47 -04:00
|
|
|
end
|
|
|
|
end
|