debian-mirror-gitlab/spec/views/projects/jobs/show.html.haml_spec.rb

228 lines
6.5 KiB
Ruby
Raw Normal View History

2016-08-24 12:49:21 +05:30
require 'spec_helper'
2017-09-10 17:25:29 +05:30
describe 'projects/jobs/show' do
2018-05-09 12:01:36 +05:30
let(:user) { create(:user) }
2017-08-17 22:00:37 +05:30
let(:project) { create(:project, :repository) }
let(:build) { create(:ci_build, pipeline: pipeline) }
2018-05-09 12:01:36 +05:30
let(:builds) { project.builds.present(current_user: user) }
2016-08-24 12:49:21 +05:30
let(:pipeline) do
2017-08-17 22:00:37 +05:30
create(:ci_pipeline, project: project, sha: project.commit.id)
2016-08-24 12:49:21 +05:30
end
before do
2017-08-17 22:00:37 +05:30
assign(:build, build.present)
2016-08-24 12:49:21 +05:30
assign(:project, project)
2018-05-09 12:01:36 +05:30
assign(:builds, builds)
2016-08-24 12:49:21 +05:30
allow(view).to receive(:can?).and_return(true)
end
2017-08-17 22:00:37 +05:30
describe 'environment info in job view' do
context 'job with latest deployment' do
let(:build) do
2018-05-09 12:01:36 +05:30
create(:ci_build, :success, :trace_artifact, environment: 'staging')
2017-08-17 22:00:37 +05:30
end
before do
create(:environment, name: 'staging')
create(:deployment, deployable: build)
end
it 'shows deployment message' do
expected_text = 'This job is the most recent deployment'
render
expect(rendered).to have_css(
'.environment-information', text: expected_text)
end
end
context 'job with outdated deployment' do
let(:build) do
2018-05-09 12:01:36 +05:30
create(:ci_build, :success, :trace_artifact, environment: 'staging', pipeline: pipeline)
2017-08-17 22:00:37 +05:30
end
let(:second_build) do
2018-05-09 12:01:36 +05:30
create(:ci_build, :success, :trace_artifact, environment: 'staging', pipeline: pipeline)
2017-08-17 22:00:37 +05:30
end
let(:environment) do
create(:environment, name: 'staging', project: project)
end
let!(:first_deployment) do
create(:deployment, environment: environment, deployable: build)
end
let!(:second_deployment) do
create(:deployment, environment: environment, deployable: second_build)
end
it 'shows deployment message' do
expected_text = 'This job is an out-of-date deployment ' \
"to staging.\nView the most recent deployment ##{second_deployment.iid}."
render
expect(rendered).to have_css('.environment-information', text: expected_text)
end
end
context 'job failed to deploy' do
let(:build) do
2018-05-09 12:01:36 +05:30
create(:ci_build, :failed, :trace_artifact, environment: 'staging', pipeline: pipeline)
2017-08-17 22:00:37 +05:30
end
let!(:environment) do
create(:environment, name: 'staging', project: project)
end
it 'shows deployment message' do
expected_text = 'The deployment of this job to staging did not succeed.'
render
expect(rendered).to have_css(
'.environment-information', text: expected_text)
end
end
context 'job will deploy' do
let(:build) do
2018-05-09 12:01:36 +05:30
create(:ci_build, :running, :trace_live, environment: 'staging', pipeline: pipeline)
2017-08-17 22:00:37 +05:30
end
context 'when environment exists' do
let!(:environment) do
create(:environment, name: 'staging', project: project)
end
it 'shows deployment message' do
expected_text = 'This job is creating a deployment to staging'
render
expect(rendered).to have_css(
'.environment-information', text: expected_text)
end
context 'when it has deployment' do
let!(:deployment) do
create(:deployment, environment: environment)
end
it 'shows that deployment will be overwritten' do
expected_text = 'This job is creating a deployment to staging'
render
expect(rendered).to have_css(
'.environment-information', text: expected_text)
expect(rendered).to have_css(
'.environment-information', text: 'latest deployment')
end
end
end
context 'when environment does not exist' do
it 'shows deployment message' do
expected_text = 'This job is creating a deployment to staging'
render
expect(rendered).to have_css(
'.environment-information', text: expected_text)
expect(rendered).not_to have_css(
'.environment-information', text: 'latest deployment')
end
end
end
context 'job that failed to deploy and environment has not been created' do
let(:build) do
2018-05-09 12:01:36 +05:30
create(:ci_build, :failed, :trace_artifact, environment: 'staging', pipeline: pipeline)
2017-08-17 22:00:37 +05:30
end
let!(:environment) do
create(:environment, name: 'staging', project: project)
end
it 'shows deployment message' do
expected_text = 'The deployment of this job to staging did not succeed'
render
expect(rendered).to have_css(
'.environment-information', text: expected_text)
end
end
context 'job that will deploy and environment has not been created' do
let(:build) do
2018-05-09 12:01:36 +05:30
create(:ci_build, :running, :trace_live, environment: 'staging', pipeline: pipeline)
2017-08-17 22:00:37 +05:30
end
let!(:environment) do
create(:environment, name: 'staging', project: project)
end
it 'shows deployment message' do
expected_text = 'This job is creating a deployment to staging'
render
expect(rendered).to have_css(
'.environment-information', text: expected_text)
expect(rendered).not_to have_css(
'.environment-information', text: 'latest deployment')
end
end
end
context 'when job is running' do
2018-05-09 12:01:36 +05:30
let(:build) { create(:ci_build, :trace_live, :running, pipeline: pipeline) }
2016-08-24 12:49:21 +05:30
before do
render
end
it 'does not show retry button' do
expect(rendered).not_to have_link('Retry')
end
2017-08-17 22:00:37 +05:30
it 'does not show New issue button' do
expect(rendered).not_to have_link('New issue')
end
2016-08-24 12:49:21 +05:30
end
2018-03-17 18:26:18 +05:30
context 'when incomplete trigger_request is used' do
before do
build.trigger_request = FactoryBot.build(:ci_trigger_request, trigger: nil)
end
2016-08-24 12:49:21 +05:30
2018-03-17 18:26:18 +05:30
it 'test should not render token block' do
2016-08-24 12:49:21 +05:30
render
2016-09-13 17:45:13 +05:30
2018-03-17 18:26:18 +05:30
expect(rendered).not_to have_content('Token')
2016-08-24 12:49:21 +05:30
end
end
2016-09-13 17:45:13 +05:30
2018-03-17 18:26:18 +05:30
context 'when complete trigger_request is used' do
2016-09-13 17:45:13 +05:30
before do
2018-03-17 18:26:18 +05:30
build.trigger_request = FactoryBot.build(:ci_trigger_request)
end
it 'should render token' do
2016-09-13 17:45:13 +05:30
render
2018-03-17 18:26:18 +05:30
expect(rendered).to have_content('Token')
expect(rendered).to have_content(build.trigger_request.trigger.short_token)
2016-09-13 17:45:13 +05:30
end
2018-03-17 18:26:18 +05:30
end
describe 'commit title in sidebar' do
let(:commit_title) { project.commit.title }
2016-09-13 17:45:13 +05:30
2018-03-17 18:26:18 +05:30
it 'shows commit title and not show commit message' do
render
expect(rendered).to have_css('p.build-light-text.append-bottom-0',
text: /\A\n#{Regexp.escape(commit_title)}\n\Z/)
2016-09-13 17:45:13 +05:30
end
end
2016-08-24 12:49:21 +05:30
end