Commit b208da94 authored by Doug Stull's avatar Doug Stull

Resolve logic error for non ci config files

- we need to check if this is a config file before
  we try and check valid? on it as that method
  does not exist on all files.
parent 36a5f50e
......@@ -344,8 +344,8 @@ module BlobHelper
def show_suggest_pipeline_creation_celebration?
experiment_enabled?(:suggest_pipeline) &&
@blob.auxiliary_viewer.valid?(project: @project, sha: @commit.sha, user: current_user) &&
@blob.path == Gitlab::FileDetector::PATTERNS[:gitlab_ci] &&
@blob.auxiliary_viewer.valid?(project: @project, sha: @commit.sha, user: current_user) &&
@project.uses_default_ci_config? &&
cookies[suggest_pipeline_commit_cookie_name].present?
end
......
......@@ -204,7 +204,6 @@ describe BlobHelper do
end
describe '#show_suggest_pipeline_creation_celebration?' do
let(:blob) { fake_blob(path: Gitlab::FileDetector::PATTERNS[:gitlab_ci]) }
let(:current_user) { create(:user) }
before do
......@@ -212,52 +211,68 @@ describe BlobHelper do
assign(:blob, blob)
assign(:commit, double('Commit', sha: 'whatever'))
helper.request.cookies["suggest_gitlab_ci_yml_commit_#{project.id}"] = 'true'
allow(blob).to receive(:auxiliary_viewer).and_return(double('viewer', valid?: true))
allow(helper).to receive(:current_user).and_return(current_user)
end
context 'experiment enabled' do
before do
allow(helper).to receive(:experiment_enabled?).and_return(true)
end
it 'is true' do
expect(helper.show_suggest_pipeline_creation_celebration?).to be_truthy
end
context 'when file is a pipeline config file' do
let(:data) { File.read(Rails.root.join('spec/support/gitlab_stubs/gitlab_ci.yml')) }
let(:blob) { fake_blob(path: Gitlab::FileDetector::PATTERNS[:gitlab_ci], data: data) }
context 'file is invalid format' do
context 'experiment enabled' do
before do
allow(blob).to receive(:auxiliary_viewer).and_return(double('viewer', valid?: false))
allow(helper).to receive(:experiment_enabled?).and_return(true)
end
it 'is false' do
expect(helper.show_suggest_pipeline_creation_celebration?).to be_falsey
it 'is true' do
expect(helper.show_suggest_pipeline_creation_celebration?).to be_truthy
end
end
context 'path is not a ci file' do
before do
allow(blob).to receive(:path).and_return('something_bad')
context 'file is invalid format' do
let(:data) { 'foo' }
it 'is false' do
expect(helper.show_suggest_pipeline_creation_celebration?).to be_falsey
end
end
it 'is false' do
expect(helper.show_suggest_pipeline_creation_celebration?).to be_falsey
context 'does not use the default ci config' do
before do
project.ci_config_path = 'something_bad'
end
it 'is false' do
expect(helper.show_suggest_pipeline_creation_celebration?).to be_falsey
end
end
context 'does not have the needed cookie' do
before do
helper.request.cookies.delete "suggest_gitlab_ci_yml_commit_#{project.id}"
end
it 'is false' do
expect(helper.show_suggest_pipeline_creation_celebration?).to be_falsey
end
end
end
context 'does not use the default ci config' do
context 'experiment disabled' do
before do
project.ci_config_path = 'something_bad'
allow(helper).to receive(:experiment_enabled?).and_return(false)
end
it 'is false' do
expect(helper.show_suggest_pipeline_creation_celebration?).to be_falsey
end
end
end
context 'does not have the needed cookie' do
context 'when file is not a pipeline config file' do
let(:blob) { fake_blob(path: 'LICENSE') }
context 'experiment enabled' do
before do
helper.request.cookies.delete "suggest_gitlab_ci_yml_commit_#{project.id}"
allow(helper).to receive(:experiment_enabled?).and_return(true)
end
it 'is false' do
......@@ -265,16 +280,6 @@ describe BlobHelper do
end
end
end
context 'experiment disabled' do
before do
allow(helper).to receive(:experiment_enabled?).and_return(false)
end
it 'is false' do
expect(helper.show_suggest_pipeline_creation_celebration?).to be_falsey
end
end
end
end
......
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