Commit cddc5cac authored by Rémy Coutable's avatar Rémy Coutable

Use described_class when possible

Signed-off-by: default avatarRémy Coutable <remy@rymai.me>
parent ddccd24c
...@@ -5,37 +5,37 @@ describe Settings do ...@@ -5,37 +5,37 @@ describe Settings do
describe '#host_without_www' do describe '#host_without_www' do
context 'URL with protocol' do context 'URL with protocol' do
it 'returns the host' do it 'returns the host' do
expect(Settings.host_without_www('http://foo.com')).to eq 'foo.com' expect(described_class.host_without_www('http://foo.com')).to eq 'foo.com'
expect(Settings.host_without_www('http://www.foo.com')).to eq 'foo.com' expect(described_class.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(described_class.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://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(described_class.host_without_www('https://foo.com')).to eq 'foo.com'
expect(Settings.host_without_www('https://www.foo.com')).to eq 'foo.com' expect(described_class.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(described_class.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://secure.gravatar.com/avatar/%{hash}?s=%{size}&d=identicon')).to eq 'secure.gravatar.com'
end end
end end
context 'URL without protocol' do context 'URL without protocol' do
it 'returns the host' do it 'returns the host' do
expect(Settings.host_without_www('foo.com')).to eq 'foo.com' expect(described_class.host_without_www('foo.com')).to eq 'foo.com'
expect(Settings.host_without_www('www.foo.com')).to eq 'foo.com' expect(described_class.host_without_www('www.foo.com')).to eq 'foo.com'
expect(Settings.host_without_www('secure.foo.com')).to eq 'secure.foo.com' expect(described_class.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('www.gravatar.com/avatar/%{hash}?s=%{size}&d=identicon')).to eq 'gravatar.com'
end end
context 'URL with user/port' do context 'URL with user/port' do
it 'returns the host' do it 'returns the host' do
expect(Settings.host_without_www('bob:pass@foo.com:8080')).to eq 'foo.com' expect(described_class.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(described_class.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(described_class.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@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(described_class.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(described_class.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(described_class.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@www.gravatar.com:8080/avatar/%{hash}?s=%{size}&d=identicon')).to eq 'gravatar.com'
end end
end end
end end
......
...@@ -2,7 +2,7 @@ require 'spec_helper' ...@@ -2,7 +2,7 @@ require 'spec_helper'
describe DisableEmailInterceptor do describe DisableEmailInterceptor do
before do before do
Mail.register_interceptor(DisableEmailInterceptor) Mail.register_interceptor(described_class)
end end
it 'does not send emails' do it 'does not send emails' do
...@@ -14,7 +14,7 @@ describe DisableEmailInterceptor do ...@@ -14,7 +14,7 @@ describe DisableEmailInterceptor do
# Removing interceptor from the list because unregister_interceptor is # Removing interceptor from the list because unregister_interceptor is
# implemented in later version of mail gem # implemented in later version of mail gem
# See: https://github.com/mikel/mail/pull/705 # See: https://github.com/mikel/mail/pull/705
Mail.unregister_interceptor(DisableEmailInterceptor) Mail.unregister_interceptor(described_class)
end end
def deliver_mail def deliver_mail
......
...@@ -16,42 +16,42 @@ describe EventFilter do ...@@ -16,42 +16,42 @@ describe EventFilter do
let!(:left_event) { create(:event, :left, project: public_project, target: public_project, author: source_user) } let!(:left_event) { create(:event, :left, project: public_project, target: public_project, author: source_user) }
it 'applies push filter' do 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) expect(events).to contain_exactly(push_event)
end end
it 'applies merged filter' do 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) expect(events).to contain_exactly(merged_event)
end end
it 'applies issue filter' do 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) expect(events).to contain_exactly(created_event, updated_event, closed_event, reopened_event)
end end
it 'applies comments filter' do 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) expect(events).to contain_exactly(comments_event)
end end
it 'applies team filter' do 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) expect(events).to contain_exactly(joined_event, left_event)
end end
it 'applies all filter' do 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) 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
it 'applies no filter' do 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) 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
it 'applies unknown filter' do 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) 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
end end
......
require 'spec_helper' require 'spec_helper'
describe ExtractsPath do describe ExtractsPath do
include ExtractsPath include described_class
include RepoHelpers include RepoHelpers
include Gitlab::Routing include Gitlab::Routing
......
require 'spec_helper' require 'spec_helper'
describe FileSizeValidator do describe FileSizeValidator do
let(:validator) { FileSizeValidator.new(options) } let(:validator) { described_class.new(options) }
let(:attachment) { AttachmentUploader.new } let(:attachment) { AttachmentUploader.new }
let(:note) { create(:note) } let(:note) { create(:note) }
......
...@@ -58,7 +58,7 @@ describe Gitlab::BitbucketImport::Importer do ...@@ -58,7 +58,7 @@ describe Gitlab::BitbucketImport::Importer do
) )
end end
let(:importer) { Gitlab::BitbucketImport::Importer.new(project) } let(:importer) { described_class.new(project) }
let(:issues_statuses_sample_data) do let(:issues_statuses_sample_data) do
{ {
......
...@@ -27,7 +27,7 @@ describe Gitlab::BitbucketImport::ProjectCreator do ...@@ -27,7 +27,7 @@ describe Gitlab::BitbucketImport::ProjectCreator do
it 'creates project' do it 'creates project' do
allow_any_instance_of(Project).to receive(:add_import_job) 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 project = project_creator.execute
expect(project.import_url).to eq("ssh://git@bitbucket.org/asd/vim.git") expect(project.import_url).to eq("ssh://git@bitbucket.org/asd/vim.git")
......
require 'spec_helper' require 'spec_helper'
describe Gitlab::CiAccess do describe Gitlab::CiAccess do
let(:access) { Gitlab::CiAccess.new } let(:access) { described_class.new }
describe '#can_do_action?' do describe '#can_do_action?' do
context 'when action is :build_download_code' do context 'when action is :build_download_code' do
......
...@@ -10,7 +10,7 @@ describe Gitlab::Conflict::File do ...@@ -10,7 +10,7 @@ describe Gitlab::Conflict::File do
let(:index) { rugged.merge_commits(our_commit, their_commit) } let(:index) { rugged.merge_commits(our_commit, their_commit) }
let(:conflict) { index.conflicts.last } let(:conflict) { index.conflicts.last }
let(:merge_file_result) { index.merge_file('files/ruby/regex.rb') } 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 describe '#resolve_lines' do
let(:section_keys) { conflict_file.sections.map { |section| section[:id] }.compact } let(:section_keys) { conflict_file.sections.map { |section| section[:id] }.compact }
...@@ -220,7 +220,7 @@ end ...@@ -220,7 +220,7 @@ end
FILE FILE
end 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 } let(:sections) { conflict_file.sections }
it 'sets the correct match line headers' do it 'sets the correct match line headers' do
......
require 'spec_helper' require 'spec_helper'
describe Gitlab::Conflict::Parser do describe Gitlab::Conflict::Parser do
let(:parser) { Gitlab::Conflict::Parser.new } let(:parser) { described_class.new }
describe '#parse' do describe '#parse' do
def parse_text(text) def parse_text(text)
......
...@@ -3,7 +3,7 @@ require 'spec_helper' ...@@ -3,7 +3,7 @@ require 'spec_helper'
describe Gitlab::Database::MigrationHelpers do describe Gitlab::Database::MigrationHelpers do
let(:model) do let(:model) do
ActiveRecord::Migration.new.extend( ActiveRecord::Migration.new.extend(
Gitlab::Database::MigrationHelpers described_class
) )
end end
......
...@@ -10,7 +10,7 @@ describe Gitlab::Diff::Highlight do ...@@ -10,7 +10,7 @@ describe Gitlab::Diff::Highlight do
describe '#highlight' do describe '#highlight' do
context "with a diff file" 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 it 'returns Gitlab::Diff::Line elements' do
expect(subject.first).to be_an_instance_of(Gitlab::Diff::Line) expect(subject.first).to be_an_instance_of(Gitlab::Diff::Line)
...@@ -41,7 +41,7 @@ describe Gitlab::Diff::Highlight do ...@@ -41,7 +41,7 @@ describe Gitlab::Diff::Highlight do
end end
context "with diff lines" do 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 it 'returns Gitlab::Diff::Line elements' do
expect(subject.first).to be_an_instance_of(Gitlab::Diff::Line) expect(subject.first).to be_an_instance_of(Gitlab::Diff::Line)
......
...@@ -6,7 +6,7 @@ describe Gitlab::Diff::Parser do ...@@ -6,7 +6,7 @@ describe Gitlab::Diff::Parser do
let(:project) { create(:project) } let(:project) { create(:project) }
let(:commit) { project.commit(sample_commit.id) } let(:commit) { project.commit(sample_commit.id) }
let(:diff) { commit.raw_diffs.first } let(:diff) { commit.raw_diffs.first }
let(:parser) { Gitlab::Diff::Parser.new } let(:parser) { described_class.new }
describe '#parse' do describe '#parse' do
let(:diff) do let(:diff) do
......
...@@ -5,7 +5,7 @@ describe Gitlab::Git::Hook do ...@@ -5,7 +5,7 @@ describe Gitlab::Git::Hook do
before do before do
# We need this because in the spec/spec_helper.rb we define it like this: # 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_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 end
describe "#trigger" do describe "#trigger" do
...@@ -48,7 +48,7 @@ describe Gitlab::Git::Hook do ...@@ -48,7 +48,7 @@ describe Gitlab::Git::Hook do
it "returns success with no errors" do it "returns success with no errors" do
create_hook(hook_name) create_hook(hook_name)
hook = Gitlab::Git::Hook.new(hook_name, project) hook = described_class.new(hook_name, project)
blank = Gitlab::Git::BLANK_SHA blank = Gitlab::Git::BLANK_SHA
ref = Gitlab::Git::BRANCH_REF_PREFIX + 'new_branch' ref = Gitlab::Git::BRANCH_REF_PREFIX + 'new_branch'
...@@ -66,7 +66,7 @@ describe Gitlab::Git::Hook do ...@@ -66,7 +66,7 @@ describe Gitlab::Git::Hook do
context "when the hook is unsuccessful" do context "when the hook is unsuccessful" do
it "returns failure with errors" do it "returns failure with errors" do
create_failing_hook(hook_name) 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 blank = Gitlab::Git::BLANK_SHA
ref = Gitlab::Git::BRANCH_REF_PREFIX + 'new_branch' ref = Gitlab::Git::BRANCH_REF_PREFIX + 'new_branch'
...@@ -80,7 +80,7 @@ describe Gitlab::Git::Hook do ...@@ -80,7 +80,7 @@ describe Gitlab::Git::Hook do
context "when the hook doesn't exist" do context "when the hook doesn't exist" do
it "returns success with no errors" 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 blank = Gitlab::Git::BLANK_SHA
ref = Gitlab::Git::BRANCH_REF_PREFIX + 'new_branch' ref = Gitlab::Git::BRANCH_REF_PREFIX + 'new_branch'
......
...@@ -11,7 +11,7 @@ describe Gitlab::Git::RevList do ...@@ -11,7 +11,7 @@ describe Gitlab::Git::RevList do
end end
context "#new_refs" do 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 it 'calls out to `popen`' do
expect(Gitlab::Popen).to receive(:popen).with([ expect(Gitlab::Popen).to receive(:popen).with([
...@@ -33,7 +33,7 @@ describe Gitlab::Git::RevList do ...@@ -33,7 +33,7 @@ describe Gitlab::Git::RevList do
end end
context "#missed_ref" do 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 it 'calls out to `popen`' do
expect(Gitlab::Popen).to receive(:popen).with([ expect(Gitlab::Popen).to receive(:popen).with([
......
...@@ -3,7 +3,7 @@ require 'spec_helper' ...@@ -3,7 +3,7 @@ require 'spec_helper'
describe Gitlab::GitAccess do describe Gitlab::GitAccess do
let(:pull_access_check) { access.check('git-upload-pack', '_any') } let(:pull_access_check) { access.check('git-upload-pack', '_any') }
let(:push_access_check) { access.check('git-receive-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(:project) { create(:project, :repository) }
let(:user) { create(:user) } let(:user) { create(:user) }
let(:actor) { user } let(:actor) { user }
...@@ -280,7 +280,7 @@ describe Gitlab::GitAccess do ...@@ -280,7 +280,7 @@ describe Gitlab::GitAccess do
context 'when project is public' do context 'when project is public' do
let(:public_project) { create(:project, :public, :repository) } 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 context 'when repository is enabled' do
it 'give access to download code' do it 'give access to download code' do
...@@ -441,7 +441,7 @@ describe Gitlab::GitAccess do ...@@ -441,7 +441,7 @@ describe Gitlab::GitAccess do
end end
permissions_matrix[role].each do |action, allowed| permissions_matrix[role].each do |action, allowed|
context action do context action.to_s do
subject { access.send(:check_push_access!, changes[action]) } subject { access.send(:check_push_access!, changes[action]) }
it do it do
......
require 'spec_helper' require 'spec_helper'
describe Gitlab::GitAccessWiki do 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(:project) { create(:project, :repository) }
let(:user) { create(:user) } let(:user) { create(:user) }
let(:redirected_path) { nil } let(:redirected_path) { nil }
......
require 'spec_helper' require 'spec_helper'
describe Gitlab::GitRefValidator do describe Gitlab::GitRefValidator do
it { expect(Gitlab::GitRefValidator.validate('feature/new')).to be_truthy } it { expect(described_class.validate('feature/new')).to be_truthy }
it { expect(Gitlab::GitRefValidator.validate('implement_@all')).to be_truthy } it { expect(described_class.validate('implement_@all')).to be_truthy }
it { expect(Gitlab::GitRefValidator.validate('my_new_feature')).to be_truthy } it { expect(described_class.validate('my_new_feature')).to be_truthy }
it { expect(Gitlab::GitRefValidator.validate('#1')).to be_truthy } it { expect(described_class.validate('#1')).to be_truthy }
it { expect(Gitlab::GitRefValidator.validate('feature/refs/heads/foo')).to be_truthy } it { expect(described_class.validate('feature/refs/heads/foo')).to be_truthy }
it { expect(Gitlab::GitRefValidator.validate('feature/~new/')).to be_falsey } it { expect(described_class.validate('feature/~new/')).to be_falsey }
it { expect(Gitlab::GitRefValidator.validate('feature/^new/')).to be_falsey } it { expect(described_class.validate('feature/^new/')).to be_falsey }
it { expect(Gitlab::GitRefValidator.validate('feature/:new/')).to be_falsey } it { expect(described_class.validate('feature/:new/')).to be_falsey }
it { expect(Gitlab::GitRefValidator.validate('feature/?new/')).to be_falsey } it { expect(described_class.validate('feature/?new/')).to be_falsey }
it { expect(Gitlab::GitRefValidator.validate('feature/*new/')).to be_falsey } it { expect(described_class.validate('feature/*new/')).to be_falsey }
it { expect(Gitlab::GitRefValidator.validate('feature/[new/')).to be_falsey } it { expect(described_class.validate('feature/[new/')).to be_falsey }
it { expect(Gitlab::GitRefValidator.validate('feature/new/')).to be_falsey } it { expect(described_class.validate('feature/new/')).to be_falsey }
it { expect(Gitlab::GitRefValidator.validate('feature/new.')).to be_falsey } it { expect(described_class.validate('feature/new.')).to be_falsey }
it { expect(Gitlab::GitRefValidator.validate('feature\@{')).to be_falsey } it { expect(described_class.validate('feature\@{')).to be_falsey }
it { expect(Gitlab::GitRefValidator.validate('feature\new')).to be_falsey } it { expect(described_class.validate('feature\new')).to be_falsey }
it { expect(Gitlab::GitRefValidator.validate('feature//new')).to be_falsey } it { expect(described_class.validate('feature//new')).to be_falsey }
it { expect(Gitlab::GitRefValidator.validate('feature new')).to be_falsey } it { expect(described_class.validate('feature new')).to be_falsey }
it { expect(Gitlab::GitRefValidator.validate('refs/heads/')).to be_falsey } it { expect(described_class.validate('refs/heads/')).to be_falsey }
it { expect(Gitlab::GitRefValidator.validate('refs/remotes/')).to be_falsey } it { expect(described_class.validate('refs/remotes/')).to be_falsey }
it { expect(Gitlab::GitRefValidator.validate('refs/heads/feature')).to be_falsey } it { expect(described_class.validate('refs/heads/feature')).to be_falsey }
it { expect(Gitlab::GitRefValidator.validate('refs/remotes/origin')).to be_falsey } it { expect(described_class.validate('refs/remotes/origin')).to be_falsey }
end end
...@@ -6,7 +6,7 @@ describe Gitlab::Git do ...@@ -6,7 +6,7 @@ describe Gitlab::Git do
describe 'committer_hash' do describe 'committer_hash' do
it "returns a hash containing the given email and name" 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[:email]).to eq(committer_email)
expect(committer_hash[:name]).to eq(committer_name) expect(committer_hash[:name]).to eq(committer_name)
...@@ -15,7 +15,7 @@ describe Gitlab::Git do ...@@ -15,7 +15,7 @@ describe Gitlab::Git do
context 'when email is nil' do context 'when email is nil' do
it "returns 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 expect(committer_hash).to be_nil
end end
...@@ -23,7 +23,7 @@ describe Gitlab::Git do ...@@ -23,7 +23,7 @@ describe Gitlab::Git do
context 'when name is nil' do context 'when name is nil' do
it "returns 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 expect(committer_hash).to be_nil
end end
......
...@@ -4,7 +4,7 @@ describe Gitlab::GitlabImport::Client do ...@@ -4,7 +4,7 @@ describe Gitlab::GitlabImport::Client do
include ImportSpecHelper include ImportSpecHelper
let(:token) { '123456' } let(:token) { '123456' }
let(:client) { Gitlab::GitlabImport::Client.new(token) } let(:client) { described_class.new(token) }
before do before do
stub_omniauth_provider('gitlab') stub_omniauth_provider('gitlab')
......
...@@ -23,7 +23,7 @@ describe Gitlab::GitlabImport::ProjectCreator do ...@@ -23,7 +23,7 @@ describe Gitlab::GitlabImport::ProjectCreator do
it 'creates project' do it 'creates project' do
allow_any_instance_of(Project).to receive(:add_import_job) 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 project = project_creator.execute
expect(project.import_url).to eq("https://oauth2:asdffg@gitlab.com/asd/vim.git") expect(project.import_url).to eq("https://oauth2:asdffg@gitlab.com/asd/vim.git")
......
...@@ -18,7 +18,7 @@ describe Gitlab::GoogleCodeImport::ProjectCreator do ...@@ -18,7 +18,7 @@ describe Gitlab::GoogleCodeImport::ProjectCreator do
it 'creates project' do it 'creates project' do
allow_any_instance_of(Project).to receive(:add_import_job) 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 project = project_creator.execute
expect(project.import_url).to eq("https://vim.googlecode.com/git/") expect(project.import_url).to eq("https://vim.googlecode.com/git/")
......
...@@ -12,7 +12,7 @@ describe Gitlab::Highlight do ...@@ -12,7 +12,7 @@ describe Gitlab::Highlight do
let(:blob) { repository.blob_at_branch(branch, path) } let(:blob) { repository.blob_at_branch(branch, path) }
let(:highlighter) do let(:highlighter) do
Gitlab::Highlight.new(blob.path, blob.data, repository: repository) described_class.new(blob.path, blob.data, repository: repository)
end end
before do before do
...@@ -42,7 +42,7 @@ describe Gitlab::Highlight do ...@@ -42,7 +42,7 @@ describe Gitlab::Highlight do
let(:path) { 'files/whitespace' } let(:path) { 'files/whitespace' }
let(:blob) { repository.blob_at_branch(branch, path) } let(:blob) { repository.blob_at_branch(branch, path) }
let(:lines) do let(:lines) do
Gitlab::Highlight.highlight(blob.path, blob.data, repository: repository).lines described_class.highlight(blob.path, blob.data, repository: repository).lines
end end
it 'strips extra LFs' do it 'strips extra LFs' do
......
...@@ -6,7 +6,7 @@ describe Gitlab::KeyFingerprint do ...@@ -6,7 +6,7 @@ describe Gitlab::KeyFingerprint do
describe "#fingerprint" do describe "#fingerprint" do
it "generates the key's 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 end
end end
require 'spec_helper' require 'spec_helper'
describe Gitlab::LDAP::Access do describe Gitlab::LDAP::Access do
let(:access) { Gitlab::LDAP::Access.new user } let(:access) { described_class.new user }
let(:user) { create(:omniauth_user) } let(:user) { create(:omniauth_user) }
describe '.allowed?' do describe '.allowed?' do
......
...@@ -2,7 +2,7 @@ require 'spec_helper' ...@@ -2,7 +2,7 @@ require 'spec_helper'
describe Gitlab::LDAP::AuthHash do describe Gitlab::LDAP::AuthHash do
let(:auth_hash) do let(:auth_hash) do
Gitlab::LDAP::AuthHash.new( described_class.new(
OmniAuth::AuthHash.new( OmniAuth::AuthHash.new(
uid: '123456', uid: '123456',
provider: 'ldapmain', provider: 'ldapmain',
......
...@@ -3,11 +3,11 @@ require 'spec_helper' ...@@ -3,11 +3,11 @@ require 'spec_helper'
describe Gitlab::LDAP::Config do describe Gitlab::LDAP::Config do
include LdapHelpers include LdapHelpers
let(:config) { Gitlab::LDAP::Config.new('ldapmain') } let(:config) { described_class.new('ldapmain') }
describe '#initialize' do describe '#initialize' do
it 'requires a provider' do it 'requires a provider' do
expect{ Gitlab::LDAP::Config.new }.to raise_error ArgumentError expect{ described_class.new }.to raise_error ArgumentError
end end
it 'works' do it 'works' do
...@@ -15,7 +15,7 @@ describe Gitlab::LDAP::Config do ...@@ -15,7 +15,7 @@ describe Gitlab::LDAP::Config do
end end
it 'raises an error if a unknown provider is used' do 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
end end
......
require 'spec_helper' require 'spec_helper'
describe Gitlab::LDAP::User do 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(:gl_user) { ldap_user.gl_user }
let(:info) do let(:info) do
{ {
...@@ -13,7 +13,7 @@ describe Gitlab::LDAP::User do ...@@ -13,7 +13,7 @@ describe Gitlab::LDAP::User do
let(:auth_hash) do let(:auth_hash) do
OmniAuth::AuthHash.new(uid: 'my-uid', provider: 'ldapmain', info: info) OmniAuth::AuthHash.new(uid: 'my-uid', provider: 'ldapmain', info: info)
end 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 let(:info_upper_case) do
{ {
name: 'John', name: 'John',
......
...@@ -5,36 +5,36 @@ describe Gitlab::MarkupHelper do ...@@ -5,36 +5,36 @@ describe Gitlab::MarkupHelper do
%w(textile rdoc org creole wiki %w(textile rdoc org creole wiki
mediawiki rst adoc ad asciidoc mdown md markdown).each do |type| mediawiki rst adoc ad asciidoc mdown md markdown).each do |type|
it "returns true for #{type} files" do 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
end end
it 'returns false when given a non-markup filename' do 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
end end
describe '#gitlab_markdown?' do describe '#gitlab_markdown?' do
%w(mdown mkd mkdn md markdown).each do |type| %w(mdown mkd mkdn md markdown).each do |type|
it "returns true for #{type} files" do 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
end end
it 'returns false when given a non-markdown filename' do 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
end end
describe '#asciidoc?' do describe '#asciidoc?' do
%w(adoc ad asciidoc ADOC).each do |type| %w(adoc ad asciidoc ADOC).each do |type|
it "returns true for #{type} files" do 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
end end
it 'returns false when given a non-asciidoc filename' do 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 end
end end
...@@ -2,7 +2,7 @@ require 'spec_helper' ...@@ -2,7 +2,7 @@ require 'spec_helper'
describe Gitlab::OAuth::AuthHash do describe Gitlab::OAuth::AuthHash do
let(:auth_hash) do let(:auth_hash) do
Gitlab::OAuth::AuthHash.new( described_class.new(
OmniAuth::AuthHash.new( OmniAuth::AuthHash.new(
provider: provider_ascii, provider: provider_ascii,
uid: uid_ascii, uid: uid_ascii,
......
require 'spec_helper' require 'spec_helper'
describe Gitlab::OAuth::User do 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(:gl_user) { oauth_user.gl_user }
let(:uid) { 'my-uid' } let(:uid) { 'my-uid' }
let(:provider) { 'my-provider' } let(:provider) { 'my-provider' }
......
...@@ -3,7 +3,7 @@ require 'spec_helper' ...@@ -3,7 +3,7 @@ require 'spec_helper'
describe Gitlab::ProjectTransfer do describe Gitlab::ProjectTransfer do
before do before do
@root_dir = File.join(Rails.root, "public", "uploads") @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) allow(@project_transfer).to receive(:root_dir).and_return(@root_dir)
@project_path_was = "test_project_was" @project_path_was = "test_project_was"
......
...@@ -7,7 +7,7 @@ describe Gitlab::ReferenceExtractor do ...@@ -7,7 +7,7 @@ describe Gitlab::ReferenceExtractor do
project.team << [project.creator, :developer] project.team << [project.creator, :developer]
end end
subject { Gitlab::ReferenceExtractor.new(project, project.creator) } subject { described_class.new(project, project.creator) }
it 'accesses valid user objects' do it 'accesses valid user objects' do
@u_foo = create(:user, username: 'foo') @u_foo = create(:user, username: 'foo')
......
...@@ -2,7 +2,7 @@ require 'spec_helper' ...@@ -2,7 +2,7 @@ require 'spec_helper'
describe Gitlab::RequestContext do describe Gitlab::RequestContext do
describe '#client_ip' do describe '#client_ip' do
subject { Gitlab::RequestContext.client_ip } subject { described_class.client_ip }
let(:app) { -> (env) {} } let(:app) { -> (env) {} }
let(:env) { Hash.new } let(:env) { Hash.new }
...@@ -16,7 +16,7 @@ describe Gitlab::RequestContext do ...@@ -16,7 +16,7 @@ describe Gitlab::RequestContext do
before do before do
allow_any_instance_of(Rack::Request).to receive(:ip).and_return(ip) 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 end
it { is_expected.to eq(ip) } it { is_expected.to eq(ip) }
......
...@@ -3,7 +3,7 @@ require 'stringio' ...@@ -3,7 +3,7 @@ require 'stringio'
describe Gitlab::Shell do describe Gitlab::Shell do
let(:project) { double('Project', id: 7, path: 'diaspora') } 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'] } } let(:popen_vars) { { 'GIT_TERMINAL_PROMPT' => ENV['GIT_TERMINAL_PROMPT'] } }
before do before do
...@@ -30,7 +30,7 @@ describe Gitlab::Shell 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(:secret_file).and_return(secret_file)
allow(Gitlab.config.gitlab_shell).to receive(:path).and_return('tmp/tests/shell-secret-test') allow(Gitlab.config.gitlab_shell).to receive(:path).and_return('tmp/tests/shell-secret-test')
FileUtils.mkdir('tmp/tests/shell-secret-test') FileUtils.mkdir('tmp/tests/shell-secret-test')
Gitlab::Shell.ensure_secret_token! described_class.ensure_secret_token!
end end
after do after do
...@@ -39,7 +39,7 @@ describe Gitlab::Shell do ...@@ -39,7 +39,7 @@ describe Gitlab::Shell do
end end
it 'creates and links the secret token file' do 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.exist?(secret_file)).to be(true)
expect(File.read(secret_file).chomp).to eq(secret_token) expect(File.read(secret_file).chomp).to eq(secret_token)
......
require 'spec_helper' require 'spec_helper'
describe Gitlab::Upgrader do describe Gitlab::Upgrader do
let(:upgrader) { Gitlab::Upgrader.new } let(:upgrader) { described_class.new }
let(:current_version) { Gitlab::VERSION } let(:current_version) { Gitlab::VERSION }
describe 'current_version_raw' do describe 'current_version_raw' do
......
require 'spec_helper' require 'spec_helper'
describe Gitlab::UserAccess do 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(:project) { create(:project) }
let(:user) { create(:user) } let(:user) { create(:user) }
...@@ -28,7 +28,7 @@ describe Gitlab::UserAccess do ...@@ -28,7 +28,7 @@ describe Gitlab::UserAccess do
describe 'push to empty project' do describe 'push to empty project' do
let(:empty_project) { create(:project_empty_repo) } 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 it 'returns true if user is master' do
empty_project.team << [user, :master] empty_project.team << [user, :master]
......
...@@ -63,13 +63,13 @@ describe Gitlab::Workhorse do ...@@ -63,13 +63,13 @@ describe Gitlab::Workhorse do
end end
context 'without ca_pem' do context 'without ca_pem' do
subject { Gitlab::Workhorse.terminal_websocket(terminal) } subject { described_class.terminal_websocket(terminal) }
it { is_expected.to eq(workhorse) } it { is_expected.to eq(workhorse) }
end end
context 'with ca_pem' do 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")) } it { is_expected.to eq(workhorse(ca_pem: "foo")) }
end end
......
...@@ -3,7 +3,7 @@ require 'spec_helper' ...@@ -3,7 +3,7 @@ require 'spec_helper'
describe RepositoryCache do describe RepositoryCache do
let(:project) { create(:empty_project) } let(:project) { create(:empty_project) }
let(:backend) { double('backend').as_null_object } 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 describe '#cache_key' do
it 'includes the namespace' do it 'includes the namespace' do
......
...@@ -19,7 +19,7 @@ describe SystemCheck do ...@@ -19,7 +19,7 @@ describe SystemCheck do
end end
describe '.run' do describe '.run' do
subject { SystemCheck } subject { described_class }
it 'detects execution of SimpleCheck' do it 'detects execution of SimpleCheck' do
is_expected.to execute_check(SimpleCheck) is_expected.to execute_check(SimpleCheck)
......
...@@ -3,7 +3,7 @@ require 'spec_helper' ...@@ -3,7 +3,7 @@ require 'spec_helper'
describe Ability do describe Ability do
context 'using a nil subject' do context 'using a nil subject' do
it 'has no permissions' 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
end end
......
require 'spec_helper' require 'spec_helper'
describe ApplicationSetting do 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).to be_valid }
it { expect(setting.uuid).to be_present } it { expect(setting.uuid).to be_present }
...@@ -159,10 +159,10 @@ describe ApplicationSetting do ...@@ -159,10 +159,10 @@ describe ApplicationSetting do
context 'redis unavailable' do context 'redis unavailable' do
it 'returns an ApplicationSetting' do it 'returns an ApplicationSetting' do
allow(Rails.cache).to receive(:fetch).and_call_original 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(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 end
end end
......
...@@ -24,26 +24,26 @@ describe BroadcastMessage do ...@@ -24,26 +24,26 @@ describe BroadcastMessage do
it 'returns message if time match' do it 'returns message if time match' do
message = create(:broadcast_message) message = create(:broadcast_message)
expect(BroadcastMessage.current).to include(message) expect(described_class.current).to include(message)
end end
it 'returns multiple messages if time match' do it 'returns multiple messages if time match' do
message1 = create(:broadcast_message) message1 = create(:broadcast_message)
message2 = 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 end
it 'returns empty list if time not come' do it 'returns empty list if time not come' do
create(:broadcast_message, :future) create(:broadcast_message, :future)
expect(BroadcastMessage.current).to be_empty expect(described_class.current).to be_empty
end end
it 'returns empty list if time has passed' do it 'returns empty list if time has passed' do
create(:broadcast_message, :expired) create(:broadcast_message, :expired)
expect(BroadcastMessage.current).to be_empty expect(described_class.current).to be_empty
end end
end end
......
...@@ -46,7 +46,7 @@ describe Ci::PipelineSchedule do ...@@ -46,7 +46,7 @@ describe Ci::PipelineSchedule do
end end
it 'updates next_run_at automatically' do 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
end end
...@@ -61,7 +61,7 @@ describe Ci::PipelineSchedule do ...@@ -61,7 +61,7 @@ describe Ci::PipelineSchedule do
it 'updates next_run_at automatically' do it 'updates next_run_at automatically' do
pipeline_schedule.update!(cron: new_cron) 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 end
end end
......
...@@ -50,7 +50,7 @@ describe Ci::Runner do ...@@ -50,7 +50,7 @@ describe Ci::Runner do
end end
describe '.online' do describe '.online' do
subject { Ci::Runner.online } subject { described_class.online }
before do before do
@runner1 = FactoryGirl.create(:ci_runner, :shared, contacted_at: 1.year.ago) @runner1 = FactoryGirl.create(:ci_runner, :shared, contacted_at: 1.year.ago)
...@@ -352,13 +352,13 @@ describe Ci::Runner do ...@@ -352,13 +352,13 @@ describe Ci::Runner do
end end
context 'does not give owned 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 } it { is_expected.to be_empty }
end end
context 'does not give shared runner' do 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 } it { is_expected.to be_empty }
end end
...@@ -366,13 +366,13 @@ describe Ci::Runner do ...@@ -366,13 +366,13 @@ describe Ci::Runner do
context 'with unlocked runner' do context 'with unlocked runner' do
context 'does not give owned 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 } it { is_expected.to be_empty }
end end
context 'does give a specific runner' do 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) } it { is_expected.to contain_exactly(runner) }
end end
...@@ -384,13 +384,13 @@ describe Ci::Runner do ...@@ -384,13 +384,13 @@ describe Ci::Runner do
end end
context 'does not give owned 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 } it { is_expected.to be_empty }
end end
context 'does not give a locked runner' do 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 } it { is_expected.to be_empty }
end end
......
...@@ -72,7 +72,7 @@ describe GlobalMilestone do ...@@ -72,7 +72,7 @@ describe GlobalMilestone do
project3 project3
] ]
@global_milestones = GlobalMilestone.build_collection(projects, {}) @global_milestones = described_class.build_collection(projects, {})
end end
it 'has all project milestones' do it 'has all project milestones' do
...@@ -106,7 +106,7 @@ describe GlobalMilestone do ...@@ -106,7 +106,7 @@ describe GlobalMilestone do
it 'returns the quantity of global milestones in each possible state' do it 'returns the quantity of global milestones in each possible state' do
expected_count = { opened: 1, closed: 2, all: 2 } 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) expect(count).to eq(expected_count)
end end
...@@ -120,7 +120,7 @@ describe GlobalMilestone do ...@@ -120,7 +120,7 @@ describe GlobalMilestone do
it 'returns 0 as the quantity of global milestones in each state' do it 'returns 0 as the quantity of global milestones in each state' do
expected_count = { opened: 0, closed: 0, all: 0 } 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) expect(count).to eq(expected_count)
end end
...@@ -141,7 +141,7 @@ describe GlobalMilestone do ...@@ -141,7 +141,7 @@ describe GlobalMilestone do
] ]
milestones_relation = Milestone.where(id: milestones.map(&:id)) 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 end
it 'has exactly one group milestone' do it 'has exactly one group milestone' do
...@@ -157,7 +157,7 @@ describe GlobalMilestone do ...@@ -157,7 +157,7 @@ describe GlobalMilestone do
let(:milestone) { create(:milestone, title: "git / test", project: project1) } let(:milestone) { create(:milestone, title: "git / test", project: project1) }
it 'strips out slashes and spaces' do 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') expect(global_milestone.safe_title).to eq('git-test')
end end
...@@ -171,7 +171,7 @@ describe GlobalMilestone do ...@@ -171,7 +171,7 @@ describe GlobalMilestone do
create(:active_milestone, title: title), create(:active_milestone, title: title),
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('active') expect(global_milestone.state).to eq('active')
end end
...@@ -184,7 +184,7 @@ describe GlobalMilestone do ...@@ -184,7 +184,7 @@ describe GlobalMilestone do
create(:closed_milestone, title: title), create(:closed_milestone, title: title),
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') expect(global_milestone.state).to eq('closed')
end end
......
...@@ -9,7 +9,7 @@ describe GroupMilestone do ...@@ -9,7 +9,7 @@ describe GroupMilestone do
describe '.build' do describe '.build' do
it 'returns milestone with group assigned' do it 'returns milestone with group assigned' do
milestone = GroupMilestone.build( milestone = described_class.build(
group, group,
[project], [project],
project_milestone.title project_milestone.title
...@@ -25,7 +25,7 @@ describe GroupMilestone do ...@@ -25,7 +25,7 @@ describe GroupMilestone do
end end
it 'returns array of milestones, each with group assigned' do 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)) expect(milestones).to all(have_attributes(group: group))
end end
end end
......
...@@ -357,7 +357,7 @@ describe Group do ...@@ -357,7 +357,7 @@ describe Group do
subject { build(:group, :nested) } subject { build(:group, :nested) }
it { is_expected.to be_valid } 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 end
describe '#members_with_parents', :nested_groups do describe '#members_with_parents', :nested_groups do
......
...@@ -8,13 +8,13 @@ describe Guest do ...@@ -8,13 +8,13 @@ describe Guest do
describe '.can_pull?' do describe '.can_pull?' do
context 'when project is private' do context 'when project is private' do
it 'does not allow to pull the repo' 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
end end
context 'when project is internal' do context 'when project is internal' do
it 'does not allow to pull the repo' 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
end end
...@@ -23,7 +23,7 @@ describe Guest do ...@@ -23,7 +23,7 @@ describe Guest do
it 'does not allow to pull the repo' do it 'does not allow to pull the repo' do
public_project.project_feature.update_attribute(:repository_access_level, ProjectFeature::DISABLED) 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
end end
...@@ -31,13 +31,13 @@ describe Guest do ...@@ -31,13 +31,13 @@ describe Guest do
it 'does not allow to pull the repo' do it 'does not allow to pull the repo' do
public_project.project_feature.update_attribute(:repository_access_level, ProjectFeature::PRIVATE) 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
end end
context 'when repository is enabled' do context 'when repository is enabled' do
it 'allows to pull the repo' 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 end
end end
......
...@@ -13,7 +13,7 @@ describe ProjectHook do ...@@ -13,7 +13,7 @@ describe ProjectHook do
it 'returns hooks for push events only' do it 'returns hooks for push events only' do
hook = create(:project_hook, push_events: true) hook = create(:project_hook, push_events: true)
create(:project_hook, push_events: false) create(:project_hook, push_events: false)
expect(ProjectHook.push_hooks).to eq([hook]) expect(described_class.push_hooks).to eq([hook])
end end
end end
...@@ -21,7 +21,7 @@ describe ProjectHook do ...@@ -21,7 +21,7 @@ describe ProjectHook do
it 'returns hooks for tag push events only' do it 'returns hooks for tag push events only' do
hook = create(:project_hook, tag_push_events: true) hook = create(:project_hook, tag_push_events: true)
create(:project_hook, tag_push_events: false) 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 end
end end
...@@ -122,7 +122,7 @@ describe SystemHook do ...@@ -122,7 +122,7 @@ describe SystemHook do
it 'returns hooks for repository update events only' do it 'returns hooks for repository update events only' do
hook = create(:system_hook, repository_update_events: true) hook = create(:system_hook, repository_update_events: true)
create(:system_hook, repository_update_events: false) 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
end end
......
...@@ -6,7 +6,7 @@ describe Member do ...@@ -6,7 +6,7 @@ describe Member do
end end
describe "Validation" do 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(:user) }
it { is_expected.to validate_presence_of(:source) } it { is_expected.to validate_presence_of(:source) }
......
...@@ -139,7 +139,7 @@ describe ProjectMember do ...@@ -139,7 +139,7 @@ describe ProjectMember do
@project_1.team << [@user_1, :developer] @project_1.team << [@user_1, :developer]
@project_2.team << [@user_2, :reporter] @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 end
it { expect(@project_1.users).to be_empty } it { expect(@project_1.users).to be_empty }
......
...@@ -98,7 +98,7 @@ describe MergeRequestDiff do ...@@ -98,7 +98,7 @@ describe MergeRequestDiff do
end end
it 'saves empty state' do 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([]) .and_return([])
mr_diff = create(:merge_request).merge_request_diff mr_diff = create(:merge_request).merge_request_diff
......
...@@ -37,13 +37,13 @@ describe Milestone do ...@@ -37,13 +37,13 @@ describe Milestone do
describe "unique milestone title" do describe "unique milestone title" do
context "per project" do context "per project" do
it "does not accept the same title in a project twice" 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 expect(new_milestone).not_to be_valid
end end
it "accepts the same title in another project" do it "accepts the same title in another project" do
project = create(:empty_project) 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 expect(new_milestone).to be_valid
end end
...@@ -58,7 +58,7 @@ describe Milestone do ...@@ -58,7 +58,7 @@ describe Milestone do
end end
it "does not accept the same title in a group twice" do 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 expect(new_milestone).not_to be_valid
end end
...@@ -66,7 +66,7 @@ describe Milestone do ...@@ -66,7 +66,7 @@ describe Milestone do
it "does not accept the same title of a child project milestone" do it "does not accept the same title of a child project milestone" do
create(:milestone, project: group.projects.first) 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 expect(new_milestone).not_to be_valid
end end
...@@ -214,7 +214,7 @@ describe Milestone do ...@@ -214,7 +214,7 @@ describe Milestone do
# The call to `#try` is because this returns a relation with a Postgres DB, # The call to `#try` is because this returns a relation with a Postgres DB,
# and an array of IDs with a MySQL 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 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) expect(milestone_ids).to contain_exactly(current_milestone_project_1.id, current_milestone_project_2.id)
......
...@@ -133,7 +133,7 @@ describe Namespace do ...@@ -133,7 +133,7 @@ describe Namespace do
it "sums all project storage counters in the namespace" do it "sums all project storage counters in the namespace" do
project1 project1
project2 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.storage_size).to eq 666
expect(statistics.repository_size).to eq 111 expect(statistics.repository_size).to eq 111
...@@ -142,7 +142,7 @@ describe Namespace do ...@@ -142,7 +142,7 @@ describe Namespace do
end end
it "correctly handles namespaces without projects" do 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.storage_size).to eq 0
expect(statistics.repository_size).to eq 0 expect(statistics.repository_size).to eq 0
...@@ -286,9 +286,9 @@ describe Namespace do ...@@ -286,9 +286,9 @@ describe Namespace do
@namespace = create(:namespace, name: 'WoW', path: 'woW') @namespace = create(:namespace, name: 'WoW', path: 'woW')
end end
it { expect(Namespace.find_by_path_or_name('wow')).to eq(@namespace) } it { expect(described_class.find_by_path_or_name('wow')).to eq(@namespace) }
it { expect(Namespace.find_by_path_or_name('WOW')).to eq(@namespace) } it { expect(described_class.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('unknown')).to eq(nil) }
end end
describe ".clean_path" do describe ".clean_path" do
...@@ -296,8 +296,8 @@ describe Namespace do ...@@ -296,8 +296,8 @@ describe Namespace do
let!(:namespace) { create(:namespace, path: "JohnGitLab-etc1") } let!(:namespace) { create(:namespace, path: "JohnGitLab-etc1") }
it "cleans the path and makes sure it's available" do 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(described_class.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("--%+--valid_*&%name=.git.%.atom.atom.@email.com")).to eq("valid_name")
end end
end end
......
...@@ -525,7 +525,7 @@ describe Note do ...@@ -525,7 +525,7 @@ describe Note do
it "has a discussion id" do it "has a discussion id" do
# The discussion_id is set in `after_initialize`, so `reload` won't work # 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).not_to be_nil
expect(reloaded_note.discussion_id).to match(/\A\h{40}\z/) expect(reloaded_note.discussion_id).to match(/\A\h{40}\z/)
......
...@@ -35,7 +35,7 @@ describe AsanaService do ...@@ -35,7 +35,7 @@ describe AsanaService do
end end
before do before do
@asana = AsanaService.new @asana = described_class.new
allow(@asana).to receive_messages( allow(@asana).to receive_messages(
project: project, project: project,
project_id: project.id, project_id: project.id,
......
...@@ -11,7 +11,7 @@ describe AssemblaService do ...@@ -11,7 +11,7 @@ describe AssemblaService do
let(:project) { create(:project, :repository) } let(:project) { create(:project, :repository) }
before do before do
@assembla_service = AssemblaService.new @assembla_service = described_class.new
allow(@assembla_service).to receive_messages( allow(@assembla_service).to receive_messages(
project_id: project.id, project_id: project.id,
project: project, project: project,
......
...@@ -29,7 +29,7 @@ describe CampfireService do ...@@ -29,7 +29,7 @@ describe CampfireService do
let(:project) { create(:project, :repository) } let(:project) { create(:project, :repository) }
before do before do
@campfire_service = CampfireService.new @campfire_service = described_class.new
allow(@campfire_service).to receive_messages( allow(@campfire_service).to receive_messages(
project_id: project.id, project_id: project.id,
project: project, project: project,
......
...@@ -29,7 +29,7 @@ describe FlowdockService do ...@@ -29,7 +29,7 @@ describe FlowdockService do
let(:project) { create(:project, :repository) } let(:project) { create(:project, :repository) }
before do before do
@flowdock_service = FlowdockService.new @flowdock_service = described_class.new
allow(@flowdock_service).to receive_messages( allow(@flowdock_service).to receive_messages(
project_id: project.id, project_id: project.id,
project: project, project: project,
......
...@@ -31,7 +31,7 @@ describe GemnasiumService do ...@@ -31,7 +31,7 @@ describe GemnasiumService do
let(:project) { create(:project, :repository) } let(:project) { create(:project, :repository) }
before do before do
@gemnasium_service = GemnasiumService.new @gemnasium_service = described_class.new
allow(@gemnasium_service).to receive_messages( allow(@gemnasium_service).to receive_messages(
project_id: project.id, project_id: project.id,
project: project, project: project,
......
...@@ -27,7 +27,7 @@ describe GitlabIssueTrackerService do ...@@ -27,7 +27,7 @@ describe GitlabIssueTrackerService do
context 'with absolute urls' do context 'with absolute urls' do
before 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 end
it 'gives the correct path' do it 'gives the correct path' do
...@@ -39,7 +39,7 @@ describe GitlabIssueTrackerService do ...@@ -39,7 +39,7 @@ describe GitlabIssueTrackerService do
context 'with relative urls' do context 'with relative urls' do
before 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 end
it 'gives the correct path' do it 'gives the correct path' do
......
...@@ -25,7 +25,7 @@ describe HipchatService do ...@@ -25,7 +25,7 @@ describe HipchatService do
end end
describe "Execute" do describe "Execute" do
let(:hipchat) { HipchatService.new } let(:hipchat) { described_class.new }
let(:user) { create(:user) } let(:user) { create(:user) }
let(:project) { create(:project, :repository) } let(:project) { create(:project, :repository) }
let(:api_url) { 'https://hipchat.example.com/v2/room/123456/notification?auth_token=verySecret' } let(:api_url) { 'https://hipchat.example.com/v2/room/123456/notification?auth_token=verySecret' }
......
...@@ -27,7 +27,7 @@ describe IrkerService do ...@@ -27,7 +27,7 @@ describe IrkerService do
end end
describe 'Execute' do describe 'Execute' do
let(:irker) { IrkerService.new } let(:irker) { described_class.new }
let(:user) { create(:user) } let(:user) { create(:user) }
let(:project) { create(:project, :repository) } let(:project) { create(:project, :repository) }
let(:sample_data) do let(:sample_data) do
......
...@@ -78,7 +78,7 @@ describe JiraService do ...@@ -78,7 +78,7 @@ describe JiraService do
let(:merge_request) { create(:merge_request) } let(:merge_request) { create(:merge_request) }
before do before do
@jira_service = JiraService.new @jira_service = described_class.new
allow(@jira_service).to receive_messages( allow(@jira_service).to receive_messages(
project_id: project.id, project_id: project.id,
project: project, project: project,
...@@ -167,7 +167,7 @@ describe JiraService do ...@@ -167,7 +167,7 @@ describe JiraService do
stub_config_setting(relative_url_root: '/gitlab') stub_config_setting(relative_url_root: '/gitlab')
stub_config_setting(url: Settings.send(:build_gitlab_url)) 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' } { script_name: '/gitlab' }
end end
...@@ -220,7 +220,7 @@ describe JiraService do ...@@ -220,7 +220,7 @@ describe JiraService do
context "when a password was previously set" do context "when a password was previously set" do
before do before do
@jira_service = JiraService.create!( @jira_service = described_class.create!(
project: project, project: project,
properties: { properties: {
url: 'http://jira.example.com/web', url: 'http://jira.example.com/web',
...@@ -301,7 +301,7 @@ describe JiraService do ...@@ -301,7 +301,7 @@ describe JiraService do
context 'when no password was previously set' do context 'when no password was previously set' do
before do before do
@jira_service = JiraService.create( @jira_service = described_class.create(
project: project, project: project,
properties: { properties: {
url: 'http://jira.example.com/rest/api/2', url: 'http://jira.example.com/rest/api/2',
......
...@@ -26,7 +26,7 @@ describe PivotaltrackerService do ...@@ -26,7 +26,7 @@ describe PivotaltrackerService do
describe 'Execute' do describe 'Execute' do
let(:service) do let(:service) do
PivotaltrackerService.new.tap do |service| described_class.new.tap do |service|
service.token = 'secret_api_token' service.token = 'secret_api_token'
end end
end end
......
...@@ -29,7 +29,7 @@ describe PushoverService do ...@@ -29,7 +29,7 @@ describe PushoverService do
end end
describe 'Execute' do describe 'Execute' do
let(:pushover) { PushoverService.new } let(:pushover) { described_class.new }
let(:user) { create(:user) } let(:user) { create(:user) }
let(:project) { create(:project, :repository) } let(:project) { create(:project, :repository) }
let(:sample_data) do let(:sample_data) do
......
...@@ -77,7 +77,7 @@ describe Project do ...@@ -77,7 +77,7 @@ describe Project do
context 'after initialized' do context 'after initialized' do
it "has a project_feature" 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
end end
...@@ -438,7 +438,7 @@ describe Project do ...@@ -438,7 +438,7 @@ describe Project do
end end
it 'returns valid url to repo' do 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') expect(project.url_to_repo).to eq(Gitlab.config.gitlab_shell.ssh_path_prefix + 'somewhere.git')
end end
...@@ -917,7 +917,7 @@ describe Project do ...@@ -917,7 +917,7 @@ describe Project do
end end
describe '.with_shared_runners' do 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 context 'when shared runners are enabled for project' do
let!(:project) { create(:empty_project, shared_runners_enabled: true) } let!(:project) { create(:empty_project, shared_runners_enabled: true) }
...@@ -942,10 +942,10 @@ describe Project do ...@@ -942,10 +942,10 @@ describe Project do
let!(:project2) { create(:empty_project, :public, group: group) } let!(:project2) { create(:empty_project, :public, group: group) }
it 'returns total project count' do 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 3.times do
expect(Project.cached_count).to eq(2) expect(described_class.cached_count).to eq(2)
end end
end end
end end
...@@ -990,7 +990,7 @@ describe Project do ...@@ -990,7 +990,7 @@ describe Project do
user1.toggle_star(project1) user1.toggle_star(project1)
user2.toggle_star(project2) 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
end end
...@@ -2012,7 +2012,7 @@ describe Project do ...@@ -2012,7 +2012,7 @@ describe Project do
let!(:path) { project1.namespace.full_path } let!(:path) { project1.namespace.full_path }
it 'returns correct project' do it 'returns correct project' do
expect(Project.inside_path(path)).to eq([project1]) expect(described_class.inside_path(path)).to eq([project1])
end end
end end
...@@ -2216,7 +2216,7 @@ describe Project do ...@@ -2216,7 +2216,7 @@ describe Project do
context 'with a user' do context 'with a user' do
let(:projects) do let(:projects) do
Project.all.public_or_visible_to_user(user) described_class.all.public_or_visible_to_user(user)
end end
it 'includes projects the user has access to' do it 'includes projects the user has access to' do
...@@ -2230,7 +2230,7 @@ describe Project do ...@@ -2230,7 +2230,7 @@ describe Project do
context 'without a user' do context 'without a user' do
it 'only includes public projects' 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]) expect(projects).to eq([public_project])
end end
......
...@@ -5,7 +5,7 @@ describe ProjectWiki do ...@@ -5,7 +5,7 @@ describe ProjectWiki do
let(:repository) { project.repository } let(:repository) { project.repository }
let(:user) { project.owner } let(:user) { project.owner }
let(:gitlab_shell) { Gitlab::Shell.new } let(:gitlab_shell) { Gitlab::Shell.new }
let(:project_wiki) { ProjectWiki.new(project, user) } let(:project_wiki) { described_class.new(project, user) }
subject { project_wiki } subject { project_wiki }
......
...@@ -101,17 +101,17 @@ describe ProtectedBranch do ...@@ -101,17 +101,17 @@ describe ProtectedBranch do
production = create(:protected_branch, name: "production") production = create(:protected_branch, name: "production")
staging = create(:protected_branch, name: "staging") staging = create(:protected_branch, name: "staging")
expect(ProtectedBranch.matching("production")).to include(production) expect(described_class.matching("production")).to include(production)
expect(ProtectedBranch.matching("production")).not_to include(staging) expect(described_class.matching("production")).not_to include(staging)
end end
it "accepts a list of protected branches to search from, so as to avoid a DB call" do it "accepts a list of protected branches to search from, so as to avoid a DB call" do
production = build(:protected_branch, name: "production") production = build(:protected_branch, name: "production")
staging = build(:protected_branch, name: "staging") staging = build(:protected_branch, name: "staging")
expect(ProtectedBranch.matching("production")).to be_empty expect(described_class.matching("production")).to be_empty
expect(ProtectedBranch.matching("production", protected_refs: [production, staging])).to include(production) expect(described_class.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", protected_refs: [production, staging])).not_to include(staging)
end end
end end
...@@ -120,17 +120,17 @@ describe ProtectedBranch do ...@@ -120,17 +120,17 @@ describe ProtectedBranch do
production = create(:protected_branch, name: "production/*") production = create(:protected_branch, name: "production/*")
staging = create(:protected_branch, name: "staging/*") staging = create(:protected_branch, name: "staging/*")
expect(ProtectedBranch.matching("production/some-branch")).to include(production) expect(described_class.matching("production/some-branch")).to include(production)
expect(ProtectedBranch.matching("production/some-branch")).not_to include(staging) expect(described_class.matching("production/some-branch")).not_to include(staging)
end end
it "accepts a list of protected branches to search from, so as to avoid a DB call" do it "accepts a list of protected branches to search from, so as to avoid a DB call" do
production = build(:protected_branch, name: "production/*") production = build(:protected_branch, name: "production/*")
staging = build(:protected_branch, name: "staging/*") staging = build(:protected_branch, name: "staging/*")
expect(ProtectedBranch.matching("production/some-branch")).to be_empty expect(described_class.matching("production/some-branch")).to be_empty
expect(ProtectedBranch.matching("production/some-branch", protected_refs: [production, staging])).to include(production) expect(described_class.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", protected_refs: [production, staging])).not_to include(staging)
end end
end end
end end
...@@ -142,23 +142,23 @@ describe ProtectedBranch do ...@@ -142,23 +142,23 @@ describe ProtectedBranch do
it 'returns true when the branch matches a protected branch via direct match' do it 'returns true when the branch matches a protected branch via direct match' do
create(:protected_branch, project: project, name: "foo") 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 end
it 'returns true when the branch matches a protected branch via wildcard match' do it 'returns true when the branch matches a protected branch via wildcard match' do
create(:protected_branch, project: project, name: "production/*") 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 end
it 'returns false when the branch does not match a protected branch via direct match' do 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 end
it 'returns false when the branch does not match a protected branch via wildcard match' do it 'returns false when the branch does not match a protected branch via wildcard match' do
create(:protected_branch, project: project, name: "production/*") 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
end end
...@@ -168,25 +168,25 @@ describe ProtectedBranch do ...@@ -168,25 +168,25 @@ describe ProtectedBranch do
it 'returns false when default_protected_branch is unprotected' do it 'returns false when default_protected_branch is unprotected' do
stub_application_setting(default_branch_protection: Gitlab::Access::PROTECTION_NONE) 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 end
it 'returns false when default_protected_branch lets developers push' do it 'returns false when default_protected_branch lets developers push' do
stub_application_setting(default_branch_protection: Gitlab::Access::PROTECTION_DEV_CAN_PUSH) 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 end
it 'returns true when default_branch_protection does not let developers push but let developer merge branches' do 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) 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 end
it 'returns true when default_branch_protection is in full protection' do it 'returns true when default_branch_protection is in full protection' do
stub_application_setting(default_branch_protection: Gitlab::Access::PROTECTION_FULL) 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 end
end end
......
...@@ -21,7 +21,7 @@ describe RedirectRoute do ...@@ -21,7 +21,7 @@ describe RedirectRoute do
let!(:redirect5) { group.redirect_routes.create(path: 'gitlabb/test/baz') } let!(:redirect5) { group.redirect_routes.create(path: 'gitlabb/test/baz') }
it 'returns correct routes' do 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 end
end end
...@@ -34,7 +34,7 @@ describe Route do ...@@ -34,7 +34,7 @@ describe Route do
context 'after create' do context 'after create' do
it 'calls #delete_conflicting_redirects' do it 'calls #delete_conflicting_redirects' do
route.destroy 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) expect(new_route).to receive(:delete_conflicting_redirects)
new_route.save! new_route.save!
end end
...@@ -49,7 +49,7 @@ describe Route do ...@@ -49,7 +49,7 @@ describe Route do
let!(:another_group_nested) { create(:group, path: 'another', name: 'another', parent: similar_group) } let!(:another_group_nested) { create(:group, path: 'another', name: 'another', parent: similar_group) }
it 'returns correct routes' do 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
end end
......
...@@ -38,7 +38,7 @@ describe SentNotification do ...@@ -38,7 +38,7 @@ describe SentNotification do
let(:issue) { create(:issue) } let(:issue) { create(:issue) }
it 'creates a new SentNotification' do 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
end end
...@@ -47,7 +47,7 @@ describe SentNotification do ...@@ -47,7 +47,7 @@ describe SentNotification do
let(:note) { create(:diff_note_on_merge_request) } let(:note) { create(:diff_note_on_merge_request) }
it 'creates a new SentNotification' do 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
end end
......
...@@ -261,7 +261,7 @@ describe User do ...@@ -261,7 +261,7 @@ describe User do
it "returns users with 2fa enabled via OTP" do it "returns users with 2fa enabled via OTP" do
user_with_2fa = create(:user, :two_factor_via_otp) user_with_2fa = create(:user, :two_factor_via_otp)
user_without_2fa = create(:user) 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).to include(user_with_2fa.id)
expect(users_with_two_factor).not_to include(user_without_2fa.id) expect(users_with_two_factor).not_to include(user_without_2fa.id)
...@@ -270,7 +270,7 @@ describe User do ...@@ -270,7 +270,7 @@ describe User do
it "returns users with 2fa enabled via U2F" do it "returns users with 2fa enabled via U2F" do
user_with_2fa = create(:user, :two_factor_via_u2f) user_with_2fa = create(:user, :two_factor_via_u2f)
user_without_2fa = create(:user) 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).to include(user_with_2fa.id)
expect(users_with_two_factor).not_to include(user_without_2fa.id) expect(users_with_two_factor).not_to include(user_without_2fa.id)
...@@ -279,7 +279,7 @@ describe User do ...@@ -279,7 +279,7 @@ describe User do
it "returns users with 2fa enabled via OTP and U2F" 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_with_2fa = create(:user, :two_factor_via_otp, :two_factor_via_u2f)
user_without_2fa = create(:user) 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).to eq([user_with_2fa.id])
expect(users_with_two_factor).not_to include(user_without_2fa.id) expect(users_with_two_factor).not_to include(user_without_2fa.id)
...@@ -290,7 +290,7 @@ describe User do ...@@ -290,7 +290,7 @@ describe User do
it "excludes users with 2fa enabled via OTP" do it "excludes users with 2fa enabled via OTP" do
user_with_2fa = create(:user, :two_factor_via_otp) user_with_2fa = create(:user, :two_factor_via_otp)
user_without_2fa = create(:user) 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).to include(user_without_2fa.id)
expect(users_without_two_factor).not_to include(user_with_2fa.id) expect(users_without_two_factor).not_to include(user_with_2fa.id)
...@@ -299,7 +299,7 @@ describe User do ...@@ -299,7 +299,7 @@ describe User do
it "excludes users with 2fa enabled via U2F" do it "excludes users with 2fa enabled via U2F" do
user_with_2fa = create(:user, :two_factor_via_u2f) user_with_2fa = create(:user, :two_factor_via_u2f)
user_without_2fa = create(:user) 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).to include(user_without_2fa.id)
expect(users_without_two_factor).not_to include(user_with_2fa.id) expect(users_without_two_factor).not_to include(user_with_2fa.id)
...@@ -308,7 +308,7 @@ describe User do ...@@ -308,7 +308,7 @@ describe User do
it "excludes users with 2fa enabled via OTP and U2F" 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_with_2fa = create(:user, :two_factor_via_otp, :two_factor_via_u2f)
user_without_2fa = create(:user) 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).to include(user_without_2fa.id)
expect(users_without_two_factor).not_to include(user_with_2fa.id) expect(users_without_two_factor).not_to include(user_with_2fa.id)
...@@ -324,8 +324,8 @@ describe User do ...@@ -324,8 +324,8 @@ describe User do
create(:todo, user: current_user, author: user_2, state: :done) create(:todo, user: current_user, author: user_2, state: :done)
create(:todo, user: current_user, author: user_3, state: :pending) create(:todo, user: current_user, author: user_3, state: :pending)
expect(User.todo_authors(current_user.id, 'pending')).to eq [user_3] expect(described_class.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, 'done')).to eq [user_2]
end end
end end
end end
...@@ -609,39 +609,39 @@ describe User do ...@@ -609,39 +609,39 @@ describe User do
let(:user) { double } let(:user) { double }
it 'filters by active users by default' do 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 end
it 'filters by admins' do 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 end
it 'filters by blocked' do 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 end
it 'filters by two_factor_disabled' do 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 end
it 'filters by two_factor_enabled' do 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 end
it 'filters by wop' do 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
end end
...@@ -662,9 +662,9 @@ describe User do ...@@ -662,9 +662,9 @@ describe User do
project.request_access(user_without_project2) project.request_access(user_without_project2)
end end
it { expect(User.without_projects).not_to include user } it { expect(described_class.without_projects).not_to include user }
it { expect(User.without_projects).to include user_without_project } it { expect(described_class.without_projects).to include user_without_project }
it { expect(User.without_projects).to include user_without_project2 } it { expect(described_class.without_projects).to include user_without_project2 }
end end
describe 'user creation' do describe 'user creation' do
...@@ -680,7 +680,7 @@ describe User do ...@@ -680,7 +680,7 @@ describe User do
end end
describe 'with defaults' do describe 'with defaults' do
let(:user) { User.new } let(:user) { described_class.new }
it "applies defaults to user" do it "applies defaults to user" do
expect(user.projects_limit).to eq(Gitlab.config.gitlab.default_projects_limit) expect(user.projects_limit).to eq(Gitlab.config.gitlab.default_projects_limit)
...@@ -690,7 +690,7 @@ describe User do ...@@ -690,7 +690,7 @@ describe User do
end end
describe 'with default overrides' do 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 it "applies defaults to user" do
expect(user.projects_limit).to eq(123) expect(user.projects_limit).to eq(123)
...@@ -740,18 +740,18 @@ describe User do ...@@ -740,18 +740,18 @@ describe User do
it 'finds by primary email' do it 'finds by primary email' do
user = create(:user, email: 'foo@example.com') 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 end
it 'finds by secondary email' do it 'finds by secondary email' do
email = create(:email, email: 'foo@example.com') email = create(:email, email: 'foo@example.com')
user = email.user 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 end
it 'returns nil when nothing found' do 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
end end
...@@ -899,12 +899,12 @@ describe User do ...@@ -899,12 +899,12 @@ describe User do
let!(:user) { create(:user, username: username) } let!(:user) { create(:user, username: username) }
it 'gets the correct user' do it 'gets the correct user' do
expect(User.by_login(user.email.upcase)).to eq user expect(described_class.by_login(user.email.upcase)).to eq user
expect(User.by_login(user.email)).to eq user expect(described_class.by_login(user.email)).to eq user
expect(User.by_login(username.downcase)).to eq user expect(described_class.by_login(username.downcase)).to eq user
expect(User.by_login(username)).to eq user expect(described_class.by_login(username)).to eq user
expect(User.by_login(nil)).to be_nil expect(described_class.by_login(nil)).to be_nil
expect(User.by_login('')).to be_nil expect(described_class.by_login('')).to be_nil
end end
end end
...@@ -938,12 +938,12 @@ describe User do ...@@ -938,12 +938,12 @@ describe User do
let!(:route) { user.namespace.route } let!(:route) { user.namespace.route }
it 'returns the user' do 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 end
it 'is case-insensitive' do it 'is case-insensitive' do
expect(User.find_by_full_path(route.path.upcase)).to eq(user) expect(described_class.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.downcase)).to eq(user)
end end
end end
...@@ -952,18 +952,18 @@ describe User do ...@@ -952,18 +952,18 @@ describe User do
context 'without the follow_redirects option' do context 'without the follow_redirects option' do
it 'returns nil' 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
end end
context 'with the follow_redirects option set to true' do context 'with the follow_redirects option set to true' do
it 'returns the user' 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 end
it 'is case-insensitive' do it 'is case-insensitive' do
expect(User.find_by_full_path(redirect_route.path.upcase, follow_redirects: true)).to eq(user) expect(described_class.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.downcase, follow_redirects: true)).to eq(user)
end end
end end
end end
...@@ -971,12 +971,12 @@ describe User do ...@@ -971,12 +971,12 @@ describe User do
context 'without a route or a redirect route matching the given path' do context 'without a route or a redirect route matching the given path' do
context 'without the follow_redirects option' do context 'without the follow_redirects option' do
it 'returns nil' 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
end end
context 'with the follow_redirects option set to true' do context 'with the follow_redirects option set to true' do
it 'returns nil' 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 end
end end
...@@ -986,7 +986,7 @@ describe User do ...@@ -986,7 +986,7 @@ describe User do
let!(:group) { create(:group, path: 'group_path', owner: user) } let!(:group) { create(:group, path: 'group_path', owner: user) }
it 'returns nil' do 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 end
...@@ -994,7 +994,7 @@ describe User do ...@@ -994,7 +994,7 @@ describe User do
let!(:group) { create(:group, path: 'group_path') } let!(:group) { create(:group, path: 'group_path') }
it 'returns nil' do 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 end
end end
...@@ -1044,7 +1044,7 @@ describe User do ...@@ -1044,7 +1044,7 @@ describe User do
end end
describe '#requires_ldap_check?' do describe '#requires_ldap_check?' do
let(:user) { User.new } let(:user) { described_class.new }
it 'is false when LDAP is disabled' do it 'is false when LDAP is disabled' do
# Create a condition which would otherwise cause 'true' to be returned # Create a condition which would otherwise cause 'true' to be returned
...@@ -1215,7 +1215,7 @@ describe User do ...@@ -1215,7 +1215,7 @@ describe User do
describe '#sort' do describe '#sort' do
before 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' @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' @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' @user2 = create :user, created_at: Date.today - 2, last_sign_in_at: nil, name: 'Beta'
...@@ -1223,34 +1223,34 @@ describe User do ...@@ -1223,34 +1223,34 @@ describe User do
context 'when sort by recent_sign_in' do context 'when sort by recent_sign_in' do
it 'sorts users by the recent sign-in time' 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 end
it 'pushes users who never signed in to the end' do 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
end end
context 'when sort by oldest_sign_in' do context 'when sort by oldest_sign_in' do
it 'sorts users by the oldest sign-in time' 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 end
it 'pushes users who never signed in to the end' do 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
end end
it 'sorts users in descending order by their creation time' do 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 end
it 'sorts users in ascending order by their creation time' do 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 end
it 'sorts users by id in descending order when nil is passed' do 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
end end
...@@ -1770,7 +1770,7 @@ describe User do ...@@ -1770,7 +1770,7 @@ describe User do
describe '.ghost' do describe '.ghost' do
it "creates a ghost user if one isn't already present" 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_ghost
expect(ghost).to be_persisted expect(ghost).to be_persisted
...@@ -1778,16 +1778,16 @@ describe User do ...@@ -1778,16 +1778,16 @@ describe User do
it "does not create a second ghost user if one is already present" do it "does not create a second ghost user if one is already present" do
expect do expect do
User.ghost described_class.ghost
User.ghost described_class.ghost
end.to change { User.count }.by(1) end.to change { described_class.count }.by(1)
expect(User.ghost).to eq(User.ghost) expect(described_class.ghost).to eq(described_class.ghost)
end end
context "when a regular user exists with the username 'ghost'" do context "when a regular user exists with the username 'ghost'" do
it "creates a ghost user with a non-conflicting username" do it "creates a ghost user with a non-conflicting username" do
create(:user, username: 'ghost') create(:user, username: 'ghost')
ghost = User.ghost ghost = described_class.ghost
expect(ghost).to be_persisted expect(ghost).to be_persisted
expect(ghost.username).to eq('ghost1') expect(ghost.username).to eq('ghost1')
...@@ -1797,7 +1797,7 @@ describe User do ...@@ -1797,7 +1797,7 @@ describe User do
context "when a regular user exists with the email 'ghost@example.com'" 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 it "creates a ghost user with a non-conflicting email" do
create(:user, email: 'ghost@example.com') create(:user, email: 'ghost@example.com')
ghost = User.ghost ghost = described_class.ghost
expect(ghost).to be_persisted expect(ghost).to be_persisted
expect(ghost.email).to eq('ghost1@example.com') expect(ghost.email).to eq('ghost1@example.com')
...@@ -1810,7 +1810,7 @@ describe User do ...@@ -1810,7 +1810,7 @@ describe User do
end end
it 'creates a ghost user' do it 'creates a ghost user' do
expect(User.ghost).to be_persisted expect(described_class.ghost).to be_persisted
end end
end end
end end
...@@ -1889,13 +1889,13 @@ describe User do ...@@ -1889,13 +1889,13 @@ describe User do
context '.active' do context '.active' do
before do before do
User.ghost described_class.ghost
create(:user, name: 'user', state: 'active') create(:user, name: 'user', state: 'active')
create(:user, name: 'user', state: 'blocked') create(:user, name: 'user', state: 'blocked')
end end
it 'only counts active and non internal users' do 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
end end
......
...@@ -10,7 +10,7 @@ RSpec.describe WikiDirectory do ...@@ -10,7 +10,7 @@ RSpec.describe WikiDirectory do
describe '#initialize' do describe '#initialize' do
context 'when there are pages' do context 'when there are pages' do
let(:pages) { [build(:wiki_page)] } 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 it 'sets the slug attribute' do
expect(directory.slug).to eq('/path_up_to/dir') expect(directory.slug).to eq('/path_up_to/dir')
...@@ -22,7 +22,7 @@ RSpec.describe WikiDirectory do ...@@ -22,7 +22,7 @@ RSpec.describe WikiDirectory do
end end
context 'when there are no pages' do 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 it 'sets the slug attribute' do
expect(directory.slug).to eq('/path_up_to/dir') expect(directory.slug).to eq('/path_up_to/dir')
......
...@@ -5,13 +5,13 @@ describe WikiPage do ...@@ -5,13 +5,13 @@ describe WikiPage do
let(:user) { project.owner } let(:user) { project.owner }
let(:wiki) { ProjectWiki.new(project, user) } let(:wiki) { ProjectWiki.new(project, user) }
subject { WikiPage.new(wiki) } subject { described_class.new(wiki) }
describe '.group_by_directory' do describe '.group_by_directory' do
context 'when there are no pages' do context 'when there are no pages' do
it 'returns an empty array' do it 'returns an empty array' do
expect(WikiPage.group_by_directory(nil)).to eq([]) expect(described_class.group_by_directory(nil)).to eq([])
expect(WikiPage.group_by_directory([])).to eq([]) expect(described_class.group_by_directory([])).to eq([])
end end
end end
...@@ -39,7 +39,7 @@ describe WikiPage do ...@@ -39,7 +39,7 @@ describe WikiPage do
it 'returns an array with pages and directories' do it 'returns an array with pages and directories' do
expected_grouped_entries = [page_1, dir_1, dir_1_1, dir_2] 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| grouped_entries.each_with_index do |page_or_dir, i|
expected_page_or_dir = expected_grouped_entries[i] expected_page_or_dir = expected_grouped_entries[i]
...@@ -56,7 +56,7 @@ describe WikiPage do ...@@ -56,7 +56,7 @@ describe WikiPage do
expected_order = ['page_1', 'dir_1/page_2', 'dir_1/dir_1_1/page_3', expected_order = ['page_1', 'dir_1/page_2', 'dir_1/dir_1_1/page_3',
'dir_2/page_4', 'dir_2/page_5'] '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 = actual_order =
grouped_entries.map do |page_or_dir| grouped_entries.map do |page_or_dir|
...@@ -72,7 +72,7 @@ describe WikiPage do ...@@ -72,7 +72,7 @@ describe WikiPage do
it 'removes hyphens from a name' do it 'removes hyphens from a name' do
name = 'a-name--with-hyphens' 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
end end
...@@ -81,7 +81,7 @@ describe WikiPage do ...@@ -81,7 +81,7 @@ describe WikiPage do
before do before do
create_page("test page", "test content") create_page("test page", "test content")
@page = wiki.wiki.paged("test page") @page = wiki.wiki.paged("test page")
@wiki_page = WikiPage.new(wiki, @page, true) @wiki_page = described_class.new(wiki, @page, true)
end end
it "sets the slug attribute" do it "sets the slug attribute" do
......
...@@ -4,7 +4,7 @@ describe GlobalPolicy do ...@@ -4,7 +4,7 @@ describe GlobalPolicy do
let(:current_user) { create(:user) } let(:current_user) { create(:user) }
let(: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 describe "reading the list of users" do
context "for a logged in user" do context "for a logged in user" do
......
...@@ -4,7 +4,7 @@ describe UserPolicy do ...@@ -4,7 +4,7 @@ describe UserPolicy do
let(:current_user) { create(:user) } let(:current_user) { create(:user) }
let(: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 describe "reading a user's information" do
it { is_expected.to be_allowed(:read_user) } it { is_expected.to be_allowed(:read_user) }
......
...@@ -5,7 +5,7 @@ describe CreateReleaseService do ...@@ -5,7 +5,7 @@ describe CreateReleaseService do
let(:user) { create(:user) } let(:user) { create(:user) }
let(:tag_name) { project.repository.tag_names.first } let(:tag_name) { project.repository.tag_names.first }
let(:description) { 'Awesome release!' } let(:description) { 'Awesome release!' }
let(:service) { CreateReleaseService.new(project, user) } let(:service) { described_class.new(project, user) }
it 'creates a new release' do it 'creates a new release' do
result = service.execute(tag_name, description) result = service.execute(tag_name, description)
......
...@@ -3,7 +3,7 @@ require 'spec_helper' ...@@ -3,7 +3,7 @@ require 'spec_helper'
describe EventCreateService do describe EventCreateService do
include UserActivitiesHelpers include UserActivitiesHelpers
let(:service) { EventCreateService.new } let(:service) { described_class.new }
describe 'Issues' do describe 'Issues' do
describe '#open_issue' do describe '#open_issue' do
......
...@@ -5,7 +5,7 @@ describe GitHooksService do ...@@ -5,7 +5,7 @@ describe GitHooksService do
let(:user) { create(:user) } let(:user) { create(:user) }
let(:project) { create(:project, :repository) } let(:project) { create(:project, :repository) }
let(:service) { GitHooksService.new } let(:service) { described_class.new }
before do before do
@blankrev = Gitlab::Git::BLANK_SHA @blankrev = Gitlab::Git::BLANK_SHA
......
...@@ -5,7 +5,7 @@ describe GitTagPushService do ...@@ -5,7 +5,7 @@ describe GitTagPushService do
let(:user) { create(:user) } let(:user) { create(:user) }
let(:project) { create(:project, :repository) } 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(:oldrev) { Gitlab::Git::BLANK_SHA }
let(:newrev) { "8a2a6eb295bb170b34c24c76c49ed0e9b2eaf34b" } # gitlab-test: git rev-parse refs/tags/v1.1.0 let(:newrev) { "8a2a6eb295bb170b34c24c76c49ed0e9b2eaf34b" } # gitlab-test: git rev-parse refs/tags/v1.1.0
...@@ -184,7 +184,7 @@ describe GitTagPushService do ...@@ -184,7 +184,7 @@ describe GitTagPushService do
describe "Webhooks" do describe "Webhooks" do
context "execute 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 it "when pushing tags" do
expect(project).to receive(:execute_hooks) expect(project).to receive(:execute_hooks)
......
...@@ -100,7 +100,7 @@ describe Groups::DestroyService do ...@@ -100,7 +100,7 @@ describe Groups::DestroyService do
# Kick off the initial group destroy in a new thread, so that # Kick off the initial group destroy in a new thread, so that
# it doesn't share this spec's database transaction. # 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| group_record = run_with_new_database_connection do |conn|
conn.execute("SELECT * FROM namespaces WHERE id = #{group.id}").first conn.execute("SELECT * FROM namespaces WHERE id = #{group.id}").first
......
...@@ -488,7 +488,7 @@ describe Issues::UpdateService do ...@@ -488,7 +488,7 @@ describe Issues::UpdateService do
context 'updating mentions' do context 'updating mentions' do
let(:mentionable) { issue } let(:mentionable) { issue }
include_examples 'updating mentions', Issues::UpdateService include_examples 'updating mentions', described_class
end end
context 'duplicate issue' do context 'duplicate issue' do
......
...@@ -17,7 +17,7 @@ describe Labels::CreateService do ...@@ -17,7 +17,7 @@ describe Labels::CreateService do
context 'in a project' do context 'in a project' do
context 'with color in hex-code' do context 'with color in hex-code' do
it 'creates a label' 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).to be_persisted
expect(label.color).to eq expected_saved_color expect(label.color).to eq expected_saved_color
...@@ -26,7 +26,7 @@ describe Labels::CreateService do ...@@ -26,7 +26,7 @@ describe Labels::CreateService do
context 'with color in allowed name' do context 'with color in allowed name' do
it 'creates a label' 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).to be_persisted
expect(label.color).to eq expected_saved_color expect(label.color).to eq expected_saved_color
...@@ -35,7 +35,7 @@ describe Labels::CreateService do ...@@ -35,7 +35,7 @@ describe Labels::CreateService do
context 'with color in up-case allowed name' do context 'with color in up-case allowed name' do
it 'creates a label' 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).to be_persisted
expect(label.color).to eq expected_saved_color expect(label.color).to eq expected_saved_color
...@@ -44,7 +44,7 @@ describe Labels::CreateService do ...@@ -44,7 +44,7 @@ describe Labels::CreateService do
context 'with color surrounded by spaces' do context 'with color surrounded by spaces' do
it 'creates a label' 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).to be_persisted
expect(label.color).to eq expected_saved_color expect(label.color).to eq expected_saved_color
...@@ -53,7 +53,7 @@ describe Labels::CreateService do ...@@ -53,7 +53,7 @@ describe Labels::CreateService do
context 'with unknown color' do context 'with unknown color' do
it 'doesn\'t create a label' 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 expect(label).not_to be_persisted
end end
...@@ -61,7 +61,7 @@ describe Labels::CreateService do ...@@ -61,7 +61,7 @@ describe Labels::CreateService do
context 'with no color' do context 'with no color' do
it 'doesn\'t create a label' 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 expect(label).not_to be_persisted
end end
...@@ -71,7 +71,7 @@ describe Labels::CreateService do ...@@ -71,7 +71,7 @@ describe Labels::CreateService do
context 'in a group' do context 'in a group' do
context 'with color in hex-code' do context 'with color in hex-code' do
it 'creates a label' 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).to be_persisted
expect(label.color).to eq expected_saved_color expect(label.color).to eq expected_saved_color
...@@ -80,7 +80,7 @@ describe Labels::CreateService do ...@@ -80,7 +80,7 @@ describe Labels::CreateService do
context 'with color in allowed name' do context 'with color in allowed name' do
it 'creates a label' 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).to be_persisted
expect(label.color).to eq expected_saved_color expect(label.color).to eq expected_saved_color
...@@ -89,7 +89,7 @@ describe Labels::CreateService do ...@@ -89,7 +89,7 @@ describe Labels::CreateService do
context 'with color in up-case allowed name' do context 'with color in up-case allowed name' do
it 'creates a label' 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).to be_persisted
expect(label.color).to eq expected_saved_color expect(label.color).to eq expected_saved_color
...@@ -98,7 +98,7 @@ describe Labels::CreateService do ...@@ -98,7 +98,7 @@ describe Labels::CreateService do
context 'with color surrounded by spaces' do context 'with color surrounded by spaces' do
it 'creates a label' 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).to be_persisted
expect(label.color).to eq expected_saved_color expect(label.color).to eq expected_saved_color
...@@ -107,7 +107,7 @@ describe Labels::CreateService do ...@@ -107,7 +107,7 @@ describe Labels::CreateService do
context 'with unknown color' do context 'with unknown color' do
it 'doesn\'t create a label' 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 expect(label).not_to be_persisted
end end
...@@ -115,7 +115,7 @@ describe Labels::CreateService do ...@@ -115,7 +115,7 @@ describe Labels::CreateService do
context 'with no color' do context 'with no color' do
it 'doesn\'t create a label' 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 expect(label).not_to be_persisted
end end
...@@ -125,7 +125,7 @@ describe Labels::CreateService do ...@@ -125,7 +125,7 @@ describe Labels::CreateService do
context 'in admin area' do context 'in admin area' do
context 'with color in hex-code' do context 'with color in hex-code' do
it 'creates a label' 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).to be_persisted
expect(label.color).to eq expected_saved_color expect(label.color).to eq expected_saved_color
...@@ -134,7 +134,7 @@ describe Labels::CreateService do ...@@ -134,7 +134,7 @@ describe Labels::CreateService do
context 'with color in allowed name' do context 'with color in allowed name' do
it 'creates a label' 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).to be_persisted
expect(label.color).to eq expected_saved_color expect(label.color).to eq expected_saved_color
...@@ -143,7 +143,7 @@ describe Labels::CreateService do ...@@ -143,7 +143,7 @@ describe Labels::CreateService do
context 'with color in up-case allowed name' do context 'with color in up-case allowed name' do
it 'creates a label' 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).to be_persisted
expect(label.color).to eq expected_saved_color expect(label.color).to eq expected_saved_color
...@@ -152,7 +152,7 @@ describe Labels::CreateService do ...@@ -152,7 +152,7 @@ describe Labels::CreateService do
context 'with color surrounded by spaces' do context 'with color surrounded by spaces' do
it 'creates a label' 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).to be_persisted
expect(label.color).to eq expected_saved_color expect(label.color).to eq expected_saved_color
...@@ -161,7 +161,7 @@ describe Labels::CreateService do ...@@ -161,7 +161,7 @@ describe Labels::CreateService do
context 'with unknown color' do context 'with unknown color' do
it 'doesn\'t create a label' 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 expect(label).not_to be_persisted
end end
...@@ -169,7 +169,7 @@ describe Labels::CreateService do ...@@ -169,7 +169,7 @@ describe Labels::CreateService do
context 'with no color' do context 'with no color' do
it 'doesn\'t create a label' 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 expect(label).not_to be_persisted
end end
......
...@@ -20,7 +20,7 @@ describe Labels::UpdateService do ...@@ -20,7 +20,7 @@ describe Labels::UpdateService do
context 'with color in hex-code' do context 'with color in hex-code' do
it 'updates the label' 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).to be_valid
expect(label.reload.color).to eq expected_saved_color expect(label.reload.color).to eq expected_saved_color
...@@ -29,7 +29,7 @@ describe Labels::UpdateService do ...@@ -29,7 +29,7 @@ describe Labels::UpdateService do
context 'with color in allowed name' do context 'with color in allowed name' do
it 'updates the label' 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).to be_valid
expect(label.reload.color).to eq expected_saved_color expect(label.reload.color).to eq expected_saved_color
...@@ -38,7 +38,7 @@ describe Labels::UpdateService do ...@@ -38,7 +38,7 @@ describe Labels::UpdateService do
context 'with color in up-case allowed name' do context 'with color in up-case allowed name' do
it 'updates the label' 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).to be_valid
expect(label.reload.color).to eq expected_saved_color expect(label.reload.color).to eq expected_saved_color
...@@ -47,7 +47,7 @@ describe Labels::UpdateService do ...@@ -47,7 +47,7 @@ describe Labels::UpdateService do
context 'with color surrounded by spaces' do context 'with color surrounded by spaces' do
it 'updates the label' 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).to be_valid
expect(label.reload.color).to eq expected_saved_color expect(label.reload.color).to eq expected_saved_color
...@@ -56,7 +56,7 @@ describe Labels::UpdateService do ...@@ -56,7 +56,7 @@ describe Labels::UpdateService do
context 'with unknown color' do context 'with unknown color' do
it 'doesn\'t update the label' 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 expect(label).not_to be_valid
end end
...@@ -64,7 +64,7 @@ describe Labels::UpdateService do ...@@ -64,7 +64,7 @@ describe Labels::UpdateService do
context 'with no color' do context 'with no color' do
it 'doesn\'t update the label' 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 expect(label).not_to be_valid
end end
......
...@@ -19,7 +19,7 @@ describe MergeRequests::BuildService do ...@@ -19,7 +19,7 @@ describe MergeRequests::BuildService do
let(:commits) { nil } let(:commits) { nil }
let(:service) do let(:service) do
MergeRequests::BuildService.new(project, user, described_class.new(project, user,
description: description, description: description,
source_branch: source_branch, source_branch: source_branch,
target_branch: target_branch, target_branch: target_branch,
......
...@@ -13,7 +13,7 @@ describe MergeRequests::MergeService do ...@@ -13,7 +13,7 @@ describe MergeRequests::MergeService do
describe '#execute' do describe '#execute' do
context 'valid params' 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 before do
allow(service).to receive(:execute_hooks) allow(service).to receive(:execute_hooks)
...@@ -112,7 +112,7 @@ describe MergeRequests::MergeService do ...@@ -112,7 +112,7 @@ describe MergeRequests::MergeService do
context 'closes related todos' do context 'closes related todos' do
let(:merge_request) { create(:merge_request, assignee: user, author: user) } let(:merge_request) { create(:merge_request, assignee: user, author: user) }
let(:project) { merge_request.project } 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 let!(:todo) do
create(:todo, :assigned, create(:todo, :assigned,
project: project, project: project,
...@@ -136,7 +136,7 @@ describe MergeRequests::MergeService do ...@@ -136,7 +136,7 @@ describe MergeRequests::MergeService do
context 'source branch removal' do context 'source branch removal' do
context 'when the source branch is protected' do context 'when the source branch is protected' do
let(:service) 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 end
before do before do
...@@ -151,7 +151,7 @@ describe MergeRequests::MergeService do ...@@ -151,7 +151,7 @@ describe MergeRequests::MergeService do
context 'when the source branch is the default branch' do context 'when the source branch is the default branch' do
let(:service) 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 end
before do before do
...@@ -169,7 +169,7 @@ describe MergeRequests::MergeService do ...@@ -169,7 +169,7 @@ describe MergeRequests::MergeService do
let(:service) do let(:service) do
merge_request.merge_params['force_remove_source_branch'] = '1' merge_request.merge_params['force_remove_source_branch'] = '1'
merge_request.save! merge_request.save!
MergeRequests::MergeService.new(project, user, commit_message: 'Awesome message') described_class.new(project, user, commit_message: 'Awesome message')
end end
it 'removes the source branch using the author user' do it 'removes the source branch using the author user' do
...@@ -182,7 +182,7 @@ describe MergeRequests::MergeService do ...@@ -182,7 +182,7 @@ describe MergeRequests::MergeService do
context 'when MR merger set the source branch to be removed' do context 'when MR merger set the source branch to be removed' do
let(:service) 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 end
it 'removes the source branch using the current user' do it 'removes the source branch using the current user' do
...@@ -196,7 +196,7 @@ describe MergeRequests::MergeService do ...@@ -196,7 +196,7 @@ describe MergeRequests::MergeService do
end end
context "error handling" do 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 before do
allow(Rails.logger).to receive(:error) allow(Rails.logger).to receive(:error)
......
...@@ -3,7 +3,7 @@ require 'spec_helper' ...@@ -3,7 +3,7 @@ require 'spec_helper'
describe MergeRequests::RefreshService do describe MergeRequests::RefreshService do
let(:project) { create(:project, :repository) } let(:project) { create(:project, :repository) }
let(:user) { create(:user) } let(:user) { create(:user) }
let(:service) { MergeRequests::RefreshService } let(:service) { described_class }
describe '#execute' do describe '#execute' do
before do before do
......
...@@ -55,7 +55,7 @@ describe MergeRequests::UpdateService do ...@@ -55,7 +55,7 @@ describe MergeRequests::UpdateService do
} }
end end
let(:service) { MergeRequests::UpdateService.new(project, user, opts) } let(:service) { described_class.new(project, user, opts) }
before do before do
allow(service).to receive(:execute_hooks) allow(service).to receive(:execute_hooks)
...@@ -145,7 +145,7 @@ describe MergeRequests::UpdateService do ...@@ -145,7 +145,7 @@ describe MergeRequests::UpdateService do
} }
end end
let(:service) { MergeRequests::UpdateService.new(project, user, opts) } let(:service) { described_class.new(project, user, opts) }
context 'without pipeline' do context 'without pipeline' do
before do before do
...@@ -205,7 +205,7 @@ describe MergeRequests::UpdateService do ...@@ -205,7 +205,7 @@ describe MergeRequests::UpdateService do
context 'with a non-authorised user' do context 'with a non-authorised user' do
let(:visitor) { create(:user) } let(:visitor) { create(:user) }
let(:service) { MergeRequests::UpdateService.new(project, visitor, opts) } let(:service) { described_class.new(project, visitor, opts) }
before do before do
merge_request.update_attribute(:merge_error, 'Error') merge_request.update_attribute(:merge_error, 'Error')
...@@ -348,7 +348,7 @@ describe MergeRequests::UpdateService do ...@@ -348,7 +348,7 @@ describe MergeRequests::UpdateService do
opts = { label_ids: [label.id] } opts = { label_ids: [label.id] }
perform_enqueued_jobs do 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 end
should_email(subscriber) should_email(subscriber)
...@@ -364,7 +364,7 @@ describe MergeRequests::UpdateService do ...@@ -364,7 +364,7 @@ describe MergeRequests::UpdateService do
opts = { label_ids: [label.id, label2.id] } opts = { label_ids: [label.id, label2.id] }
perform_enqueued_jobs do 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 end
should_not_email(subscriber) should_not_email(subscriber)
...@@ -375,7 +375,7 @@ describe MergeRequests::UpdateService do ...@@ -375,7 +375,7 @@ describe MergeRequests::UpdateService do
opts = { label_ids: [label2.id] } opts = { label_ids: [label2.id] }
perform_enqueued_jobs do 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 end
should_not_email(subscriber) should_not_email(subscriber)
...@@ -386,7 +386,7 @@ describe MergeRequests::UpdateService do ...@@ -386,7 +386,7 @@ describe MergeRequests::UpdateService do
context 'updating mentions' do context 'updating mentions' do
let(:mentionable) { merge_request } let(:mentionable) { merge_request }
include_examples 'updating mentions', MergeRequests::UpdateService include_examples 'updating mentions', described_class
end end
context 'when MergeRequest has tasks' do context 'when MergeRequest has tasks' do
......
...@@ -11,7 +11,7 @@ describe Milestones::CloseService do ...@@ -11,7 +11,7 @@ describe Milestones::CloseService do
describe '#execute' do describe '#execute' do
before do before do
Milestones::CloseService.new(project, user, {}).execute(milestone) described_class.new(project, user, {}).execute(milestone)
end end
it { expect(milestone).to be_valid } it { expect(milestone).to be_valid }
......
...@@ -14,7 +14,7 @@ describe Milestones::CreateService do ...@@ -14,7 +14,7 @@ describe Milestones::CreateService do
description: 'Patch release to fix security issue' description: 'Patch release to fix security issue'
} }
@milestone = Milestones::CreateService.new(project, user, opts).execute @milestone = described_class.new(project, user, opts).execute
end end
it { expect(@milestone).to be_valid } it { expect(@milestone).to be_valid }
......
...@@ -21,7 +21,7 @@ describe Notes::PostProcessService do ...@@ -21,7 +21,7 @@ describe Notes::PostProcessService do
expect(project).to receive(:execute_hooks) expect(project).to receive(:execute_hooks)
expect(project).to receive(:execute_services) expect(project).to receive(:execute_services)
Notes::PostProcessService.new(@note).execute described_class.new(@note).execute
end end
end end
end end
...@@ -3,7 +3,7 @@ require 'spec_helper' ...@@ -3,7 +3,7 @@ require 'spec_helper'
describe NotificationService do describe NotificationService do
include EmailHelpers include EmailHelpers
let(:notification) { NotificationService.new } let(:notification) { described_class.new }
let(:assignee) { create(:user) } let(:assignee) { create(:user) }
around(:each) do |example| around(:each) do |example|
......
...@@ -3,7 +3,7 @@ require 'spec_helper' ...@@ -3,7 +3,7 @@ require 'spec_helper'
describe PagesService do describe PagesService do
let(:build) { create(:ci_build) } let(:build) { create(:ci_build) }
let(:data) { Gitlab::DataBuilder::Build.build(build) } let(:data) { Gitlab::DataBuilder::Build.build(build) }
let(:service) { PagesService.new(data) } let(:service) { described_class.new(data) }
before do before do
allow(Gitlab.config.pages).to receive(:enabled).and_return(true) allow(Gitlab.config.pages).to receive(:enabled).and_return(true)
......
...@@ -81,7 +81,7 @@ describe Projects::DestroyService do ...@@ -81,7 +81,7 @@ describe Projects::DestroyService do
before do before do
new_user = create(:user) new_user = create(:user)
project.team.add_user(new_user, Gitlab::Access::DEVELOPER) 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 end
it 'keeps project team intact upon an error' do it 'keeps project team intact upon an error' do
...@@ -114,7 +114,7 @@ describe Projects::DestroyService do ...@@ -114,7 +114,7 @@ describe Projects::DestroyService do
context 'errors' do context 'errors' do
context 'when `remove_legacy_registry_tags` fails' do context 'when `remove_legacy_registry_tags` fails' do
before do before do
expect_any_instance_of(Projects::DestroyService) expect_any_instance_of(described_class)
.to receive(:remove_legacy_registry_tags).and_return(false) .to receive(:remove_legacy_registry_tags).and_return(false)
end end
...@@ -123,7 +123,7 @@ describe Projects::DestroyService do ...@@ -123,7 +123,7 @@ describe Projects::DestroyService do
context 'when `remove_repository` fails' do context 'when `remove_repository` fails' do
before do before do
expect_any_instance_of(Projects::DestroyService) expect_any_instance_of(described_class)
.to receive(:remove_repository).and_return(false) .to receive(:remove_repository).and_return(false)
end end
......
...@@ -37,7 +37,7 @@ describe Projects::TransferService do ...@@ -37,7 +37,7 @@ describe Projects::TransferService do
end end
it 'executes system hooks' do 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) transfer_project(project, user, group)
end end
...@@ -80,7 +80,7 @@ describe Projects::TransferService do ...@@ -80,7 +80,7 @@ describe Projects::TransferService do
end end
it "doesn't run system hooks" do 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 attempt_project_transfer
end end
......
require 'spec_helper' require 'spec_helper'
describe Projects::UnlinkForkService do 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_link) { create(:forked_project_link) }
let(:fork_project) { fork_link.forked_to_project } let(:fork_project) { fork_link.forked_to_project }
......
...@@ -3,7 +3,7 @@ require 'spec_helper' ...@@ -3,7 +3,7 @@ require 'spec_helper'
describe RepairLdapBlockedUserService do describe RepairLdapBlockedUserService do
let(:user) { create(:omniauth_user, provider: 'ldapmain', state: 'ldap_blocked') } let(:user) { create(:omniauth_user, provider: 'ldapmain', state: 'ldap_blocked') }
let(:identity) { user.ldap_identity } let(:identity) { user.ldap_identity }
subject(:service) { RepairLdapBlockedUserService.new(user) } subject(:service) { described_class.new(user) }
describe '#execute' do describe '#execute' do
it 'changes to normal block after destroying last ldap identity' do it 'changes to normal block after destroying last ldap identity' do
......
...@@ -16,7 +16,7 @@ describe Search::GlobalService do ...@@ -16,7 +16,7 @@ describe Search::GlobalService do
describe '#execute' do describe '#execute' do
context 'unauthenticated' do context 'unauthenticated' do
it 'returns public projects only' do it 'returns public projects only' do
results = Search::GlobalService.new(nil, search: "searchable").execute results = described_class.new(nil, search: "searchable").execute
expect(results.objects('projects')).to match_array [public_project] expect(results.objects('projects')).to match_array [public_project]
end end
...@@ -24,19 +24,19 @@ describe Search::GlobalService do ...@@ -24,19 +24,19 @@ describe Search::GlobalService do
context 'authenticated' do context 'authenticated' do
it 'returns public, internal and private projects' do it 'returns public, internal and private projects' do
results = Search::GlobalService.new(user, search: "searchable").execute results = described_class.new(user, search: "searchable").execute
expect(results.objects('projects')).to match_array [public_project, found_project, internal_project] expect(results.objects('projects')).to match_array [public_project, found_project, internal_project]
end end
it 'returns only public & internal projects' do it 'returns only public & internal projects' do
results = Search::GlobalService.new(internal_user, search: "searchable").execute results = described_class.new(internal_user, search: "searchable").execute
expect(results.objects('projects')).to match_array [internal_project, public_project] expect(results.objects('projects')).to match_array [internal_project, public_project]
end end
it 'namespace name is searchable' do it 'namespace name is searchable' do
results = Search::GlobalService.new(user, search: found_project.namespace.path).execute results = described_class.new(user, search: found_project.namespace.path).execute
expect(results.objects('projects')).to match_array [found_project] expect(results.objects('projects')).to match_array [found_project]
end end
......
...@@ -17,7 +17,7 @@ describe Search::GroupService do ...@@ -17,7 +17,7 @@ describe Search::GroupService do
let!(:project2) { create(:empty_project, :internal, namespace: nested_group, name: "Inner #{term} 2") } let!(:project2) { create(:empty_project, :internal, namespace: nested_group, name: "Inner #{term} 2") }
let!(:project3) { create(:empty_project, :internal, namespace: nested_group.parent, name: "Outer #{term}") } let!(:project3) { create(:empty_project, :internal, namespace: nested_group.parent, name: "Outer #{term}") }
let(:results) { Search::GroupService.new(user, search_group, search: term).execute } let(:results) { described_class.new(user, search_group, search: term).execute }
subject { results.objects('projects') } subject { results.objects('projects') }
context 'in parent group' do context 'in parent group' do
......
...@@ -22,7 +22,7 @@ describe SearchService do ...@@ -22,7 +22,7 @@ describe SearchService do
describe '#project' do describe '#project' do
context 'when the project is accessible' do context 'when the project is accessible' do
it 'returns the project' do it 'returns the project' do
project = SearchService.new(user, project_id: accessible_project.id).project project = described_class.new(user, project_id: accessible_project.id).project
expect(project).to eq accessible_project expect(project).to eq accessible_project
end end
...@@ -31,7 +31,7 @@ describe SearchService do ...@@ -31,7 +31,7 @@ describe SearchService do
search_project = create :empty_project search_project = create :empty_project
search_project.add_guest(user) search_project.add_guest(user)
project = SearchService.new(user, project_id: search_project.id).project project = described_class.new(user, project_id: search_project.id).project
expect(project).to eq search_project expect(project).to eq search_project
end end
...@@ -39,7 +39,7 @@ describe SearchService do ...@@ -39,7 +39,7 @@ describe SearchService do
context 'when the project is not accessible' do context 'when the project is not accessible' do
it 'returns nil' do it 'returns nil' do
project = SearchService.new(user, project_id: inaccessible_project.id).project project = described_class.new(user, project_id: inaccessible_project.id).project
expect(project).to be_nil expect(project).to be_nil
end end
...@@ -47,7 +47,7 @@ describe SearchService do ...@@ -47,7 +47,7 @@ describe SearchService do
context 'when there is no project_id' do context 'when there is no project_id' do
it 'returns nil' do it 'returns nil' do
project = SearchService.new(user).project project = described_class.new(user).project
expect(project).to be_nil expect(project).to be_nil
end end
...@@ -57,7 +57,7 @@ describe SearchService do ...@@ -57,7 +57,7 @@ describe SearchService do
describe '#group' do describe '#group' do
context 'when the group is accessible' do context 'when the group is accessible' do
it 'returns the group' do it 'returns the group' do
group = SearchService.new(user, group_id: accessible_group.id).group group = described_class.new(user, group_id: accessible_group.id).group
expect(group).to eq accessible_group expect(group).to eq accessible_group
end end
...@@ -65,7 +65,7 @@ describe SearchService do ...@@ -65,7 +65,7 @@ describe SearchService do
context 'when the group is not accessible' do context 'when the group is not accessible' do
it 'returns nil' do it 'returns nil' do
group = SearchService.new(user, group_id: inaccessible_group.id).group group = described_class.new(user, group_id: inaccessible_group.id).group
expect(group).to be_nil expect(group).to be_nil
end end
...@@ -73,7 +73,7 @@ describe SearchService do ...@@ -73,7 +73,7 @@ describe SearchService do
context 'when there is no group_id' do context 'when there is no group_id' do
it 'returns nil' do it 'returns nil' do
group = SearchService.new(user).group group = described_class.new(user).group
expect(group).to be_nil expect(group).to be_nil
end end
...@@ -83,7 +83,7 @@ describe SearchService do ...@@ -83,7 +83,7 @@ describe SearchService do
describe '#show_snippets?' do describe '#show_snippets?' do
context 'when :snippets is \'true\'' do context 'when :snippets is \'true\'' do
it 'returns true' do it 'returns true' do
show_snippets = SearchService.new(user, snippets: 'true').show_snippets? show_snippets = described_class.new(user, snippets: 'true').show_snippets?
expect(show_snippets).to be_truthy expect(show_snippets).to be_truthy
end end
...@@ -91,7 +91,7 @@ describe SearchService do ...@@ -91,7 +91,7 @@ describe SearchService do
context 'when :snippets is not \'true\'' do context 'when :snippets is not \'true\'' do
it 'returns false' do it 'returns false' do
show_snippets = SearchService.new(user, snippets: 'tru').show_snippets? show_snippets = described_class.new(user, snippets: 'tru').show_snippets?
expect(show_snippets).to be_falsey expect(show_snippets).to be_falsey
end end
...@@ -99,7 +99,7 @@ describe SearchService do ...@@ -99,7 +99,7 @@ describe SearchService do
context 'when :snippets is missing' do context 'when :snippets is missing' do
it 'returns false' do it 'returns false' do
show_snippets = SearchService.new(user).show_snippets? show_snippets = described_class.new(user).show_snippets?
expect(show_snippets).to be_falsey expect(show_snippets).to be_falsey
end end
...@@ -110,7 +110,7 @@ describe SearchService do ...@@ -110,7 +110,7 @@ describe SearchService do
context 'with accessible project_id' do context 'with accessible project_id' do
context 'and allowed scope' do context 'and allowed scope' do
it 'returns the specified scope' do it 'returns the specified scope' do
scope = SearchService.new(user, project_id: accessible_project.id, scope: 'notes').scope scope = described_class.new(user, project_id: accessible_project.id, scope: 'notes').scope
expect(scope).to eq 'notes' expect(scope).to eq 'notes'
end end
...@@ -118,7 +118,7 @@ describe SearchService do ...@@ -118,7 +118,7 @@ describe SearchService do
context 'and disallowed scope' do context 'and disallowed scope' do
it 'returns the default scope' do it 'returns the default scope' do
scope = SearchService.new(user, project_id: accessible_project.id, scope: 'projects').scope scope = described_class.new(user, project_id: accessible_project.id, scope: 'projects').scope
expect(scope).to eq 'blobs' expect(scope).to eq 'blobs'
end end
...@@ -126,7 +126,7 @@ describe SearchService do ...@@ -126,7 +126,7 @@ describe SearchService do
context 'and no scope' do context 'and no scope' do
it 'returns the default scope' do it 'returns the default scope' do
scope = SearchService.new(user, project_id: accessible_project.id).scope scope = described_class.new(user, project_id: accessible_project.id).scope
expect(scope).to eq 'blobs' expect(scope).to eq 'blobs'
end end
...@@ -136,7 +136,7 @@ describe SearchService do ...@@ -136,7 +136,7 @@ describe SearchService do
context 'with \'true\' snippets' do context 'with \'true\' snippets' do
context 'and allowed scope' do context 'and allowed scope' do
it 'returns the specified scope' do it 'returns the specified scope' do
scope = SearchService.new(user, snippets: 'true', scope: 'snippet_titles').scope scope = described_class.new(user, snippets: 'true', scope: 'snippet_titles').scope
expect(scope).to eq 'snippet_titles' expect(scope).to eq 'snippet_titles'
end end
...@@ -144,7 +144,7 @@ describe SearchService do ...@@ -144,7 +144,7 @@ describe SearchService do
context 'and disallowed scope' do context 'and disallowed scope' do
it 'returns the default scope' do it 'returns the default scope' do
scope = SearchService.new(user, snippets: 'true', scope: 'projects').scope scope = described_class.new(user, snippets: 'true', scope: 'projects').scope
expect(scope).to eq 'snippet_blobs' expect(scope).to eq 'snippet_blobs'
end end
...@@ -152,7 +152,7 @@ describe SearchService do ...@@ -152,7 +152,7 @@ describe SearchService do
context 'and no scope' do context 'and no scope' do
it 'returns the default scope' do it 'returns the default scope' do
scope = SearchService.new(user, snippets: 'true').scope scope = described_class.new(user, snippets: 'true').scope
expect(scope).to eq 'snippet_blobs' expect(scope).to eq 'snippet_blobs'
end end
...@@ -162,7 +162,7 @@ describe SearchService do ...@@ -162,7 +162,7 @@ describe SearchService do
context 'with no project_id, no snippets' do context 'with no project_id, no snippets' do
context 'and allowed scope' do context 'and allowed scope' do
it 'returns the specified scope' do it 'returns the specified scope' do
scope = SearchService.new(user, scope: 'issues').scope scope = described_class.new(user, scope: 'issues').scope
expect(scope).to eq 'issues' expect(scope).to eq 'issues'
end end
...@@ -170,7 +170,7 @@ describe SearchService do ...@@ -170,7 +170,7 @@ describe SearchService do
context 'and disallowed scope' do context 'and disallowed scope' do
it 'returns the default scope' do it 'returns the default scope' do
scope = SearchService.new(user, scope: 'blobs').scope scope = described_class.new(user, scope: 'blobs').scope
expect(scope).to eq 'projects' expect(scope).to eq 'projects'
end end
...@@ -178,7 +178,7 @@ describe SearchService do ...@@ -178,7 +178,7 @@ describe SearchService do
context 'and no scope' do context 'and no scope' do
it 'returns the default scope' do it 'returns the default scope' do
scope = SearchService.new(user).scope scope = described_class.new(user).scope
expect(scope).to eq 'projects' expect(scope).to eq 'projects'
end end
...@@ -189,7 +189,7 @@ describe SearchService do ...@@ -189,7 +189,7 @@ describe SearchService do
describe '#search_results' do describe '#search_results' do
context 'with accessible project_id' do context 'with accessible project_id' do
it 'returns an instance of Gitlab::ProjectSearchResults' do it 'returns an instance of Gitlab::ProjectSearchResults' do
search_results = SearchService.new( search_results = described_class.new(
user, user,
project_id: accessible_project.id, project_id: accessible_project.id,
scope: 'notes', scope: 'notes',
...@@ -201,7 +201,7 @@ describe SearchService do ...@@ -201,7 +201,7 @@ describe SearchService do
context 'with accessible project_id and \'true\' snippets' do context 'with accessible project_id and \'true\' snippets' do
it 'returns an instance of Gitlab::ProjectSearchResults' do it 'returns an instance of Gitlab::ProjectSearchResults' do
search_results = SearchService.new( search_results = described_class.new(
user, user,
project_id: accessible_project.id, project_id: accessible_project.id,
snippets: 'true', snippets: 'true',
...@@ -214,7 +214,7 @@ describe SearchService do ...@@ -214,7 +214,7 @@ describe SearchService do
context 'with \'true\' snippets' do context 'with \'true\' snippets' do
it 'returns an instance of Gitlab::SnippetSearchResults' do it 'returns an instance of Gitlab::SnippetSearchResults' do
search_results = SearchService.new( search_results = described_class.new(
user, user,
snippets: 'true', snippets: 'true',
search: snippet.content).search_results search: snippet.content).search_results
...@@ -225,7 +225,7 @@ describe SearchService do ...@@ -225,7 +225,7 @@ describe SearchService do
context 'with no project_id and no snippets' do context 'with no project_id and no snippets' do
it 'returns an instance of Gitlab::SearchResults' do it 'returns an instance of Gitlab::SearchResults' do
search_results = SearchService.new( search_results = described_class.new(
user, user,
search: public_project.name).search_results search: public_project.name).search_results
...@@ -237,7 +237,7 @@ describe SearchService do ...@@ -237,7 +237,7 @@ describe SearchService do
describe '#search_objects' do describe '#search_objects' do
context 'with accessible project_id' do context 'with accessible project_id' do
it 'returns objects in the project' do it 'returns objects in the project' do
search_objects = SearchService.new( search_objects = described_class.new(
user, user,
project_id: accessible_project.id, project_id: accessible_project.id,
scope: 'notes', scope: 'notes',
...@@ -249,7 +249,7 @@ describe SearchService do ...@@ -249,7 +249,7 @@ describe SearchService do
context 'with accessible project_id and \'true\' snippets' do context 'with accessible project_id and \'true\' snippets' do
it 'returns objects in the project' do it 'returns objects in the project' do
search_objects = SearchService.new( search_objects = described_class.new(
user, user,
project_id: accessible_project.id, project_id: accessible_project.id,
snippets: 'true', snippets: 'true',
...@@ -262,7 +262,7 @@ describe SearchService do ...@@ -262,7 +262,7 @@ describe SearchService do
context 'with \'true\' snippets' do context 'with \'true\' snippets' do
it 'returns objects in snippets' do it 'returns objects in snippets' do
search_objects = SearchService.new( search_objects = described_class.new(
user, user,
snippets: 'true', snippets: 'true',
search: snippet.content).search_objects search: snippet.content).search_objects
...@@ -273,7 +273,7 @@ describe SearchService do ...@@ -273,7 +273,7 @@ describe SearchService do
context 'with accessible group_id' do context 'with accessible group_id' do
it 'returns objects in the group' do it 'returns objects in the group' do
search_objects = SearchService.new( search_objects = described_class.new(
user, user,
group_id: accessible_group.id, group_id: accessible_group.id,
search: group_project.name).search_objects search: group_project.name).search_objects
...@@ -284,7 +284,7 @@ describe SearchService do ...@@ -284,7 +284,7 @@ describe SearchService do
context 'with no project_id, group_id or snippets' do context 'with no project_id, group_id or snippets' do
it 'returns objects in global' do it 'returns objects in global' do
search_objects = SearchService.new( search_objects = described_class.new(
user, user,
search: public_project.name).search_objects search: public_project.name).search_objects
......
...@@ -873,21 +873,21 @@ describe TodoService do ...@@ -873,21 +873,21 @@ describe TodoService do
create(:todo, :mentioned, user: john_doe, target: issue, project: project) create(:todo, :mentioned, user: john_doe, target: issue, project: project)
todos = TodosFinder.new(john_doe, {}).execute todos = TodosFinder.new(john_doe, {}).execute
expect { TodoService.new.mark_todos_as_done(todos, john_doe) } expect { described_class.new.mark_todos_as_done(todos, john_doe) }
.to change { john_doe.todos.done.count }.from(0).to(1) .to change { john_doe.todos.done.count }.from(0).to(1)
end end
it 'marks an array of todos as done' do it 'marks an array of todos as done' do
todo = create(:todo, :mentioned, user: john_doe, target: issue, project: project) todo = create(:todo, :mentioned, user: john_doe, target: issue, project: project)
expect { TodoService.new.mark_todos_as_done([todo], john_doe) } expect { described_class.new.mark_todos_as_done([todo], john_doe) }
.to change { todo.reload.state }.from('pending').to('done') .to change { todo.reload.state }.from('pending').to('done')
end end
it 'returns the ids of updated todos' do # Needed on API it 'returns the ids of updated todos' do # Needed on API
todo = create(:todo, :mentioned, user: john_doe, target: issue, project: project) todo = create(:todo, :mentioned, user: john_doe, target: issue, project: project)
expect(TodoService.new.mark_todos_as_done([todo], john_doe)).to eq([todo.id]) expect(described_class.new.mark_todos_as_done([todo], john_doe)).to eq([todo.id])
end end
context 'when some of the todos are done already' do context 'when some of the todos are done already' do
...@@ -895,23 +895,23 @@ describe TodoService do ...@@ -895,23 +895,23 @@ describe TodoService do
let!(:second_todo) { create(:todo, :mentioned, user: john_doe, target: another_issue, project: project) } let!(:second_todo) { create(:todo, :mentioned, user: john_doe, target: another_issue, project: project) }
it 'returns the ids of those still pending' do it 'returns the ids of those still pending' do
TodoService.new.mark_pending_todos_as_done(issue, john_doe) described_class.new.mark_pending_todos_as_done(issue, john_doe)
expect(TodoService.new.mark_todos_as_done(Todo.all, john_doe)).to eq([second_todo.id]) expect(described_class.new.mark_todos_as_done(Todo.all, john_doe)).to eq([second_todo.id])
end end
it 'returns an empty array if all are done' do it 'returns an empty array if all are done' do
TodoService.new.mark_pending_todos_as_done(issue, john_doe) described_class.new.mark_pending_todos_as_done(issue, john_doe)
TodoService.new.mark_pending_todos_as_done(another_issue, john_doe) described_class.new.mark_pending_todos_as_done(another_issue, john_doe)
expect(TodoService.new.mark_todos_as_done(Todo.all, john_doe)).to eq([]) expect(described_class.new.mark_todos_as_done(Todo.all, john_doe)).to eq([])
end end
end end
it 'caches the number of todos of a user', :use_clean_rails_memory_store_caching do it 'caches the number of todos of a user', :use_clean_rails_memory_store_caching do
create(:todo, :mentioned, user: john_doe, target: issue, project: project) create(:todo, :mentioned, user: john_doe, target: issue, project: project)
todo = create(:todo, :mentioned, user: john_doe, target: issue, project: project) todo = create(:todo, :mentioned, user: john_doe, target: issue, project: project)
TodoService.new.mark_todos_as_done([todo], john_doe) described_class.new.mark_todos_as_done([todo], john_doe)
expect_any_instance_of(TodosFinder).not_to receive(:execute) expect_any_instance_of(TodosFinder).not_to receive(:execute)
......
...@@ -6,7 +6,7 @@ describe UpdateReleaseService do ...@@ -6,7 +6,7 @@ describe UpdateReleaseService do
let(:tag_name) { project.repository.tag_names.first } let(:tag_name) { project.repository.tag_names.first }
let(:description) { 'Awesome release!' } let(:description) { 'Awesome release!' }
let(:new_description) { 'The best release!' } let(:new_description) { 'The best release!' }
let(:service) { UpdateReleaseService.new(project, user) } let(:service) { described_class.new(project, user) }
context 'with an existing release' do context 'with an existing release' do
let(:create_service) { CreateReleaseService.new(project, user) } let(:create_service) { CreateReleaseService.new(project, user) }
......
...@@ -12,7 +12,7 @@ describe WebHookService do ...@@ -12,7 +12,7 @@ describe WebHookService do
let(:data) do let(:data) do
{ before: 'oldrev', after: 'newrev', ref: 'ref' } { before: 'oldrev', after: 'newrev', ref: 'ref' }
end end
let(:service_instance) { WebHookService.new(project_hook, data, 'push_hooks') } let(:service_instance) { described_class.new(project_hook, data, 'push_hooks') }
describe '#execute' do describe '#execute' do
before(:each) do before(:each) do
...@@ -114,7 +114,7 @@ describe WebHookService do ...@@ -114,7 +114,7 @@ describe WebHookService do
context 'should not log ServiceHooks' do context 'should not log ServiceHooks' do
let(:service_hook) { create(:service_hook) } let(:service_hook) { create(:service_hook) }
let(:service_instance) { WebHookService.new(service_hook, data, 'service_hook') } let(:service_instance) { described_class.new(service_hook, data, 'service_hook') }
before do before do
WebMock.stub_request(:post, service_hook.url).to_return(status: 200, body: 'Success') WebMock.stub_request(:post, service_hook.url).to_return(status: 200, body: 'Success')
...@@ -131,7 +131,7 @@ describe WebHookService do ...@@ -131,7 +131,7 @@ describe WebHookService do
it 'enqueue WebHookWorker' do it 'enqueue WebHookWorker' do
expect(Sidekiq::Client).to receive(:enqueue).with(WebHookWorker, project_hook.id, data, 'push_hooks') expect(Sidekiq::Client).to receive(:enqueue).with(WebHookWorker, project_hook.id, data, 'push_hooks')
WebHookService.new(project_hook, data, 'push_hooks').async_execute described_class.new(project_hook, data, 'push_hooks').async_execute
end end
end end
end end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment