2019-10-08 12:06:01 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-01-17 17:14:49 +00:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2020-06-24 15:08:50 +00:00
|
|
|
RSpec.describe 'ci/status/_badge' do
|
2017-01-17 17:14:49 +00:00
|
|
|
let(:user) { create(:user) }
|
2017-08-02 19:55:11 +00:00
|
|
|
let(:project) { create(:project, :private) }
|
2017-01-17 17:14:49 +00:00
|
|
|
let(:pipeline) { create(:ci_pipeline, project: project) }
|
|
|
|
|
|
|
|
context 'when rendering status for build' do
|
2017-02-26 12:29:37 +00:00
|
|
|
let(:build) do
|
|
|
|
create(:ci_build, :success, pipeline: pipeline)
|
2017-01-17 17:14:49 +00:00
|
|
|
end
|
|
|
|
|
2017-02-26 12:35:29 +00:00
|
|
|
context 'when user has ability to see details' do
|
2017-01-17 17:14:49 +00:00
|
|
|
before do
|
2017-02-26 12:29:37 +00:00
|
|
|
project.add_developer(user)
|
2017-01-17 17:14:49 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'has link to build details page' do
|
2017-06-29 17:06:35 +00:00
|
|
|
details_path = project_job_path(project, build)
|
2017-02-26 12:29:37 +00:00
|
|
|
|
|
|
|
render_status(build)
|
|
|
|
|
2017-01-17 17:14:49 +00:00
|
|
|
expect(rendered).to have_link 'passed', href: details_path
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-02-26 12:35:29 +00:00
|
|
|
context 'when user do not have ability to see build details' do
|
2017-02-26 12:29:37 +00:00
|
|
|
before do
|
|
|
|
render_status(build)
|
|
|
|
end
|
2017-01-17 17:14:49 +00:00
|
|
|
|
|
|
|
it 'contains build status text' do
|
|
|
|
expect(rendered).to have_content 'passed'
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'does not contain links' do
|
|
|
|
expect(rendered).not_to have_link 'passed'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when rendering status for external job' do
|
2017-02-26 12:35:29 +00:00
|
|
|
context 'when user has ability to see commit status details' do
|
|
|
|
before do
|
|
|
|
project.add_developer(user)
|
|
|
|
end
|
2017-02-26 12:29:37 +00:00
|
|
|
|
2017-02-26 12:35:29 +00:00
|
|
|
context 'status has external target url' do
|
|
|
|
before do
|
|
|
|
external_job = create(:generic_commit_status,
|
|
|
|
status: :running,
|
|
|
|
pipeline: pipeline,
|
|
|
|
target_url: 'http://gitlab.com')
|
2017-01-17 17:14:49 +00:00
|
|
|
|
2017-02-26 12:35:29 +00:00
|
|
|
render_status(external_job)
|
|
|
|
end
|
2017-01-17 17:14:49 +00:00
|
|
|
|
2017-02-26 12:35:29 +00:00
|
|
|
it 'contains valid commit status text' do
|
|
|
|
expect(rendered).to have_content 'running'
|
|
|
|
end
|
2017-01-17 17:14:49 +00:00
|
|
|
|
2017-02-26 12:35:29 +00:00
|
|
|
it 'has link to external status page' do
|
|
|
|
expect(rendered).to have_link 'running', href: 'http://gitlab.com'
|
|
|
|
end
|
2017-01-17 17:14:49 +00:00
|
|
|
end
|
|
|
|
|
2017-02-26 12:35:29 +00:00
|
|
|
context 'status do not have external target url' do
|
|
|
|
before do
|
|
|
|
external_job = create(:generic_commit_status, status: :canceled)
|
2017-01-17 17:14:49 +00:00
|
|
|
|
2017-02-26 12:35:29 +00:00
|
|
|
render_status(external_job)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'contains valid commit status text' do
|
|
|
|
expect(rendered).to have_content 'canceled'
|
|
|
|
end
|
2017-01-17 17:14:49 +00:00
|
|
|
|
2017-02-26 12:35:29 +00:00
|
|
|
it 'has link to external status page' do
|
|
|
|
expect(rendered).not_to have_link 'canceled'
|
|
|
|
end
|
2017-01-17 17:14:49 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-02-26 12:29:37 +00:00
|
|
|
def render_status(resource)
|
2017-01-17 17:14:49 +00:00
|
|
|
render 'ci/status/badge', status: resource.detailed_status(user)
|
|
|
|
end
|
|
|
|
end
|