diff options
Diffstat (limited to 'spec')
106 files changed, 390 insertions, 390 deletions
diff --git a/spec/initializers/settings_spec.rb b/spec/initializers/settings_spec.rb index 61439ac9506..ebdabcf93f1 100644 --- a/spec/initializers/settings_spec.rb +++ b/spec/initializers/settings_spec.rb @@ -5,37 +5,37 @@ describe Settings do describe '#host_without_www' do context 'URL with protocol' do it 'returns the host' do - expect(Settings.host_without_www('http://foo.com')).to eq 'foo.com' - expect(Settings.host_without_www('http://www.foo.com')).to eq 'foo.com' - expect(Settings.host_without_www('http://secure.foo.com')).to eq 'secure.foo.com' - expect(Settings.host_without_www('http://www.gravatar.com/avatar/%{hash}?s=%{size}&d=identicon')).to eq 'gravatar.com' + expect(described_class.host_without_www('http://foo.com')).to eq 'foo.com' + expect(described_class.host_without_www('http://www.foo.com')).to eq 'foo.com' + expect(described_class.host_without_www('http://secure.foo.com')).to eq 'secure.foo.com' + expect(described_class.host_without_www('http://www.gravatar.com/avatar/%{hash}?s=%{size}&d=identicon')).to eq 'gravatar.com' - expect(Settings.host_without_www('https://foo.com')).to eq 'foo.com' - expect(Settings.host_without_www('https://www.foo.com')).to eq 'foo.com' - expect(Settings.host_without_www('https://secure.foo.com')).to eq 'secure.foo.com' - expect(Settings.host_without_www('https://secure.gravatar.com/avatar/%{hash}?s=%{size}&d=identicon')).to eq 'secure.gravatar.com' + expect(described_class.host_without_www('https://foo.com')).to eq 'foo.com' + expect(described_class.host_without_www('https://www.foo.com')).to eq 'foo.com' + expect(described_class.host_without_www('https://secure.foo.com')).to eq 'secure.foo.com' + expect(described_class.host_without_www('https://secure.gravatar.com/avatar/%{hash}?s=%{size}&d=identicon')).to eq 'secure.gravatar.com' end end context 'URL without protocol' do it 'returns the host' do - expect(Settings.host_without_www('foo.com')).to eq 'foo.com' - expect(Settings.host_without_www('www.foo.com')).to eq 'foo.com' - expect(Settings.host_without_www('secure.foo.com')).to eq 'secure.foo.com' - expect(Settings.host_without_www('www.gravatar.com/avatar/%{hash}?s=%{size}&d=identicon')).to eq 'gravatar.com' + expect(described_class.host_without_www('foo.com')).to eq 'foo.com' + expect(described_class.host_without_www('www.foo.com')).to eq 'foo.com' + expect(described_class.host_without_www('secure.foo.com')).to eq 'secure.foo.com' + expect(described_class.host_without_www('www.gravatar.com/avatar/%{hash}?s=%{size}&d=identicon')).to eq 'gravatar.com' end context 'URL with user/port' do it 'returns the host' do - expect(Settings.host_without_www('bob:pass@foo.com:8080')).to eq 'foo.com' - expect(Settings.host_without_www('bob:pass@www.foo.com:8080')).to eq 'foo.com' - expect(Settings.host_without_www('bob:pass@secure.foo.com:8080')).to eq 'secure.foo.com' - expect(Settings.host_without_www('bob:pass@www.gravatar.com:8080/avatar/%{hash}?s=%{size}&d=identicon')).to eq 'gravatar.com' + expect(described_class.host_without_www('bob:pass@foo.com:8080')).to eq 'foo.com' + expect(described_class.host_without_www('bob:pass@www.foo.com:8080')).to eq 'foo.com' + expect(described_class.host_without_www('bob:pass@secure.foo.com:8080')).to eq 'secure.foo.com' + expect(described_class.host_without_www('bob:pass@www.gravatar.com:8080/avatar/%{hash}?s=%{size}&d=identicon')).to eq 'gravatar.com' - expect(Settings.host_without_www('http://bob:pass@foo.com:8080')).to eq 'foo.com' - expect(Settings.host_without_www('http://bob:pass@www.foo.com:8080')).to eq 'foo.com' - expect(Settings.host_without_www('http://bob:pass@secure.foo.com:8080')).to eq 'secure.foo.com' - expect(Settings.host_without_www('http://bob:pass@www.gravatar.com:8080/avatar/%{hash}?s=%{size}&d=identicon')).to eq 'gravatar.com' + expect(described_class.host_without_www('http://bob:pass@foo.com:8080')).to eq 'foo.com' + expect(described_class.host_without_www('http://bob:pass@www.foo.com:8080')).to eq 'foo.com' + expect(described_class.host_without_www('http://bob:pass@secure.foo.com:8080')).to eq 'secure.foo.com' + expect(described_class.host_without_www('http://bob:pass@www.gravatar.com:8080/avatar/%{hash}?s=%{size}&d=identicon')).to eq 'gravatar.com' end end end diff --git a/spec/lib/disable_email_interceptor_spec.rb b/spec/lib/disable_email_interceptor_spec.rb index 9fc1dd523f1..3652d928c43 100644 --- a/spec/lib/disable_email_interceptor_spec.rb +++ b/spec/lib/disable_email_interceptor_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' describe DisableEmailInterceptor do before do - Mail.register_interceptor(DisableEmailInterceptor) + Mail.register_interceptor(described_class) end it 'does not send emails' do @@ -14,7 +14,7 @@ describe DisableEmailInterceptor do # Removing interceptor from the list because unregister_interceptor is # implemented in later version of mail gem # See: https://github.com/mikel/mail/pull/705 - Mail.unregister_interceptor(DisableEmailInterceptor) + Mail.unregister_interceptor(described_class) end def deliver_mail diff --git a/spec/lib/event_filter_spec.rb b/spec/lib/event_filter_spec.rb index 09425c6bf68..b1366e74802 100644 --- a/spec/lib/event_filter_spec.rb +++ b/spec/lib/event_filter_spec.rb @@ -16,42 +16,42 @@ describe EventFilter do let!(:left_event) { create(:event, :left, project: public_project, target: public_project, author: source_user) } it 'applies push filter' do - events = EventFilter.new(EventFilter.push).apply_filter(Event.all) + events = described_class.new(described_class.push).apply_filter(Event.all) expect(events).to contain_exactly(push_event) end it 'applies merged filter' do - events = EventFilter.new(EventFilter.merged).apply_filter(Event.all) + events = described_class.new(described_class.merged).apply_filter(Event.all) expect(events).to contain_exactly(merged_event) end it 'applies issue filter' do - events = EventFilter.new(EventFilter.issue).apply_filter(Event.all) + events = described_class.new(described_class.issue).apply_filter(Event.all) expect(events).to contain_exactly(created_event, updated_event, closed_event, reopened_event) end it 'applies comments filter' do - events = EventFilter.new(EventFilter.comments).apply_filter(Event.all) + events = described_class.new(described_class.comments).apply_filter(Event.all) expect(events).to contain_exactly(comments_event) end it 'applies team filter' do - events = EventFilter.new(EventFilter.team).apply_filter(Event.all) + events = described_class.new(described_class.team).apply_filter(Event.all) expect(events).to contain_exactly(joined_event, left_event) end it 'applies all filter' do - events = EventFilter.new(EventFilter.all).apply_filter(Event.all) + events = described_class.new(described_class.all).apply_filter(Event.all) expect(events).to contain_exactly(push_event, merged_event, created_event, updated_event, closed_event, reopened_event, comments_event, joined_event, left_event) end it 'applies no filter' do - events = EventFilter.new(nil).apply_filter(Event.all) + events = described_class.new(nil).apply_filter(Event.all) expect(events).to contain_exactly(push_event, merged_event, created_event, updated_event, closed_event, reopened_event, comments_event, joined_event, left_event) end it 'applies unknown filter' do - events = EventFilter.new('').apply_filter(Event.all) + events = described_class.new('').apply_filter(Event.all) expect(events).to contain_exactly(push_event, merged_event, created_event, updated_event, closed_event, reopened_event, comments_event, joined_event, left_event) end end diff --git a/spec/lib/extracts_path_spec.rb b/spec/lib/extracts_path_spec.rb index 1772ca216e4..9b89f47ae7e 100644 --- a/spec/lib/extracts_path_spec.rb +++ b/spec/lib/extracts_path_spec.rb @@ -1,7 +1,7 @@ require 'spec_helper' describe ExtractsPath do - include ExtractsPath + include described_class include RepoHelpers include Gitlab::Routing diff --git a/spec/lib/file_size_validator_spec.rb b/spec/lib/file_size_validator_spec.rb index 681cc9ef21c..49501931dd2 100644 --- a/spec/lib/file_size_validator_spec.rb +++ b/spec/lib/file_size_validator_spec.rb @@ -1,7 +1,7 @@ require 'spec_helper' describe FileSizeValidator do - let(:validator) { FileSizeValidator.new(options) } + let(:validator) { described_class.new(options) } let(:attachment) { AttachmentUploader.new } let(:note) { create(:note) } diff --git a/spec/lib/gitlab/bitbucket_import/importer_spec.rb b/spec/lib/gitlab/bitbucket_import/importer_spec.rb index 35c8a24aef4..df66a031fec 100644 --- a/spec/lib/gitlab/bitbucket_import/importer_spec.rb +++ b/spec/lib/gitlab/bitbucket_import/importer_spec.rb @@ -58,7 +58,7 @@ describe Gitlab::BitbucketImport::Importer do ) end - let(:importer) { Gitlab::BitbucketImport::Importer.new(project) } + let(:importer) { described_class.new(project) } let(:issues_statuses_sample_data) do { diff --git a/spec/lib/gitlab/bitbucket_import/project_creator_spec.rb b/spec/lib/gitlab/bitbucket_import/project_creator_spec.rb index 4bc0eaddd9e..d7f7b26740d 100644 --- a/spec/lib/gitlab/bitbucket_import/project_creator_spec.rb +++ b/spec/lib/gitlab/bitbucket_import/project_creator_spec.rb @@ -27,7 +27,7 @@ describe Gitlab::BitbucketImport::ProjectCreator do it 'creates project' do allow_any_instance_of(Project).to receive(:add_import_job) - project_creator = Gitlab::BitbucketImport::ProjectCreator.new(repo, 'vim', namespace, user, access_params) + project_creator = described_class.new(repo, 'vim', namespace, user, access_params) project = project_creator.execute expect(project.import_url).to eq("ssh://git@bitbucket.org/asd/vim.git") diff --git a/spec/lib/gitlab/ci_access_spec.rb b/spec/lib/gitlab/ci_access_spec.rb index fcb9f10d6c0..75b90e76083 100644 --- a/spec/lib/gitlab/ci_access_spec.rb +++ b/spec/lib/gitlab/ci_access_spec.rb @@ -1,7 +1,7 @@ require 'spec_helper' describe Gitlab::CiAccess do - let(:access) { Gitlab::CiAccess.new } + let(:access) { described_class.new } describe '#can_do_action?' do context 'when action is :build_download_code' do diff --git a/spec/lib/gitlab/conflict/file_spec.rb b/spec/lib/gitlab/conflict/file_spec.rb index c0a10124730..5356e9742b4 100644 --- a/spec/lib/gitlab/conflict/file_spec.rb +++ b/spec/lib/gitlab/conflict/file_spec.rb @@ -10,7 +10,7 @@ describe Gitlab::Conflict::File do let(:index) { rugged.merge_commits(our_commit, their_commit) } let(:conflict) { index.conflicts.last } let(:merge_file_result) { index.merge_file('files/ruby/regex.rb') } - let(:conflict_file) { Gitlab::Conflict::File.new(merge_file_result, conflict, merge_request: merge_request) } + let(:conflict_file) { described_class.new(merge_file_result, conflict, merge_request: merge_request) } describe '#resolve_lines' do let(:section_keys) { conflict_file.sections.map { |section| section[:id] }.compact } @@ -220,7 +220,7 @@ end FILE end - let(:conflict_file) { Gitlab::Conflict::File.new({ data: file }, conflict, merge_request: merge_request) } + let(:conflict_file) { described_class.new({ data: file }, conflict, merge_request: merge_request) } let(:sections) { conflict_file.sections } it 'sets the correct match line headers' do diff --git a/spec/lib/gitlab/conflict/parser_spec.rb b/spec/lib/gitlab/conflict/parser_spec.rb index ad99a5fb6bf..fce606a2bb5 100644 --- a/spec/lib/gitlab/conflict/parser_spec.rb +++ b/spec/lib/gitlab/conflict/parser_spec.rb @@ -1,7 +1,7 @@ require 'spec_helper' describe Gitlab::Conflict::Parser do - let(:parser) { Gitlab::Conflict::Parser.new } + let(:parser) { described_class.new } describe '#parse' do def parse_text(text) diff --git a/spec/lib/gitlab/database/migration_helpers_spec.rb b/spec/lib/gitlab/database/migration_helpers_spec.rb index 0e0354bc532..d3dbd82e8ba 100644 --- a/spec/lib/gitlab/database/migration_helpers_spec.rb +++ b/spec/lib/gitlab/database/migration_helpers_spec.rb @@ -3,7 +3,7 @@ require 'spec_helper' describe Gitlab::Database::MigrationHelpers do let(:model) do ActiveRecord::Migration.new.extend( - Gitlab::Database::MigrationHelpers + described_class ) end diff --git a/spec/lib/gitlab/diff/highlight_spec.rb b/spec/lib/gitlab/diff/highlight_spec.rb index ffa83d6a8f2..cd602ccab8e 100644 --- a/spec/lib/gitlab/diff/highlight_spec.rb +++ b/spec/lib/gitlab/diff/highlight_spec.rb @@ -10,7 +10,7 @@ describe Gitlab::Diff::Highlight do describe '#highlight' do context "with a diff file" do - let(:subject) { Gitlab::Diff::Highlight.new(diff_file, repository: project.repository).highlight } + let(:subject) { described_class.new(diff_file, repository: project.repository).highlight } it 'returns Gitlab::Diff::Line elements' do expect(subject.first).to be_an_instance_of(Gitlab::Diff::Line) @@ -41,7 +41,7 @@ describe Gitlab::Diff::Highlight do end context "with diff lines" do - let(:subject) { Gitlab::Diff::Highlight.new(diff_file.diff_lines, repository: project.repository).highlight } + let(:subject) { described_class.new(diff_file.diff_lines, repository: project.repository).highlight } it 'returns Gitlab::Diff::Line elements' do expect(subject.first).to be_an_instance_of(Gitlab::Diff::Line) diff --git a/spec/lib/gitlab/diff/parser_spec.rb b/spec/lib/gitlab/diff/parser_spec.rb index e16c31d7eb8..c71568e2a65 100644 --- a/spec/lib/gitlab/diff/parser_spec.rb +++ b/spec/lib/gitlab/diff/parser_spec.rb @@ -6,7 +6,7 @@ describe Gitlab::Diff::Parser do let(:project) { create(:project) } let(:commit) { project.commit(sample_commit.id) } let(:diff) { commit.raw_diffs.first } - let(:parser) { Gitlab::Diff::Parser.new } + let(:parser) { described_class.new } describe '#parse' do let(:diff) do diff --git a/spec/lib/gitlab/git/hook_spec.rb b/spec/lib/gitlab/git/hook_spec.rb index ff823e53cac..19391a70cf6 100644 --- a/spec/lib/gitlab/git/hook_spec.rb +++ b/spec/lib/gitlab/git/hook_spec.rb @@ -5,7 +5,7 @@ describe Gitlab::Git::Hook do before do # We need this because in the spec/spec_helper.rb we define it like this: # allow_any_instance_of(Gitlab::Git::Hook).to receive(:trigger).and_return([true, nil]) - allow_any_instance_of(Gitlab::Git::Hook).to receive(:trigger).and_call_original + allow_any_instance_of(described_class).to receive(:trigger).and_call_original end describe "#trigger" do @@ -48,7 +48,7 @@ describe Gitlab::Git::Hook do it "returns success with no errors" do create_hook(hook_name) - hook = Gitlab::Git::Hook.new(hook_name, project) + hook = described_class.new(hook_name, project) blank = Gitlab::Git::BLANK_SHA ref = Gitlab::Git::BRANCH_REF_PREFIX + 'new_branch' @@ -66,7 +66,7 @@ describe Gitlab::Git::Hook do context "when the hook is unsuccessful" do it "returns failure with errors" do create_failing_hook(hook_name) - hook = Gitlab::Git::Hook.new(hook_name, project) + hook = described_class.new(hook_name, project) blank = Gitlab::Git::BLANK_SHA ref = Gitlab::Git::BRANCH_REF_PREFIX + 'new_branch' @@ -80,7 +80,7 @@ describe Gitlab::Git::Hook do context "when the hook doesn't exist" do it "returns success with no errors" do - hook = Gitlab::Git::Hook.new('unknown_hook', project) + hook = described_class.new('unknown_hook', project) blank = Gitlab::Git::BLANK_SHA ref = Gitlab::Git::BRANCH_REF_PREFIX + 'new_branch' diff --git a/spec/lib/gitlab/git/rev_list_spec.rb b/spec/lib/gitlab/git/rev_list_spec.rb index 26fc33b8327..b051a088171 100644 --- a/spec/lib/gitlab/git/rev_list_spec.rb +++ b/spec/lib/gitlab/git/rev_list_spec.rb @@ -11,7 +11,7 @@ describe Gitlab::Git::RevList do end context "#new_refs" do - let(:rev_list) { Gitlab::Git::RevList.new(newrev: 'newrev', path_to_repo: project.repository.path_to_repo) } + let(:rev_list) { described_class.new(newrev: 'newrev', path_to_repo: project.repository.path_to_repo) } it 'calls out to `popen`' do expect(Gitlab::Popen).to receive(:popen).with([ @@ -33,7 +33,7 @@ describe Gitlab::Git::RevList do end context "#missed_ref" do - let(:rev_list) { Gitlab::Git::RevList.new(oldrev: 'oldrev', newrev: 'newrev', path_to_repo: project.repository.path_to_repo) } + let(:rev_list) { described_class.new(oldrev: 'oldrev', newrev: 'newrev', path_to_repo: project.repository.path_to_repo) } it 'calls out to `popen`' do expect(Gitlab::Popen).to receive(:popen).with([ diff --git a/spec/lib/gitlab/git_access_spec.rb b/spec/lib/gitlab/git_access_spec.rb index 14c424b86e4..2d6ea37d0ac 100644 --- a/spec/lib/gitlab/git_access_spec.rb +++ b/spec/lib/gitlab/git_access_spec.rb @@ -3,7 +3,7 @@ require 'spec_helper' describe Gitlab::GitAccess do let(:pull_access_check) { access.check('git-upload-pack', '_any') } let(:push_access_check) { access.check('git-receive-pack', '_any') } - let(:access) { Gitlab::GitAccess.new(actor, project, protocol, authentication_abilities: authentication_abilities, redirected_path: redirected_path) } + let(:access) { described_class.new(actor, project, protocol, authentication_abilities: authentication_abilities, redirected_path: redirected_path) } let(:project) { create(:project, :repository) } let(:user) { create(:user) } let(:actor) { user } @@ -280,7 +280,7 @@ describe Gitlab::GitAccess do context 'when project is public' do let(:public_project) { create(:project, :public, :repository) } - let(:access) { Gitlab::GitAccess.new(nil, public_project, 'web', authentication_abilities: []) } + let(:access) { described_class.new(nil, public_project, 'web', authentication_abilities: []) } context 'when repository is enabled' do it 'give access to download code' do @@ -441,7 +441,7 @@ describe Gitlab::GitAccess do end permissions_matrix[role].each do |action, allowed| - context action do + context action.to_s do subject { access.send(:check_push_access!, changes[action]) } it do diff --git a/spec/lib/gitlab/git_access_wiki_spec.rb b/spec/lib/gitlab/git_access_wiki_spec.rb index 2a710fbdf06..0376b4ee783 100644 --- a/spec/lib/gitlab/git_access_wiki_spec.rb +++ b/spec/lib/gitlab/git_access_wiki_spec.rb @@ -1,7 +1,7 @@ require 'spec_helper' describe Gitlab::GitAccessWiki do - let(:access) { Gitlab::GitAccessWiki.new(user, project, 'web', authentication_abilities: authentication_abilities, redirected_path: redirected_path) } + let(:access) { described_class.new(user, project, 'web', authentication_abilities: authentication_abilities, redirected_path: redirected_path) } let(:project) { create(:project, :repository) } let(:user) { create(:user) } let(:redirected_path) { nil } diff --git a/spec/lib/gitlab/git_ref_validator_spec.rb b/spec/lib/gitlab/git_ref_validator_spec.rb index 91a25b7c0f0..e1fa8ae03f8 100644 --- a/spec/lib/gitlab/git_ref_validator_spec.rb +++ b/spec/lib/gitlab/git_ref_validator_spec.rb @@ -1,25 +1,25 @@ require 'spec_helper' describe Gitlab::GitRefValidator do - it { expect(Gitlab::GitRefValidator.validate('feature/new')).to be_truthy } - it { expect(Gitlab::GitRefValidator.validate('implement_@all')).to be_truthy } - it { expect(Gitlab::GitRefValidator.validate('my_new_feature')).to be_truthy } - it { expect(Gitlab::GitRefValidator.validate('#1')).to be_truthy } - it { expect(Gitlab::GitRefValidator.validate('feature/refs/heads/foo')).to be_truthy } - it { expect(Gitlab::GitRefValidator.validate('feature/~new/')).to be_falsey } - it { expect(Gitlab::GitRefValidator.validate('feature/^new/')).to be_falsey } - it { expect(Gitlab::GitRefValidator.validate('feature/:new/')).to be_falsey } - it { expect(Gitlab::GitRefValidator.validate('feature/?new/')).to be_falsey } - it { expect(Gitlab::GitRefValidator.validate('feature/*new/')).to be_falsey } - it { expect(Gitlab::GitRefValidator.validate('feature/[new/')).to be_falsey } - it { expect(Gitlab::GitRefValidator.validate('feature/new/')).to be_falsey } - it { expect(Gitlab::GitRefValidator.validate('feature/new.')).to be_falsey } - it { expect(Gitlab::GitRefValidator.validate('feature\@{')).to be_falsey } - it { expect(Gitlab::GitRefValidator.validate('feature\new')).to be_falsey } - it { expect(Gitlab::GitRefValidator.validate('feature//new')).to be_falsey } - it { expect(Gitlab::GitRefValidator.validate('feature new')).to be_falsey } - it { expect(Gitlab::GitRefValidator.validate('refs/heads/')).to be_falsey } - it { expect(Gitlab::GitRefValidator.validate('refs/remotes/')).to be_falsey } - it { expect(Gitlab::GitRefValidator.validate('refs/heads/feature')).to be_falsey } - it { expect(Gitlab::GitRefValidator.validate('refs/remotes/origin')).to be_falsey } + it { expect(described_class.validate('feature/new')).to be_truthy } + it { expect(described_class.validate('implement_@all')).to be_truthy } + it { expect(described_class.validate('my_new_feature')).to be_truthy } + it { expect(described_class.validate('#1')).to be_truthy } + it { expect(described_class.validate('feature/refs/heads/foo')).to be_truthy } + it { expect(described_class.validate('feature/~new/')).to be_falsey } + it { expect(described_class.validate('feature/^new/')).to be_falsey } + it { expect(described_class.validate('feature/:new/')).to be_falsey } + it { expect(described_class.validate('feature/?new/')).to be_falsey } + it { expect(described_class.validate('feature/*new/')).to be_falsey } + it { expect(described_class.validate('feature/[new/')).to be_falsey } + it { expect(described_class.validate('feature/new/')).to be_falsey } + it { expect(described_class.validate('feature/new.')).to be_falsey } + it { expect(described_class.validate('feature\@{')).to be_falsey } + it { expect(described_class.validate('feature\new')).to be_falsey } + it { expect(described_class.validate('feature//new')).to be_falsey } + it { expect(described_class.validate('feature new')).to be_falsey } + it { expect(described_class.validate('refs/heads/')).to be_falsey } + it { expect(described_class.validate('refs/remotes/')).to be_falsey } + it { expect(described_class.validate('refs/heads/feature')).to be_falsey } + it { expect(described_class.validate('refs/remotes/origin')).to be_falsey } end diff --git a/spec/lib/gitlab/git_spec.rb b/spec/lib/gitlab/git_spec.rb index 88f5c106c80..4702a978f19 100644 --- a/spec/lib/gitlab/git_spec.rb +++ b/spec/lib/gitlab/git_spec.rb @@ -6,7 +6,7 @@ describe Gitlab::Git do describe 'committer_hash' do it "returns a hash containing the given email and name" do - committer_hash = Gitlab::Git.committer_hash(email: committer_email, name: committer_name) + committer_hash = described_class.committer_hash(email: committer_email, name: committer_name) expect(committer_hash[:email]).to eq(committer_email) expect(committer_hash[:name]).to eq(committer_name) @@ -15,7 +15,7 @@ describe Gitlab::Git do context 'when email is nil' do it "returns nil" do - committer_hash = Gitlab::Git.committer_hash(email: nil, name: committer_name) + committer_hash = described_class.committer_hash(email: nil, name: committer_name) expect(committer_hash).to be_nil end @@ -23,7 +23,7 @@ describe Gitlab::Git do context 'when name is nil' do it "returns nil" do - committer_hash = Gitlab::Git.committer_hash(email: committer_email, name: nil) + committer_hash = described_class.committer_hash(email: committer_email, name: nil) expect(committer_hash).to be_nil end diff --git a/spec/lib/gitlab/gitlab_import/client_spec.rb b/spec/lib/gitlab/gitlab_import/client_spec.rb index 977135b3310..50e8d7183ce 100644 --- a/spec/lib/gitlab/gitlab_import/client_spec.rb +++ b/spec/lib/gitlab/gitlab_import/client_spec.rb @@ -4,7 +4,7 @@ describe Gitlab::GitlabImport::Client do include ImportSpecHelper let(:token) { '123456' } - let(:client) { Gitlab::GitlabImport::Client.new(token) } + let(:client) { described_class.new(token) } before do stub_omniauth_provider('gitlab') diff --git a/spec/lib/gitlab/gitlab_import/project_creator_spec.rb b/spec/lib/gitlab/gitlab_import/project_creator_spec.rb index 2d8923d14bb..da48d8f0670 100644 --- a/spec/lib/gitlab/gitlab_import/project_creator_spec.rb +++ b/spec/lib/gitlab/gitlab_import/project_creator_spec.rb @@ -23,7 +23,7 @@ describe Gitlab::GitlabImport::ProjectCreator do it 'creates project' do allow_any_instance_of(Project).to receive(:add_import_job) - project_creator = Gitlab::GitlabImport::ProjectCreator.new(repo, namespace, user, access_params) + project_creator = described_class.new(repo, namespace, user, access_params) project = project_creator.execute expect(project.import_url).to eq("https://oauth2:asdffg@gitlab.com/asd/vim.git") diff --git a/spec/lib/gitlab/google_code_import/project_creator_spec.rb b/spec/lib/gitlab/google_code_import/project_creator_spec.rb index 35549b48687..aad53938d52 100644 --- a/spec/lib/gitlab/google_code_import/project_creator_spec.rb +++ b/spec/lib/gitlab/google_code_import/project_creator_spec.rb @@ -18,7 +18,7 @@ describe Gitlab::GoogleCodeImport::ProjectCreator do it 'creates project' do allow_any_instance_of(Project).to receive(:add_import_job) - project_creator = Gitlab::GoogleCodeImport::ProjectCreator.new(repo, namespace, user) + project_creator = described_class.new(repo, namespace, user) project = project_creator.execute expect(project.import_url).to eq("https://vim.googlecode.com/git/") diff --git a/spec/lib/gitlab/highlight_spec.rb b/spec/lib/gitlab/highlight_spec.rb index 9afd9916264..29e61d15726 100644 --- a/spec/lib/gitlab/highlight_spec.rb +++ b/spec/lib/gitlab/highlight_spec.rb @@ -12,7 +12,7 @@ describe Gitlab::Highlight do let(:blob) { repository.blob_at_branch(branch, path) } let(:highlighter) do - Gitlab::Highlight.new(blob.path, blob.data, repository: repository) + described_class.new(blob.path, blob.data, repository: repository) end before do @@ -42,7 +42,7 @@ describe Gitlab::Highlight do let(:path) { 'files/whitespace' } let(:blob) { repository.blob_at_branch(branch, path) } let(:lines) do - Gitlab::Highlight.highlight(blob.path, blob.data, repository: repository).lines + described_class.highlight(blob.path, blob.data, repository: repository).lines end it 'strips extra LFs' do diff --git a/spec/lib/gitlab/key_fingerprint_spec.rb b/spec/lib/gitlab/key_fingerprint_spec.rb index 266eab6e793..d7bebaca675 100644 --- a/spec/lib/gitlab/key_fingerprint_spec.rb +++ b/spec/lib/gitlab/key_fingerprint_spec.rb @@ -6,7 +6,7 @@ describe Gitlab::KeyFingerprint do describe "#fingerprint" do it "generates the key's fingerprint" do - expect(Gitlab::KeyFingerprint.new(key).fingerprint).to eq(fingerprint) + expect(described_class.new(key).fingerprint).to eq(fingerprint) end end end diff --git a/spec/lib/gitlab/ldap/access_spec.rb b/spec/lib/gitlab/ldap/access_spec.rb index f800e267568..6a47350be81 100644 --- a/spec/lib/gitlab/ldap/access_spec.rb +++ b/spec/lib/gitlab/ldap/access_spec.rb @@ -1,7 +1,7 @@ require 'spec_helper' describe Gitlab::LDAP::Access do - let(:access) { Gitlab::LDAP::Access.new user } + let(:access) { described_class.new user } let(:user) { create(:omniauth_user) } describe '.allowed?' do diff --git a/spec/lib/gitlab/ldap/auth_hash_spec.rb b/spec/lib/gitlab/ldap/auth_hash_spec.rb index bd546115afa..57a91193004 100644 --- a/spec/lib/gitlab/ldap/auth_hash_spec.rb +++ b/spec/lib/gitlab/ldap/auth_hash_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' describe Gitlab::LDAP::AuthHash do let(:auth_hash) do - Gitlab::LDAP::AuthHash.new( + described_class.new( OmniAuth::AuthHash.new( uid: '123456', provider: 'ldapmain', diff --git a/spec/lib/gitlab/ldap/config_spec.rb b/spec/lib/gitlab/ldap/config_spec.rb index 0d99ebf23e8..292ec064a67 100644 --- a/spec/lib/gitlab/ldap/config_spec.rb +++ b/spec/lib/gitlab/ldap/config_spec.rb @@ -3,11 +3,11 @@ require 'spec_helper' describe Gitlab::LDAP::Config do include LdapHelpers - let(:config) { Gitlab::LDAP::Config.new('ldapmain') } + let(:config) { described_class.new('ldapmain') } describe '#initialize' do it 'requires a provider' do - expect{ Gitlab::LDAP::Config.new }.to raise_error ArgumentError + expect{ described_class.new }.to raise_error ArgumentError end it 'works' do @@ -15,7 +15,7 @@ describe Gitlab::LDAP::Config do end it 'raises an error if a unknown provider is used' do - expect{ Gitlab::LDAP::Config.new 'unknown' }.to raise_error(RuntimeError) + expect{ described_class.new 'unknown' }.to raise_error(RuntimeError) end end diff --git a/spec/lib/gitlab/ldap/user_spec.rb b/spec/lib/gitlab/ldap/user_spec.rb index efc7a551761..175ceec44d7 100644 --- a/spec/lib/gitlab/ldap/user_spec.rb +++ b/spec/lib/gitlab/ldap/user_spec.rb @@ -1,7 +1,7 @@ require 'spec_helper' describe Gitlab::LDAP::User do - let(:ldap_user) { Gitlab::LDAP::User.new(auth_hash) } + let(:ldap_user) { described_class.new(auth_hash) } let(:gl_user) { ldap_user.gl_user } let(:info) do { @@ -13,7 +13,7 @@ describe Gitlab::LDAP::User do let(:auth_hash) do OmniAuth::AuthHash.new(uid: 'my-uid', provider: 'ldapmain', info: info) end - let(:ldap_user_upper_case) { Gitlab::LDAP::User.new(auth_hash_upper_case) } + let(:ldap_user_upper_case) { described_class.new(auth_hash_upper_case) } let(:info_upper_case) do { name: 'John', diff --git a/spec/lib/gitlab/markup_helper_spec.rb b/spec/lib/gitlab/markup_helper_spec.rb index e610fab05da..09e518ff989 100644 --- a/spec/lib/gitlab/markup_helper_spec.rb +++ b/spec/lib/gitlab/markup_helper_spec.rb @@ -5,36 +5,36 @@ describe Gitlab::MarkupHelper do %w(textile rdoc org creole wiki mediawiki rst adoc ad asciidoc mdown md markdown).each do |type| it "returns true for #{type} files" do - expect(Gitlab::MarkupHelper.markup?("README.#{type}")).to be_truthy + expect(described_class.markup?("README.#{type}")).to be_truthy end end it 'returns false when given a non-markup filename' do - expect(Gitlab::MarkupHelper.markup?('README.rb')).not_to be_truthy + expect(described_class.markup?('README.rb')).not_to be_truthy end end describe '#gitlab_markdown?' do %w(mdown mkd mkdn md markdown).each do |type| it "returns true for #{type} files" do - expect(Gitlab::MarkupHelper.gitlab_markdown?("README.#{type}")).to be_truthy + expect(described_class.gitlab_markdown?("README.#{type}")).to be_truthy end end it 'returns false when given a non-markdown filename' do - expect(Gitlab::MarkupHelper.gitlab_markdown?('README.rb')).not_to be_truthy + expect(described_class.gitlab_markdown?('README.rb')).not_to be_truthy end end describe '#asciidoc?' do %w(adoc ad asciidoc ADOC).each do |type| it "returns true for #{type} files" do - expect(Gitlab::MarkupHelper.asciidoc?("README.#{type}")).to be_truthy + expect(described_class.asciidoc?("README.#{type}")).to be_truthy end end it 'returns false when given a non-asciidoc filename' do - expect(Gitlab::MarkupHelper.asciidoc?('README.rb')).not_to be_truthy + expect(described_class.asciidoc?('README.rb')).not_to be_truthy end end end diff --git a/spec/lib/gitlab/o_auth/auth_hash_spec.rb b/spec/lib/gitlab/o_auth/auth_hash_spec.rb index 4b77e6473be..d5f4da3ce36 100644 --- a/spec/lib/gitlab/o_auth/auth_hash_spec.rb +++ b/spec/lib/gitlab/o_auth/auth_hash_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' describe Gitlab::OAuth::AuthHash do let(:auth_hash) do - Gitlab::OAuth::AuthHash.new( + described_class.new( OmniAuth::AuthHash.new( provider: provider_ascii, uid: uid_ascii, diff --git a/spec/lib/gitlab/o_auth/user_spec.rb b/spec/lib/gitlab/o_auth/user_spec.rb index b70e49e2602..47aa19d5fd9 100644 --- a/spec/lib/gitlab/o_auth/user_spec.rb +++ b/spec/lib/gitlab/o_auth/user_spec.rb @@ -1,7 +1,7 @@ require 'spec_helper' describe Gitlab::OAuth::User do - let(:oauth_user) { Gitlab::OAuth::User.new(auth_hash) } + let(:oauth_user) { described_class.new(auth_hash) } let(:gl_user) { oauth_user.gl_user } let(:uid) { 'my-uid' } let(:provider) { 'my-provider' } diff --git a/spec/lib/gitlab/project_transfer_spec.rb b/spec/lib/gitlab/project_transfer_spec.rb index ff943db1d9c..10c5fb148cd 100644 --- a/spec/lib/gitlab/project_transfer_spec.rb +++ b/spec/lib/gitlab/project_transfer_spec.rb @@ -3,7 +3,7 @@ require 'spec_helper' describe Gitlab::ProjectTransfer do before do @root_dir = File.join(Rails.root, "public", "uploads") - @project_transfer = Gitlab::ProjectTransfer.new + @project_transfer = described_class.new allow(@project_transfer).to receive(:root_dir).and_return(@root_dir) @project_path_was = "test_project_was" diff --git a/spec/lib/gitlab/reference_extractor_spec.rb b/spec/lib/gitlab/reference_extractor_spec.rb index e41e2faac15..1a0357534f2 100644 --- a/spec/lib/gitlab/reference_extractor_spec.rb +++ b/spec/lib/gitlab/reference_extractor_spec.rb @@ -7,7 +7,7 @@ describe Gitlab::ReferenceExtractor do project.team << [project.creator, :developer] end - subject { Gitlab::ReferenceExtractor.new(project, project.creator) } + subject { described_class.new(project, project.creator) } it 'accesses valid user objects' do @u_foo = create(:user, username: 'foo') diff --git a/spec/lib/gitlab/request_context_spec.rb b/spec/lib/gitlab/request_context_spec.rb index 16673ea313e..e272bdb9284 100644 --- a/spec/lib/gitlab/request_context_spec.rb +++ b/spec/lib/gitlab/request_context_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' describe Gitlab::RequestContext do describe '#client_ip' do - subject { Gitlab::RequestContext.client_ip } + subject { described_class.client_ip } let(:app) { -> (env) {} } let(:env) { Hash.new } @@ -16,7 +16,7 @@ describe Gitlab::RequestContext do before do allow_any_instance_of(Rack::Request).to receive(:ip).and_return(ip) - Gitlab::RequestContext.new(app).call(env) + described_class.new(app).call(env) end it { is_expected.to eq(ip) } diff --git a/spec/lib/gitlab/shell_spec.rb b/spec/lib/gitlab/shell_spec.rb index 8ab250a6203..b90d8dede0f 100644 --- a/spec/lib/gitlab/shell_spec.rb +++ b/spec/lib/gitlab/shell_spec.rb @@ -3,7 +3,7 @@ require 'stringio' describe Gitlab::Shell do let(:project) { double('Project', id: 7, path: 'diaspora') } - let(:gitlab_shell) { Gitlab::Shell.new } + let(:gitlab_shell) { described_class.new } let(:popen_vars) { { 'GIT_TERMINAL_PROMPT' => ENV['GIT_TERMINAL_PROMPT'] } } before do @@ -30,7 +30,7 @@ describe Gitlab::Shell do allow(Gitlab.config.gitlab_shell).to receive(:secret_file).and_return(secret_file) allow(Gitlab.config.gitlab_shell).to receive(:path).and_return('tmp/tests/shell-secret-test') FileUtils.mkdir('tmp/tests/shell-secret-test') - Gitlab::Shell.ensure_secret_token! + described_class.ensure_secret_token! end after do @@ -39,7 +39,7 @@ describe Gitlab::Shell do end it 'creates and links the secret token file' do - secret_token = Gitlab::Shell.secret_token + secret_token = described_class.secret_token expect(File.exist?(secret_file)).to be(true) expect(File.read(secret_file).chomp).to eq(secret_token) diff --git a/spec/lib/gitlab/upgrader_spec.rb b/spec/lib/gitlab/upgrader_spec.rb index eb128e343e6..6106f13c774 100644 --- a/spec/lib/gitlab/upgrader_spec.rb +++ b/spec/lib/gitlab/upgrader_spec.rb @@ -1,7 +1,7 @@ require 'spec_helper' describe Gitlab::Upgrader do - let(:upgrader) { Gitlab::Upgrader.new } + let(:upgrader) { described_class.new } let(:current_version) { Gitlab::VERSION } describe 'current_version_raw' do diff --git a/spec/lib/gitlab/user_access_spec.rb b/spec/lib/gitlab/user_access_spec.rb index 648c464db78..5ebaf6c1507 100644 --- a/spec/lib/gitlab/user_access_spec.rb +++ b/spec/lib/gitlab/user_access_spec.rb @@ -1,7 +1,7 @@ require 'spec_helper' describe Gitlab::UserAccess do - let(:access) { Gitlab::UserAccess.new(user, project: project) } + let(:access) { described_class.new(user, project: project) } let(:project) { create(:project) } let(:user) { create(:user) } @@ -28,7 +28,7 @@ describe Gitlab::UserAccess do describe 'push to empty project' do let(:empty_project) { create(:project_empty_repo) } - let(:project_access) { Gitlab::UserAccess.new(user, project: empty_project) } + let(:project_access) { described_class.new(user, project: empty_project) } it 'returns true if user is master' do empty_project.team << [user, :master] diff --git a/spec/lib/gitlab/workhorse_spec.rb b/spec/lib/gitlab/workhorse_spec.rb index c593e1db1bf..654397ccffb 100644 --- a/spec/lib/gitlab/workhorse_spec.rb +++ b/spec/lib/gitlab/workhorse_spec.rb @@ -63,13 +63,13 @@ describe Gitlab::Workhorse do end context 'without ca_pem' do - subject { Gitlab::Workhorse.terminal_websocket(terminal) } + subject { described_class.terminal_websocket(terminal) } it { is_expected.to eq(workhorse) } end context 'with ca_pem' do - subject { Gitlab::Workhorse.terminal_websocket(terminal(ca_pem: "foo")) } + subject { described_class.terminal_websocket(terminal(ca_pem: "foo")) } it { is_expected.to eq(workhorse(ca_pem: "foo")) } end diff --git a/spec/lib/repository_cache_spec.rb b/spec/lib/repository_cache_spec.rb index 41d1706ab6d..0c15ba22bf2 100644 --- a/spec/lib/repository_cache_spec.rb +++ b/spec/lib/repository_cache_spec.rb @@ -3,7 +3,7 @@ require 'spec_helper' describe RepositoryCache do let(:project) { create(:empty_project) } let(:backend) { double('backend').as_null_object } - let(:cache) { RepositoryCache.new('example', project.id, backend) } + let(:cache) { described_class.new('example', project.id, backend) } describe '#cache_key' do it 'includes the namespace' do diff --git a/spec/lib/system_check_spec.rb b/spec/lib/system_check_spec.rb index 9a75c41f783..4d9e17fa6ec 100644 --- a/spec/lib/system_check_spec.rb +++ b/spec/lib/system_check_spec.rb @@ -19,7 +19,7 @@ describe SystemCheck do end describe '.run' do - subject { SystemCheck } + subject { described_class } it 'detects execution of SimpleCheck' do is_expected.to execute_check(SimpleCheck) diff --git a/spec/models/ability_spec.rb b/spec/models/ability_spec.rb index cb57626b597..aa019288700 100644 --- a/spec/models/ability_spec.rb +++ b/spec/models/ability_spec.rb @@ -3,7 +3,7 @@ require 'spec_helper' describe Ability do context 'using a nil subject' do it 'has no permissions' do - expect(Ability.policy_for(nil, nil)).to be_banned + expect(described_class.policy_for(nil, nil)).to be_banned end end diff --git a/spec/models/application_setting_spec.rb b/spec/models/application_setting_spec.rb index 41129b945b6..359753b600e 100644 --- a/spec/models/application_setting_spec.rb +++ b/spec/models/application_setting_spec.rb @@ -1,7 +1,7 @@ require 'spec_helper' describe ApplicationSetting do - let(:setting) { ApplicationSetting.create_from_defaults } + let(:setting) { described_class.create_from_defaults } it { expect(setting).to be_valid } it { expect(setting.uuid).to be_present } @@ -159,10 +159,10 @@ describe ApplicationSetting do context 'redis unavailable' do it 'returns an ApplicationSetting' do allow(Rails.cache).to receive(:fetch).and_call_original - allow(ApplicationSetting).to receive(:last).and_return(:last) + allow(described_class).to receive(:last).and_return(:last) expect(Rails.cache).to receive(:fetch).with(ApplicationSetting::CACHE_KEY).and_raise(ArgumentError) - expect(ApplicationSetting.current).to eq(:last) + expect(described_class.current).to eq(:last) end end end diff --git a/spec/models/broadcast_message_spec.rb b/spec/models/broadcast_message_spec.rb index 75e7c7d42bd..a8ca1d110e4 100644 --- a/spec/models/broadcast_message_spec.rb +++ b/spec/models/broadcast_message_spec.rb @@ -24,26 +24,26 @@ describe BroadcastMessage do it 'returns message if time match' do message = create(:broadcast_message) - expect(BroadcastMessage.current).to include(message) + expect(described_class.current).to include(message) end it 'returns multiple messages if time match' do message1 = create(:broadcast_message) message2 = create(:broadcast_message) - expect(BroadcastMessage.current).to contain_exactly(message1, message2) + expect(described_class.current).to contain_exactly(message1, message2) end it 'returns empty list if time not come' do create(:broadcast_message, :future) - expect(BroadcastMessage.current).to be_empty + expect(described_class.current).to be_empty end it 'returns empty list if time has passed' do create(:broadcast_message, :expired) - expect(BroadcastMessage.current).to be_empty + expect(described_class.current).to be_empty end end diff --git a/spec/models/ci/pipeline_schedule_spec.rb b/spec/models/ci/pipeline_schedule_spec.rb index 3ae86ab2b4b..9a278212efc 100644 --- a/spec/models/ci/pipeline_schedule_spec.rb +++ b/spec/models/ci/pipeline_schedule_spec.rb @@ -46,7 +46,7 @@ describe Ci::PipelineSchedule do end it 'updates next_run_at automatically' do - expect(Ci::PipelineSchedule.last.next_run_at).to eq(expected_next_run_at) + expect(described_class.last.next_run_at).to eq(expected_next_run_at) end end @@ -61,7 +61,7 @@ describe Ci::PipelineSchedule do it 'updates next_run_at automatically' do pipeline_schedule.update!(cron: new_cron) - expect(Ci::PipelineSchedule.last.next_run_at).to eq(expected_next_run_at) + expect(described_class.last.next_run_at).to eq(expected_next_run_at) end end end diff --git a/spec/models/ci/runner_spec.rb b/spec/models/ci/runner_spec.rb index 9a4ed86990a..8d12a9c09ca 100644 --- a/spec/models/ci/runner_spec.rb +++ b/spec/models/ci/runner_spec.rb @@ -50,7 +50,7 @@ describe Ci::Runner do end describe '.online' do - subject { Ci::Runner.online } + subject { described_class.online } before do @runner1 = FactoryGirl.create(:ci_runner, :shared, contacted_at: 1.year.ago) @@ -352,13 +352,13 @@ describe Ci::Runner do end context 'does not give owned runner' do - subject { Ci::Runner.assignable_for(project) } + subject { described_class.assignable_for(project) } it { is_expected.to be_empty } end context 'does not give shared runner' do - subject { Ci::Runner.assignable_for(another_project) } + subject { described_class.assignable_for(another_project) } it { is_expected.to be_empty } end @@ -366,13 +366,13 @@ describe Ci::Runner do context 'with unlocked runner' do context 'does not give owned runner' do - subject { Ci::Runner.assignable_for(project) } + subject { described_class.assignable_for(project) } it { is_expected.to be_empty } end context 'does give a specific runner' do - subject { Ci::Runner.assignable_for(another_project) } + subject { described_class.assignable_for(another_project) } it { is_expected.to contain_exactly(runner) } end @@ -384,13 +384,13 @@ describe Ci::Runner do end context 'does not give owned runner' do - subject { Ci::Runner.assignable_for(project) } + subject { described_class.assignable_for(project) } it { is_expected.to be_empty } end context 'does not give a locked runner' do - subject { Ci::Runner.assignable_for(another_project) } + subject { described_class.assignable_for(another_project) } it { is_expected.to be_empty } end diff --git a/spec/models/global_milestone_spec.rb b/spec/models/global_milestone_spec.rb index 17462f70a6d..5584a1a5a31 100644 --- a/spec/models/global_milestone_spec.rb +++ b/spec/models/global_milestone_spec.rb @@ -72,7 +72,7 @@ describe GlobalMilestone do project3 ] - @global_milestones = GlobalMilestone.build_collection(projects, {}) + @global_milestones = described_class.build_collection(projects, {}) end it 'has all project milestones' do @@ -106,7 +106,7 @@ describe GlobalMilestone do it 'returns the quantity of global milestones in each possible state' do expected_count = { opened: 1, closed: 2, all: 2 } - count = GlobalMilestone.states_count(Project.all) + count = described_class.states_count(Project.all) expect(count).to eq(expected_count) end @@ -120,7 +120,7 @@ describe GlobalMilestone do it 'returns 0 as the quantity of global milestones in each state' do expected_count = { opened: 0, closed: 0, all: 0 } - count = GlobalMilestone.states_count(Project.all) + count = described_class.states_count(Project.all) expect(count).to eq(expected_count) end @@ -141,7 +141,7 @@ describe GlobalMilestone do ] milestones_relation = Milestone.where(id: milestones.map(&:id)) - @global_milestone = GlobalMilestone.new(milestone1_project1.title, milestones_relation) + @global_milestone = described_class.new(milestone1_project1.title, milestones_relation) end it 'has exactly one group milestone' do @@ -157,7 +157,7 @@ describe GlobalMilestone do let(:milestone) { create(:milestone, title: "git / test", project: project1) } it 'strips out slashes and spaces' do - global_milestone = GlobalMilestone.new(milestone.title, Milestone.where(id: milestone.id)) + global_milestone = described_class.new(milestone.title, Milestone.where(id: milestone.id)) expect(global_milestone.safe_title).to eq('git-test') end @@ -171,7 +171,7 @@ describe GlobalMilestone do create(:active_milestone, title: title), create(:closed_milestone, title: title) ] - global_milestone = GlobalMilestone.new(title, milestones) + global_milestone = described_class.new(title, milestones) expect(global_milestone.state).to eq('active') end @@ -184,7 +184,7 @@ describe GlobalMilestone do create(:closed_milestone, title: title), create(:closed_milestone, title: title) ] - global_milestone = GlobalMilestone.new(title, milestones) + global_milestone = described_class.new(title, milestones) expect(global_milestone.state).to eq('closed') end diff --git a/spec/models/group_milestone_spec.rb b/spec/models/group_milestone_spec.rb index 6d1a7f188c8..ac76c927c39 100644 --- a/spec/models/group_milestone_spec.rb +++ b/spec/models/group_milestone_spec.rb @@ -9,7 +9,7 @@ describe GroupMilestone do describe '.build' do it 'returns milestone with group assigned' do - milestone = GroupMilestone.build( + milestone = described_class.build( group, [project], project_milestone.title @@ -25,7 +25,7 @@ describe GroupMilestone do end it 'returns array of milestones, each with group assigned' do - milestones = GroupMilestone.build_collection(group, [project], {}) + milestones = described_class.build_collection(group, [project], {}) expect(milestones).to all(have_attributes(group: group)) end end diff --git a/spec/models/group_spec.rb b/spec/models/group_spec.rb index 3f66d9b0ab9..112bd605a64 100644 --- a/spec/models/group_spec.rb +++ b/spec/models/group_spec.rb @@ -357,7 +357,7 @@ describe Group do subject { build(:group, :nested) } it { is_expected.to be_valid } - it { expect(subject.parent).to be_kind_of(Group) } + it { expect(subject.parent).to be_kind_of(described_class) } end describe '#members_with_parents', :nested_groups do diff --git a/spec/models/guest_spec.rb b/spec/models/guest_spec.rb index ac9aaa76550..0e9b94aac97 100644 --- a/spec/models/guest_spec.rb +++ b/spec/models/guest_spec.rb @@ -8,13 +8,13 @@ describe Guest do describe '.can_pull?' do context 'when project is private' do it 'does not allow to pull the repo' do - expect(Guest.can?(:download_code, private_project)).to eq(false) + expect(described_class.can?(:download_code, private_project)).to eq(false) end end context 'when project is internal' do it 'does not allow to pull the repo' do - expect(Guest.can?(:download_code, internal_project)).to eq(false) + expect(described_class.can?(:download_code, internal_project)).to eq(false) end end @@ -23,7 +23,7 @@ describe Guest do it 'does not allow to pull the repo' do public_project.project_feature.update_attribute(:repository_access_level, ProjectFeature::DISABLED) - expect(Guest.can?(:download_code, public_project)).to eq(false) + expect(described_class.can?(:download_code, public_project)).to eq(false) end end @@ -31,13 +31,13 @@ describe Guest do it 'does not allow to pull the repo' do public_project.project_feature.update_attribute(:repository_access_level, ProjectFeature::PRIVATE) - expect(Guest.can?(:download_code, public_project)).to eq(false) + expect(described_class.can?(:download_code, public_project)).to eq(false) end end context 'when repository is enabled' do it 'allows to pull the repo' do - expect(Guest.can?(:download_code, public_project)).to eq(true) + expect(described_class.can?(:download_code, public_project)).to eq(true) end end end diff --git a/spec/models/hooks/project_hook_spec.rb b/spec/models/hooks/project_hook_spec.rb index c9b948fb747..5dd31b1b5de 100644 --- a/spec/models/hooks/project_hook_spec.rb +++ b/spec/models/hooks/project_hook_spec.rb @@ -13,7 +13,7 @@ describe ProjectHook do it 'returns hooks for push events only' do hook = create(:project_hook, push_events: true) create(:project_hook, push_events: false) - expect(ProjectHook.push_hooks).to eq([hook]) + expect(described_class.push_hooks).to eq([hook]) end end @@ -21,7 +21,7 @@ describe ProjectHook do it 'returns hooks for tag push events only' do hook = create(:project_hook, tag_push_events: true) create(:project_hook, tag_push_events: false) - expect(ProjectHook.tag_push_hooks).to eq([hook]) + expect(described_class.tag_push_hooks).to eq([hook]) end end end diff --git a/spec/models/hooks/system_hook_spec.rb b/spec/models/hooks/system_hook_spec.rb index 812dcb437f5..eadc232a989 100644 --- a/spec/models/hooks/system_hook_spec.rb +++ b/spec/models/hooks/system_hook_spec.rb @@ -122,7 +122,7 @@ describe SystemHook do it 'returns hooks for repository update events only' do hook = create(:system_hook, repository_update_events: true) create(:system_hook, repository_update_events: false) - expect(SystemHook.repository_update_hooks).to eq([hook]) + expect(described_class.repository_update_hooks).to eq([hook]) end end diff --git a/spec/models/member_spec.rb b/spec/models/member_spec.rb index 22e62ee0823..8bfd70b8d46 100644 --- a/spec/models/member_spec.rb +++ b/spec/models/member_spec.rb @@ -6,7 +6,7 @@ describe Member do end describe "Validation" do - subject { Member.new(access_level: Member::GUEST) } + subject { described_class.new(access_level: Member::GUEST) } it { is_expected.to validate_presence_of(:user) } it { is_expected.to validate_presence_of(:source) } diff --git a/spec/models/members/project_member_spec.rb b/spec/models/members/project_member_spec.rb index 93df1b2fb6c..025fb2bf441 100644 --- a/spec/models/members/project_member_spec.rb +++ b/spec/models/members/project_member_spec.rb @@ -139,7 +139,7 @@ describe ProjectMember do @project_1.team << [@user_1, :developer] @project_2.team << [@user_2, :reporter] - ProjectMember.truncate_teams([@project_1.id, @project_2.id]) + described_class.truncate_teams([@project_1.id, @project_2.id]) end it { expect(@project_1.users).to be_empty } diff --git a/spec/models/merge_request_diff_spec.rb b/spec/models/merge_request_diff_spec.rb index d09f880423b..0cfaa17676e 100644 --- a/spec/models/merge_request_diff_spec.rb +++ b/spec/models/merge_request_diff_spec.rb @@ -98,7 +98,7 @@ describe MergeRequestDiff do end it 'saves empty state' do - allow_any_instance_of(MergeRequestDiff).to receive_message_chain(:compare, :commits) + allow_any_instance_of(described_class).to receive_message_chain(:compare, :commits) .and_return([]) mr_diff = create(:merge_request).merge_request_diff diff --git a/spec/models/milestone_spec.rb b/spec/models/milestone_spec.rb index 0dd8a86106b..aa376e242e8 100644 --- a/spec/models/milestone_spec.rb +++ b/spec/models/milestone_spec.rb @@ -37,13 +37,13 @@ describe Milestone do describe "unique milestone title" do context "per project" do it "does not accept the same title in a project twice" do - new_milestone = Milestone.new(project: milestone.project, title: milestone.title) + new_milestone = described_class.new(project: milestone.project, title: milestone.title) expect(new_milestone).not_to be_valid end it "accepts the same title in another project" do project = create(:empty_project) - new_milestone = Milestone.new(project: project, title: milestone.title) + new_milestone = described_class.new(project: project, title: milestone.title) expect(new_milestone).to be_valid end @@ -58,7 +58,7 @@ describe Milestone do end it "does not accept the same title in a group twice" do - new_milestone = Milestone.new(group: group, title: milestone.title) + new_milestone = described_class.new(group: group, title: milestone.title) expect(new_milestone).not_to be_valid end @@ -66,7 +66,7 @@ describe Milestone do it "does not accept the same title of a child project milestone" do create(:milestone, project: group.projects.first) - new_milestone = Milestone.new(group: group, title: milestone.title) + new_milestone = described_class.new(group: group, title: milestone.title) expect(new_milestone).not_to be_valid end @@ -214,7 +214,7 @@ describe Milestone do # The call to `#try` is because this returns a relation with a Postgres DB, # and an array of IDs with a MySQL DB. - let(:milestone_ids) { Milestone.upcoming_ids_by_projects(projects).map { |id| id.try(:id) || id } } + let(:milestone_ids) { described_class.upcoming_ids_by_projects(projects).map { |id| id.try(:id) || id } } it 'returns the next upcoming open milestone ID for each project' do expect(milestone_ids).to contain_exactly(current_milestone_project_1.id, current_milestone_project_2.id) diff --git a/spec/models/namespace_spec.rb b/spec/models/namespace_spec.rb index 827356b660e..f12fe226e6b 100644 --- a/spec/models/namespace_spec.rb +++ b/spec/models/namespace_spec.rb @@ -133,7 +133,7 @@ describe Namespace do it "sums all project storage counters in the namespace" do project1 project2 - statistics = Namespace.with_statistics.find(namespace.id) + statistics = described_class.with_statistics.find(namespace.id) expect(statistics.storage_size).to eq 666 expect(statistics.repository_size).to eq 111 @@ -142,7 +142,7 @@ describe Namespace do end it "correctly handles namespaces without projects" do - statistics = Namespace.with_statistics.find(namespace.id) + statistics = described_class.with_statistics.find(namespace.id) expect(statistics.storage_size).to eq 0 expect(statistics.repository_size).to eq 0 @@ -286,9 +286,9 @@ describe Namespace do @namespace = create(:namespace, name: 'WoW', path: 'woW') end - it { expect(Namespace.find_by_path_or_name('wow')).to eq(@namespace) } - it { expect(Namespace.find_by_path_or_name('WOW')).to eq(@namespace) } - it { expect(Namespace.find_by_path_or_name('unknown')).to eq(nil) } + it { expect(described_class.find_by_path_or_name('wow')).to eq(@namespace) } + it { expect(described_class.find_by_path_or_name('WOW')).to eq(@namespace) } + it { expect(described_class.find_by_path_or_name('unknown')).to eq(nil) } end describe ".clean_path" do @@ -296,8 +296,8 @@ describe Namespace do let!(:namespace) { create(:namespace, path: "JohnGitLab-etc1") } it "cleans the path and makes sure it's available" do - expect(Namespace.clean_path("-john+gitlab-ETC%.git@gmail.com")).to eq("johngitlab-ETC2") - expect(Namespace.clean_path("--%+--valid_*&%name=.git.%.atom.atom.@email.com")).to eq("valid_name") + expect(described_class.clean_path("-john+gitlab-ETC%.git@gmail.com")).to eq("johngitlab-ETC2") + expect(described_class.clean_path("--%+--valid_*&%name=.git.%.atom.atom.@email.com")).to eq("valid_name") end end diff --git a/spec/models/note_spec.rb b/spec/models/note_spec.rb index d20816bc31f..cbe6d42ef53 100644 --- a/spec/models/note_spec.rb +++ b/spec/models/note_spec.rb @@ -525,7 +525,7 @@ describe Note do it "has a discussion id" do # The discussion_id is set in `after_initialize`, so `reload` won't work - reloaded_note = Note.find(note.id) + reloaded_note = described_class.find(note.id) expect(reloaded_note.discussion_id).not_to be_nil expect(reloaded_note.discussion_id).to match(/\A\h{40}\z/) diff --git a/spec/models/project_services/asana_service_spec.rb b/spec/models/project_services/asana_service_spec.rb index 3e568ec3dad..4684c970885 100644 --- a/spec/models/project_services/asana_service_spec.rb +++ b/spec/models/project_services/asana_service_spec.rb @@ -35,7 +35,7 @@ describe AsanaService do end before do - @asana = AsanaService.new + @asana = described_class.new allow(@asana).to receive_messages( project: project, project_id: project.id, diff --git a/spec/models/project_services/assembla_service_spec.rb b/spec/models/project_services/assembla_service_spec.rb index a06bd2de0eb..5cb6d63659e 100644 --- a/spec/models/project_services/assembla_service_spec.rb +++ b/spec/models/project_services/assembla_service_spec.rb @@ -11,7 +11,7 @@ describe AssemblaService do let(:project) { create(:project, :repository) } before do - @assembla_service = AssemblaService.new + @assembla_service = described_class.new allow(@assembla_service).to receive_messages( project_id: project.id, project: project, diff --git a/spec/models/project_services/campfire_service_spec.rb b/spec/models/project_services/campfire_service_spec.rb index 176850b4c72..ed8347edffd 100644 --- a/spec/models/project_services/campfire_service_spec.rb +++ b/spec/models/project_services/campfire_service_spec.rb @@ -29,7 +29,7 @@ describe CampfireService do let(:project) { create(:project, :repository) } before do - @campfire_service = CampfireService.new + @campfire_service = described_class.new allow(@campfire_service).to receive_messages( project_id: project.id, project: project, diff --git a/spec/models/project_services/flowdock_service_spec.rb b/spec/models/project_services/flowdock_service_spec.rb index e439abb45a4..5e8e880985e 100644 --- a/spec/models/project_services/flowdock_service_spec.rb +++ b/spec/models/project_services/flowdock_service_spec.rb @@ -29,7 +29,7 @@ describe FlowdockService do let(:project) { create(:project, :repository) } before do - @flowdock_service = FlowdockService.new + @flowdock_service = described_class.new allow(@flowdock_service).to receive_messages( project_id: project.id, project: project, diff --git a/spec/models/project_services/gemnasium_service_spec.rb b/spec/models/project_services/gemnasium_service_spec.rb index d89e7ee8a2a..4c61bc0af95 100644 --- a/spec/models/project_services/gemnasium_service_spec.rb +++ b/spec/models/project_services/gemnasium_service_spec.rb @@ -31,7 +31,7 @@ describe GemnasiumService do let(:project) { create(:project, :repository) } before do - @gemnasium_service = GemnasiumService.new + @gemnasium_service = described_class.new allow(@gemnasium_service).to receive_messages( project_id: project.id, project: project, diff --git a/spec/models/project_services/gitlab_issue_tracker_service_spec.rb b/spec/models/project_services/gitlab_issue_tracker_service_spec.rb index ff0f73eff4c..d19dab8fd39 100644 --- a/spec/models/project_services/gitlab_issue_tracker_service_spec.rb +++ b/spec/models/project_services/gitlab_issue_tracker_service_spec.rb @@ -27,7 +27,7 @@ describe GitlabIssueTrackerService do context 'with absolute urls' do before do - allow(GitlabIssueTrackerService).to receive(:default_url_options).and_return(script_name: "/gitlab/root") + allow(described_class).to receive(:default_url_options).and_return(script_name: "/gitlab/root") end it 'gives the correct path' do @@ -39,7 +39,7 @@ describe GitlabIssueTrackerService do context 'with relative urls' do before do - allow(GitlabIssueTrackerService).to receive(:default_url_options).and_return(script_name: "/gitlab/root") + allow(described_class).to receive(:default_url_options).and_return(script_name: "/gitlab/root") end it 'gives the correct path' do diff --git a/spec/models/project_services/hipchat_service_spec.rb b/spec/models/project_services/hipchat_service_spec.rb index f08e6c863a4..7614bb897e8 100644 --- a/spec/models/project_services/hipchat_service_spec.rb +++ b/spec/models/project_services/hipchat_service_spec.rb @@ -25,7 +25,7 @@ describe HipchatService do end describe "Execute" do - let(:hipchat) { HipchatService.new } + let(:hipchat) { described_class.new } let(:user) { create(:user) } let(:project) { create(:project, :repository) } let(:api_url) { 'https://hipchat.example.com/v2/room/123456/notification?auth_token=verySecret' } diff --git a/spec/models/project_services/irker_service_spec.rb b/spec/models/project_services/irker_service_spec.rb index ce2b26436b3..cb9ca76fc3f 100644 --- a/spec/models/project_services/irker_service_spec.rb +++ b/spec/models/project_services/irker_service_spec.rb @@ -27,7 +27,7 @@ describe IrkerService do end describe 'Execute' do - let(:irker) { IrkerService.new } + let(:irker) { described_class.new } let(:user) { create(:user) } let(:project) { create(:project, :repository) } let(:sample_data) do diff --git a/spec/models/project_services/jira_service_spec.rb b/spec/models/project_services/jira_service_spec.rb index 62e1d51104e..c9e8d7e194d 100644 --- a/spec/models/project_services/jira_service_spec.rb +++ b/spec/models/project_services/jira_service_spec.rb @@ -78,7 +78,7 @@ describe JiraService do let(:merge_request) { create(:merge_request) } before do - @jira_service = JiraService.new + @jira_service = described_class.new allow(@jira_service).to receive_messages( project_id: project.id, project: project, @@ -167,7 +167,7 @@ describe JiraService do stub_config_setting(relative_url_root: '/gitlab') stub_config_setting(url: Settings.send(:build_gitlab_url)) - allow(JiraService).to receive(:default_url_options) do + allow(described_class).to receive(:default_url_options) do { script_name: '/gitlab' } end @@ -220,7 +220,7 @@ describe JiraService do context "when a password was previously set" do before do - @jira_service = JiraService.create!( + @jira_service = described_class.create!( project: project, properties: { url: 'http://jira.example.com/web', @@ -301,7 +301,7 @@ describe JiraService do context 'when no password was previously set' do before do - @jira_service = JiraService.create( + @jira_service = described_class.create( project: project, properties: { url: 'http://jira.example.com/rest/api/2', diff --git a/spec/models/project_services/pivotaltracker_service_spec.rb b/spec/models/project_services/pivotaltracker_service_spec.rb index 002476c1a17..f7d2372eca2 100644 --- a/spec/models/project_services/pivotaltracker_service_spec.rb +++ b/spec/models/project_services/pivotaltracker_service_spec.rb @@ -26,7 +26,7 @@ describe PivotaltrackerService do describe 'Execute' do let(:service) do - PivotaltrackerService.new.tap do |service| + described_class.new.tap do |service| service.token = 'secret_api_token' end end diff --git a/spec/models/project_services/pushover_service_spec.rb b/spec/models/project_services/pushover_service_spec.rb index e77c4ddcc78..54b8c658ff6 100644 --- a/spec/models/project_services/pushover_service_spec.rb +++ b/spec/models/project_services/pushover_service_spec.rb @@ -29,7 +29,7 @@ describe PushoverService do end describe 'Execute' do - let(:pushover) { PushoverService.new } + let(:pushover) { described_class.new } let(:user) { create(:user) } let(:project) { create(:project, :repository) } let(:sample_data) do diff --git a/spec/models/project_spec.rb b/spec/models/project_spec.rb index 2df31a54628..473b7a88d61 100644 --- a/spec/models/project_spec.rb +++ b/spec/models/project_spec.rb @@ -77,7 +77,7 @@ describe Project do context 'after initialized' do it "has a project_feature" do - expect(Project.new.project_feature).to be_present + expect(described_class.new.project_feature).to be_present end end @@ -438,7 +438,7 @@ describe Project do end it 'returns valid url to repo' do - project = Project.new(path: 'somewhere') + project = described_class.new(path: 'somewhere') expect(project.url_to_repo).to eq(Gitlab.config.gitlab_shell.ssh_path_prefix + 'somewhere.git') end @@ -917,7 +917,7 @@ describe Project do end describe '.with_shared_runners' do - subject { Project.with_shared_runners } + subject { described_class.with_shared_runners } context 'when shared runners are enabled for project' do let!(:project) { create(:empty_project, shared_runners_enabled: true) } @@ -942,10 +942,10 @@ describe Project do let!(:project2) { create(:empty_project, :public, group: group) } it 'returns total project count' do - expect(Project).to receive(:count).once.and_call_original + expect(described_class).to receive(:count).once.and_call_original 3.times do - expect(Project.cached_count).to eq(2) + expect(described_class.cached_count).to eq(2) end end end @@ -990,7 +990,7 @@ describe Project do user1.toggle_star(project1) user2.toggle_star(project2) - expect(Project.starred_by(user1)).to contain_exactly(project1) + expect(described_class.starred_by(user1)).to contain_exactly(project1) end end @@ -2012,7 +2012,7 @@ describe Project do let!(:path) { project1.namespace.full_path } it 'returns correct project' do - expect(Project.inside_path(path)).to eq([project1]) + expect(described_class.inside_path(path)).to eq([project1]) end end @@ -2216,7 +2216,7 @@ describe Project do context 'with a user' do let(:projects) do - Project.all.public_or_visible_to_user(user) + described_class.all.public_or_visible_to_user(user) end it 'includes projects the user has access to' do @@ -2230,7 +2230,7 @@ describe Project do context 'without a user' do it 'only includes public projects' do - projects = Project.all.public_or_visible_to_user + projects = described_class.all.public_or_visible_to_user expect(projects).to eq([public_project]) end diff --git a/spec/models/project_wiki_spec.rb b/spec/models/project_wiki_spec.rb index fc1cdb3b1e6..7fcbeb459e0 100644 --- a/spec/models/project_wiki_spec.rb +++ b/spec/models/project_wiki_spec.rb @@ -5,7 +5,7 @@ describe ProjectWiki do let(:repository) { project.repository } let(:user) { project.owner } let(:gitlab_shell) { Gitlab::Shell.new } - let(:project_wiki) { ProjectWiki.new(project, user) } + let(:project_wiki) { described_class.new(project, user) } subject { project_wiki } diff --git a/spec/models/protected_branch_spec.rb b/spec/models/protected_branch_spec.rb index 6e8b07b44fb..a54af3bfe59 100644 --- a/spec/models/protected_branch_spec.rb +++ b/spec/models/protected_branch_spec.rb @@ -101,17 +101,17 @@ describe ProtectedBranch do production = create(:protected_branch, name: "production") staging = create(:protected_branch, name: "staging") - expect(ProtectedBranch.matching("production")).to include(production) - expect(ProtectedBranch.matching("production")).not_to include(staging) + expect(described_class.matching("production")).to include(production) + expect(described_class.matching("production")).not_to include(staging) end it "accepts a list of protected branches to search from, so as to avoid a DB call" do production = build(:protected_branch, name: "production") staging = build(:protected_branch, name: "staging") - expect(ProtectedBranch.matching("production")).to be_empty - expect(ProtectedBranch.matching("production", protected_refs: [production, staging])).to include(production) - expect(ProtectedBranch.matching("production", protected_refs: [production, staging])).not_to include(staging) + expect(described_class.matching("production")).to be_empty + expect(described_class.matching("production", protected_refs: [production, staging])).to include(production) + expect(described_class.matching("production", protected_refs: [production, staging])).not_to include(staging) end end @@ -120,17 +120,17 @@ describe ProtectedBranch do production = create(:protected_branch, name: "production/*") staging = create(:protected_branch, name: "staging/*") - expect(ProtectedBranch.matching("production/some-branch")).to include(production) - expect(ProtectedBranch.matching("production/some-branch")).not_to include(staging) + expect(described_class.matching("production/some-branch")).to include(production) + expect(described_class.matching("production/some-branch")).not_to include(staging) end it "accepts a list of protected branches to search from, so as to avoid a DB call" do production = build(:protected_branch, name: "production/*") staging = build(:protected_branch, name: "staging/*") - expect(ProtectedBranch.matching("production/some-branch")).to be_empty - expect(ProtectedBranch.matching("production/some-branch", protected_refs: [production, staging])).to include(production) - expect(ProtectedBranch.matching("production/some-branch", protected_refs: [production, staging])).not_to include(staging) + expect(described_class.matching("production/some-branch")).to be_empty + expect(described_class.matching("production/some-branch", protected_refs: [production, staging])).to include(production) + expect(described_class.matching("production/some-branch", protected_refs: [production, staging])).not_to include(staging) end end end @@ -142,23 +142,23 @@ describe ProtectedBranch do it 'returns true when the branch matches a protected branch via direct match' do create(:protected_branch, project: project, name: "foo") - expect(ProtectedBranch.protected?(project, 'foo')).to eq(true) + expect(described_class.protected?(project, 'foo')).to eq(true) end it 'returns true when the branch matches a protected branch via wildcard match' do create(:protected_branch, project: project, name: "production/*") - expect(ProtectedBranch.protected?(project, 'production/some-branch')).to eq(true) + expect(described_class.protected?(project, 'production/some-branch')).to eq(true) end it 'returns false when the branch does not match a protected branch via direct match' do - expect(ProtectedBranch.protected?(project, 'foo')).to eq(false) + expect(described_class.protected?(project, 'foo')).to eq(false) end it 'returns false when the branch does not match a protected branch via wildcard match' do create(:protected_branch, project: project, name: "production/*") - expect(ProtectedBranch.protected?(project, 'staging/some-branch')).to eq(false) + expect(described_class.protected?(project, 'staging/some-branch')).to eq(false) end end @@ -168,25 +168,25 @@ describe ProtectedBranch do it 'returns false when default_protected_branch is unprotected' do stub_application_setting(default_branch_protection: Gitlab::Access::PROTECTION_NONE) - expect(ProtectedBranch.protected?(project, 'master')).to be false + expect(described_class.protected?(project, 'master')).to be false end it 'returns false when default_protected_branch lets developers push' do stub_application_setting(default_branch_protection: Gitlab::Access::PROTECTION_DEV_CAN_PUSH) - expect(ProtectedBranch.protected?(project, 'master')).to be false + expect(described_class.protected?(project, 'master')).to be false end it 'returns true when default_branch_protection does not let developers push but let developer merge branches' do stub_application_setting(default_branch_protection: Gitlab::Access::PROTECTION_DEV_CAN_MERGE) - expect(ProtectedBranch.protected?(project, 'master')).to be true + expect(described_class.protected?(project, 'master')).to be true end it 'returns true when default_branch_protection is in full protection' do stub_application_setting(default_branch_protection: Gitlab::Access::PROTECTION_FULL) - expect(ProtectedBranch.protected?(project, 'master')).to be true + expect(described_class.protected?(project, 'master')).to be true end end end diff --git a/spec/models/redirect_route_spec.rb b/spec/models/redirect_route_spec.rb index 37948ea3f86..80943877095 100644 --- a/spec/models/redirect_route_spec.rb +++ b/spec/models/redirect_route_spec.rb @@ -21,7 +21,7 @@ describe RedirectRoute do let!(:redirect5) { group.redirect_routes.create(path: 'gitlabb/test/baz') } it 'returns correct routes' do - expect(RedirectRoute.matching_path_and_descendants('gitlabb/test')).to match_array([redirect2, redirect3, redirect4, redirect5]) + expect(described_class.matching_path_and_descendants('gitlabb/test')).to match_array([redirect2, redirect3, redirect4, redirect5]) end end end diff --git a/spec/models/route_spec.rb b/spec/models/route_spec.rb index 32cd5d1d944..bdacc60fb53 100644 --- a/spec/models/route_spec.rb +++ b/spec/models/route_spec.rb @@ -34,7 +34,7 @@ describe Route do context 'after create' do it 'calls #delete_conflicting_redirects' do route.destroy - new_route = Route.new(source: group, path: group.path) + new_route = described_class.new(source: group, path: group.path) expect(new_route).to receive(:delete_conflicting_redirects) new_route.save! end @@ -49,7 +49,7 @@ describe Route do let!(:another_group_nested) { create(:group, path: 'another', name: 'another', parent: similar_group) } it 'returns correct routes' do - expect(Route.inside_path('git_lab')).to match_array([nested_group.route, deep_nested_group.route]) + expect(described_class.inside_path('git_lab')).to match_array([nested_group.route, deep_nested_group.route]) end end diff --git a/spec/models/sent_notification_spec.rb b/spec/models/sent_notification_spec.rb index 823cdb853eb..8b6b02916ae 100644 --- a/spec/models/sent_notification_spec.rb +++ b/spec/models/sent_notification_spec.rb @@ -38,7 +38,7 @@ describe SentNotification do let(:issue) { create(:issue) } it 'creates a new SentNotification' do - expect { described_class.record(issue, user.id) }.to change { SentNotification.count }.by(1) + expect { described_class.record(issue, user.id) }.to change { described_class.count }.by(1) end end @@ -47,7 +47,7 @@ describe SentNotification do let(:note) { create(:diff_note_on_merge_request) } it 'creates a new SentNotification' do - expect { described_class.record_note(note, user.id) }.to change { SentNotification.count }.by(1) + expect { described_class.record_note(note, user.id) }.to change { described_class.count }.by(1) end end diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb index 105d41957c3..71aadbb4186 100644 --- a/spec/models/user_spec.rb +++ b/spec/models/user_spec.rb @@ -261,7 +261,7 @@ describe User do it "returns users with 2fa enabled via OTP" do user_with_2fa = create(:user, :two_factor_via_otp) user_without_2fa = create(:user) - users_with_two_factor = User.with_two_factor.pluck(:id) + users_with_two_factor = described_class.with_two_factor.pluck(:id) expect(users_with_two_factor).to include(user_with_2fa.id) expect(users_with_two_factor).not_to include(user_without_2fa.id) @@ -270,7 +270,7 @@ describe User do it "returns users with 2fa enabled via U2F" do user_with_2fa = create(:user, :two_factor_via_u2f) user_without_2fa = create(:user) - users_with_two_factor = User.with_two_factor.pluck(:id) + users_with_two_factor = described_class.with_two_factor.pluck(:id) expect(users_with_two_factor).to include(user_with_2fa.id) expect(users_with_two_factor).not_to include(user_without_2fa.id) @@ -279,7 +279,7 @@ describe User do it "returns users with 2fa enabled via OTP and U2F" do user_with_2fa = create(:user, :two_factor_via_otp, :two_factor_via_u2f) user_without_2fa = create(:user) - users_with_two_factor = User.with_two_factor.pluck(:id) + users_with_two_factor = described_class.with_two_factor.pluck(:id) expect(users_with_two_factor).to eq([user_with_2fa.id]) expect(users_with_two_factor).not_to include(user_without_2fa.id) @@ -290,7 +290,7 @@ describe User do it "excludes users with 2fa enabled via OTP" do user_with_2fa = create(:user, :two_factor_via_otp) user_without_2fa = create(:user) - users_without_two_factor = User.without_two_factor.pluck(:id) + users_without_two_factor = described_class.without_two_factor.pluck(:id) expect(users_without_two_factor).to include(user_without_2fa.id) expect(users_without_two_factor).not_to include(user_with_2fa.id) @@ -299,7 +299,7 @@ describe User do it "excludes users with 2fa enabled via U2F" do user_with_2fa = create(:user, :two_factor_via_u2f) user_without_2fa = create(:user) - users_without_two_factor = User.without_two_factor.pluck(:id) + users_without_two_factor = described_class.without_two_factor.pluck(:id) expect(users_without_two_factor).to include(user_without_2fa.id) expect(users_without_two_factor).not_to include(user_with_2fa.id) @@ -308,7 +308,7 @@ describe User do it "excludes users with 2fa enabled via OTP and U2F" do user_with_2fa = create(:user, :two_factor_via_otp, :two_factor_via_u2f) user_without_2fa = create(:user) - users_without_two_factor = User.without_two_factor.pluck(:id) + users_without_two_factor = described_class.without_two_factor.pluck(:id) expect(users_without_two_factor).to include(user_without_2fa.id) expect(users_without_two_factor).not_to include(user_with_2fa.id) @@ -324,8 +324,8 @@ describe User do create(:todo, user: current_user, author: user_2, state: :done) create(:todo, user: current_user, author: user_3, state: :pending) - expect(User.todo_authors(current_user.id, 'pending')).to eq [user_3] - expect(User.todo_authors(current_user.id, 'done')).to eq [user_2] + expect(described_class.todo_authors(current_user.id, 'pending')).to eq [user_3] + expect(described_class.todo_authors(current_user.id, 'done')).to eq [user_2] end end end @@ -609,39 +609,39 @@ describe User do let(:user) { double } it 'filters by active users by default' do - expect(User).to receive(:active).and_return([user]) + expect(described_class).to receive(:active).and_return([user]) - expect(User.filter(nil)).to include user + expect(described_class.filter(nil)).to include user end it 'filters by admins' do - expect(User).to receive(:admins).and_return([user]) + expect(described_class).to receive(:admins).and_return([user]) - expect(User.filter('admins')).to include user + expect(described_class.filter('admins')).to include user end it 'filters by blocked' do - expect(User).to receive(:blocked).and_return([user]) + expect(described_class).to receive(:blocked).and_return([user]) - expect(User.filter('blocked')).to include user + expect(described_class.filter('blocked')).to include user end it 'filters by two_factor_disabled' do - expect(User).to receive(:without_two_factor).and_return([user]) + expect(described_class).to receive(:without_two_factor).and_return([user]) - expect(User.filter('two_factor_disabled')).to include user + expect(described_class.filter('two_factor_disabled')).to include user end it 'filters by two_factor_enabled' do - expect(User).to receive(:with_two_factor).and_return([user]) + expect(described_class).to receive(:with_two_factor).and_return([user]) - expect(User.filter('two_factor_enabled')).to include user + expect(described_class.filter('two_factor_enabled')).to include user end it 'filters by wop' do - expect(User).to receive(:without_projects).and_return([user]) + expect(described_class).to receive(:without_projects).and_return([user]) - expect(User.filter('wop')).to include user + expect(described_class.filter('wop')).to include user end end @@ -662,9 +662,9 @@ describe User do project.request_access(user_without_project2) end - it { expect(User.without_projects).not_to include user } - it { expect(User.without_projects).to include user_without_project } - it { expect(User.without_projects).to include user_without_project2 } + it { expect(described_class.without_projects).not_to include user } + it { expect(described_class.without_projects).to include user_without_project } + it { expect(described_class.without_projects).to include user_without_project2 } end describe 'user creation' do @@ -680,7 +680,7 @@ describe User do end describe 'with defaults' do - let(:user) { User.new } + let(:user) { described_class.new } it "applies defaults to user" do expect(user.projects_limit).to eq(Gitlab.config.gitlab.default_projects_limit) @@ -690,7 +690,7 @@ describe User do end describe 'with default overrides' do - let(:user) { User.new(projects_limit: 123, can_create_group: false, can_create_team: true) } + let(:user) { described_class.new(projects_limit: 123, can_create_group: false, can_create_team: true) } it "applies defaults to user" do expect(user.projects_limit).to eq(123) @@ -740,18 +740,18 @@ describe User do it 'finds by primary email' do user = create(:user, email: 'foo@example.com') - expect(User.find_by_any_email(user.email)).to eq user + expect(described_class.find_by_any_email(user.email)).to eq user end it 'finds by secondary email' do email = create(:email, email: 'foo@example.com') user = email.user - expect(User.find_by_any_email(email.email)).to eq user + expect(described_class.find_by_any_email(email.email)).to eq user end it 'returns nil when nothing found' do - expect(User.find_by_any_email('')).to be_nil + expect(described_class.find_by_any_email('')).to be_nil end end @@ -899,12 +899,12 @@ describe User do let!(:user) { create(:user, username: username) } it 'gets the correct user' do - expect(User.by_login(user.email.upcase)).to eq user - expect(User.by_login(user.email)).to eq user - expect(User.by_login(username.downcase)).to eq user - expect(User.by_login(username)).to eq user - expect(User.by_login(nil)).to be_nil - expect(User.by_login('')).to be_nil + expect(described_class.by_login(user.email.upcase)).to eq user + expect(described_class.by_login(user.email)).to eq user + expect(described_class.by_login(username.downcase)).to eq user + expect(described_class.by_login(username)).to eq user + expect(described_class.by_login(nil)).to be_nil + expect(described_class.by_login('')).to be_nil end end @@ -938,12 +938,12 @@ describe User do let!(:route) { user.namespace.route } it 'returns the user' do - expect(User.find_by_full_path(route.path)).to eq(user) + expect(described_class.find_by_full_path(route.path)).to eq(user) end it 'is case-insensitive' do - expect(User.find_by_full_path(route.path.upcase)).to eq(user) - expect(User.find_by_full_path(route.path.downcase)).to eq(user) + expect(described_class.find_by_full_path(route.path.upcase)).to eq(user) + expect(described_class.find_by_full_path(route.path.downcase)).to eq(user) end end @@ -952,18 +952,18 @@ describe User do context 'without the follow_redirects option' do it 'returns nil' do - expect(User.find_by_full_path(redirect_route.path)).to eq(nil) + expect(described_class.find_by_full_path(redirect_route.path)).to eq(nil) end end context 'with the follow_redirects option set to true' do it 'returns the user' do - expect(User.find_by_full_path(redirect_route.path, follow_redirects: true)).to eq(user) + expect(described_class.find_by_full_path(redirect_route.path, follow_redirects: true)).to eq(user) end it 'is case-insensitive' do - expect(User.find_by_full_path(redirect_route.path.upcase, follow_redirects: true)).to eq(user) - expect(User.find_by_full_path(redirect_route.path.downcase, follow_redirects: true)).to eq(user) + expect(described_class.find_by_full_path(redirect_route.path.upcase, follow_redirects: true)).to eq(user) + expect(described_class.find_by_full_path(redirect_route.path.downcase, follow_redirects: true)).to eq(user) end end end @@ -971,12 +971,12 @@ describe User do context 'without a route or a redirect route matching the given path' do context 'without the follow_redirects option' do it 'returns nil' do - expect(User.find_by_full_path('unknown')).to eq(nil) + expect(described_class.find_by_full_path('unknown')).to eq(nil) end end context 'with the follow_redirects option set to true' do it 'returns nil' do - expect(User.find_by_full_path('unknown', follow_redirects: true)).to eq(nil) + expect(described_class.find_by_full_path('unknown', follow_redirects: true)).to eq(nil) end end end @@ -986,7 +986,7 @@ describe User do let!(:group) { create(:group, path: 'group_path', owner: user) } it 'returns nil' do - expect(User.find_by_full_path('group_path')).to eq(nil) + expect(described_class.find_by_full_path('group_path')).to eq(nil) end end @@ -994,7 +994,7 @@ describe User do let!(:group) { create(:group, path: 'group_path') } it 'returns nil' do - expect(User.find_by_full_path('group_path')).to eq(nil) + expect(described_class.find_by_full_path('group_path')).to eq(nil) end end end @@ -1044,7 +1044,7 @@ describe User do end describe '#requires_ldap_check?' do - let(:user) { User.new } + let(:user) { described_class.new } it 'is false when LDAP is disabled' do # Create a condition which would otherwise cause 'true' to be returned @@ -1215,7 +1215,7 @@ describe User do describe '#sort' do before do - User.delete_all + described_class.delete_all @user = create :user, created_at: Date.today, last_sign_in_at: Date.today, name: 'Alpha' @user1 = create :user, created_at: Date.today - 1, last_sign_in_at: Date.today - 1, name: 'Omega' @user2 = create :user, created_at: Date.today - 2, last_sign_in_at: nil, name: 'Beta' @@ -1223,34 +1223,34 @@ describe User do context 'when sort by recent_sign_in' do it 'sorts users by the recent sign-in time' do - expect(User.sort('recent_sign_in').first).to eq(@user) + expect(described_class.sort('recent_sign_in').first).to eq(@user) end it 'pushes users who never signed in to the end' do - expect(User.sort('recent_sign_in').third).to eq(@user2) + expect(described_class.sort('recent_sign_in').third).to eq(@user2) end end context 'when sort by oldest_sign_in' do it 'sorts users by the oldest sign-in time' do - expect(User.sort('oldest_sign_in').first).to eq(@user1) + expect(described_class.sort('oldest_sign_in').first).to eq(@user1) end it 'pushes users who never signed in to the end' do - expect(User.sort('oldest_sign_in').third).to eq(@user2) + expect(described_class.sort('oldest_sign_in').third).to eq(@user2) end end it 'sorts users in descending order by their creation time' do - expect(User.sort('created_desc').first).to eq(@user) + expect(described_class.sort('created_desc').first).to eq(@user) end it 'sorts users in ascending order by their creation time' do - expect(User.sort('created_asc').first).to eq(@user2) + expect(described_class.sort('created_asc').first).to eq(@user2) end it 'sorts users by id in descending order when nil is passed' do - expect(User.sort(nil).first).to eq(@user2) + expect(described_class.sort(nil).first).to eq(@user2) end end @@ -1770,7 +1770,7 @@ describe User do describe '.ghost' do it "creates a ghost user if one isn't already present" do - ghost = User.ghost + ghost = described_class.ghost expect(ghost).to be_ghost expect(ghost).to be_persisted @@ -1778,16 +1778,16 @@ describe User do it "does not create a second ghost user if one is already present" do expect do - User.ghost - User.ghost - end.to change { User.count }.by(1) - expect(User.ghost).to eq(User.ghost) + described_class.ghost + described_class.ghost + end.to change { described_class.count }.by(1) + expect(described_class.ghost).to eq(described_class.ghost) end context "when a regular user exists with the username 'ghost'" do it "creates a ghost user with a non-conflicting username" do create(:user, username: 'ghost') - ghost = User.ghost + ghost = described_class.ghost expect(ghost).to be_persisted expect(ghost.username).to eq('ghost1') @@ -1797,7 +1797,7 @@ describe User do context "when a regular user exists with the email 'ghost@example.com'" do it "creates a ghost user with a non-conflicting email" do create(:user, email: 'ghost@example.com') - ghost = User.ghost + ghost = described_class.ghost expect(ghost).to be_persisted expect(ghost.email).to eq('ghost1@example.com') @@ -1810,7 +1810,7 @@ describe User do end it 'creates a ghost user' do - expect(User.ghost).to be_persisted + expect(described_class.ghost).to be_persisted end end end @@ -1889,13 +1889,13 @@ describe User do context '.active' do before do - User.ghost + described_class.ghost create(:user, name: 'user', state: 'active') create(:user, name: 'user', state: 'blocked') end it 'only counts active and non internal users' do - expect(User.active.count).to eq(1) + expect(described_class.active.count).to eq(1) end end diff --git a/spec/models/wiki_directory_spec.rb b/spec/models/wiki_directory_spec.rb index c3c62c42b35..fb8575cfe2b 100644 --- a/spec/models/wiki_directory_spec.rb +++ b/spec/models/wiki_directory_spec.rb @@ -10,7 +10,7 @@ RSpec.describe WikiDirectory do describe '#initialize' do context 'when there are pages' do let(:pages) { [build(:wiki_page)] } - let(:directory) { WikiDirectory.new('/path_up_to/dir', pages) } + let(:directory) { described_class.new('/path_up_to/dir', pages) } it 'sets the slug attribute' do expect(directory.slug).to eq('/path_up_to/dir') @@ -22,7 +22,7 @@ RSpec.describe WikiDirectory do end context 'when there are no pages' do - let(:directory) { WikiDirectory.new('/path_up_to/dir') } + let(:directory) { described_class.new('/path_up_to/dir') } it 'sets the slug attribute' do expect(directory.slug).to eq('/path_up_to/dir') diff --git a/spec/models/wiki_page_spec.rb b/spec/models/wiki_page_spec.rb index 77506a78459..90ad3cdeb93 100644 --- a/spec/models/wiki_page_spec.rb +++ b/spec/models/wiki_page_spec.rb @@ -5,13 +5,13 @@ describe WikiPage do let(:user) { project.owner } let(:wiki) { ProjectWiki.new(project, user) } - subject { WikiPage.new(wiki) } + subject { described_class.new(wiki) } describe '.group_by_directory' do context 'when there are no pages' do it 'returns an empty array' do - expect(WikiPage.group_by_directory(nil)).to eq([]) - expect(WikiPage.group_by_directory([])).to eq([]) + expect(described_class.group_by_directory(nil)).to eq([]) + expect(described_class.group_by_directory([])).to eq([]) end end @@ -39,7 +39,7 @@ describe WikiPage do it 'returns an array with pages and directories' do expected_grouped_entries = [page_1, dir_1, dir_1_1, dir_2] - grouped_entries = WikiPage.group_by_directory(wiki.pages) + grouped_entries = described_class.group_by_directory(wiki.pages) grouped_entries.each_with_index do |page_or_dir, i| expected_page_or_dir = expected_grouped_entries[i] @@ -56,7 +56,7 @@ describe WikiPage do expected_order = ['page_1', 'dir_1/page_2', 'dir_1/dir_1_1/page_3', 'dir_2/page_4', 'dir_2/page_5'] - grouped_entries = WikiPage.group_by_directory(wiki.pages) + grouped_entries = described_class.group_by_directory(wiki.pages) actual_order = grouped_entries.map do |page_or_dir| @@ -72,7 +72,7 @@ describe WikiPage do it 'removes hyphens from a name' do name = 'a-name--with-hyphens' - expect(WikiPage.unhyphenize(name)).to eq('a name with hyphens') + expect(described_class.unhyphenize(name)).to eq('a name with hyphens') end end @@ -81,7 +81,7 @@ describe WikiPage do before do create_page("test page", "test content") @page = wiki.wiki.paged("test page") - @wiki_page = WikiPage.new(wiki, @page, true) + @wiki_page = described_class.new(wiki, @page, true) end it "sets the slug attribute" do diff --git a/spec/policies/global_policy_spec.rb b/spec/policies/global_policy_spec.rb index 2a590e12232..a6bf70c1e09 100644 --- a/spec/policies/global_policy_spec.rb +++ b/spec/policies/global_policy_spec.rb @@ -4,7 +4,7 @@ describe GlobalPolicy do let(:current_user) { create(:user) } let(:user) { create(:user) } - subject { GlobalPolicy.new(current_user, [user]) } + subject { described_class.new(current_user, [user]) } describe "reading the list of users" do context "for a logged in user" do diff --git a/spec/policies/user_policy_spec.rb b/spec/policies/user_policy_spec.rb index 67ab239e4c8..6593a6ca3b9 100644 --- a/spec/policies/user_policy_spec.rb +++ b/spec/policies/user_policy_spec.rb @@ -4,7 +4,7 @@ describe UserPolicy do let(:current_user) { create(:user) } let(:user) { create(:user) } - subject { UserPolicy.new(current_user, user) } + subject { described_class.new(current_user, user) } describe "reading a user's information" do it { is_expected.to be_allowed(:read_user) } diff --git a/spec/services/create_release_service_spec.rb b/spec/services/create_release_service_spec.rb index e4d1c1a8f9d..ac0a0458f56 100644 --- a/spec/services/create_release_service_spec.rb +++ b/spec/services/create_release_service_spec.rb @@ -5,7 +5,7 @@ describe CreateReleaseService do let(:user) { create(:user) } let(:tag_name) { project.repository.tag_names.first } let(:description) { 'Awesome release!' } - let(:service) { CreateReleaseService.new(project, user) } + let(:service) { described_class.new(project, user) } it 'creates a new release' do result = service.execute(tag_name, description) diff --git a/spec/services/event_create_service_spec.rb b/spec/services/event_create_service_spec.rb index 561b9d14a0f..00104ae1fd9 100644 --- a/spec/services/event_create_service_spec.rb +++ b/spec/services/event_create_service_spec.rb @@ -3,7 +3,7 @@ require 'spec_helper' describe EventCreateService do include UserActivitiesHelpers - let(:service) { EventCreateService.new } + let(:service) { described_class.new } describe 'Issues' do describe '#open_issue' do diff --git a/spec/services/git_hooks_service_spec.rb b/spec/services/git_hooks_service_spec.rb index f1242df7e93..3ce01a995b4 100644 --- a/spec/services/git_hooks_service_spec.rb +++ b/spec/services/git_hooks_service_spec.rb @@ -5,7 +5,7 @@ describe GitHooksService do let(:user) { create(:user) } let(:project) { create(:project, :repository) } - let(:service) { GitHooksService.new } + let(:service) { described_class.new } before do @blankrev = Gitlab::Git::BLANK_SHA diff --git a/spec/services/git_tag_push_service_spec.rb b/spec/services/git_tag_push_service_spec.rb index d2baeb7b746..f877c145390 100644 --- a/spec/services/git_tag_push_service_spec.rb +++ b/spec/services/git_tag_push_service_spec.rb @@ -5,7 +5,7 @@ describe GitTagPushService do let(:user) { create(:user) } let(:project) { create(:project, :repository) } - let(:service) { GitTagPushService.new(project, user, oldrev: oldrev, newrev: newrev, ref: ref) } + let(:service) { described_class.new(project, user, oldrev: oldrev, newrev: newrev, ref: ref) } let(:oldrev) { Gitlab::Git::BLANK_SHA } let(:newrev) { "8a2a6eb295bb170b34c24c76c49ed0e9b2eaf34b" } # gitlab-test: git rev-parse refs/tags/v1.1.0 @@ -184,7 +184,7 @@ describe GitTagPushService do describe "Webhooks" do context "execute webhooks" do - let(:service) { GitTagPushService.new(project, user, oldrev: 'oldrev', newrev: 'newrev', ref: 'refs/tags/v1.0.0') } + let(:service) { described_class.new(project, user, oldrev: 'oldrev', newrev: 'newrev', ref: 'refs/tags/v1.0.0') } it "when pushing tags" do expect(project).to receive(:execute_hooks) diff --git a/spec/services/groups/destroy_service_spec.rb b/spec/services/groups/destroy_service_spec.rb index b3ceb5428cd..3e7aa8c835c 100644 --- a/spec/services/groups/destroy_service_spec.rb +++ b/spec/services/groups/destroy_service_spec.rb @@ -100,7 +100,7 @@ describe Groups::DestroyService do # Kick off the initial group destroy in a new thread, so that # it doesn't share this spec's database transaction. - Thread.new { Groups::DestroyService.new(group, user).async_execute }.join(5) + Thread.new { described_class.new(group, user).async_execute }.join(5) group_record = run_with_new_database_connection do |conn| conn.execute("SELECT * FROM namespaces WHERE id = #{group.id}").first diff --git a/spec/services/issues/update_service_spec.rb b/spec/services/issues/update_service_spec.rb index 17d4a072e3d..eec2096fa34 100644 --- a/spec/services/issues/update_service_spec.rb +++ b/spec/services/issues/update_service_spec.rb @@ -488,7 +488,7 @@ describe Issues::UpdateService do context 'updating mentions' do let(:mentionable) { issue } - include_examples 'updating mentions', Issues::UpdateService + include_examples 'updating mentions', described_class end context 'duplicate issue' do diff --git a/spec/services/labels/create_service_spec.rb b/spec/services/labels/create_service_spec.rb index 0fa7b5199fe..ecb88653001 100644 --- a/spec/services/labels/create_service_spec.rb +++ b/spec/services/labels/create_service_spec.rb @@ -17,7 +17,7 @@ describe Labels::CreateService do context 'in a project' do context 'with color in hex-code' do it 'creates a label' do - label = Labels::CreateService.new(params_with(hex_color)).execute(project: project) + label = described_class.new(params_with(hex_color)).execute(project: project) expect(label).to be_persisted expect(label.color).to eq expected_saved_color @@ -26,7 +26,7 @@ describe Labels::CreateService do context 'with color in allowed name' do it 'creates a label' do - label = Labels::CreateService.new(params_with(named_color)).execute(project: project) + label = described_class.new(params_with(named_color)).execute(project: project) expect(label).to be_persisted expect(label.color).to eq expected_saved_color @@ -35,7 +35,7 @@ describe Labels::CreateService do context 'with color in up-case allowed name' do it 'creates a label' do - label = Labels::CreateService.new(params_with(upcase_color)).execute(project: project) + label = described_class.new(params_with(upcase_color)).execute(project: project) expect(label).to be_persisted expect(label.color).to eq expected_saved_color @@ -44,7 +44,7 @@ describe Labels::CreateService do context 'with color surrounded by spaces' do it 'creates a label' do - label = Labels::CreateService.new(params_with(spaced_color)).execute(project: project) + label = described_class.new(params_with(spaced_color)).execute(project: project) expect(label).to be_persisted expect(label.color).to eq expected_saved_color @@ -53,7 +53,7 @@ describe Labels::CreateService do context 'with unknown color' do it 'doesn\'t create a label' do - label = Labels::CreateService.new(params_with(unknown_color)).execute(project: project) + label = described_class.new(params_with(unknown_color)).execute(project: project) expect(label).not_to be_persisted end @@ -61,7 +61,7 @@ describe Labels::CreateService do context 'with no color' do it 'doesn\'t create a label' do - label = Labels::CreateService.new(params_with(no_color)).execute(project: project) + label = described_class.new(params_with(no_color)).execute(project: project) expect(label).not_to be_persisted end @@ -71,7 +71,7 @@ describe Labels::CreateService do context 'in a group' do context 'with color in hex-code' do it 'creates a label' do - label = Labels::CreateService.new(params_with(hex_color)).execute(group: group) + label = described_class.new(params_with(hex_color)).execute(group: group) expect(label).to be_persisted expect(label.color).to eq expected_saved_color @@ -80,7 +80,7 @@ describe Labels::CreateService do context 'with color in allowed name' do it 'creates a label' do - label = Labels::CreateService.new(params_with(named_color)).execute(group: group) + label = described_class.new(params_with(named_color)).execute(group: group) expect(label).to be_persisted expect(label.color).to eq expected_saved_color @@ -89,7 +89,7 @@ describe Labels::CreateService do context 'with color in up-case allowed name' do it 'creates a label' do - label = Labels::CreateService.new(params_with(upcase_color)).execute(group: group) + label = described_class.new(params_with(upcase_color)).execute(group: group) expect(label).to be_persisted expect(label.color).to eq expected_saved_color @@ -98,7 +98,7 @@ describe Labels::CreateService do context 'with color surrounded by spaces' do it 'creates a label' do - label = Labels::CreateService.new(params_with(spaced_color)).execute(group: group) + label = described_class.new(params_with(spaced_color)).execute(group: group) expect(label).to be_persisted expect(label.color).to eq expected_saved_color @@ -107,7 +107,7 @@ describe Labels::CreateService do context 'with unknown color' do it 'doesn\'t create a label' do - label = Labels::CreateService.new(params_with(unknown_color)).execute(group: group) + label = described_class.new(params_with(unknown_color)).execute(group: group) expect(label).not_to be_persisted end @@ -115,7 +115,7 @@ describe Labels::CreateService do context 'with no color' do it 'doesn\'t create a label' do - label = Labels::CreateService.new(params_with(no_color)).execute(group: group) + label = described_class.new(params_with(no_color)).execute(group: group) expect(label).not_to be_persisted end @@ -125,7 +125,7 @@ describe Labels::CreateService do context 'in admin area' do context 'with color in hex-code' do it 'creates a label' do - label = Labels::CreateService.new(params_with(hex_color)).execute(template: true) + label = described_class.new(params_with(hex_color)).execute(template: true) expect(label).to be_persisted expect(label.color).to eq expected_saved_color @@ -134,7 +134,7 @@ describe Labels::CreateService do context 'with color in allowed name' do it 'creates a label' do - label = Labels::CreateService.new(params_with(named_color)).execute(template: true) + label = described_class.new(params_with(named_color)).execute(template: true) expect(label).to be_persisted expect(label.color).to eq expected_saved_color @@ -143,7 +143,7 @@ describe Labels::CreateService do context 'with color in up-case allowed name' do it 'creates a label' do - label = Labels::CreateService.new(params_with(upcase_color)).execute(template: true) + label = described_class.new(params_with(upcase_color)).execute(template: true) expect(label).to be_persisted expect(label.color).to eq expected_saved_color @@ -152,7 +152,7 @@ describe Labels::CreateService do context 'with color surrounded by spaces' do it 'creates a label' do - label = Labels::CreateService.new(params_with(spaced_color)).execute(template: true) + label = described_class.new(params_with(spaced_color)).execute(template: true) expect(label).to be_persisted expect(label.color).to eq expected_saved_color @@ -161,7 +161,7 @@ describe Labels::CreateService do context 'with unknown color' do it 'doesn\'t create a label' do - label = Labels::CreateService.new(params_with(unknown_color)).execute(template: true) + label = described_class.new(params_with(unknown_color)).execute(template: true) expect(label).not_to be_persisted end @@ -169,7 +169,7 @@ describe Labels::CreateService do context 'with no color' do it 'doesn\'t create a label' do - label = Labels::CreateService.new(params_with(no_color)).execute(template: true) + label = described_class.new(params_with(no_color)).execute(template: true) expect(label).not_to be_persisted end diff --git a/spec/services/labels/update_service_spec.rb b/spec/services/labels/update_service_spec.rb index 83ea11f62a6..bb95fe20fbf 100644 --- a/spec/services/labels/update_service_spec.rb +++ b/spec/services/labels/update_service_spec.rb @@ -20,7 +20,7 @@ describe Labels::UpdateService do context 'with color in hex-code' do it 'updates the label' do - label = Labels::UpdateService.new(params_with(hex_color)).execute(@label) + label = described_class.new(params_with(hex_color)).execute(@label) expect(label).to be_valid expect(label.reload.color).to eq expected_saved_color @@ -29,7 +29,7 @@ describe Labels::UpdateService do context 'with color in allowed name' do it 'updates the label' do - label = Labels::UpdateService.new(params_with(named_color)).execute(@label) + label = described_class.new(params_with(named_color)).execute(@label) expect(label).to be_valid expect(label.reload.color).to eq expected_saved_color @@ -38,7 +38,7 @@ describe Labels::UpdateService do context 'with color in up-case allowed name' do it 'updates the label' do - label = Labels::UpdateService.new(params_with(upcase_color)).execute(@label) + label = described_class.new(params_with(upcase_color)).execute(@label) expect(label).to be_valid expect(label.reload.color).to eq expected_saved_color @@ -47,7 +47,7 @@ describe Labels::UpdateService do context 'with color surrounded by spaces' do it 'updates the label' do - label = Labels::UpdateService.new(params_with(spaced_color)).execute(@label) + label = described_class.new(params_with(spaced_color)).execute(@label) expect(label).to be_valid expect(label.reload.color).to eq expected_saved_color @@ -56,7 +56,7 @@ describe Labels::UpdateService do context 'with unknown color' do it 'doesn\'t update the label' do - label = Labels::UpdateService.new(params_with(unknown_color)).execute(@label) + label = described_class.new(params_with(unknown_color)).execute(@label) expect(label).not_to be_valid end @@ -64,7 +64,7 @@ describe Labels::UpdateService do context 'with no color' do it 'doesn\'t update the label' do - label = Labels::UpdateService.new(params_with(no_color)).execute(@label) + label = described_class.new(params_with(no_color)).execute(@label) expect(label).not_to be_valid end diff --git a/spec/services/merge_requests/build_service_spec.rb b/spec/services/merge_requests/build_service_spec.rb index 0dcb636dd35..ea192e51f89 100644 --- a/spec/services/merge_requests/build_service_spec.rb +++ b/spec/services/merge_requests/build_service_spec.rb @@ -19,7 +19,7 @@ describe MergeRequests::BuildService do let(:commits) { nil } let(:service) do - MergeRequests::BuildService.new(project, user, + described_class.new(project, user, description: description, source_branch: source_branch, target_branch: target_branch, diff --git a/spec/services/merge_requests/merge_service_spec.rb b/spec/services/merge_requests/merge_service_spec.rb index a8f24b744c2..e593bfeeaf7 100644 --- a/spec/services/merge_requests/merge_service_spec.rb +++ b/spec/services/merge_requests/merge_service_spec.rb @@ -13,7 +13,7 @@ describe MergeRequests::MergeService do describe '#execute' do context 'valid params' do - let(:service) { MergeRequests::MergeService.new(project, user, commit_message: 'Awesome message') } + let(:service) { described_class.new(project, user, commit_message: 'Awesome message') } before do allow(service).to receive(:execute_hooks) @@ -112,7 +112,7 @@ describe MergeRequests::MergeService do context 'closes related todos' do let(:merge_request) { create(:merge_request, assignee: user, author: user) } let(:project) { merge_request.project } - let(:service) { MergeRequests::MergeService.new(project, user, commit_message: 'Awesome message') } + let(:service) { described_class.new(project, user, commit_message: 'Awesome message') } let!(:todo) do create(:todo, :assigned, project: project, @@ -136,7 +136,7 @@ describe MergeRequests::MergeService do context 'source branch removal' do context 'when the source branch is protected' do let(:service) do - MergeRequests::MergeService.new(project, user, should_remove_source_branch: '1') + described_class.new(project, user, should_remove_source_branch: '1') end before do @@ -151,7 +151,7 @@ describe MergeRequests::MergeService do context 'when the source branch is the default branch' do let(:service) do - MergeRequests::MergeService.new(project, user, should_remove_source_branch: '1') + described_class.new(project, user, should_remove_source_branch: '1') end before do @@ -169,7 +169,7 @@ describe MergeRequests::MergeService do let(:service) do merge_request.merge_params['force_remove_source_branch'] = '1' merge_request.save! - MergeRequests::MergeService.new(project, user, commit_message: 'Awesome message') + described_class.new(project, user, commit_message: 'Awesome message') end it 'removes the source branch using the author user' do @@ -182,7 +182,7 @@ describe MergeRequests::MergeService do context 'when MR merger set the source branch to be removed' do let(:service) do - MergeRequests::MergeService.new(project, user, commit_message: 'Awesome message', should_remove_source_branch: '1') + described_class.new(project, user, commit_message: 'Awesome message', should_remove_source_branch: '1') end it 'removes the source branch using the current user' do @@ -196,7 +196,7 @@ describe MergeRequests::MergeService do end context "error handling" do - let(:service) { MergeRequests::MergeService.new(project, user, commit_message: 'Awesome message') } + let(:service) { described_class.new(project, user, commit_message: 'Awesome message') } before do allow(Rails.logger).to receive(:error) diff --git a/spec/services/merge_requests/refresh_service_spec.rb b/spec/services/merge_requests/refresh_service_spec.rb index 6c703dded36..2af2485eeed 100644 --- a/spec/services/merge_requests/refresh_service_spec.rb +++ b/spec/services/merge_requests/refresh_service_spec.rb @@ -3,7 +3,7 @@ require 'spec_helper' describe MergeRequests::RefreshService do let(:project) { create(:project, :repository) } let(:user) { create(:user) } - let(:service) { MergeRequests::RefreshService } + let(:service) { described_class } describe '#execute' do before do diff --git a/spec/services/merge_requests/update_service_spec.rb b/spec/services/merge_requests/update_service_spec.rb index dddb526e58e..dd3ac9c4ac6 100644 --- a/spec/services/merge_requests/update_service_spec.rb +++ b/spec/services/merge_requests/update_service_spec.rb @@ -55,7 +55,7 @@ describe MergeRequests::UpdateService do } end - let(:service) { MergeRequests::UpdateService.new(project, user, opts) } + let(:service) { described_class.new(project, user, opts) } before do allow(service).to receive(:execute_hooks) @@ -145,7 +145,7 @@ describe MergeRequests::UpdateService do } end - let(:service) { MergeRequests::UpdateService.new(project, user, opts) } + let(:service) { described_class.new(project, user, opts) } context 'without pipeline' do before do @@ -205,7 +205,7 @@ describe MergeRequests::UpdateService do context 'with a non-authorised user' do let(:visitor) { create(:user) } - let(:service) { MergeRequests::UpdateService.new(project, visitor, opts) } + let(:service) { described_class.new(project, visitor, opts) } before do merge_request.update_attribute(:merge_error, 'Error') @@ -348,7 +348,7 @@ describe MergeRequests::UpdateService do opts = { label_ids: [label.id] } perform_enqueued_jobs do - @merge_request = MergeRequests::UpdateService.new(project, user, opts).execute(merge_request) + @merge_request = described_class.new(project, user, opts).execute(merge_request) end should_email(subscriber) @@ -364,7 +364,7 @@ describe MergeRequests::UpdateService do opts = { label_ids: [label.id, label2.id] } perform_enqueued_jobs do - @merge_request = MergeRequests::UpdateService.new(project, user, opts).execute(merge_request) + @merge_request = described_class.new(project, user, opts).execute(merge_request) end should_not_email(subscriber) @@ -375,7 +375,7 @@ describe MergeRequests::UpdateService do opts = { label_ids: [label2.id] } perform_enqueued_jobs do - @merge_request = MergeRequests::UpdateService.new(project, user, opts).execute(merge_request) + @merge_request = described_class.new(project, user, opts).execute(merge_request) end should_not_email(subscriber) @@ -386,7 +386,7 @@ describe MergeRequests::UpdateService do context 'updating mentions' do let(:mentionable) { merge_request } - include_examples 'updating mentions', MergeRequests::UpdateService + include_examples 'updating mentions', described_class end context 'when MergeRequest has tasks' do diff --git a/spec/services/milestones/close_service_spec.rb b/spec/services/milestones/close_service_spec.rb index 0838131a18a..fa0686d8061 100644 --- a/spec/services/milestones/close_service_spec.rb +++ b/spec/services/milestones/close_service_spec.rb @@ -11,7 +11,7 @@ describe Milestones::CloseService do describe '#execute' do before do - Milestones::CloseService.new(project, user, {}).execute(milestone) + described_class.new(project, user, {}).execute(milestone) end it { expect(milestone).to be_valid } diff --git a/spec/services/milestones/create_service_spec.rb b/spec/services/milestones/create_service_spec.rb index 0c2c41929d7..c6fe8e65912 100644 --- a/spec/services/milestones/create_service_spec.rb +++ b/spec/services/milestones/create_service_spec.rb @@ -14,7 +14,7 @@ describe Milestones::CreateService do description: 'Patch release to fix security issue' } - @milestone = Milestones::CreateService.new(project, user, opts).execute + @milestone = described_class.new(project, user, opts).execute end it { expect(@milestone).to be_valid } diff --git a/spec/services/notes/post_process_service_spec.rb b/spec/services/notes/post_process_service_spec.rb index 9044771939d..bf9320e5fce 100644 --- a/spec/services/notes/post_process_service_spec.rb +++ b/spec/services/notes/post_process_service_spec.rb @@ -21,7 +21,7 @@ describe Notes::PostProcessService do expect(project).to receive(:execute_hooks) expect(project).to receive(:execute_services) - Notes::PostProcessService.new(@note).execute + described_class.new(@note).execute end end end diff --git a/spec/services/notification_service_spec.rb b/spec/services/notification_service_spec.rb index 30fbe363fed..c98eb87b94e 100644 --- a/spec/services/notification_service_spec.rb +++ b/spec/services/notification_service_spec.rb @@ -3,7 +3,7 @@ require 'spec_helper' describe NotificationService do include EmailHelpers - let(:notification) { NotificationService.new } + let(:notification) { described_class.new } let(:assignee) { create(:user) } around(:each) do |example| diff --git a/spec/services/pages_service_spec.rb b/spec/services/pages_service_spec.rb index 7b9c92c0ce7..f8db6900a0a 100644 --- a/spec/services/pages_service_spec.rb +++ b/spec/services/pages_service_spec.rb @@ -3,7 +3,7 @@ require 'spec_helper' describe PagesService do let(:build) { create(:ci_build) } let(:data) { Gitlab::DataBuilder::Build.build(build) } - let(:service) { PagesService.new(data) } + let(:service) { described_class.new(data) } before do allow(Gitlab.config.pages).to receive(:enabled).and_return(true) diff --git a/spec/services/projects/destroy_service_spec.rb b/spec/services/projects/destroy_service_spec.rb index 6851c96a6d6..85b05ef6d05 100644 --- a/spec/services/projects/destroy_service_spec.rb +++ b/spec/services/projects/destroy_service_spec.rb @@ -81,7 +81,7 @@ describe Projects::DestroyService do before do new_user = create(:user) project.team.add_user(new_user, Gitlab::Access::DEVELOPER) - allow_any_instance_of(Projects::DestroyService).to receive(:flush_caches).and_raise(::Redis::CannotConnectError) + allow_any_instance_of(described_class).to receive(:flush_caches).and_raise(::Redis::CannotConnectError) end it 'keeps project team intact upon an error' do @@ -114,7 +114,7 @@ describe Projects::DestroyService do context 'errors' do context 'when `remove_legacy_registry_tags` fails' do before do - expect_any_instance_of(Projects::DestroyService) + expect_any_instance_of(described_class) .to receive(:remove_legacy_registry_tags).and_return(false) end @@ -123,7 +123,7 @@ describe Projects::DestroyService do context 'when `remove_repository` fails' do before do - expect_any_instance_of(Projects::DestroyService) + expect_any_instance_of(described_class) .to receive(:remove_repository).and_return(false) end diff --git a/spec/services/projects/transfer_service_spec.rb b/spec/services/projects/transfer_service_spec.rb index 53668c07285..ae32e85b2a7 100644 --- a/spec/services/projects/transfer_service_spec.rb +++ b/spec/services/projects/transfer_service_spec.rb @@ -37,7 +37,7 @@ describe Projects::TransferService do end it 'executes system hooks' do - expect_any_instance_of(Projects::TransferService).to receive(:execute_system_hooks) + expect_any_instance_of(described_class).to receive(:execute_system_hooks) transfer_project(project, user, group) end @@ -80,7 +80,7 @@ describe Projects::TransferService do end it "doesn't run system hooks" do - expect_any_instance_of(Projects::TransferService).not_to receive(:execute_system_hooks) + expect_any_instance_of(described_class).not_to receive(:execute_system_hooks) attempt_project_transfer end diff --git a/spec/services/projects/unlink_fork_service_spec.rb b/spec/services/projects/unlink_fork_service_spec.rb index cd5b443b043..2ae8d5f7c54 100644 --- a/spec/services/projects/unlink_fork_service_spec.rb +++ b/spec/services/projects/unlink_fork_service_spec.rb @@ -1,7 +1,7 @@ require 'spec_helper' describe Projects::UnlinkForkService do - subject { Projects::UnlinkForkService.new(fork_project, user) } + subject { described_class.new(fork_project, user) } let(:fork_link) { create(:forked_project_link) } let(:fork_project) { fork_link.forked_to_project } diff --git a/spec/services/repair_ldap_blocked_user_service_spec.rb b/spec/services/repair_ldap_blocked_user_service_spec.rb index 57a6162206c..bf79cfe74b7 100644 --- a/spec/services/repair_ldap_blocked_user_service_spec.rb +++ b/spec/services/repair_ldap_blocked_user_service_spec.rb @@ -3,7 +3,7 @@ require 'spec_helper' describe RepairLdapBlockedUserService do let(:user) { create(:omniauth_user, provider: 'ldapmain', state: 'ldap_blocked') } let(:identity) { user.ldap_identity } - subject(:service) { RepairLdapBlockedUserService.new(user) } + subject(:service) { described_class.new(user) } describe '#execute' do it 'changes to normal block after destroying last ldap identity' do diff --git a/spec/services/search/global_service_spec.rb b/spec/services/search/global_service_spec.rb index c376cdeb725..de921573b1a 100644 --- a/spec/services/search/global_service_spec.rb +++ b/spec/services/search/global_service_spec.rb @@ -16,7 +16,7 @@ describe Search::GlobalService do describe '#execute' do context 'unauthenticated' 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] end @@ -24,19 +24,19 @@ describe Search::GlobalService do context 'authenticated' 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] end 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] end 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] end diff --git a/spec/services/search/group_service_spec.rb b/spec/services/search/group_service_spec.rb index 3315d74658e..cb3f02d2883 100644 --- a/spec/services/search/group_service_spec.rb +++ b/spec/services/search/group_service_spec.rb @@ -17,7 +17,7 @@ describe Search::GroupService do 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(: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') } context 'in parent group' do diff --git a/spec/services/search_service_spec.rb b/spec/services/search_service_spec.rb index a6ec324fe8f..a6ef7561bc8 100644 --- a/spec/services/search_service_spec.rb +++ b/spec/services/search_service_spec.rb @@ -22,7 +22,7 @@ describe SearchService do describe '#project' do context 'when the project is accessible' 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 end @@ -31,7 +31,7 @@ describe SearchService do search_project = create :empty_project 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 end @@ -39,7 +39,7 @@ describe SearchService do context 'when the project is not accessible' 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 end @@ -47,7 +47,7 @@ describe SearchService do context 'when there is no project_id' do it 'returns nil' do - project = SearchService.new(user).project + project = described_class.new(user).project expect(project).to be_nil end @@ -57,7 +57,7 @@ describe SearchService do describe '#group' do context 'when the group is accessible' 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 end @@ -65,7 +65,7 @@ describe SearchService do context 'when the group is not accessible' 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 end @@ -73,7 +73,7 @@ describe SearchService do context 'when there is no group_id' do it 'returns nil' do - group = SearchService.new(user).group + group = described_class.new(user).group expect(group).to be_nil end @@ -83,7 +83,7 @@ describe SearchService do describe '#show_snippets?' do context 'when :snippets is \'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 end @@ -91,7 +91,7 @@ describe SearchService do context 'when :snippets is not \'true\'' 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 end @@ -99,7 +99,7 @@ describe SearchService do context 'when :snippets is missing' 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 end @@ -110,7 +110,7 @@ describe SearchService do context 'with accessible project_id' do context 'and allowed 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' end @@ -118,7 +118,7 @@ describe SearchService do context 'and disallowed 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' end @@ -126,7 +126,7 @@ describe SearchService do context 'and no 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' end @@ -136,7 +136,7 @@ describe SearchService do context 'with \'true\' snippets' do context 'and allowed 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' end @@ -144,7 +144,7 @@ describe SearchService do context 'and disallowed 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' end @@ -152,7 +152,7 @@ describe SearchService do context 'and no 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' end @@ -162,7 +162,7 @@ describe SearchService do context 'with no project_id, no snippets' do context 'and allowed 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' end @@ -170,7 +170,7 @@ describe SearchService do context 'and disallowed 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' end @@ -178,7 +178,7 @@ describe SearchService do context 'and no scope' do it 'returns the default scope' do - scope = SearchService.new(user).scope + scope = described_class.new(user).scope expect(scope).to eq 'projects' end @@ -189,7 +189,7 @@ describe SearchService do describe '#search_results' do context 'with accessible project_id' do it 'returns an instance of Gitlab::ProjectSearchResults' do - search_results = SearchService.new( + search_results = described_class.new( user, project_id: accessible_project.id, scope: 'notes', @@ -201,7 +201,7 @@ describe SearchService do context 'with accessible project_id and \'true\' snippets' do it 'returns an instance of Gitlab::ProjectSearchResults' do - search_results = SearchService.new( + search_results = described_class.new( user, project_id: accessible_project.id, snippets: 'true', @@ -214,7 +214,7 @@ describe SearchService do context 'with \'true\' snippets' do it 'returns an instance of Gitlab::SnippetSearchResults' do - search_results = SearchService.new( + search_results = described_class.new( user, snippets: 'true', search: snippet.content).search_results @@ -225,7 +225,7 @@ describe SearchService do context 'with no project_id and no snippets' do it 'returns an instance of Gitlab::SearchResults' do - search_results = SearchService.new( + search_results = described_class.new( user, search: public_project.name).search_results @@ -237,7 +237,7 @@ describe SearchService do describe '#search_objects' do context 'with accessible project_id' do it 'returns objects in the project' do - search_objects = SearchService.new( + search_objects = described_class.new( user, project_id: accessible_project.id, scope: 'notes', @@ -249,7 +249,7 @@ describe SearchService do context 'with accessible project_id and \'true\' snippets' do it 'returns objects in the project' do - search_objects = SearchService.new( + search_objects = described_class.new( user, project_id: accessible_project.id, snippets: 'true', @@ -262,7 +262,7 @@ describe SearchService do context 'with \'true\' snippets' do it 'returns objects in snippets' do - search_objects = SearchService.new( + search_objects = described_class.new( user, snippets: 'true', search: snippet.content).search_objects @@ -273,7 +273,7 @@ describe SearchService do context 'with accessible group_id' do it 'returns objects in the group' do - search_objects = SearchService.new( + search_objects = described_class.new( user, group_id: accessible_group.id, search: group_project.name).search_objects @@ -284,7 +284,7 @@ describe SearchService do context 'with no project_id, group_id or snippets' do it 'returns objects in global' do - search_objects = SearchService.new( + search_objects = described_class.new( user, search: public_project.name).search_objects diff --git a/spec/services/todo_service_spec.rb b/spec/services/todo_service_spec.rb index 8cbffc8ec61..230e40de9e0 100644 --- a/spec/services/todo_service_spec.rb +++ b/spec/services/todo_service_spec.rb @@ -873,21 +873,21 @@ describe TodoService do create(:todo, :mentioned, user: john_doe, target: issue, project: project) 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) end it 'marks an array of todos as done' do 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') end it 'returns the ids of updated todos' do # Needed on API 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 context 'when some of the todos are done already' do @@ -895,23 +895,23 @@ describe TodoService do let!(:second_todo) { create(:todo, :mentioned, user: john_doe, target: another_issue, project: project) } 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 it 'returns an empty array if all are done' do - TodoService.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(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 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) 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) diff --git a/spec/services/update_release_service_spec.rb b/spec/services/update_release_service_spec.rb index fecd50e6ca0..dc2d0e2d47a 100644 --- a/spec/services/update_release_service_spec.rb +++ b/spec/services/update_release_service_spec.rb @@ -6,7 +6,7 @@ describe UpdateReleaseService do let(:tag_name) { project.repository.tag_names.first } let(:description) { 'Awesome 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 let(:create_service) { CreateReleaseService.new(project, user) } diff --git a/spec/services/web_hook_service_spec.rb b/spec/services/web_hook_service_spec.rb index 8d91050b924..a5de86a0835 100644 --- a/spec/services/web_hook_service_spec.rb +++ b/spec/services/web_hook_service_spec.rb @@ -12,7 +12,7 @@ describe WebHookService do let(:data) do { before: 'oldrev', after: 'newrev', ref: 'ref' } 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 before(:each) do @@ -114,7 +114,7 @@ describe WebHookService do context 'should not log ServiceHooks' do 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 WebMock.stub_request(:post, service_hook.url).to_return(status: 200, body: 'Success') @@ -131,7 +131,7 @@ describe WebHookService do it 'enqueue WebHookWorker' do 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 |