Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2019-10-16 06:06:12 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2019-10-16 06:06:12 +0300
commitf155cc9034f2247c5d368f9b0212ad44248b0c5e (patch)
tree902480293b665d74a337aeae6a0521104f561988 /spec
parentc920712fab6abdc37de9444e6bbcd170c295b21a (diff)
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec')
-rw-r--r--spec/factories/uploads.rb2
-rw-r--r--spec/helpers/blob_helper_spec.rb28
-rw-r--r--spec/lib/banzai/filter/video_link_filter_spec.rb1
-rw-r--r--spec/lib/gitlab/ci/status/external/factory_spec.rb2
-rw-r--r--spec/lib/gitlab/ci/status/factory_spec.rb2
-rw-r--r--spec/lib/gitlab/ci/status/pipeline/factory_spec.rb2
-rw-r--r--spec/lib/gitlab/ci/status/stage/factory_spec.rb2
-rw-r--r--spec/lib/gitlab/config/entry/simplifiable_spec.rb6
-rw-r--r--spec/lib/gitlab/patch/prependable_spec.rb10
-rw-r--r--spec/rubocop/cop/gitlab/const_get_inherit_false_spec.rb80
-rw-r--r--spec/support/shared_examples/models/cluster_application_status_shared_examples.rb4
-rw-r--r--spec/support/shared_examples/models/cluster_application_version_shared_examples.rb2
-rw-r--r--spec/views/projects/tree/_tree_header.html.haml_spec.rb44
13 files changed, 169 insertions, 16 deletions
diff --git a/spec/factories/uploads.rb b/spec/factories/uploads.rb
index ef464d3d6e0..a060cd7d6f8 100644
--- a/spec/factories/uploads.rb
+++ b/spec/factories/uploads.rb
@@ -15,7 +15,7 @@ FactoryBot.define do
end
path do
- uploader_instance = Object.const_get(uploader.to_s).new(model, mount_point)
+ uploader_instance = Object.const_get(uploader.to_s, false).new(model, mount_point)
File.join(uploader_instance.store_dir, filename)
end
diff --git a/spec/helpers/blob_helper_spec.rb b/spec/helpers/blob_helper_spec.rb
index e5e16e69833..4996e27c2e6 100644
--- a/spec/helpers/blob_helper_spec.rb
+++ b/spec/helpers/blob_helper_spec.rb
@@ -270,4 +270,32 @@ describe BlobHelper do
end
end
end
+
+ describe '#ide_fork_and_edit_path' do
+ let(:project) { create(:project) }
+ let(:current_user) { create(:user) }
+ let(:can_push_code) { true }
+
+ before do
+ allow(helper).to receive(:current_user).and_return(current_user)
+ allow(helper).to receive(:can?).and_return(can_push_code)
+ end
+
+ it 'returns path to fork the repo with a redirect param to the full IDE path' do
+ uri = URI(helper.ide_fork_and_edit_path(project, "master", ""))
+ params = CGI.unescape(uri.query)
+
+ expect(uri.path).to eq("/#{project.namespace.path}/#{project.path}/-/forks")
+ expect(params).to include("continue[to]=/-/ide/project/#{project.namespace.path}/#{project.path}/edit/master")
+ expect(params).to include("namespace_key=#{current_user.namespace.id}")
+ end
+
+ context 'when user is not logged in' do
+ let(:current_user) { nil }
+
+ it 'returns nil' do
+ expect(helper.ide_fork_and_edit_path(project, "master", "")).to be_nil
+ end
+ end
+ end
end
diff --git a/spec/lib/banzai/filter/video_link_filter_spec.rb b/spec/lib/banzai/filter/video_link_filter_spec.rb
index 332817d6585..a395b021f32 100644
--- a/spec/lib/banzai/filter/video_link_filter_spec.rb
+++ b/spec/lib/banzai/filter/video_link_filter_spec.rb
@@ -32,6 +32,7 @@ describe Banzai::Filter::VideoLinkFilter do
expect(video.name).to eq 'video'
expect(video['src']).to eq src
+ expect(video['width']).to eq "100%"
expect(paragraph.name).to eq 'p'
diff --git a/spec/lib/gitlab/ci/status/external/factory_spec.rb b/spec/lib/gitlab/ci/status/external/factory_spec.rb
index 3b90fb60cca..9d7dfc42848 100644
--- a/spec/lib/gitlab/ci/status/external/factory_spec.rb
+++ b/spec/lib/gitlab/ci/status/external/factory_spec.rb
@@ -22,7 +22,7 @@ describe Gitlab::Ci::Status::External::Factory do
end
let(:expected_status) do
- Gitlab::Ci::Status.const_get(simple_status.capitalize)
+ Gitlab::Ci::Status.const_get(simple_status.capitalize, false)
end
it "fabricates a core status #{simple_status}" do
diff --git a/spec/lib/gitlab/ci/status/factory_spec.rb b/spec/lib/gitlab/ci/status/factory_spec.rb
index b51c0bec47e..c6d7a1ec5d9 100644
--- a/spec/lib/gitlab/ci/status/factory_spec.rb
+++ b/spec/lib/gitlab/ci/status/factory_spec.rb
@@ -13,7 +13,7 @@ describe Gitlab::Ci::Status::Factory do
let(:resource) { double('resource', status: simple_status) }
let(:expected_status) do
- Gitlab::Ci::Status.const_get(simple_status.capitalize)
+ Gitlab::Ci::Status.const_get(simple_status.capitalize, false)
end
it "fabricates a core status #{simple_status}" do
diff --git a/spec/lib/gitlab/ci/status/pipeline/factory_spec.rb b/spec/lib/gitlab/ci/status/pipeline/factory_spec.rb
index 8a36cd1b658..3acc767ab7a 100644
--- a/spec/lib/gitlab/ci/status/pipeline/factory_spec.rb
+++ b/spec/lib/gitlab/ci/status/pipeline/factory_spec.rb
@@ -18,7 +18,7 @@ describe Gitlab::Ci::Status::Pipeline::Factory do
let(:pipeline) { create(:ci_pipeline, status: simple_status) }
let(:expected_status) do
- Gitlab::Ci::Status.const_get(simple_status.capitalize)
+ Gitlab::Ci::Status.const_get(simple_status.capitalize, false)
end
it "matches correct core status for #{simple_status}" do
diff --git a/spec/lib/gitlab/ci/status/stage/factory_spec.rb b/spec/lib/gitlab/ci/status/stage/factory_spec.rb
index 8f5b1ff62a5..dcb53712157 100644
--- a/spec/lib/gitlab/ci/status/stage/factory_spec.rb
+++ b/spec/lib/gitlab/ci/status/stage/factory_spec.rb
@@ -34,7 +34,7 @@ describe Gitlab::Ci::Status::Stage::Factory do
it "fabricates a core status #{core_status}" do
expect(status).to be_a(
- Gitlab::Ci::Status.const_get(core_status.capitalize))
+ Gitlab::Ci::Status.const_get(core_status.capitalize, false))
end
it 'extends core status with common stage methods' do
diff --git a/spec/lib/gitlab/config/entry/simplifiable_spec.rb b/spec/lib/gitlab/config/entry/simplifiable_spec.rb
index 65e18fe3f10..5c208cab449 100644
--- a/spec/lib/gitlab/config/entry/simplifiable_spec.rb
+++ b/spec/lib/gitlab/config/entry/simplifiable_spec.rb
@@ -24,9 +24,9 @@ describe Gitlab::Config::Entry::Simplifiable do
let(:unknown) { double('unknown strategy') }
before do
- stub_const("#{described_class.name}::Something", first)
- stub_const("#{described_class.name}::DifferentOne", second)
- stub_const("#{described_class.name}::UnknownStrategy", unknown)
+ entry::Something = first
+ entry::DifferentOne = second
+ entry::UnknownStrategy = unknown
end
context 'when first strategy should be used' do
diff --git a/spec/lib/gitlab/patch/prependable_spec.rb b/spec/lib/gitlab/patch/prependable_spec.rb
index 725d733d176..255324f89d5 100644
--- a/spec/lib/gitlab/patch/prependable_spec.rb
+++ b/spec/lib/gitlab/patch/prependable_spec.rb
@@ -72,8 +72,8 @@ describe Gitlab::Patch::Prependable do
expect(subject.ancestors.take(3)).to eq([subject, ee, ce])
expect(subject.singleton_class.ancestors.take(3))
.to eq([subject.singleton_class,
- ee.const_get(:ClassMethods),
- ce.const_get(:ClassMethods)])
+ ee.const_get(:ClassMethods, false),
+ ce.const_get(:ClassMethods, false)])
end
it 'prepends only once even if called twice' do
@@ -115,8 +115,8 @@ describe Gitlab::Patch::Prependable do
it 'has the expected ancestors' do
expect(subject.ancestors.take(3)).to eq([ee, ce, subject])
expect(subject.singleton_class.ancestors.take(3))
- .to eq([ee.const_get(:ClassMethods),
- ce.const_get(:ClassMethods),
+ .to eq([ee.const_get(:ClassMethods, false),
+ ce.const_get(:ClassMethods, false),
subject.singleton_class])
end
@@ -152,7 +152,7 @@ describe Gitlab::Patch::Prependable do
it 'has the expected ancestors' do
expect(subject.ancestors.take(2)).to eq([ee, subject])
expect(subject.singleton_class.ancestors.take(2))
- .to eq([ee.const_get(:ClassMethods),
+ .to eq([ee.const_get(:ClassMethods, false),
subject.singleton_class])
end
diff --git a/spec/rubocop/cop/gitlab/const_get_inherit_false_spec.rb b/spec/rubocop/cop/gitlab/const_get_inherit_false_spec.rb
new file mode 100644
index 00000000000..0ff06b431eb
--- /dev/null
+++ b/spec/rubocop/cop/gitlab/const_get_inherit_false_spec.rb
@@ -0,0 +1,80 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+require 'rubocop'
+require 'rubocop/rspec/support'
+require_relative '../../../../rubocop/cop/gitlab/const_get_inherit_false'
+
+describe RuboCop::Cop::Gitlab::ConstGetInheritFalse do
+ include CopHelper
+
+ subject(:cop) { described_class.new }
+
+ context 'Object.const_get' do
+ it 'registers an offense with no 2nd argument' do
+ expect_offense(<<~PATTERN.strip_indent)
+ Object.const_get(:CONSTANT)
+ ^^^^^^^^^ Use inherit=false when using const_get.
+ PATTERN
+ end
+
+ it 'autocorrects' do
+ expect(autocorrect_source('Object.const_get(:CONSTANT)')).to eq('Object.const_get(:CONSTANT, false)')
+ end
+
+ context 'inherit=false' do
+ it 'does not register an offense' do
+ expect_no_offenses(<<~PATTERN.strip_indent)
+ Object.const_get(:CONSTANT, false)
+ PATTERN
+ end
+ end
+
+ context 'inherit=true' do
+ it 'registers an offense' do
+ expect_offense(<<~PATTERN.strip_indent)
+ Object.const_get(:CONSTANT, true)
+ ^^^^^^^^^ Use inherit=false when using const_get.
+ PATTERN
+ end
+
+ it 'autocorrects' do
+ expect(autocorrect_source('Object.const_get(:CONSTANT, true)')).to eq('Object.const_get(:CONSTANT, false)')
+ end
+ end
+ end
+
+ context 'const_get for a nested class' do
+ it 'registers an offense on reload usage' do
+ expect_offense(<<~PATTERN.strip_indent)
+ Nested::Blog.const_get(:CONSTANT)
+ ^^^^^^^^^ Use inherit=false when using const_get.
+ PATTERN
+ end
+
+ it 'autocorrects' do
+ expect(autocorrect_source('Nested::Blag.const_get(:CONSTANT)')).to eq('Nested::Blag.const_get(:CONSTANT, false)')
+ end
+
+ context 'inherit=false' do
+ it 'does not register an offense' do
+ expect_no_offenses(<<~PATTERN.strip_indent)
+ Nested::Blog.const_get(:CONSTANT, false)
+ PATTERN
+ end
+ end
+
+ context 'inherit=true' do
+ it 'registers an offense if inherit is true' do
+ expect_offense(<<~PATTERN.strip_indent)
+ Nested::Blog.const_get(:CONSTANT, true)
+ ^^^^^^^^^ Use inherit=false when using const_get.
+ PATTERN
+ end
+
+ it 'autocorrects' do
+ expect(autocorrect_source('Nested::Blag.const_get(:CONSTANT, true)')).to eq('Nested::Blag.const_get(:CONSTANT, false)')
+ end
+ end
+ end
+end
diff --git a/spec/support/shared_examples/models/cluster_application_status_shared_examples.rb b/spec/support/shared_examples/models/cluster_application_status_shared_examples.rb
index 6f06d323a82..f95b612eb70 100644
--- a/spec/support/shared_examples/models/cluster_application_status_shared_examples.rb
+++ b/spec/support/shared_examples/models/cluster_application_status_shared_examples.rb
@@ -75,7 +75,7 @@ shared_examples 'cluster application status specs' do |application_name|
subject.reload
- expect(subject.version).to eq(subject.class.const_get(:VERSION))
+ expect(subject.version).to eq(subject.class.const_get(:VERSION, false))
end
context 'application is updating' do
@@ -104,7 +104,7 @@ shared_examples 'cluster application status specs' do |application_name|
subject.reload
- expect(subject.version).to eq(subject.class.const_get(:VERSION))
+ expect(subject.version).to eq(subject.class.const_get(:VERSION, false))
end
end
end
diff --git a/spec/support/shared_examples/models/cluster_application_version_shared_examples.rb b/spec/support/shared_examples/models/cluster_application_version_shared_examples.rb
index 181b102e685..ba02da41b53 100644
--- a/spec/support/shared_examples/models/cluster_application_version_shared_examples.rb
+++ b/spec/support/shared_examples/models/cluster_application_version_shared_examples.rb
@@ -12,7 +12,7 @@ shared_examples 'cluster application version specs' do |application_name|
context 'version is the same as VERSION' do
let(:application) { build(application_name) }
- let(:version) { application.class.const_get(:VERSION) }
+ let(:version) { application.class.const_get(:VERSION, false) }
it { is_expected.to be_falsey }
end
diff --git a/spec/views/projects/tree/_tree_header.html.haml_spec.rb b/spec/views/projects/tree/_tree_header.html.haml_spec.rb
new file mode 100644
index 00000000000..4b71ea9ffe3
--- /dev/null
+++ b/spec/views/projects/tree/_tree_header.html.haml_spec.rb
@@ -0,0 +1,44 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+describe 'projects/tree/_tree_header' do
+ let(:project) { create(:project, :repository) }
+ let(:current_user) { create(:user) }
+ let(:repository) { project.repository }
+
+ before do
+ assign(:project, project)
+ assign(:repository, repository)
+ assign(:id, File.join('master', ''))
+ assign(:ref, 'master')
+
+ allow(view).to receive(:current_user).and_return(current_user)
+ allow(view).to receive(:can_collaborate_with_project?) { true }
+ end
+
+ it 'does not render the WebIDE button when user cannot create fork or cannot open MR' do
+ allow(view).to receive(:can?) { false }
+
+ render
+
+ expect(rendered).not_to have_link('Web IDE')
+ end
+
+ it 'renders the WebIDE button when user can create fork and can open MR in project' do
+ allow(view).to receive(:can?) { true }
+
+ render
+
+ expect(rendered).to have_link('Web IDE')
+ end
+
+ it 'opens a popup confirming a fork if the user can create fork/MR but cannot collaborate with the project' do
+ allow(view).to receive(:can?) { true }
+ allow(view).to receive(:can_collaborate_with_project?) { false }
+
+ render
+
+ expect(rendered).to have_link('Web IDE', href: '#modal-confirm-fork')
+ end
+end