Use described_class when possible

Signed-off-by: Rémy Coutable <remy@rymai.me>
This commit is contained in:
Rémy Coutable 2017-07-25 19:09:00 +02:00
parent ddccd24c13
commit cddc5cacfb
106 changed files with 390 additions and 390 deletions

View File

@ -5,37 +5,37 @@ describe Settings do
describe '#host_without_www' do
context 'URL with protocol' do
it 'returns the host' do
expect(Settings.host_without_www('http://foo.com')).to eq 'foo.com'
expect(Settings.host_without_www('http://www.foo.com')).to eq 'foo.com'
expect(Settings.host_without_www('http://secure.foo.com')).to eq 'secure.foo.com'
expect(Settings.host_without_www('http://www.gravatar.com/avatar/%{hash}?s=%{size}&d=identicon')).to eq 'gravatar.com'
expect(described_class.host_without_www('http://foo.com')).to eq 'foo.com'
expect(described_class.host_without_www('http://www.foo.com')).to eq 'foo.com'
expect(described_class.host_without_www('http://secure.foo.com')).to eq 'secure.foo.com'
expect(described_class.host_without_www('http://www.gravatar.com/avatar/%{hash}?s=%{size}&d=identicon')).to eq 'gravatar.com'
expect(Settings.host_without_www('https://foo.com')).to eq 'foo.com'
expect(Settings.host_without_www('https://www.foo.com')).to eq 'foo.com'
expect(Settings.host_without_www('https://secure.foo.com')).to eq 'secure.foo.com'
expect(Settings.host_without_www('https://secure.gravatar.com/avatar/%{hash}?s=%{size}&d=identicon')).to eq 'secure.gravatar.com'
expect(described_class.host_without_www('https://foo.com')).to eq 'foo.com'
expect(described_class.host_without_www('https://www.foo.com')).to eq 'foo.com'
expect(described_class.host_without_www('https://secure.foo.com')).to eq 'secure.foo.com'
expect(described_class.host_without_www('https://secure.gravatar.com/avatar/%{hash}?s=%{size}&d=identicon')).to eq 'secure.gravatar.com'
end
end
context 'URL without protocol' do
it 'returns the host' do
expect(Settings.host_without_www('foo.com')).to eq 'foo.com'
expect(Settings.host_without_www('www.foo.com')).to eq 'foo.com'
expect(Settings.host_without_www('secure.foo.com')).to eq 'secure.foo.com'
expect(Settings.host_without_www('www.gravatar.com/avatar/%{hash}?s=%{size}&d=identicon')).to eq 'gravatar.com'
expect(described_class.host_without_www('foo.com')).to eq 'foo.com'
expect(described_class.host_without_www('www.foo.com')).to eq 'foo.com'
expect(described_class.host_without_www('secure.foo.com')).to eq 'secure.foo.com'
expect(described_class.host_without_www('www.gravatar.com/avatar/%{hash}?s=%{size}&d=identicon')).to eq 'gravatar.com'
end
context 'URL with user/port' do
it 'returns the host' do
expect(Settings.host_without_www('bob:pass@foo.com:8080')).to eq 'foo.com'
expect(Settings.host_without_www('bob:pass@www.foo.com:8080')).to eq 'foo.com'
expect(Settings.host_without_www('bob:pass@secure.foo.com:8080')).to eq 'secure.foo.com'
expect(Settings.host_without_www('bob:pass@www.gravatar.com:8080/avatar/%{hash}?s=%{size}&d=identicon')).to eq 'gravatar.com'
expect(described_class.host_without_www('bob:pass@foo.com:8080')).to eq 'foo.com'
expect(described_class.host_without_www('bob:pass@www.foo.com:8080')).to eq 'foo.com'
expect(described_class.host_without_www('bob:pass@secure.foo.com:8080')).to eq 'secure.foo.com'
expect(described_class.host_without_www('bob:pass@www.gravatar.com:8080/avatar/%{hash}?s=%{size}&d=identicon')).to eq 'gravatar.com'
expect(Settings.host_without_www('http://bob:pass@foo.com:8080')).to eq 'foo.com'
expect(Settings.host_without_www('http://bob:pass@www.foo.com:8080')).to eq 'foo.com'
expect(Settings.host_without_www('http://bob:pass@secure.foo.com:8080')).to eq 'secure.foo.com'
expect(Settings.host_without_www('http://bob:pass@www.gravatar.com:8080/avatar/%{hash}?s=%{size}&d=identicon')).to eq 'gravatar.com'
expect(described_class.host_without_www('http://bob:pass@foo.com:8080')).to eq 'foo.com'
expect(described_class.host_without_www('http://bob:pass@www.foo.com:8080')).to eq 'foo.com'
expect(described_class.host_without_www('http://bob:pass@secure.foo.com:8080')).to eq 'secure.foo.com'
expect(described_class.host_without_www('http://bob:pass@www.gravatar.com:8080/avatar/%{hash}?s=%{size}&d=identicon')).to eq 'gravatar.com'
end
end
end

View File

@ -2,7 +2,7 @@ require 'spec_helper'
describe DisableEmailInterceptor do
before do
Mail.register_interceptor(DisableEmailInterceptor)
Mail.register_interceptor(described_class)
end
it 'does not send emails' do
@ -14,7 +14,7 @@ describe DisableEmailInterceptor do
# Removing interceptor from the list because unregister_interceptor is
# implemented in later version of mail gem
# See: https://github.com/mikel/mail/pull/705
Mail.unregister_interceptor(DisableEmailInterceptor)
Mail.unregister_interceptor(described_class)
end
def deliver_mail

View File

@ -16,42 +16,42 @@ describe EventFilter do
let!(:left_event) { create(:event, :left, project: public_project, target: public_project, author: source_user) }
it 'applies push filter' do
events = EventFilter.new(EventFilter.push).apply_filter(Event.all)
events = described_class.new(described_class.push).apply_filter(Event.all)
expect(events).to contain_exactly(push_event)
end
it 'applies merged filter' do
events = EventFilter.new(EventFilter.merged).apply_filter(Event.all)
events = described_class.new(described_class.merged).apply_filter(Event.all)
expect(events).to contain_exactly(merged_event)
end
it 'applies issue filter' do
events = EventFilter.new(EventFilter.issue).apply_filter(Event.all)
events = described_class.new(described_class.issue).apply_filter(Event.all)
expect(events).to contain_exactly(created_event, updated_event, closed_event, reopened_event)
end
it 'applies comments filter' do
events = EventFilter.new(EventFilter.comments).apply_filter(Event.all)
events = described_class.new(described_class.comments).apply_filter(Event.all)
expect(events).to contain_exactly(comments_event)
end
it 'applies team filter' do
events = EventFilter.new(EventFilter.team).apply_filter(Event.all)
events = described_class.new(described_class.team).apply_filter(Event.all)
expect(events).to contain_exactly(joined_event, left_event)
end
it 'applies all filter' do
events = EventFilter.new(EventFilter.all).apply_filter(Event.all)
events = described_class.new(described_class.all).apply_filter(Event.all)
expect(events).to contain_exactly(push_event, merged_event, created_event, updated_event, closed_event, reopened_event, comments_event, joined_event, left_event)
end
it 'applies no filter' do
events = EventFilter.new(nil).apply_filter(Event.all)
events = described_class.new(nil).apply_filter(Event.all)
expect(events).to contain_exactly(push_event, merged_event, created_event, updated_event, closed_event, reopened_event, comments_event, joined_event, left_event)
end
it 'applies unknown filter' do
events = EventFilter.new('').apply_filter(Event.all)
events = described_class.new('').apply_filter(Event.all)
expect(events).to contain_exactly(push_event, merged_event, created_event, updated_event, closed_event, reopened_event, comments_event, joined_event, left_event)
end
end

View File

@ -1,7 +1,7 @@
require 'spec_helper'
describe ExtractsPath do
include ExtractsPath
include described_class
include RepoHelpers
include Gitlab::Routing

View File

@ -1,7 +1,7 @@
require 'spec_helper'
describe FileSizeValidator do
let(:validator) { FileSizeValidator.new(options) }
let(:validator) { described_class.new(options) }
let(:attachment) { AttachmentUploader.new }
let(:note) { create(:note) }

View File

