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