@ -58,7 +58,7 @@ describe Gitlab::BitbucketImport::Importer do
)
end
let(:importer) { Gitlab::BitbucketImport::Importer.new(project) }
let(:importer) { described_class.new(project) }
let(:issues_statuses_sample_data) do
{

View File

@ -27,7 +27,7 @@ describe Gitlab::BitbucketImport::ProjectCreator do
it 'creates project' do
allow_any_instance_of(Project).to receive(:add_import_job)
project_creator = Gitlab::BitbucketImport::ProjectCreator.new(repo, 'vim', namespace, user, access_params)
project_creator = described_class.new(repo, 'vim', namespace, user, access_params)
project = project_creator.execute
expect(project.import_url).to eq("ssh://git@bitbucket.org/asd/vim.git")

View File

@ -1,7 +1,7 @@
require 'spec_helper'
describe Gitlab::CiAccess do
let(:access) { Gitlab::CiAccess.new }
let(:access) { described_class.new }
describe '#can_do_action?' do
context 'when action is :build_download_code' do

View File

@ -10,7 +10,7 @@ describe Gitlab::Conflict::File do
let(:index) { rugged.merge_commits(our_commit, their_commit) }
let(:conflict) { index.conflicts.last }
let(:merge_file_result) { index.merge_file('files/ruby/regex.rb') }
let(:conflict_file) { Gitlab::Conflict::File.new(merge_file_result, conflict, merge_request: merge_request) }
let(:conflict_file) { described_class.new(merge_file_result, conflict, merge_request: merge_request) }
describe '#resolve_lines' do
let(:section_keys) { conflict_file.sections.map { |section| section[:id] }.compact }
@ -220,7 +220,7 @@ end
FILE
end
let(:conflict_file) { Gitlab::Conflict::File.new({ data: file }, conflict, merge_request: merge_request) }
let(:conflict_file) { described_class.new({ data: file }, conflict, merge_request: merge_request) }
let(:sections) { conflict_file.sections }
it 'sets the correct match line headers' do

View File

@ -1,7 +1,7 @@
require 'spec_helper'
describe Gitlab::Conflict::Parser do
let(:parser) { Gitlab::Conflict::Parser.new }
let(:parser) { described_class.new }
describe '#parse' do
def parse_text(text)

View File

@ -3,7 +3,7 @@ require 'spec_helper'
describe Gitlab::Database::MigrationHelpers do
let(:model) do
ActiveRecord::Migration.new.extend(
Gitlab::Database::MigrationHelpers
described_class
)
end

View File

@ -10,7 +10,7 @@ describe Gitlab::Diff::Highlight do
describe '#highlight' do
context "with a diff file" do
let(:subject) { Gitlab::Diff::Highlight.new(diff_file, repository: project.repository).highlight }
let(:subject) { described_class.new(diff_file, repository: project.repository).highlight }
it 'returns Gitlab::Diff::Line elements' do
expect(subject.first).to be_an_instance_of(Gitlab::Diff::Line)
@ -41,7 +41,7 @@ describe Gitlab::Diff::Highlight do
end
context "with diff lines" do
let(:subject) { Gitlab::Diff::Highlight.new(diff_file.diff_lines, repository: project.repository).highlight }
let(:subject) { described_class.new(diff_file.diff_lines, repository: project.repository).highlight }
it 'returns Gitlab::Diff::Line elements' do
expect(subject.first).to be_an_instance_of(Gitlab::Diff::Line)

View File

@ -6,7 +6,7 @@ describe Gitlab::Diff::Parser do
let(:project) { create(:project) }
let(:commit) { project.commit(sample_commit.id) }
let(:diff) { commit.raw_diffs.first }
let(:parser) { Gitlab::Diff::Parser.new }
let(:parser) { described_class.new }
describe '#parse' do
let(:diff) do

View File

@ -5,7 +5,7 @@ describe Gitlab::Git::Hook do
before do
# We need this because in the spec/spec_helper.rb we define it like this:
# allow_any_instance_of(Gitlab::Git::Hook).to receive(:trigger).and_return([true, nil])
allow_any_instance_of(Gitlab::Git::Hook).to receive(:trigger).and_call_original
allow_any_instance_of(described_class).to receive(:trigger).and_call_original
end
describe "#trigger" do
@ -48,7 +48,7 @@ describe Gitlab::Git::Hook do
it "returns success with no errors" do
create_hook(hook_name)
hook = Gitlab::Git::Hook.new(hook_name, project)
hook = described_class.new(hook_name, project)
blank = Gitlab::Git::BLANK_SHA
ref = Gitlab::Git::BRANCH_REF_PREFIX + 'new_branch'
@ -66,7 +66,7 @@ describe Gitlab::Git::Hook do
context "when the hook is unsuccessful" do
it "returns failure with errors" do
create_failing_hook(hook_name)
hook = Gitlab::Git::Hook.new(hook_name, project)
hook = described_class.new(hook_name, project)
blank = Gitlab::Git::BLANK_SHA
ref = Gitlab::Git::BRANCH_REF_PREFIX + 'new_branch'
@ -80,7 +80,7 @@ describe Gitlab::Git::Hook do
context "when the hook doesn't exist" do
it "returns success with no errors" do
hook = Gitlab::Git::Hook.new('unknown_hook', project)
hook = described_class.new('unknown_hook', project)
blank = Gitlab::Git::BLANK_SHA
ref = Gitlab::Git::BRANCH_REF_PREFIX + 'new_branch'

View File

@ -11,7 +11,7 @@ describe Gitlab::Git::RevList do
end
context "#new_refs" do
let(:rev_list) { Gitlab::Git::RevList.new(newrev: 'newrev', path_to_repo: project.repository.path_to_repo) }
let(:rev_list) { described_class.new(newrev: 'newrev', path_to_repo: project.repository.path_to_repo) }
it 'calls out to `popen`' do
expect(Gitlab::Popen).to receive(:popen).with([
@ -33,7 +33,7 @@ describe Gitlab::Git::RevList do
end
context "#missed_ref" do
let(:rev_list) { Gitlab::Git::RevList.new(oldrev: 'oldrev', newrev: 'newrev', path_to_repo: project.repository.path_to_repo) }
let(:rev_list) { described_class.new(oldrev: 'oldrev', newrev: 'newrev', path_to_repo: project.repository.path_to_repo) }
it 'calls out to `popen`' do
expect(Gitlab::Popen).to receive(:popen).with([

View File

@ -3,7 +3,7 @@ require 'spec_helper'
describe Gitlab::GitAccess do
let(:pull_access_check) { access.check('git-upload-pack', '_any') }
let(:push_access_check) { access.check('git-receive-pack', '_any') }
let(:access) { Gitlab::GitAccess.new(actor, project, protocol, authentication_abilities: authentication_abilities, redirected_path: redirected_path) }
let(:access) { described_class.new(actor, project, protocol, authentication_abilities: authentication_abilities, redirected_path: redirected_path) }
let(:project) { create(:project, :repository) }
let(:user) { create(:user) }
let(:actor) { user }
@ -280,7 +280,7 @@ describe Gitlab::GitAccess do
context 'when project is public' do
let(:public_project) { create(:project, :public, :repository) }
let(:access) { Gitlab::GitAccess.new(nil, public_project, 'web', authentication_abilities: []) }
let(:access) { described_class.new(nil, public_project, 'web', authentication_abilities: []) }
context 'when repository is enabled' do
it 'give access to download code' do
@ -441,7 +441,7 @@ describe Gitlab::GitAccess do
end
permissions_matrix[role].each do |action, allowed|
context action do
context action.to_s do
subject { access.send(:check_push_access!, changes[action]) }
it do

View File

@ -1,7 +1,7 @@
require 'spec_helper'
describe Gitlab::GitAccessWiki do
let(:access) { Gitlab::GitAccessWiki.new(user, project, 'web', authentication_abilities: authentication_abilities, redirected_path: redirected_path) }
let(:access) { described_class.new(user, project, 'web', authentication_abilities: authentication_abilities, redirected_path: redirected_path) }
let(:project) { create(:project, :repository) }
let(:user) { create(:user) }
let(:redirected_path) { nil }

View File

@ -1,25 +1,25 @@
require 'spec_helper'
describe Gitlab::GitRefValidator do
it { expect(Gitlab::GitRefValidator.validate('feature/new')).to be_truthy }
it { expect(Gitlab::GitRefValidator.validate('implement_@all')).to be_truthy }
it { expect(Gitlab::GitRefValidator.validate('my_new_feature')).to be_truthy }
it { expect(Gitlab::GitRefValidator.validate('#1')).to be_truthy }
it { expect(Gitlab::GitRefValidator.validate('feature/refs/heads/foo')).to be_truthy }
it { expect(Gitlab::GitRefValidator.validate('feature/~new/')).to be_falsey }
it { expect(Gitlab::GitRefValidator.validate('feature/^new/')).to be_falsey }
it { expect(Gitlab::GitRefValidator.validate('feature/:new/')).to be_falsey }
it { expect(Gitlab::GitRefValidator.validate('feature/?new/')).to be_falsey }
it { expect(Gitlab::GitRefValidator.validate('feature/*new/')).to be_falsey }
it { expect(Gitlab::GitRefValidator.validate('feature/[new/')).to be_falsey }
it { expect(Gitlab::GitRefValidator.validate('feature/new/')).to be_falsey }
it { expect(Gitlab::GitRefValidator.validate('feature/new.')).to be_falsey }
it { expect(Gitlab::GitRefValidator.validate('feature\@{')).to be_falsey }
it { expect(Gitlab::GitRefValidator.validate('feature\new')).to be_falsey }
it { expect(Gitlab::GitRefValidator.validate('feature//new')).to be_falsey }
it { expect(Gitlab::GitRefValidator.validate('feature new')).to be_falsey }
it { expect(Gitlab::GitRefValidator.validate('refs/heads/')).to be_falsey }
it { expect(Gitlab::GitRefValidator.validate('refs/remotes/')).to be_falsey }
it { expect(Gitlab::GitRefValidator.validate('refs/heads/feature')).to be_falsey }
it { expect(Gitlab::GitRefValidator.validate('refs/remotes/origin')).to be_falsey }
it { expect(described_class.validate('feature/new')).to be_truthy }
it { expect(described_class.validate('implement_@all')).to be_truthy }
it { expect(described_class.validate('my_new_feature')).to be_truthy }
it { expect(described_class.validate('#1')).to be_truthy }
it { expect(described_class.validate('feature/refs/heads/foo')).to be_truthy }
it { expect(described_class.validate('feature/~new/')).to be_falsey }
it { expect(described_class.validate('feature/^new/')).to be_falsey }
it { expect(described_class.validate('feature/:new/')).to be_falsey }
it { expect(described_class.validate('feature/?new/')).to be_falsey }
it { expect(described_class.validate('feature/*new/')).to be_falsey }
it { expect(described_class.validate('feature/[new/')).to be_falsey }
it { expect(described_class.validate('feature/new/')).to be_falsey }
it { expect(described_class.validate('feature/new.')).to be_falsey }
it { expect(described_class.validate('feature\@{')).to be_falsey }
it { expect(described_class.validate('feature\new')).to be_falsey }
it { expect(described_class.validate('feature//new')).to be_falsey }
it { expect(described_class.validate('feature new')).to be_falsey }
it { expect(described_class.validate('refs/heads/')).to be_falsey }
it { expect(described_class.validate('refs/remotes/')).to be_falsey }
it { expect(described_class.validate('refs/heads/feature')).to be_falsey }
it { expect(described_class.validate('refs/remotes/origin')).to be_falsey }
end

View File

@ -6,7 +6,7 @@ describe Gitlab::Git do
describe 'committer_hash' do
it "returns a hash containing the given email and name" do
committer_hash = Gitlab::Git.committer_hash(email: committer_email, name: committer_name)
committer_hash = described_class.committer_hash(email: committer_email, name: committer_name)
expect(committer_hash[:email]).to eq(committer_email)
expect(committer_hash[:name]).to eq(committer_name)
@ -15,7 +15,7 @@ describe Gitlab::Git do
context 'when email is nil' do
it "returns nil" do
committer_hash = Gitlab::Git.committer_hash(email: nil, name: committer_name)
committer_hash = described_class.committer_hash(email: nil, name: committer_name)
expect(committer_hash).to be_nil
end
@ -23,7 +23,7 @@ describe Gitlab::Git do
context 'when name is nil' do
it "returns nil" do
committer_hash = Gitlab::Git.committer_hash(email: committer_email, name: nil)
committer_hash = described_class.committer_hash(email: committer_email, name: nil)
expect(committer_hash).to be_nil
end

View File

@ -4,7 +4,7 @@ describe Gitlab::GitlabImport::Client do
include ImportSpecHelper
let(:token) { '123456' }
let(:client) { Gitlab::GitlabImport::Client.new(token) }
let(:client) { described_class.new(token) }
before do
stub_omniauth_provider('gitlab')

View File

@ -23,7 +23,7 @@ describe Gitlab::GitlabImport::ProjectCreator do
it 'creates project' do
allow_any_instance_of(Project).to receive(:add_import_job)
project_creator = Gitlab::GitlabImport::ProjectCreator.new(repo, namespace, user, access_params)
project_creator = described_class.new(repo, namespace, user, access_params)
project = project_creator.execute
expect(project.import_url).to eq("https://oauth2:asdffg@gitlab.com/asd/vim.git")

View File

@ -18,7 +18,7 @@ describe Gitlab::GoogleCodeImport::ProjectCreator do
it 'creates project' do
allow_any_instance_of(Project).to receive(:add_import_job)
project_creator = Gitlab::GoogleCodeImport::ProjectCreator.new(repo, namespace, user)
project_creator = described_class.new(repo, namespace, user)
project = project_creator.execute
expect(project.import_url).to eq("https://vim.googlecode.com/git/")

View File

@ -12,7 +12,7 @@ describe Gitlab::Highlight do
let(:blob) { repository.blob_at_branch(branch, path) }
let(:highlighter) do
Gitlab::Highlight.new(blob.path, blob.data, repository: repository)
described_class.new(blob.path, blob.data, repository: repository)
end
before do
@ -42,7 +42,7 @@ describe Gitlab::Highlight do
let(:path) { 'files/whitespace' }
let(:blob) { repository.blob_at_branch(branch, path) }
let(:lines) do
Gitlab::Highlight.highlight(blob.path, blob.data, repository: repository).lines
described_class.highlight(blob.path, blob.data, repository: repository).lines
end
it 'strips extra LFs' do

View File

@ -6,7 +6,7 @@ describe Gitlab::KeyFingerprint do
describe "#fingerprint" do
it "generates the key's fingerprint" do
expect(Gitlab::KeyFingerprint.new(key).fingerprint).to eq(fingerprint)
expect(described_class.new(key).fingerprint).to eq(fingerprint)
end
end
end

View File

@ -1,7 +1,7 @@
require 'spec_helper'
describe Gitlab::LDAP::Access do
let(:access) { Gitlab::LDAP::Access.new user }
let(:access) { described_class.new user }
let(:user) { create(:omniauth_user) }
describe '.allowed?' do

View File

@ -2,7 +2,7 @@ require 'spec_helper'
describe Gitlab::LDAP::AuthHash do
let(:auth_hash) do
Gitlab::LDAP::AuthHash.new(
described_class.new(
OmniAuth::AuthHash.new(
uid: '123456',
provider: 'ldapmain',

View File

@ -3,11 +3,11 @@ require 'spec_helper'
describe Gitlab::LDAP::Config do
include LdapHelpers
let(:config) { Gitlab::LDAP::Config.new('ldapmain') }
let(:config) { described_class.new('ldapmain') }
describe '#initialize' do
it 'requires a provider' do
expect{ Gitlab::LDAP::Config.new }.to raise_error ArgumentError
expect{ described_class.new }.to raise_error ArgumentError
end
it 'works' do
@ -15,7 +15,7 @@ describe Gitlab::LDAP::Config do
end
it 'raises an error if a unknown provider is used' do
expect{ Gitlab::LDAP::Config.new 'unknown' }.to raise_error(RuntimeError)
expect{ described_class.new 'unknown' }.to raise_error(RuntimeError)
end
end

View File

@ -1,7 +1,7 @@
require 'spec_helper'
describe Gitlab::LDAP::User do
let(:ldap_user) { Gitlab::LDAP::User.new(auth_hash) }
let(:ldap_user) { described_class.new(auth_hash) }
let(:gl_user) { ldap_user.gl_user }
let(:info) do
{
@ -13,7 +13,7 @@ describe Gitlab::LDAP::User do
let(:auth_hash) do
OmniAuth::AuthHash.new(uid: 'my-uid', provider: 'ldapmain', info: info)
end
let(:ldap_user_upper_case) { Gitlab::LDAP::User.new(auth_hash_upper_case) }
let(:ldap_user_upper_case) { described_class.new(auth_hash_upper_case) }
let(:info_upper_case) do
{
name: 'John',

View File

@ -5,36 +5,36 @@ describe Gitlab::MarkupHelper do
%w(textile rdoc org creole wiki
mediawiki rst adoc ad asciidoc mdown md markdown).each do |type|
it "returns true for #{type} files" do
expect(Gitlab::MarkupHelper.markup?("README.#{type}")).to be_truthy
expect(described_class.markup?("README.#{type}")).to be_truthy
end
end
it 'returns false when given a non-markup filename' do
expect(Gitlab::MarkupHelper.markup?('README.rb')).not_to be_truthy
expect(described_class.markup?('README.rb')).not_to be_truthy
end
end
describe '#gitlab_markdown?' do
%w(mdown mkd mkdn md markdown).each do |type|
it "returns true for #{type} files" do
expect(Gitlab::MarkupHelper.gitlab_markdown?("README.#{type}")).to be_truthy
expect(described_class.gitlab_markdown?("README.#{type}")).to be_truthy
end
end
it 'returns false when given a non-markdown filename' do
expect(Gitlab::MarkupHelper.gitlab_markdown?('README.rb')).not_to be_truthy
expect(described_class.gitlab_markdown?('README.rb')).not_to be_truthy
end
end
describe '#asciidoc?' do
%w(adoc ad asciidoc ADOC).each do |type|
it "returns true for #{type} files" do
expect(Gitlab::MarkupHelper.asciidoc?("README.#{type}")).to be_truthy
expect(described_class.asciidoc?("README.#{type}")).to be_truthy
end
end
it 'returns false when given a non-asciidoc filename' do
expect(Gitlab::MarkupHelper.asciidoc?('README.rb')).not_to be_truthy
expect(described_class.asciidoc?('README.rb')).not_to be_truthy
end
end
end

View File

@ -2,7 +2,7 @@ require 'spec_helper'
describe Gitlab::OAuth::AuthHash do
let(:auth_hash) do
Gitlab::OAuth::AuthHash.new(
described_class.new(
OmniAuth::AuthHash.new(
provider: provider_ascii,
uid: uid_ascii,

View File

@ -1,7 +1,7 @@
require 'spec_helper'
describe Gitlab::OAuth::User do
let(:oauth_user) { Gitlab::OAuth::User.new(auth_hash) }
let(:oauth_user) { described_class.new(auth_hash) }
let(:gl_user) { oauth_user.gl_user }
let(:uid) { 'my-uid' }
let(:provider) { 'my-provider' }

View File

@ -3,7 +3,7 @@ require 'spec_helper'
describe Gitlab::ProjectTransfer do
before do
@root_dir = File.join(Rails.root, "public", "uploads")
@project_transfer = Gitlab::ProjectTransfer.new
@project_transfer = described_class.new
allow(@project_transfer).to receive(:root_dir).and_return(@root_dir)
@project_path_was = "test_project_was"

View File

@ -7,7 +7,7 @@ describe Gitlab::ReferenceExtractor do
project.team << [project.creator, :developer]
end
subject { Gitlab::ReferenceExtractor.new(project, project.creator) }
subject { described_class.new(project, project.creator) }
it 'accesses valid user objects' do
@u_foo = create(:user, username: 'foo')

View File

@ -2,7 +2,7 @@ require 'spec_helper'
describe Gitlab::RequestContext do
describe '#client_ip' do
subject { Gitlab::RequestContext.client_ip }
subject { described_class.client_ip }
let(:app) { -> (env) {} }
let(:env) { Hash.new }
@ -16,7 +16,7 @@ describe Gitlab::RequestContext do
before do
allow_any_instance_of(Rack::Request).to receive(:ip).and_return(ip)
Gitlab::RequestContext.new(app).call(env)
described_class.new(app).call(env)
end
it { is_expected.to eq(ip) }

View File

@ -3,7 +3,7 @@ require 'stringio'
describe Gitlab::Shell do
let(:project) { double('Project', id: 7, path: 'diaspora') }
let(:gitlab_shell) { Gitlab::Shell.new }
let(:gitlab_shell) { described_class.new }
let(:popen_vars) { { 'GIT_TERMINAL_PROMPT' => ENV['GIT_TERMINAL_PROMPT'] } }
before do
@ -30,7 +30,7 @@ describe Gitlab::Shell do
allow(Gitlab.config.gitlab_shell).to receive(:secret_file).and_return(secret_file)
allow(Gitlab.config.gitlab_shell).to receive(:path).and_return('tmp/tests/shell-secret-test')
FileUtils.mkdir('tmp/tests/shell-secret-test')
Gitlab::Shell.ensure_secret_token!
described_class.ensure_secret_token!
end
after do
@ -39,7 +39,7 @@ describe Gitlab::Shell do
end
it 'creates and links the secret token file' do
secret_token = Gitlab::Shell.secret_token
secret_token = described_class.secret_token
expect(File.exist?(secret_file)).to be(true)
expect(File.read(secret_file).chomp).to eq(secret_token)

View File

@ -1,7 +1,7 @@
require 'spec_helper'
describe Gitlab::Upgrader do
let(:upgrader) { Gitlab::Upgrader.new }
let(:upgrader) { described_class.new }
let(:current_version) { Gitlab::VERSION }
describe 'current_version_raw' do

View File

@ -1,7 +1,7 @@
require 'spec_helper'
describe Gitlab::UserAccess do
let(:access) { Gitlab::UserAccess.new(user, project: project) }
let(:access) { described_class.new(user, project: project) }
let(:project) { create(:project) }
let(:user) { create(:user) }
@ -28,7 +28,7 @@ describe Gitlab::UserAccess do
describe 'push to empty project' do
let(:empty_project) { create(:project_empty_repo) }
let(:project_access) { Gitlab::UserAccess.new(user, project: empty_project) }
let(:project_access) { described_class.new(user, project: empty_project) }
it 'returns true if user is master' do
empty_project.team << [user, :master]

View File

@ -63,13 +63,13 @@ describe Gitlab::Workhorse do
end
context 'without ca_pem' do
subject { Gitlab::Workhorse.terminal_websocket(terminal) }
subject { described_class.terminal_websocket(terminal) }
it { is_expected.to eq(workhorse) }
end
context 'with ca_pem' do
subject { Gitlab::Workhorse.terminal_websocket(terminal(ca_pem: "foo")) }
subject { described_class.terminal_websocket(terminal(ca_pem: "foo")) }
it { is_expected.to eq(workhorse(ca_pem: "foo")) }
end

View File

@ -3,7 +3,7 @@ require 'spec_helper'
describe RepositoryCache do
let(:project) { create(:empty_project) }
let(:backend) { double('backend').as_null_object }
let(:cache) { RepositoryCache.new('example', project.id, backend) }
let(:cache) { described_class.new('example', project.id, backend) }
describe '#cache_key' do
it 'includes the namespace' do

View File

@ -19,7 +19,7 @@ describe SystemCheck do
end
describe '.run' do
subject { SystemCheck }
subject { described_class }
it 'detects execution of SimpleCheck' do
is_expected.to execute_check(SimpleCheck)

View File

@ -3,7 +3,7 @@ require 'spec_helper'
describe Ability do
context 'using a nil subject' do
it 'has no permissions' do
expect(Ability.policy_for(nil, nil)).to be_banned
expect(described_class.policy_for(nil, nil)).to be_banned
end
end

View File

@ -1,7 +1,7 @@
require 'spec_helper'
describe ApplicationSetting do
let(:setting) { ApplicationSetting.create_from_defaults }
let(:setting) { described_class.create_from_defaults }
it { expect(setting).to be_valid }
it { expect(setting.uuid).to be_present }
@ -159,10 +159,10 @@ describe ApplicationSetting do
context 'redis unavailable' do
it 'returns an ApplicationSetting' do
allow(Rails.cache).to receive(:fetch).and_call_original
allow(ApplicationSetting).to receive(:last).and_return(:last)
allow(described_class).to receive(:last).and_return(:last)
expect(Rails.cache).to receive(:fetch).with(ApplicationSetting::CACHE_KEY).and_raise(ArgumentError)
expect(ApplicationSetting.current).to eq(:last)
expect(described_class.current).to eq(:last)
end
end
end

View File

@ -24,26 +24,26 @@ describe BroadcastMessage do
it 'returns message if time match' do
message = create(:broadcast_message)
expect(BroadcastMessage.current).to include(message)
expect(described_class.current).to include(message)
end
it 'returns multiple messages if time match' do
message1 = create(:broadcast_message)
message2 = create(:broadcast_message)
expect(BroadcastMessage.current).to contain_exactly(message1, message2)
expect(described_class.current).to contain_exactly(message1, message2)
end
it 'returns empty list if time not come' do
create(:broadcast_message, :future)
expect(BroadcastMessage.current).to be_empty
expect(described_class.current).to be_empty
end
it 'returns empty list if time has passed' do
create(:broadcast_message, :expired)
expect(BroadcastMessage.current).to be_empty
expect(described_class.current).to be_empty
end
end

View File

@ -46,7 +46,7 @@ describe Ci::PipelineSchedule do
end
it 'updates next_run_at automatically' do
expect(Ci::PipelineSchedule.last.next_run_at).to eq(expected_next_run_at)
expect(described_class.last.next_run_at).to eq(expected_next_run_at)
end
end
@ -61,7 +61,7 @@ describe Ci::PipelineSchedule do
it 'updates next_run_at automatically' do
pipeline_schedule.update!(cron: new_cron)
expect(Ci::PipelineSchedule.last.next_run_at).to eq(expected_next_run_at)
expect(described_class.last.next_run_at).to eq(expected_next_run_at)
end
end
end

View File

@ -50,7 +50,7 @@ describe Ci::Runner do
end
describe '.online' do
subject { Ci::Runner.online }
subject { described_class.online }
before do
@runner1 = FactoryGirl.create(:ci_runner, :shared, contacted_at: 1.year.ago)
@ -352,13 +352,13 @@ describe Ci::Runner do
end
context 'does not give owned runner' do
subject { Ci::Runner.assignable_for(project) }
subject { described_class.assignable_for(project) }
it { is_expected.to be_empty }
end
context 'does not give shared runner' do
subject { Ci::Runner.assignable_for(another_project) }
subject { described_class.assignable_for(another_project) }
it { is_expected.to be_empty }
end
@ -366,13 +366,13 @@ describe Ci::Runner do
context 'with unlocked runner' do
context 'does not give owned runner' do
subject { Ci::Runner.assignable_for(project) }
subject { described_class.assignable_for(project) }
it { is_expected.to be_empty }
end
context 'does give a specific runner' do
subject { Ci::Runner.assignable_for(another_project) }
subject { described_class.assignable_for(another_project) }
it { is_expected.to contain_exactly(runner) }
end
@ -384,13 +384,13 @@ describe Ci::Runner do
end
context 'does not give owned runner' do
subject { Ci::Runner.assignable_for(project) }
subject { described_class.assignable_for(project) }
it { is_expected.to be_empty }
end
context 'does not give a locked runner' do
subject { Ci::Runner.assignable_for(another_project) }
subject { described_class.assignable_for(another_project) }
it { is_expected.to be_empty }
end

View File

@ -72,7 +72,7 @@ describe GlobalMilestone do
project3
]
@global_milestones = GlobalMilestone.build_collection(projects, {})
@global_milestones = described_class.build_collection(projects, {})
end
it 'has all project milestones' do
@ -106,7 +106,7 @@ describe GlobalMilestone do
it 'returns the quantity of global milestones in each possible state' do
expected_count = { opened: 1, closed: 2, all: 2 }
count = GlobalMilestone.states_count(Project.all)
count = described_class.states_count(Project.all)
expect(count).to eq(expected_count)
end
@ -120,7 +120,7 @@ describe GlobalMilestone do
it 'returns 0 as the quantity of global milestones in each state' do
expected_count = { opened: 0, closed: 0, all: 0 }
count = GlobalMilestone.states_count(Project.all)
count = described_class.states_count(Project.all)
expect(count).to eq(expected_count)
end
@ -141,7 +141,7 @@ describe GlobalMilestone do
]
milestones_relation = Milestone.where(id: milestones.map(&:id))
@global_milestone = GlobalMilestone.new(milestone1_project1.title, milestones_relation)
@global_milestone = described_class.new(milestone1_project1.title, milestones_relation)
end
it 'has exactly one group milestone' do
@ -157,7 +157,7 @@ describe GlobalMilestone do
let(:milestone) { create(:milestone, title: "git / test", project: project1) }
it 'strips out slashes and spaces' do
global_milestone = GlobalMilestone.new(milestone.title, Milestone.where(id: milestone.id))
global_milestone = described_class.new(milestone.title, Milestone.where(id: milestone.id))
expect(global_milestone.safe_title).to eq('git-test')
end
@ -171,7 +171,7 @@ describe GlobalMilestone do
create(:active_milestone, title: title),
create(:closed_milestone, title: title)
]
global_milestone = GlobalMilestone.new(title, milestones)
global_milestone = described_class.new(title, milestones)
expect(global_milestone.state).to eq('active')
end
@ -184,7 +184,7 @@ describe GlobalMilestone do
create(:closed_milestone, title: title),
create(:closed_milestone, title: title)
]
global_milestone = GlobalMilestone.new(title, milestones)
global_milestone = described_class.new(title, milestones)
expect(global_milestone.state).to eq('closed')
end

View File

@ -9,7 +9,7 @@ describe GroupMilestone do
describe '.build' do
it 'returns milestone with group assigned' do
milestone = GroupMilestone.build(
milestone = described_class.build(
group,
[project],
project_milestone.title
@ -25,7 +25,7 @@ describe GroupMilestone do
end
it 'returns array of milestones, each with group assigned' do
milestones = GroupMilestone.build_collection(group, [project], {})
milestones = described_class.build_collection(group, [project], {})
expect(milestones).to all(have_attributes(group: group))
end
end

View File

@ -357,7 +357,7 @@ describe Group do
subject { build(:group, :nested) }
it { is_expected.to be_valid }
it { expect(subject.parent).to be_kind_of(Group) }
it { expect(subject.parent).to be_kind_of(described_class) }
end
describe '#members_with_parents', :nested_groups do

View File

@ -8,13 +8,13 @@ describe Guest do
describe '.can_pull?' do
context 'when project is private' do
it 'does not allow to pull the repo' do
expect(Guest.can?(:download_code, private_project)).to eq(false)
expect(described_class.can?(:download_code, private_project)).to eq(false)
end
end
context 'when project is internal' do
it 'does not allow to pull the repo' do
expect(Guest.can?(:download_code, internal_project)).to eq(false)
expect(described_class.can?(:download_code, internal_project)).to eq(false)
end
end
@ -23,7 +23,7 @@ describe Guest do
it 'does not allow to pull the repo' do
public_project.project_feature.update_attribute(:repository_access_level, ProjectFeature::DISABLED)
expect(Guest.can?(:download_code, public_project)).to eq(false)
expect(described_class.can?(:download_code, public_project)).to eq(false)
end
end
@ -31,13 +31,13 @@ describe Guest do
it 'does not allow to pull the repo' do
public_project.project_feature.update_attribute(:repository_access_level, ProjectFeature::PRIVATE)
expect(Guest.can?(:download_code, public_project)).to eq(false)
expect(described_class.can?(:download_code, public_project)).to eq(false)
end
end
context 'when repository is enabled' do
it 'allows to pull the repo' do
expect(Guest.can?(:download_code, public_project)).to eq(true)
expect(described_class.can?(:download_code, public_project)).to eq(true)
end
end
end

View File

@ -13,7 +13,7 @@ describe ProjectHook do
it 'returns hooks for push events only' do
hook = create(:project_hook, push_events: true)
create(:project_hook, push_events: false)
expect(ProjectHook.push_hooks).to eq([hook])
expect(described_class.push_hooks).to eq([hook])
end
end
@ -21,7 +21,7 @@ describe ProjectHook do
it 'returns hooks for tag push events only' do
hook = create(:project_hook, tag_push_events: true)
create(:project_hook, tag_push_events: false)
expect(ProjectHook.tag_push_hooks).to eq([hook])
expect(described_class.tag_push_hooks).to eq([hook])
end
end
end

View File

@ -122,7 +122,7 @@ describe SystemHook do
it 'returns hooks for repository update events only' do
hook = create(:system_hook, repository_update_events: true)
create(:system_hook, repository_update_events: false)
expect(SystemHook.repository_update_hooks).to eq([hook])
expect(described_class.repository_update_hooks).to eq([hook])
end
end

View File

@ -6,7 +6,7 @@ describe Member do
end
describe "Validation" do
subject { Member.new(access_level: Member::GUEST) }
subject { described_class.new(access_level: Member::GUEST) }
it { is_expected.to validate_presence_of(:user) }
it { is_expected.to validate_presence_of(:source) }

View File

@ -139,7 +139,7 @@ describe ProjectMember do
@project_1.team << [@user_1, :developer]
@project_2.team << [@user_2, :reporter]
ProjectMember.truncate_teams([@project_1.id, @project_2.id])
described_class.truncate_teams([@project_1.id, @project_2.id])
end
it { expect(@project_1.users).to be_empty }

View File

@ -98,7 +98,7 @@ describe MergeRequestDiff do
end
it 'saves empty state' do
allow_any_instance_of(MergeRequestDiff).to receive_message_chain(:compare, :commits)
allow_any_instance_of(described_class).to receive_message_chain(:compare, :commits)
.and_return([])
mr_diff = create(:merge_request).merge_request_diff

View File

@ -37,13 +37,13 @@ describe Milestone do
describe "unique milestone title" do
context "per project" do
it "does not accept the same title in a project twice" do
new_milestone = Milestone.new(project: milestone.project, title: milestone.title)
new_milestone = described_class.new(project: milestone.project, title: milestone.title)
expect(new_milestone).not_to be_valid
end
it "accepts the same title in another project" do
project = create(:empty_project)
new_milestone = Milestone.new(project: project, title: milestone.title)
new_milestone = described_class.new(project: project, title: milestone.title)
expect(new_milestone).to be_valid
end
@ -58,7 +58,7 @@ describe Milestone do
end
it "does not accept the same title in a group twice" do
new_milestone = Milestone.new(group: group, title: milestone.title)
new_milestone = described_class.new(group: group, title: milestone.title)
expect(new_milestone).not_to be_valid
end
@ -66,7 +66,7 @@ describe Milestone do
it "does not accept the same title of a child project milestone" do
create(:milestone, project: group.projects.first)
new_milestone = Milestone.new(group: group, title: milestone.title)
new_milestone = described_class.new(group: group, title: milestone.title)
expect(new_milestone).not_to be_valid
end
@ -214,7 +214,7 @@ describe Milestone do
# The call to `#try` is because this returns a relation with a Postgres DB,
# and an array of IDs with a MySQL DB.
let(:milestone_ids) { Milestone.upcoming_ids_by_projects(projects).map { |id| id.try(:id) || id } }
let(:milestone_ids) { described_class.upcoming_ids_by_projects(projects).map { |id| id.try(:id) || id } }
it 'returns the next upcoming open milestone ID for each project' do
expect(milestone_ids).to contain_exactly(current_milestone_project_1.id, current_milestone_project_2.id)

View File

@ -133,7 +133,7 @@ describe Namespace do
it "sums all project storage counters in the namespace" do
project1
project2
statistics = Namespace.with_statistics.find(namespace.id)
statistics = described_class.with_statistics.find(namespace.id)
expect(statistics.storage_size).to eq 666
expect(statistics.repository_size).to eq 111
@ -142,7 +142,7 @@ describe Namespace do
end
it "correctly handles namespaces without projects" do
statistics = Namespace.with_statistics.find(namespace.id)
statistics = described_class.with_statistics.find(namespace.id)
expect(statistics.storage_size).to eq 0
expect(statistics.repository_size).to eq 0
@ -286,9 +286,9 @@ describe Namespace do
@namespace = create(:namespace, name: 'WoW', path: 'woW')
end
it { expect(Namespace.find_by_path_or_name('wow')).to eq(@namespace) }
it { expect(Namespace.find_by_path_or_name('WOW')).to eq(@namespace) }
it { expect(Namespace.find_by_path_or_name('unknown')).to eq(nil) }
it { expect(described_class.find_by_path_or_name('wow')).to eq(@namespace) }
it { expect(described_class.find_by_path_or_name('WOW')).to eq(@namespace) }
it { expect(described_class.find_by_path_or_name('unknown')).to eq(nil) }
end
describe ".clean_path" do
@ -296,8 +296,8 @@ describe Namespace do
let!(:namespace) { create(:namespace, path: "JohnGitLab-etc1") }
it "cleans the path and makes sure it's available" do
expect(Namespace.clean_path("-john+gitlab-ETC%.git@gmail.com")).to eq("johngitlab-ETC2")
expect(Namespace.clean_path("--%+--valid_*&%name=.git.%.atom.atom.@email.com")).to eq("valid_name")
expect(described_class.clean_path("-john+gitlab-ETC%.git@gmail.com")).to eq("johngitlab-ETC2")
expect(described_class.clean_path("--%+--valid_*&%name=.git.%.atom.atom.@email.com")).to eq("valid_name")
end
end

View File

@ -525,7 +525,7 @@ describe Note do
it "has a discussion id" do
# The discussion_id is set in `after_initialize`, so `reload` won't work
reloaded_note = Note.find(note.id)
reloaded_note = described_class.find(note.id)
expect(reloaded_note.discussion_id).not_to be_nil
expect(reloaded_note.discussion_id).to match(/\A\h{40}\z/)

View File

@ -35,7 +35,7 @@ describe AsanaService do
end
before do
@asana = AsanaService.new
@asana = described_class.new
allow(@asana).to receive_messages(
project: project,
project_id: project.id,

View File

@ -11,7 +11,7 @@ describe AssemblaService do
let(:project) { create(:project, :repository) }
before do
@assembla_service = AssemblaService.new
@assembla_service = described_class.new
allow(@assembla_service).to receive_messages(
project_id: project.id,
project: project,

View File

@ -29,7 +29,7 @@ describe CampfireService do
let(:project) { create(:project, :repository) }
before do
@campfire_service = CampfireService.new
@campfire_service = described_class.new
allow(@campfire_service).to receive_messages(
project_id: project.id,
project: project,

View File

@ -29,7 +29,7 @@ describe FlowdockService do
let(:project) { create(:project, :repository) }
before do
@flowdock_service = FlowdockService.new
@flowdock_service = described_class.new
allow(@flowdock_service).to receive_messages(
project_id: project.id,
project: project,

View File

@ -31,7 +31,7 @@ describe GemnasiumService do
let(:project) { create(:project, :repository) }
before do
@gemnasium_service = GemnasiumService.new
@gemnasium_service = described_class.new
allow(@gemnasium_service).to receive_messages(
project_id: project.id,
project: project,

View File

@ -27,7 +27,7 @@ describe GitlabIssueTrackerService do
context 'with absolute urls' do
before do
allow(GitlabIssueTrackerService).to receive(:default_url_options).and_return(script_name: "/gitlab/root")
allow(described_class).to receive(:default_url_options).and_return(script_name: "/gitlab/root")
end
it 'gives the correct path' do
@ -39,7 +39,7 @@ describe GitlabIssueTrackerService do
context 'with relative urls' do
before do
allow(GitlabIssueTrackerService).to receive(:default_url_options).and_return(script_name: "/gitlab/root")
allow(described_class).to receive(:default_url_options).and_return(script_name: "/gitlab/root")
end
it 'gives the correct path' do

View File

@ -25,7 +25,7 @@ describe HipchatService do
end
describe "Execute" do
let(:hipchat) { HipchatService.new }
let(:hipchat) { described_class.new }
let(:user) { create(:user) }
let(:project) { create(:project, :repository) }
let(:api_url) { 'https://hipchat.example.com/v2/room/123456/notification?auth_token=verySecret' }

View File

@ -27,7 +27,7 @@ describe IrkerService do
end
describe 'Execute' do
let(:irker) { IrkerService.new }
let(:irker) { described_class.new }
let(:user) { create(:user) }
let(:project) { create(:project, :repository) }
let(:sample_data) do

View File

@ -78,7 +78,7 @@ describe JiraService do
let(:merge_request) { create(:merge_request) }
before do
@jira_service = JiraService.new
@jira_service = described_class.new
allow(@jira_service).to receive_messages(
project_id: project.id,
project: project,
@ -167,7 +167,7 @@ describe JiraService do
stub_config_setting(relative_url_root: '/gitlab')
stub_config_setting(url: Settings.send(:build_gitlab_url))
allow(JiraService).to receive(:default_url_options) do
allow(described_class).to receive(:default_url_options) do
{ script_name: '/gitlab' }
end
@ -220,7 +220,7 @@ describe JiraService do
context "when a password was previously set" do
before do
@jira_service = JiraService.create!(
@jira_service = described_class.create!(
project: project,
properties: {
url: 'http://jira.example.com/web',
@ -301,7 +301,7 @@ describe JiraService do
context 'when no password was previously set' do
before do
@jira_service = JiraService.create(
@jira_service = described_class.create(
project: project,
properties: {
url: 'http://jira.example.com/rest/api/2',

View File

@ -26,7 +26,7 @@ describe PivotaltrackerService do
describe 'Execute' do
let(:service) do
PivotaltrackerService.new.tap do |service|
described_class.new.tap do |service|
service.token = 'secret_api_token'
end
end

View File

@ -29,7 +29,7 @@ describe PushoverService do
end
describe 'Execute' do
let(:pushover) { PushoverService.new }
let(:pushover) { described_class.new }
let(:user) { create(:user) }
let(:project) { create(:project, :repository) }
let(:sample_data) do

View File

@ -77,7 +77,7 @@ describe Project do
context 'after initialized' do
it "has a project_feature" do
expect(Project.new.project_feature).to be_present
expect(described_class.new.project_feature).to be_present
end
end
@ -438,7 +438,7 @@ describe Project do
end
it 'returns valid url to repo' do
project = Project.new(path: 'somewhere')
project = described_class.new(path: 'somewhere')
expect(project.url_to_repo).to eq(Gitlab.config.gitlab_shell.ssh_path_prefix + 'somewhere.git')
end
@ -917,7 +917,7 @@ describe Project do
end
describe '.with_shared_runners' do
subject { Project.with_shared_runners }
subject { described_class.with_shared_runners }
context 'when shared runners are enabled for project' do
let!(:project) { create(:empty_project, shared_runners_enabled: true) }
@ -942,10 +942,10 @@ describe Project do
let!(:project2) { create(:empty_project, :public, group: group) }
it 'returns total project count' do
expect(Project).to receive(:count).once.and_call_original
expect(described_class).to receive(:count).once.and_call_original
3.times do
expect(Project.cached_count).to eq(2)
expect(described_class.cached_count).to eq(2)
end
end
end
@ -990,7 +990,7 @@ describe Project do
user1.toggle_star(project1)
user2.toggle_star(project2)
expect(Project.starred_by(user1)).to contain_exactly(project1)
expect(described_class.starred_by(user1)).to contain_exactly(project1)
end
end
@ -2012,7 +2012,7 @@ describe Project do
let!(:path) { project1.namespace.full_path }
it 'returns correct project' do
expect(Project.inside_path(path)).to eq([project1])
expect(described_class.inside_path(path)).to eq([project1])
end
end
@ -2216,7 +2216,7 @@ describe Project do
context 'with a user' do
let(:projects) do
Project.all.public_or_visible_to_user(user)
described_class.all.public_or_visible_to_user(user)
end
it 'includes projects the user has access to' do
@ -2230,7 +2230,7 @@ describe Project do
context 'without a user' do
it 'only includes public projects' do
projects = Project.all.public_or_visible_to_user
projects = described_class.all.public_or_visible_to_user
expect(projects).to eq([public_project])
end

View File

@ -5,7 +5,7 @@ describe ProjectWiki do
let(:repository) { project.repository }
let(:user) { project.owner }
let(:gitlab_shell) { Gitlab::Shell.new }
let(:project_wiki) { ProjectWiki.new(project, user) }
let(:project_wiki) { described_class.new(project, user) }
subject { project_wiki }

View File

@ -101,17 +101,17 @@ describe ProtectedBranch do
production = create(:protected_branch, name: "production")
staging = create(:protected_branch, name: "staging")
expect(ProtectedBranch.matching("production")).to include(production)
expect(ProtectedBranch.matching("production")).not_to include(staging)
expect(described_class.matching("production")).to include(production)
expect(described_class.matching("production")).not_to include(staging)
end
it "accepts a list of protected branches to search from, so as to avoid a DB call" do
production = build(:protected_branch, name: "production")
staging = build(:protected_branch, name: "staging")
expect(ProtectedBranch.matching("production")).to be_empty
expect(ProtectedBranch.matching("production", protected_refs: [production, staging])).to include(production)
expect(ProtectedBranch.matching("production", protected_refs: [production, staging])).not_to include(staging)
expect(described_class.matching("production")).to be_empty
expect(described_class.matching("production", protected_refs: [production, staging])).to include(production)
expect(described_class.matching("production", protected_refs: [production, staging])).not_to include(staging)
end
end
@ -120,17 +120,17 @@ describe ProtectedBranch do
production = create(:protected_branch, name: "production/*")
staging = create(:protected_branch, name: "staging/*")
expect(ProtectedBranch.matching("production/some-branch")).to include(production)
expect(ProtectedBranch.matching("production/some-branch")).not_to include(staging)
expect(described_class.matching("production/some-branch")).to include(production)
expect(described_class.matching("production/some-branch")).not_to include(staging)
end
it "accepts a list of protected branches to search from, so as to avoid a DB call" do
production = build(:protected_branch, name: "production/*")
staging = build(:protected_branch, name: "staging/*")
expect(ProtectedBranch.matching("production/some-branch")).to be_empty
expect(ProtectedBranch.matching("production/some-branch", protected_refs: [production, staging])).to include(production)
expect(ProtectedBranch.matching("production/some-branch", protected_refs: [production, staging])).not_to include(staging)
expect(described_class.matching("production/some-branch")).to be_empty
expect(described_class.matching("production/some-branch", protected_refs: [production, staging])).to include(production)
expect(described_class.matching("production/some-branch", protected_refs: [production, staging])).not_to include(staging)
end
end
end
@ -142,23 +142,23 @@ describe ProtectedBranch do
it 'returns true when the branch matches a protected branch via direct match' do
create(:protected_branch, project: project, name: "foo")
expect(ProtectedBranch.protected?(project, 'foo')).to eq(true)
expect(described_class.protected?(project, 'foo')).to eq(true)
end
it 'returns true when the branch matches a protected branch via wildcard match' do
create(:protected_branch, project: project, name: "production/*")
expect(ProtectedBranch.protected?(project, 'production/some-branch')).to eq(true)
expect(described_class.protected?(project, 'production/some-branch')).to eq(true)
end
it 'returns false when the branch does not match a protected branch via direct match' do
expect(ProtectedBranch.protected?(project, 'foo')).to eq(false)
expect(described_class.protected?(project, 'foo')).to eq(false)
end
it 'returns false when the branch does not match a protected branch via wildcard match' do
create(:protected_branch, project: project, name: "production/*")
expect(ProtectedBranch.protected?(project, 'staging/some-branch')).to eq(false)
expect(described_class.protected?(project, 'staging/some-branch')).to eq(false)
end
end
@ -168,25 +168,25 @@ describe ProtectedBranch do
it 'returns false when default_protected_branch is unprotected' do
stub_application_setting(default_branch_protection: Gitlab::Access::PROTECTION_NONE)
expect(ProtectedBranch.protected?(project, 'master')).to be false
expect(described_class.protected?(project, 'master')).to be false
end
it 'returns false when default_protected_branch lets developers push' do
stub_application_setting(default_branch_protection: Gitlab::Access::PROTECTION_DEV_CAN_PUSH)
expect(ProtectedBranch.protected?(project, 'master')).to be false
expect(described_class.protected?(project, 'master')).to be false
end
it 'returns true when default_branch_protection does not let developers push but let developer merge branches' do
stub_application_setting(default_branch_protection: Gitlab::Access::PROTECTION_DEV_CAN_MERGE)
expect(ProtectedBranch.protected?(project, 'master')).to be true
expect(described_class.protected?(project, 'master')).to be true
end
it 'returns true when default_branch_protection is in full protection' do
stub_application_setting(default_branch_protection: Gitlab::Access::PROTECTION_FULL)
expect(ProtectedBranch.protected?(project, 'master')).to be true
expect(described_class.protected?(project, 'master')).to be true
end
end
end

View File

@ -21,7 +21,7 @@ describe RedirectRoute do
let!(:redirect5) { group.redirect_routes.create(path: 'gitlabb/test/baz') }
it 'returns correct routes' do
expect(RedirectRoute.matching_path_and_descendants('gitlabb/test')).to match_array([redirect2, redirect3, redirect4, redirect5])
expect(described_class.matching_path_and_descendants('gitlabb/test')).to match_array([redirect2, redirect3, redirect4, redirect5])
end
end
end

View File

@ -34,7 +34,7 @@ describe Route do
context 'after create' do
it 'calls #delete_conflicting_redirects' do
route.destroy
new_route = Route.new(source: group, path: group.path)
new_route = described_class.new(source: group, path: group.path)
expect(new_route).to receive(:delete_conflicting_redirects)
new_route.save!
end
@ -49,7 +49,7 @@ describe Route do
let!(:another_group_nested) { create(:group, path: 'another', name: 'another', parent: similar_group) }
it 'returns correct routes' do
expect(Route.inside_path('git_lab')).to match_array([nested_group.route, deep_nested_group.route])
expect(described_class.inside_path('git_lab')).to match_array([nested_group.route, deep_nested_group.route])
end
end

View File

@ -38,7 +38,7 @@ describe SentNotification do
let(:issue) { create(:issue) }
it 'creates a new SentNotification' do
expect { described_class.record(issue, user.id) }.to change { SentNotification.count }.by(1)
expect { described_class.record(issue, user.id) }.to change { described_class.count }.by(1)
end
end
@ -47,7 +47,7 @@ describe SentNotification do
let(:note) { create(:diff_note_on_merge_request) }
it 'creates a new SentNotification' do
expect { described_class.record_note(note, user.id) }.to change { SentNotification.count }.by(1)
expect { described_class.record_note(note, user.id) }.to change { described_class.count }.by(1)
end
end

View File

@ -261,7 +261,7 @@ describe User do
it "returns users with 2fa enabled via OTP" do
user_with_2fa = create(:user, :two_factor_via_otp)
user_without_2fa = create(:user)
users_with_two_factor = User.with_two_factor.pluck(:id)
users_with_two_factor = described_class.with_two_factor.pluck(:id)
expect(users_with_two_factor).to include(user_with_2fa.id)
expect(users_with_two_factor).not_to include(user_without_2fa.id)
@ -270,7 +270,7 @@ describe User do
it "returns users with 2fa enabled via U2F" do
user_with_2fa = create(:user, :two_factor_via_u2f)
user_without_2fa = create(:user)
users_with_two_factor = User.with_two_factor.pluck(:id)
users_with_two_factor = described_class.with_two_factor.pluck(:id)
expect(users_with_two_factor).to include(user_with_2fa.id)
expect(users_with_two_factor).not_to include(user_without_2fa.id)
@ -279,7 +279,7 @@ describe User do
it "returns users with 2fa enabled via OTP and U2F" do
user_with_2fa = create(:user, :two_factor_via_otp, :two_factor_via_u2f)
user_without_2fa = create(:user)
users_with_two_factor = User.with_two_factor.pluck(:id)
users_with_two_factor = described_class.with_two_factor.pluck(:id)
expect(users_with_two_factor).to eq([user_with_2fa.id])
expect(users_with_two_factor).not_to include(user_without_2fa.id)
@ -290,7 +290,7 @@ describe User do
it "excludes users with 2fa enabled via OTP" do
user_with_2fa = create(:user, :two_factor_via_otp)
user_without_2fa = create(:user)
users_without_two_factor = User.without_two_factor.pluck(:id)
users_without_two_factor = described_class.without_two_factor.pluck(:id)
expect(users_without_two_factor).to include(user_without_2fa.id)
expect(users_without_two_factor).not_to include(user_with_2fa.id)
@ -299,7 +299,7 @@ describe User do
it "excludes users with 2fa enabled via U2F" do
user_with_2fa = create(:user, :two_factor_via_u2f)
user_without_2fa = create(:user)
users_without_two_factor = User.without_two_factor.pluck(:id)
users_without_two_factor = described_class.without_two_factor.pluck(:id)
expect(users_without_two_factor).to include(user_without_2fa.id)
expect(users_without_two_factor).not_to include(user_with_2fa.id)
@ -308,7 +308,7 @@ describe User do
it "excludes users with 2fa enabled via OTP and U2F" do
user_with_2fa = create(:user, :two_factor_via_otp, :two_factor_via_u2f)
user_without_2fa = create(:user)
users_without_two_factor = User.without_two_factor.pluck(:id)
users_without_two_factor = described_class.without_two_factor.pluck(:id)
expect(users_without_two_factor).to include(user_without_2fa.id)
expect(users_without_two_factor).not_to include(user_with_2fa.id)
@ -324,8 +324,8 @@ describe User do
create(:todo, user: current_user, author: user_2, state: :done)
create(:todo, user: current_user, author: user_3, state: :pending)
expect(User.todo_authors(current_user.id, 'pending')).to eq [user_3]
expect(User.todo_authors(current_user.id, 'done')).to eq [user_2]
expect(described_class.todo_authors(current_user.id, 'pending')).to eq [user_3]
expect(described_class.todo_authors(current_user.id, 'done')).to eq [user_2]
end
end
end
@ -609,39 +609,39 @@ describe User do
let(:user) { double }
it 'filters by active users by default' do
expect(User).to receive(:active).and_return([user])
expect(described_class).to receive(:active).and_return([user])
expect(User.filter(nil)).to include user
expect(described_class.filter(nil)).to include user
end
it 'filters by admins' do
expect(User).to receive(:admins).and_return([user])
expect(described_class).to receive(:admins).and_return([user])
expect(User.filter('admins')).to include user
expect(described_class.filter('admins')).to include user
end
it 'filters by blocked' do
expect(User).to receive(:blocked).and_return([user])
expect(described_class).to receive(:blocked).and_return([user])
expect(User.filter('blocked')).to include user
expect(described_class.filter('blocked')).to include user
end
it 'filters by two_factor_disabled' do
expect(User).to receive(:without_two_factor).and_return([user])
expect(described_class).to receive(:without_two_factor).and_return([user])
expect(User.filter('two_factor_disabled')).to include user
expect(described_class.filter('two_factor_disabled')).to include user
end
it 'filters by two_factor_enabled' do
expect(User).to receive(:with_two_factor).and_return([user])
expect(described_class).to receive(:with_two_factor).and_return([user])
expect(User.filter('two_factor_enabled')).to include user
expect(described_class.filter('two_factor_enabled')).to include user
end
it 'filters by wop' do
expect(User).to receive(:without_projects).and_return([user])
expect(described_class).to receive(:without_projects).and_return([user])
expect(User.filter('wop')).to include user
expect(described_class.filter('wop')).to include user
end
end
@ -662,9 +662,9 @@ describe User do
project.request_access(user_without_project2)
end
it { expect(User.without_projects).not_to include user }
it { expect(User.without_projects).to include user_without_project }
it { expect(User.without_projects).to include user_without_project2 }
it { expect(described_class.without_projects).not_to include user }
it { expect(described_class.without_projects).to include user_without_project }
it { expect(described_class.without_projects).to include user_without_project2 }
end
describe 'user creation' do
@ -680,7 +680,7 @@ describe User do
end
describe 'with defaults' do
let(:user) { User.new }
let(:user) { described_class.new }
it "applies defaults to user" do
expect(user.projects_limit).to eq(Gitlab.config.gitlab.default_projects_limit)
@ -690,7 +690,7 @@ describe User do
end
describe 'with default overrides' do
let(:user) { User.new(projects_limit: 123, can_create_group: false, can_create_team: true) }
let(:user) { described_class.new(projects_limit: 123, can_create_group: false, can_create_team: true) }
it "applies defaults to user" do
expect(user.projects_limit).to eq(123)
@ -740,18 +740,18 @@ describe User do
it 'finds by primary email' do
user = create(:user, email: 'foo@example.com')
expect(User.find_by_any_email(user.email)).to eq user
expect(described_class.find_by_any_email(user.email)).to eq user
end
it 'finds by secondary email' do
email = create(:email, email: 'foo@example.com')
user = email.user
expect(User.find_by_any_email(email.email)).to eq user
expect(described_class.find_by_any_email(email.email)).to eq user
end
it 'returns nil when nothing found' do
expect(User.find_by_any_email('')).to be_nil
expect(described_class.find_by_any_email('')).to be_nil
end
end
@ -899,12 +899,12 @@ describe User do
let!(:user) { create(:user, username: username) }
it 'gets the correct user' do
expect(User.by_login(user.email.upcase)).to eq user
expect(User.by_login(user.email)).to eq user
expect(User.by_login(username.downcase)).to eq user
expect(User.by_login(username)).to eq user
expect(User.by_login(nil)).to be_nil
expect(User.by_login('')).to be_nil
expect(described_class.by_login(user.email.upcase)).to eq user
expect(described_class.by_login(user.email)).to eq user
expect(described_class.by_login(username.downcase)).to eq user
expect(described_class.by_login(username)).to eq user
expect(described_class.by_login(nil)).to be_nil
expect(described_class.by_login('')).to be_nil
end
end
@ -938,12 +938,12 @@ describe User do
let!(:route) { user.namespace.route }
it 'returns the user' do
expect(User.find_by_full_path(route.path)).to eq(user)
expect(described_class.find_by_full_path(route.path)).to eq(user)
end
it 'is case-insensitive' do
expect(User.find_by_full_path(route.path.upcase)).to eq(user)
expect(User.find_by_full_path(route.path.downcase)).to eq(user)
expect(described_class.find_by_full_path(route.path.upcase)).to eq(user)
expect(described_class.find_by_full_path(route.path.downcase)).to eq(user)
end
end
@ -952,18 +952,18 @@ describe User do
context 'without the follow_redirects option' do
it 'returns nil' do
expect(User.find_by_full_path(redirect_route.path)).to eq(nil)
expect(described_class.find_by_full_path(redirect_route.path)).to eq(nil)
end
end
context 'with the follow_redirects option set to true' do
it 'returns the user' do
expect(User.find_by_full_path(redirect_route.path, follow_redirects: true)).to eq(user)
expect(described_class.find_by_full_path(redirect_route.path, follow_redirects: true)).to eq(user)
end
it 'is case-insensitive' do
expect(User.find_by_full_path(redirect_route.path.upcase, follow_redirects: true)).to eq(user)
expect(User.find_by_full_path(redirect_route.path.downcase, follow_redirects: true)).to eq(user)
expect(described_class.find_by_full_path(redirect_route.path.upcase, follow_redirects: true)).to eq(user)
expect(described_class.find_by_full_path(redirect_route.path.downcase, follow_redirects: true)).to eq(user)
end
end
end
@ -971,12 +971,12 @@ describe User do
context 'without a route or a redirect route matching the given path' do
context 'without the follow_redirects option' do
it 'returns nil' do
expect(User.find_by_full_path('unknown')).to eq(nil)
expect(described_class.find_by_full_path('unknown')).to eq(nil)
end
end
context 'with the follow_redirects option set to true' do
it 'returns nil' do
expect(User.find_by_full_path('unknown', follow_redirects: true)).to eq(nil)
expect(described_class.find_by_full_path('unknown', follow_redirects: true)).to eq(nil)
end
end
end
@ -986,7 +986,7 @@ describe User do
let!(:group) { create(:group, path: 'group_path', owner: user) }
it 'returns nil' do
expect(User.find_by_full_path('group_path')).to eq(nil)
expect(described_class.find_by_full_path('group_path')).to eq(nil)
end
end
@ -994,7 +994,7 @@ describe User do
let!(:group) { create(:group, path: 'group_path') }
it 'returns nil' do
expect(User.find_by_full_path('group_path')).to eq(nil)
expect(described_class.find_by_full_path('group_path')).to eq(nil)
end
end
end
@ -1044,7 +1044,7 @@ describe User do
end
describe '#requires_ldap_check?' do
let(:user) { User.new }
let(:user) { described_class.new }
it 'is false when LDAP is disabled' do
# Create a condition which would otherwise cause 'true' to be returned
@ -1215,7 +1215,7 @@ describe User do
describe '#sort' do
before do
User.delete_all
described_class.delete_all
@user = create :user, created_at: Date.today, last_sign_in_at: Date.today, name: 'Alpha'
@user1 = create :user, created_at: Date.today - 1, last_sign_in_at: Date.today - 1, name: 'Omega'
@user2 = create :user, created_at: Date.today - 2, last_sign_in_at: nil, name: 'Beta'
@ -1223,34 +1223,34 @@ describe User do
context 'when sort by recent_sign_in' do
it 'sorts users by the recent sign-in time' do
expect(User.sort('recent_sign_in').first).to eq(@user)
expect(described_class.sort('recent_sign_in').first).to eq(@user)
end
it 'pushes users who never signed in to the end' do
expect(User.sort('recent_sign_in').third).to eq(@user2)
expect(described_class.sort('recent_sign_in').third).to eq(@user2)
end
end
context 'when sort by oldest_sign_in' do
it 'sorts users by the oldest sign-in time' do
expect(User.sort('oldest_sign_in').first).to eq(@user1)
expect(described_class.sort('oldest_sign_in').first).to eq(@user1)
end
it 'pushes users who never signed in to the end' do
expect(User.sort('oldest_sign_in').third).to eq(@user2)
expect(described_class.sort('oldest_sign_in').third).to eq(@user2)
end
end
it 'sorts users in descending order by their creation time' do
expect(User.sort('created_desc').first).to eq(@user)
expect(described_class.sort('created_desc').first).to eq(@user)
end
it 'sorts users in ascending order by their creation time' do
expect(User.sort('created_asc').first).to eq(@user2)
expect(described_class.sort('created_asc').first).to eq(@user2)
end
it 'sorts users by id in descending order when nil is passed' do
expect(User.sort(nil).first).to eq(@user2)
expect(described_class.sort(nil).first).to eq(@user2)
end
end
@ -1770,7 +1770,7 @@ describe User do
describe '.ghost' do
it "creates a ghost user if one isn't already present" do
ghost = User.ghost
ghost = described_class.ghost
expect(ghost).to be_ghost
expect(ghost).to be_persisted
@ -1778,16 +1778,16 @@ describe User do
it "does not create a second ghost user if one is already present" do
expect do
User.ghost
User.ghost
end.to change { User.count }.by(1)
expect(User.ghost).to eq(User.ghost)
described_class.ghost
described_class.ghost
end.to change { described_class.count }.by(1)
expect(described_class.ghost).to eq(described_class.ghost)
end
context "when a regular user exists with the username 'ghost'" do
it "creates a ghost user with a non-conflicting username" do
create(:user, username: 'ghost')
ghost = User.ghost
ghost = described_class.ghost
expect(ghost).to be_persisted
expect(ghost.username).to eq('ghost1')
@ -1797,7 +1797,7 @@ describe User do
context "when a regular user exists with the email 'ghost@example.com'" do
it "creates a ghost user with a non-conflicting email" do
create(:user, email: 'ghost@example.com')
ghost = User.ghost
ghost = described_class.ghost
expect(ghost).to be_persisted
expect(ghost.email).to eq('ghost1@example.com')
@ -1810,7 +1810,7 @@ describe User do
end
it 'creates a ghost user' do
expect(User.ghost).to be_persisted
expect(described_class.ghost).to be_persisted
end
end
end
@ -1889,13 +1889,13 @@ describe User do
context '.active' do
before do
User.ghost
described_class.ghost
create(:user, name: 'user', state: 'active')
create(:user, name: 'user', state: 'blocked')
end
it 'only counts active and non internal users' do
expect(User.active.count).to eq(1)
expect(described_class.active.count).to eq(1)
end
end

View File

@ -10,7 +10,7 @@ RSpec.describe WikiDirectory do
describe '#initialize' do
context 'when there are pages' do
let(:pages) { [build(:wiki_page)] }
let(:directory) { WikiDirectory.new('/path_up_to/dir', pages) }
let(:directory) { described_class.new('/path_up_to/dir', pages) }
it 'sets the slug attribute' do
expect(directory.slug).to eq('/path_up_to/dir')
@ -22,7 +22,7 @@ RSpec.describe WikiDirectory do
end
context 'when there are no pages' do
let(:directory) { WikiDirectory.new('/path_up_to/dir') }
let(:directory) { described_class.new('/path_up_to/dir') }
it 'sets the slug attribute' do
expect(directory.slug).to eq('/path_up_to/dir')

View File

@ -5,13 +5,13 @@ describe WikiPage do
let(:user) { project.owner }
let(:wiki) { ProjectWiki.new(project, user) }
subject { WikiPage.new(wiki) }
subject { described_class.new(wiki) }
describe '.group_by_directory' do
context 'when there are no pages' do
it 'returns an empty array' do
expect(WikiPage.group_by_directory(nil)).to eq([])
expect(WikiPage.group_by_directory([])).to eq([])
expect(described_class.group_by_directory(nil)).to eq([])
expect(described_class.group_by_directory([])).to eq([])
end
end
@ -39,7 +39,7 @@ describe WikiPage do
it 'returns an array with pages and directories' do
expected_grouped_entries = [page_1, dir_1, dir_1_1, dir_2]
grouped_entries = WikiPage.group_by_directory(wiki.pages)
grouped_entries = described_class.group_by_directory(wiki.pages)
grouped_entries.each_with_index do |page_or_dir, i|
expected_page_or_dir = expected_grouped_entries[i]
@ -56,7 +56,7 @@ describe WikiPage do
expected_order = ['page_1', 'dir_1/page_2', 'dir_1/dir_1_1/page_3',
'dir_2/page_4', 'dir_2/page_5']
grouped_entries = WikiPage.group_by_directory(wiki.pages)
grouped_entries = described_class.group_by_directory(wiki.pages)
actual_order =
grouped_entries.map do |page_or_dir|
@ -72,7 +72,7 @@ describe WikiPage do
it 'removes hyphens from a name' do
name = 'a-name--with-hyphens'
expect(WikiPage.unhyphenize(name)).to eq('a name with hyphens')
expect(described_class.unhyphenize(name)).to eq('a name with hyphens')
end
end
@ -81,7 +81,7 @@ describe WikiPage do
before do
create_page("test page", "test content")
@page = wiki.wiki.paged("test page")
@wiki_page = WikiPage.new(wiki, @page, true)
@wiki_page = described_class.new(wiki, @page, true)
end
it "sets the slug attribute" do

View File

@ -4,7 +4,7 @@ describe GlobalPolicy do
let(:current_user) { create(:user) }
let(:user) { create(:user) }
subject { GlobalPolicy.new(current_user, [user]) }
subject { described_class.new(current_user, [user]) }
describe "reading the list of users" do
context "for a logged in user" do

View File

@ -4,7 +4,7 @@ describe UserPolicy do
let(:current_user) { create(:user) }
let(:user) { create(:user) }
subject { UserPolicy.new(current_user, user) }
subject { described_class.new(current_user, user) }
describe "reading a user's information" do
it { is_expected.to be_allowed(:read_user) }

View File

@ -5,7 +5,7 @@ describe CreateReleaseService do
let(:user) { create(:user) }
let(:tag_name) { project.repository.tag_names.first }
let(:description) { 'Awesome release!' }
let(:service) { CreateReleaseService.new(project, user) }
let(:service) { described_class.new(project, user) }
it 'creates a new release' do
result = service.execute(tag_name, description)

View File

@ -3,7 +3,7 @@ require 'spec_helper'
describe EventCreateService do
include UserActivitiesHelpers
let(:service) { EventCreateService.new }
let(:service) { described_class.new }
describe 'Issues' do
describe '#open_issue' do

View File

@ -5,7 +5,7 @@ describe GitHooksService do
let(:user) { create(:user) }
let(:project) { create(:project, :repository) }
let(:service) { GitHooksService.new }
let(:service) { described_class.new }
before do
@blankrev = Gitlab::Git::BLANK_SHA

View File

@ -5,7 +5,7 @@ describe GitTagPushService do
let(:user) { create(:user) }
let(:project) { create(:project, :repository) }
let(:service) { GitTagPushService.new(project, user, oldrev: oldrev, newrev: newrev, ref: ref) }
let(:service) { described_class.new(project, user, oldrev: oldrev, newrev: newrev, ref: ref) }
let(:oldrev) { Gitlab::Git::BLANK_SHA }
let(:newrev) { "8a2a6eb295bb170b34c24c76c49ed0e9b2eaf34b" } # gitlab-test: git rev-parse refs/tags/v1.1.0
@ -184,7 +184,7 @@ describe GitTagPushService do
describe "Webhooks" do
context "execute webhooks" do
let(:service) { GitTagPushService.new(project, user, oldrev: 'oldrev', newrev: 'newrev', ref: 'refs/tags/v1.0.0') }
let(:service) { described_class.new(project, user, oldrev: 'oldrev', newrev: 'newrev', ref: 'refs/tags/v1.0.0') }
it "when pushing tags" do
expect(project).to receive(:execute_hooks)

View File

@ -100,7 +100,7 @@ describe Groups::DestroyService do
# Kick off the initial group destroy in a new thread, so that
# it doesn't share this spec's database transaction.
Thread.new { Groups::DestroyService.new(group, user).async_execute }.join(5)
Thread.new { described_class.new(group, user).async_execute }.join(5)
group_record = run_with_new_database_connection do |conn|
conn.execute("SELECT * FROM namespaces WHERE id = #{group.id}").first

View File

@ -488,7 +488,7 @@ describe Issues::UpdateService do
context 'updating mentions' do
let(:mentionable) { issue }
include_examples 'updating mentions', Issues::UpdateService
include_examples 'updating mentions', described_class
end
context 'duplicate issue' do

View File

@ -17,7 +17,7 @@ describe Labels::CreateService do
context 'in a project' do
context 'with color in hex-code' do
it 'creates a label' do
label = Labels::CreateService.new(params_with(hex_color)).execute(project: project)
label = described_class.new(params_with(hex_color)).execute(project: project)
expect(label).to be_persisted
expect(label.color).to eq expected_saved_color
@ -26,7 +26,7 @@ describe Labels::CreateService do
context 'with color in allowed name' do
it 'creates a label' do
label = Labels::CreateService.new(params_with(named_color)).execute(project: project)
label = described_class.new(params_with(named_color)).execute(project: project)
expect(label).to be_persisted
expect(label.color).to eq expected_saved_color
@ -35,7 +35,7 @@ describe Labels::CreateService do
context 'with color in up-case allowed name' do
it 'creates a label' do
label = Labels::CreateService.new(params_with(upcase_color)).execute(project: project)
label = described_class.new(params_with(upcase_color)).execute(project: project)
expect(label).to be_persisted
expect(label.color).to eq expected_saved_color
@ -44,7 +44,7 @@ describe Labels::CreateService do
context 'with color surrounded by spaces' do
it 'creates a label' do
label = Labels::CreateService.new(params_with(spaced_color)).execute(project: project)
label = described_class.new(params_with(spaced_color)).execute(project: project)
expect(label).to be_persisted
expect(label.color).to eq expected_saved_color
@ -53,7 +53,7 @@ describe Labels::CreateService do
context 'with unknown color' do
it 'doesn\'t create a label' do
label = Labels::CreateService.new(params_with(unknown_color)).execute(project: project)
label = described_class.new(params_with(unknown_color)).execute(project: project)
expect(label).not_to be_persisted
end
@ -61,7 +61,7 @@ describe Labels::CreateService do
context 'with no color' do
it 'doesn\'t create a label' do
label = Labels::CreateService.new(params_with(no_color)).execute(project: project)
label = described_class.new(params_with(no_color)).execute(project: project)
expect(label).not_to be_persisted
end
@ -71,7 +71,7 @@ describe Labels::CreateService do
context 'in a group' do
context 'with color in hex-code' do
it 'creates a label' do
label = Labels::CreateService.new(params_with(hex_color)).execute(group: group)
label = described_class.new(params_with(hex_color)).execute(group: group)
expect(label).to be_persisted
expect(label.color).to eq expected_saved_color
@ -80,7 +80,7 @@ describe Labels::CreateService do
context 'with color in allowed name' do
it 'creates a label' do
label = Labels::CreateService.new(params_with(named_color)).execute(group: group)
label = described_class.new(params_with(named_color)).execute(group: group)
expect(label).to be_persisted
expect(label.color).to eq expected_saved_color
@ -89,7 +89,7 @@ describe Labels::CreateService do
context 'with color in up-case allowed name' do
it 'creates a label' do
label = Labels::CreateService.new(params_with(upcase_color)).execute(group: group)
label = described_class.new(params_with(upcase_color)).execute(group: group)
expect(label).to be_persisted
expect(label.color).to eq expected_saved_color
@ -98,7 +98,7 @@ describe Labels::CreateService do
context 'with color surrounded by spaces' do
it 'creates a label' do
label = Labels::CreateService.new(params_with(spaced_color)).execute(group: group)
label = described_class.new(params_with(spaced_color)).execute(group: group)
expect(label).to be_persisted
expect(label.color).to eq expected_saved_color
@ -107,7 +107,7 @@ describe Labels::CreateService do
context 'with unknown color' do
it 'doesn\'t create a label' do
label = Labels::CreateService.new(params_with(unknown_color)).execute(group: group)
label = described_class.new(params_with(unknown_color)).execute(group: group)
expect(label).not_to be_persisted
end
@ -115,7 +115,7 @@ describe Labels::CreateService do
context 'with no color' do
it 'doesn\'t create a label' do
label = Labels::CreateService.new(params_with(no_color)).execute(group: group)
label = described_class.new(params_with(no_color)).execute(group: group)
expect(label).not_to be_persisted
end
@ -125,7 +125,7 @@ describe Labels::CreateService do
context 'in admin area' do
context 'with color in hex-code' do
it 'creates a label' do
label = Labels::CreateService.new(params_with(hex_color)).execute(template: true)
label = described_class.new(params_with(hex_color)).execute(template: true)
expect(label).to be_persisted
expect(label.color).to eq expected_saved_color
@ -134,7 +134,7 @@ describe Labels::CreateService do
context 'with color in allowed name' do
it 'creates a label' do
label = Labels::CreateService.new(params_with(named_color)).execute(template: true)
label = described_class.new(params_with(named_color)).execute(template: true)
expect(label).to be_persisted
expect(label.color).to eq expected_saved_color
@ -143,7 +143,7 @@ describe Labels::CreateService do
context 'with color in up-case allowed name' do
it 'creates a label' do
label = Labels::CreateService.new(params_with(upcase_color)).execute(template: true)
label = described_class.new(params_with(upcase_color)).execute(template: true)
expect(label).to be_persisted
expect(label.color).to eq expected_saved_color
@ -152,7 +152,7 @@ describe Labels::CreateService do
context 'with color surrounded by spaces' do
it 'creates a label' do
label = Labels::CreateService.new(params_with(spaced_color)).execute(template: true)
label = described_class.new(params_with(spaced_color)).execute(template: true)
expect(label).to be_persisted
expect(label.color).to eq expected_saved_color
@ -161,7 +161,7 @@ describe Labels::CreateService do
context 'with unknown color' do
it 'doesn\'t create a label' do
label = Labels::CreateService.new(params_with(unknown_color)).execute(template: true)
label = described_class.new(params_with(unknown_color)).execute(template: true)
expect(label).not_to be_persisted
end
@ -169,7 +169,7 @@ describe Labels::CreateService do
context 'with no color' do
it 'doesn\'t create a label' do
label = Labels::CreateService.new(params_with(no_color)).execute(template: true)
label = described_class.new(params_with(no_color)).execute(template: true)
expect(label).not_to be_persisted
end

View File

@ -20,7 +20,7 @@ describe Labels::UpdateService do
context 'with color in hex-code' do
it 'updates the label' do
label = Labels::UpdateService.new(params_with(hex_color)).execute(@label)
label = described_class.new(params_with(hex_color)).execute(@label)
expect(label).to be_valid
expect(label.reload.color).to eq expected_saved_color
@ -29,7 +29,7 @@ describe Labels::UpdateService do
context 'with color in allowed name' do
it 'updates the label' do
label = Labels::UpdateService.new(params_with(named_color)).execute(@label)
label = described_class.new(params_with(named_color)).execute(@label)
expect(label).to be_valid
expect(label.reload.color).to eq expected_saved_color
@ -38,7 +38,7 @@ describe Labels::UpdateService do
context 'with color in up-case allowed name' do
it 'updates the label' do
label = Labels::UpdateService.new(params_with(upcase_color)).execute(@label)
label = described_class.new(params_with(upcase_color)).execute(@label)
expect(label).to be_valid
expect(label.reload.color).to eq expected_saved_color
@ -47,7 +47,7 @@ describe Labels::UpdateService do
context 'with color surrounded by spaces' do
it 'updates the label' do
label = Labels::UpdateService.new(params_with(spaced_color)).execute(@label)
label = described_class.new(params_with(spaced_color)).execute(@label)
expect(label).to be_valid
expect(label.reload.color).to eq expected_saved_color
@ -56,7 +56,7 @@ describe Labels::UpdateService do
context 'with unknown color' do
it 'doesn\'t update the label' do
label = Labels::UpdateService.new(params_with(unknown_color)).execute(@label)
label = described_class.new(params_with(unknown_color)).execute(@label)
expect(label).not_to be_valid
end
@ -64,7 +64,7 @@ describe Labels::UpdateService do
context 'with no color' do
it 'doesn\'t update the label' do
label = Labels::UpdateService.new(params_with(no_color)).execute(@label)
label = described_class.new(params_with(no_color)).execute(@label)
expect(label).not_to be_valid
end

View File

@ -19,7 +19,7 @@ describe MergeRequests::BuildService do
let(:commits) { nil }
let(:service) do
MergeRequests::BuildService.new(project, user,
described_class.new(project, user,
description: description,
source_branch: source_branch,
target_branch: target_branch,

View File

@ -13,7 +13,7 @@ describe MergeRequests::MergeService do
describe '#execute' do
context 'valid params' do
let(:service) { MergeRequests::MergeService.new(project, user, commit_message: 'Awesome message') }
let(:service) { described_class.new(project, user, commit_message: 'Awesome message') }
before do
allow(service).to receive(:execute_hooks)
@ -112,7 +112,7 @@ describe MergeRequests::MergeService do
context 'closes related todos' do
let(:merge_request) { create(:merge_request, assignee: user, author: user) }
let(:project) { merge_request.project }
let(:service) { MergeRequests::MergeService.new(project, user, commit_message: 'Awesome message') }
let(:service) { described_class.new(project, user, commit_message: 'Awesome message') }
let!(:todo) do
create(:todo, :assigned,
project: project,
@ -136,7 +136,7 @@ describe MergeRequests::MergeService do
context 'source branch removal' do
context 'when the source branch is protected' do
let(:service) do
MergeRequests::MergeService.new(project, user, should_remove_source_branch: '1')
described_class.new(project, user, should_remove_source_branch: '1')
end
before do
@ -151,7 +151,7 @@ describe MergeRequests::MergeService do
context 'when the source branch is the default branch' do
let(:service) do
MergeRequests::MergeService.new(project, user, should_remove_source_branch: '1')
described_class.new(project, user, should_remove_source_branch: '1')
end
before do
@ -169,7 +169,7 @@ describe MergeRequests::MergeService do
let(:service) do
merge_request.merge_params['force_remove_source_branch'] = '1'
merge_request.save!
MergeRequests::MergeService.new(project, user, commit_message: 'Awesome message')
described_class.new(project, user, commit_message: 'Awesome message')
end
it 'removes the source branch using the author user' do
@ -182,7 +182,7 @@ describe MergeRequests::MergeService do
context 'when MR merger set the source branch to be removed' do
let(:service) do
MergeRequests::MergeService.new(project, user, commit_message: 'Awesome message', should_remove_source_branch: '1')
described_class.new(project, user, commit_message: 'Awesome message', should_remove_source_branch: '1')
end
it 'removes the source branch using the current user' do
@ -196,7 +196,7 @@ describe MergeRequests::MergeService do
end
context "error handling" do
let(:service) { MergeRequests::MergeService.new(project, user, commit_message: 'Awesome message') }
let(:service) { described_class.new(project, user, commit_message: 'Awesome message') }
before do
allow(Rails.logger).to receive(:error)

View File

@ -3,7 +3,7 @@ require 'spec_helper'
describe MergeRequests::RefreshService do
let(:project) { create(:project, :repository) }
let(:user) { create(:user) }
let(:service) { MergeRequests::RefreshService }
let(:service) { described_class }
describe '#execute' do
before do

View File

@ -55,7 +55,7 @@ describe MergeRequests::UpdateService do
}
end
let(:service) { MergeRequests::UpdateService.new(project, user, opts) }
let(:service) { described_class.new(project, user, opts) }
before do
allow(service).to receive(:execute_hooks)
@ -145,7 +145,7 @@ describe MergeRequests::UpdateService do
}
end
let(:service) { MergeRequests::UpdateService.new(project, user, opts) }
let(:service) { described_class.new(project, user, opts) }
context 'without pipeline' do
before do
@ -205,7 +205,7 @@ describe MergeRequests::UpdateService do
context 'with a non-authorised user' do
let(:visitor) { create(:user) }
let(:service) { MergeRequests::UpdateService.new(project, visitor, opts) }
let(:service) { described_class.new(project, visitor, opts) }
before do
merge_request.update_attribute(:merge_error, 'Error')
@ -348,7 +348,7 @@ describe MergeRequests::UpdateService do
opts = { label_ids: [label.id] }
perform_enqueued_jobs do
@merge_request = MergeRequests::UpdateService.new(project, user, opts).execute(merge_request)
@merge_request = described_class.new(project, user, opts).execute(merge_request)
end
should_email(subscriber)
@ -364,7 +364,7 @@ describe MergeRequests::UpdateService do
opts = { label_ids: [label.id, label2.id] }
perform_enqueued_jobs do
@merge_request = MergeRequests::UpdateService.new(project, user, opts).execute(merge_request)
@merge_request = described_class.new(project, user, opts).execute(merge_request)
end
should_not_email(subscriber)
@ -375,7 +375,7 @@ describe MergeRequests::UpdateService do
opts = { label_ids: [label2.id] }
perform_enqueued_jobs do
@merge_request = MergeRequests::UpdateService.new(project, user, opts).execute(merge_request)
@merge_request = described_class.new(project, user, opts).execute(merge_request)
end
should_not_email(subscriber)
@ -386,7 +386,7 @@ describe MergeRequests::UpdateService do
context 'updating mentions' do
let(:mentionable) { merge_request }
include_examples 'updating mentions', MergeRequests::UpdateService
include_examples 'updating mentions', described_class
end
context 'when MergeRequest has tasks' do

View File

@ -11,7 +11,7 @@ describe Milestones::CloseService do
describe '#execute' do
before do
Milestones::CloseService.new(project, user, {}).execute(milestone)
described_class.new(project, user, {}).execute(milestone)
end
it { expect(milestone).to be_valid }

View File

@ -14,7 +14,7 @@ describe Milestones::CreateService do
description: 'Patch release to fix security issue'
}
@milestone = Milestones::CreateService.new(project, user, opts).execute
@milestone = described_class.new(project, user, opts).execute
end
it { expect(@milestone).to be_valid }

View File

@ -21,7 +21,7 @@ describe Notes::PostProcessService do
expect(project).to receive(:execute_hooks)
expect(project).to receive(:execute_services)
Notes::PostProcessService.new(@note).execute
described_class.new(@note).execute
end
end
end

View File

@ -3,7 +3,7 @@ require 'spec_helper'
describe NotificationService do
include EmailHelpers
let(:notification) { NotificationService.new }
let(:notification) { described_class.new }
let(:assignee) { create(:user) }
around(:each) do |example|

View File

@ -3,7 +3,7 @@ require 'spec_helper'
describe PagesService do
let(:build) { create(:ci_build) }
let(:data) { Gitlab::DataBuilder::Build.build(build) }
let(:service) { PagesService.new(data) }
let(:service) { described_class.new(data) }
before do
allow(Gitlab.config.pages).to receive(:enabled).and_return(true)

View File

@ -81,7 +81,7 @@ describe Projects::DestroyService do
before do
new_user = create(:user)
project.team.add_user(new_user, Gitlab::Access::DEVELOPER)
allow_any_instance_of(Projects::DestroyService).to receive(:flush_caches).and_raise(::Redis::CannotConnectError)
allow_any_instance_of(described_class).to receive(:flush_caches).and_raise(::Redis::CannotConnectError)
end
it 'keeps project team intact upon an error' do
@ -114,7 +114,7 @@ describe Projects::DestroyService do
context 'errors' do
context 'when `remove_legacy_registry_tags` fails' do
before do
expect_any_instance_of(Projects::DestroyService)
expect_any_instance_of(described_class)
.to receive(:remove_legacy_registry_tags).and_return(false)
end
@ -123,7 +123,7 @@ describe Projects::DestroyService do
context 'when `remove_repository` fails' do
before do
expect_any_instance_of(Projects::DestroyService)
expect_any_instance_of(described_class)
.to receive(:remove_repository).and_return(false)
end

View File

@ -37,7 +37,7 @@ describe Projects::TransferService do
end
it 'executes system hooks' do
expect_any_instance_of(Projects::TransferService).to receive(:execute_system_hooks)
expect_any_instance_of(described_class).to receive(:execute_system_hooks)
transfer_project(project, user, group)
end
@ -80,7 +80,7 @@ describe Projects::TransferService do
end
it "doesn't run system hooks" do
expect_any_instance_of(Projects::TransferService).not_to receive(:execute_system_hooks)
expect_any_instance_of(described_class).not_to receive(:execute_system_hooks)
attempt_project_transfer
end

View File

@ -1,7 +1,7 @@
require 'spec_helper'
describe Projects::UnlinkForkService do
subject { Projects::UnlinkForkService.new(fork_project, user) }
subject { described_class.new(fork_project, user) }
let(:fork_link) { create(:forked_project_link) }
let(:fork_project) { fork_link.forked_to_project }

View File

@ -3,7 +3,7 @@ require 'spec_helper'
describe RepairLdapBlockedUserService do
let(:user) { create(:omniauth_user, provider: 'ldapmain', state: 'ldap_blocked') }
let(:identity) { user.ldap_identity }
subject(:service) { RepairLdapBlockedUserService.new(user) }
subject(:service) { described_class.new(user) }
describe '#execute' do
it 'changes to normal block after destroying last ldap identity' do

Some files were not shown because too many files have changed in this diff Show More