diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2019-10-18 11:11:44 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2019-10-18 11:11:44 +0000 |
commit | 25989ab7ef1a444ed2abd5479f176d58e1d9462a (patch) | |
tree | 271bb24f3c7178f320cb9de0be0833a285327d09 /spec/lib | |
parent | 9bbb32b29703f3ce33dd35d5101145774b793a6d (diff) | |
download | gitlab-ce-25989ab7ef1a444ed2abd5479f176d58e1d9462a.tar.gz |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/lib')
47 files changed, 218 insertions, 14 deletions
diff --git a/spec/lib/backup/files_spec.rb b/spec/lib/backup/files_spec.rb index e903eada62d..b75f3bafeef 100644 --- a/spec/lib/backup/files_spec.rb +++ b/spec/lib/backup/files_spec.rb @@ -24,6 +24,7 @@ describe Backup::Files do describe '#restore' do subject { described_class.new('registry', '/var/gitlab-registry') } + let(:timestamp) { Time.utc(2017, 3, 22) } around do |example| diff --git a/spec/lib/banzai/filter/project_reference_filter_spec.rb b/spec/lib/banzai/filter/project_reference_filter_spec.rb index 927d226c400..d0b4542d503 100644 --- a/spec/lib/banzai/filter/project_reference_filter_spec.rb +++ b/spec/lib/banzai/filter/project_reference_filter_spec.rb @@ -15,6 +15,7 @@ describe Banzai::Filter::ProjectReferenceFilter do let(:project) { create(:project, :public) } subject { project } + let(:subject_name) { "project" } let(:reference) { get_reference(project) } diff --git a/spec/lib/banzai/filter/user_reference_filter_spec.rb b/spec/lib/banzai/filter/user_reference_filter_spec.rb index 6bc87d245f5..a09aeb7d7f6 100644 --- a/spec/lib/banzai/filter/user_reference_filter_spec.rb +++ b/spec/lib/banzai/filter/user_reference_filter_spec.rb @@ -12,6 +12,7 @@ describe Banzai::Filter::UserReferenceFilter do let(:project) { create(:project, :public) } let(:user) { create(:user) } subject { user } + let(:subject_name) { "user" } let(:reference) { get_reference(user) } diff --git a/spec/lib/banzai/reference_parser/commit_parser_spec.rb b/spec/lib/banzai/reference_parser/commit_parser_spec.rb index b44ae67e430..eac1cf16a8f 100644 --- a/spec/lib/banzai/reference_parser/commit_parser_spec.rb +++ b/spec/lib/banzai/reference_parser/commit_parser_spec.rb @@ -8,6 +8,7 @@ describe Banzai::ReferenceParser::CommitParser do let(:project) { create(:project, :public) } let(:user) { create(:user) } subject { described_class.new(Banzai::RenderContext.new(project, user)) } + let(:link) { empty_html_link } describe '#nodes_visible_to_user' do diff --git a/spec/lib/banzai/reference_parser/commit_range_parser_spec.rb b/spec/lib/banzai/reference_parser/commit_range_parser_spec.rb index da853233018..78b337466aa 100644 --- a/spec/lib/banzai/reference_parser/commit_range_parser_spec.rb +++ b/spec/lib/banzai/reference_parser/commit_range_parser_spec.rb @@ -8,6 +8,7 @@ describe Banzai::ReferenceParser::CommitRangeParser do let(:project) { create(:project, :public) } let(:user) { create(:user) } subject { described_class.new(Banzai::RenderContext.new(project, user)) } + let(:link) { empty_html_link } describe '#nodes_visible_to_user' do diff --git a/spec/lib/banzai/reference_parser/external_issue_parser_spec.rb b/spec/lib/banzai/reference_parser/external_issue_parser_spec.rb index 0f29a95bdcc..9343d52e44b 100644 --- a/spec/lib/banzai/reference_parser/external_issue_parser_spec.rb +++ b/spec/lib/banzai/reference_parser/external_issue_parser_spec.rb @@ -8,6 +8,7 @@ describe Banzai::ReferenceParser::ExternalIssueParser do let(:project) { create(:project, :public) } let(:user) { create(:user) } subject { described_class.new(Banzai::RenderContext.new(project, user)) } + let(:link) { empty_html_link } describe '#nodes_visible_to_user' do diff --git a/spec/lib/banzai/reference_parser/label_parser_spec.rb b/spec/lib/banzai/reference_parser/label_parser_spec.rb index cf8adb57ffc..8b66a891e69 100644 --- a/spec/lib/banzai/reference_parser/label_parser_spec.rb +++ b/spec/lib/banzai/reference_parser/label_parser_spec.rb @@ -9,6 +9,7 @@ describe Banzai::ReferenceParser::LabelParser do let(:user) { create(:user) } let(:label) { create(:label, project: project) } subject { described_class.new(Banzai::RenderContext.new(project, user)) } + let(:link) { empty_html_link } describe '#nodes_visible_to_user' do diff --git a/spec/lib/banzai/reference_parser/merge_request_parser_spec.rb b/spec/lib/banzai/reference_parser/merge_request_parser_spec.rb index 1561dabcdbf..cb65893aea0 100644 --- a/spec/lib/banzai/reference_parser/merge_request_parser_spec.rb +++ b/spec/lib/banzai/reference_parser/merge_request_parser_spec.rb @@ -9,6 +9,7 @@ describe Banzai::ReferenceParser::MergeRequestParser do let(:project) { create(:project, :public) } let(:merge_request) { create(:merge_request, source_project: project) } subject { described_class.new(Banzai::RenderContext.new(merge_request.target_project, user)) } + let(:link) { empty_html_link } describe '#nodes_visible_to_user' do diff --git a/spec/lib/banzai/reference_parser/milestone_parser_spec.rb b/spec/lib/banzai/reference_parser/milestone_parser_spec.rb index 006f8e37690..25ba41dd8a0 100644 --- a/spec/lib/banzai/reference_parser/milestone_parser_spec.rb +++ b/spec/lib/banzai/reference_parser/milestone_parser_spec.rb @@ -9,6 +9,7 @@ describe Banzai::ReferenceParser::MilestoneParser do let(:user) { create(:user) } let(:milestone) { create(:milestone, project: project) } subject { described_class.new(Banzai::RenderContext.new(project, user)) } + let(:link) { empty_html_link } describe '#nodes_visible_to_user' do diff --git a/spec/lib/banzai/reference_parser/project_parser_spec.rb b/spec/lib/banzai/reference_parser/project_parser_spec.rb index e4936aa9e57..356dde1e9c2 100644 --- a/spec/lib/banzai/reference_parser/project_parser_spec.rb +++ b/spec/lib/banzai/reference_parser/project_parser_spec.rb @@ -8,6 +8,7 @@ describe Banzai::ReferenceParser::ProjectParser do let(:project) { create(:project, :public) } let(:user) { create(:user) } subject { described_class.new(Banzai::RenderContext.new(project, user)) } + let(:link) { empty_html_link } describe '#referenced_by' do diff --git a/spec/lib/banzai/reference_parser/snippet_parser_spec.rb b/spec/lib/banzai/reference_parser/snippet_parser_spec.rb index 528f79ed020..05dc1cb4d2d 100644 --- a/spec/lib/banzai/reference_parser/snippet_parser_spec.rb +++ b/spec/lib/banzai/reference_parser/snippet_parser_spec.rb @@ -12,6 +12,7 @@ describe Banzai::ReferenceParser::SnippetParser do let(:project_member) { create(:user) } subject { described_class.new(Banzai::RenderContext.new(project, user)) } + let(:link) { empty_html_link } def visible_references(snippet_visibility, user = nil) diff --git a/spec/lib/banzai/reference_parser/user_parser_spec.rb b/spec/lib/banzai/reference_parser/user_parser_spec.rb index a5b4e59a3a1..931fb1e3953 100644 --- a/spec/lib/banzai/reference_parser/user_parser_spec.rb +++ b/spec/lib/banzai/reference_parser/user_parser_spec.rb @@ -9,6 +9,7 @@ describe Banzai::ReferenceParser::UserParser do let(:user) { create(:user) } let(:project) { create(:project, :public, group: group, creator: user) } subject { described_class.new(Banzai::RenderContext.new(project, user)) } + let(:link) { empty_html_link } describe '#referenced_by' do diff --git a/spec/lib/gitlab/bitbucket_import/importer_spec.rb b/spec/lib/gitlab/bitbucket_import/importer_spec.rb index 3d0d3f91859..7f7a285c453 100644 --- a/spec/lib/gitlab/bitbucket_import/importer_spec.rb +++ b/spec/lib/gitlab/bitbucket_import/importer_spec.rb @@ -308,8 +308,8 @@ describe Gitlab::BitbucketImport::Importer do importer.execute - expect(project.issues.where(state: "closed").size).to eq(5) - expect(project.issues.where(state: "opened").size).to eq(2) + expect(project.issues.where(state_id: Issue.available_states[:closed]).size).to eq(5) + expect(project.issues.where(state_id: Issue.available_states[:opened]).size).to eq(2) end describe 'wiki import' do diff --git a/spec/lib/gitlab/ci/build/artifacts/metadata/entry_spec.rb b/spec/lib/gitlab/ci/build/artifacts/metadata/entry_spec.rb index 24d17eb0fb3..73c3cad88bc 100644 --- a/spec/lib/gitlab/ci/build/artifacts/metadata/entry_spec.rb +++ b/spec/lib/gitlab/ci/build/artifacts/metadata/entry_spec.rb @@ -34,27 +34,32 @@ describe Gitlab::Ci::Build::Artifacts::Metadata::Entry do describe '#basename' do subject { |example| path(example).basename } + it { is_expected.to eq 'absolute_path' } end end describe 'path/dir_1/', path: 'path/dir_1/' do subject { |example| path(example) } + it { is_expected.to have_parent } it { is_expected.to be_directory } describe '#basename' do subject { |example| path(example).basename } + it { is_expected.to eq 'dir_1/' } end describe '#name' do subject { |example| path(example).name } + it { is_expected.to eq 'dir_1' } end describe '#parent' do subject { |example| path(example).parent } + it { is_expected.to eq entry('path/') } end @@ -102,21 +107,25 @@ describe Gitlab::Ci::Build::Artifacts::Metadata::Entry do describe '#nodes' do subject { |example| path(example).nodes } + it { is_expected.to eq 2 } end describe '#exists?' do subject { |example| path(example).exists? } + it { is_expected.to be true } end describe '#empty?' do subject { |example| path(example).empty? } + it { is_expected.to be false } end describe '#total_size' do subject { |example| path(example).total_size } + it { is_expected.to eq(30) } end end @@ -124,10 +133,12 @@ describe Gitlab::Ci::Build::Artifacts::Metadata::Entry do describe 'empty path', path: '' do subject { |example| path(example) } + it { is_expected.not_to have_parent } describe '#children' do subject { |example| path(example).children } + it { expect(subject.count).to eq 3 } end end @@ -135,6 +146,7 @@ describe Gitlab::Ci::Build::Artifacts::Metadata::Entry do describe 'path/dir_1/subdir/subfile', path: 'path/dir_1/subdir/subfile' do describe '#nodes' do subject { |example| path(example).nodes } + it { is_expected.to eq 4 } end @@ -153,11 +165,13 @@ describe Gitlab::Ci::Build::Artifacts::Metadata::Entry do describe 'non-existent/', path: 'non-existent/' do describe '#empty?' do subject { |example| path(example).empty? } + it { is_expected.to be true } end describe '#exists?' do subject { |example| path(example).exists? } + it { is_expected.to be false } end end @@ -165,6 +179,7 @@ describe Gitlab::Ci::Build::Artifacts::Metadata::Entry do describe 'another_directory/', path: 'another_directory/' do describe '#empty?' do subject { |example| path(example).empty? } + it { is_expected.to be true } end end diff --git a/spec/lib/gitlab/ci/build/artifacts/metadata_spec.rb b/spec/lib/gitlab/ci/build/artifacts/metadata_spec.rb index ff189c4701e..bfa65c66b33 100644 --- a/spec/lib/gitlab/ci/build/artifacts/metadata_spec.rb +++ b/spec/lib/gitlab/ci/build/artifacts/metadata_spec.rb @@ -76,21 +76,25 @@ describe Gitlab::Ci::Build::Artifacts::Metadata do describe '#to_entry' do subject { metadata('').to_entry } + it { is_expected.to be_an_instance_of(Gitlab::Ci::Build::Artifacts::Metadata::Entry) } end describe '#full_version' do subject { metadata('').full_version } + it { is_expected.to eq 'GitLab Build Artifacts Metadata 0.0.1' } end describe '#version' do subject { metadata('').version } + it { is_expected.to eq '0.0.1' } end describe '#errors' do subject { metadata('').errors } + it { is_expected.to eq({}) } end end diff --git a/spec/lib/gitlab/ci/config/entry/cache_spec.rb b/spec/lib/gitlab/ci/config/entry/cache_spec.rb index 4cb63168ec7..9aab3664e1c 100644 --- a/spec/lib/gitlab/ci/config/entry/cache_spec.rb +++ b/spec/lib/gitlab/ci/config/entry/cache_spec.rb @@ -69,6 +69,7 @@ describe Gitlab::Ci::Config::Entry::Cache do context 'when entry value is not correct' do describe '#errors' do subject { entry.errors } + context 'when is not a hash' do let(:config) { 'ls' } diff --git a/spec/lib/gitlab/ci/config/entry/coverage_spec.rb b/spec/lib/gitlab/ci/config/entry/coverage_spec.rb index 48d0864cfca..877e3ec6216 100644 --- a/spec/lib/gitlab/ci/config/entry/coverage_spec.rb +++ b/spec/lib/gitlab/ci/config/entry/coverage_spec.rb @@ -11,11 +11,13 @@ describe Gitlab::Ci::Config::Entry::Coverage do describe '#errors' do subject { entry.errors } + it { is_expected.to include(/coverage config must be a regular expression/) } end describe '#valid?' do subject { entry } + it { is_expected.not_to be_valid } end end @@ -25,16 +27,19 @@ describe Gitlab::Ci::Config::Entry::Coverage do describe '#value' do subject { entry.value } + it { is_expected.to eq(config[1...-1]) } end describe '#errors' do subject { entry.errors } + it { is_expected.to be_empty } end describe '#valid?' do subject { entry } + it { is_expected.to be_valid } end end @@ -44,11 +49,13 @@ describe Gitlab::Ci::Config::Entry::Coverage do describe '#errors' do subject { entry.errors } + it { is_expected.to include(/coverage config must be a regular expression/) } end describe '#valid?' do subject { entry } + it { is_expected.not_to be_valid } end end diff --git a/spec/lib/gitlab/cleanup/project_uploads_spec.rb b/spec/lib/gitlab/cleanup/project_uploads_spec.rb index 7bad788e44e..5787cce7d20 100644 --- a/spec/lib/gitlab/cleanup/project_uploads_spec.rb +++ b/spec/lib/gitlab/cleanup/project_uploads_spec.rb @@ -4,6 +4,7 @@ require 'spec_helper' describe Gitlab::Cleanup::ProjectUploads do subject { described_class.new(logger: logger) } + let(:logger) { double(:logger) } before do diff --git a/spec/lib/gitlab/danger/teammate_spec.rb b/spec/lib/gitlab/danger/teammate_spec.rb index 1e9cf0017be..bd1c2b10dc8 100644 --- a/spec/lib/gitlab/danger/teammate_spec.rb +++ b/spec/lib/gitlab/danger/teammate_spec.rb @@ -8,6 +8,7 @@ require 'gitlab/danger/teammate' describe Gitlab::Danger::Teammate do subject { described_class.new(options.stringify_keys) } + let(:options) { { username: 'luigi', projects: projects, role: role } } let(:projects) { { project => capabilities } } let(:role) { 'Engineer, Manage' } diff --git a/spec/lib/gitlab/discussions_diff/file_collection_spec.rb b/spec/lib/gitlab/discussions_diff/file_collection_spec.rb index 6ef1e41450f..a13727b62ea 100644 --- a/spec/lib/gitlab/discussions_diff/file_collection_spec.rb +++ b/spec/lib/gitlab/discussions_diff/file_collection_spec.rb @@ -40,6 +40,14 @@ describe Gitlab::DiscussionsDiff::FileCollection do subject.load_highlight end + it 'does not write cache for empty mapping' do + allow(subject).to receive(:highlighted_lines_by_ids).and_return([]) + + expect(Gitlab::DiscussionsDiff::HighlightCache).not_to receive(:write_multiple) + + subject.load_highlight + end + it 'does not write cache for resolved notes' do diff_note_a.update_column(:resolved_at, Time.now) diff --git a/spec/lib/gitlab/downtime_check_spec.rb b/spec/lib/gitlab/downtime_check_spec.rb index 56ad49d528f..5a5e34961a4 100644 --- a/spec/lib/gitlab/downtime_check_spec.rb +++ b/spec/lib/gitlab/downtime_check_spec.rb @@ -4,6 +4,7 @@ require 'spec_helper' describe Gitlab::DowntimeCheck do subject { described_class.new } + let(:path) { 'foo.rb' } describe '#check' do diff --git a/spec/lib/gitlab/email/message/repository_push_spec.rb b/spec/lib/gitlab/email/message/repository_push_spec.rb index 84c5b38127e..b57764bceef 100644 --- a/spec/lib/gitlab/email/message/repository_push_spec.rb +++ b/spec/lib/gitlab/email/message/repository_push_spec.rb @@ -28,90 +28,107 @@ describe Gitlab::Email::Message::RepositoryPush do describe '#project' do subject { message.project } + it { is_expected.to eq project } it { is_expected.to be_an_instance_of Project } end describe '#project_namespace' do subject { message.project_namespace } + it { is_expected.to eq group } it { is_expected.to be_kind_of Namespace } end describe '#project_name_with_namespace' do subject { message.project_name_with_namespace } + it { is_expected.to eq "#{group.name} / #{project.path}" } end describe '#author' do subject { message.author } + it { is_expected.to eq author } it { is_expected.to be_an_instance_of User } end describe '#author_name' do subject { message.author_name } + it { is_expected.to eq 'Author' } end describe '#commits' do subject { message.commits } + it { is_expected.to be_kind_of Array } it { is_expected.to all(be_instance_of Commit) } end describe '#diffs' do subject { message.diffs } + it { is_expected.to all(be_an_instance_of Gitlab::Diff::File) } end describe '#diffs_count' do subject { message.diffs_count } + it { is_expected.to eq raw_compare.diffs.size } end describe '#compare' do subject { message.compare } + it { is_expected.to be_an_instance_of Compare } end describe '#compare_timeout' do subject { message.compare_timeout } + it { is_expected.to eq raw_compare.diffs.overflow? } end describe '#reverse_compare?' do subject { message.reverse_compare? } + it { is_expected.to eq false } end describe '#disable_diffs?' do subject { message.disable_diffs? } + it { is_expected.to eq false } end describe '#send_from_committer_email?' do subject { message.send_from_committer_email? } + it { is_expected.to eq true } end describe '#action_name' do subject { message.action_name } + it { is_expected.to eq 'pushed to' } end describe '#ref_name' do subject { message.ref_name } + it { is_expected.to eq 'master' } end describe '#ref_type' do subject { message.ref_type } + it { is_expected.to eq 'branch' } end describe '#target_url' do subject { message.target_url } + it { is_expected.to include 'compare' } it { is_expected.to include compare.commits.first.parents.first.id } it { is_expected.to include compare.commits.last.id } @@ -119,6 +136,7 @@ describe Gitlab::Email::Message::RepositoryPush do describe '#subject' do subject { message.subject } + it { is_expected.to include "[Git][#{project.full_path}]" } it { is_expected.to include "#{compare.commits.length} commits" } it { is_expected.to include compare.commits.first.message.split("\n").first } diff --git a/spec/lib/gitlab/experimentation_spec.rb b/spec/lib/gitlab/experimentation_spec.rb index 4d473731f39..2e5fd16d370 100644 --- a/spec/lib/gitlab/experimentation_spec.rb +++ b/spec/lib/gitlab/experimentation_spec.rb @@ -75,6 +75,7 @@ describe Gitlab::Experimentation do describe '.enabled?' do subject { described_class.enabled?(:test_experiment, experimentation_subject_index) } + let(:experimentation_subject_index) { 9 } context 'feature toggle is enabled, we are on the right environment and we are selected' do diff --git a/spec/lib/gitlab/gfm/uploads_rewriter_spec.rb b/spec/lib/gitlab/gfm/uploads_rewriter_spec.rb index d24f5c45107..eef3b9de476 100644 --- a/spec/lib/gitlab/gfm/uploads_rewriter_spec.rb +++ b/spec/lib/gitlab/gfm/uploads_rewriter_spec.rb @@ -84,11 +84,13 @@ describe Gitlab::Gfm::UploadsRewriter do describe '#needs_rewrite?' do subject { rewriter.needs_rewrite? } + it { is_expected.to eq true } end describe '#files' do subject { rewriter.files } + it { is_expected.to be_an(Array) } end end diff --git a/spec/lib/gitlab/git/branch_spec.rb b/spec/lib/gitlab/git/branch_spec.rb index 0764e525ede..02ef7b92538 100644 --- a/spec/lib/gitlab/git/branch_spec.rb +++ b/spec/lib/gitlab/git/branch_spec.rb @@ -44,6 +44,7 @@ describe Gitlab::Git::Branch, :seed_helper do describe '#size' do subject { super().size } + it { is_expected.to eq(SeedRepo::Repo::BRANCHES.size) } end diff --git a/spec/lib/gitlab/git/commit_spec.rb b/spec/lib/gitlab/git/commit_spec.rb index 3f0e6b34291..23651e3d7f2 100644 --- a/spec/lib/gitlab/git/commit_spec.rb +++ b/spec/lib/gitlab/git/commit_spec.rb @@ -174,6 +174,7 @@ describe Gitlab::Git::Commit, :seed_helper do describe '#id' do subject { super().id } + it { is_expected.to eq(SeedRepo::LastCommit::ID) } end end @@ -183,6 +184,7 @@ describe Gitlab::Git::Commit, :seed_helper do describe '#id' do subject { super().id } + it { is_expected.to eq(SeedRepo::Commit::ID) } end end @@ -192,6 +194,7 @@ describe Gitlab::Git::Commit, :seed_helper do describe '#id' do subject { super().id } + it { is_expected.to eq(SeedRepo::BigCommit::ID) } end end @@ -544,11 +547,13 @@ describe Gitlab::Git::Commit, :seed_helper do describe '#id' do subject { super().id } + it { is_expected.to eq(sample_commit_hash[:id])} end describe '#message' do subject { super().message } + it { is_expected.to eq(sample_commit_hash[:message])} end end @@ -558,16 +563,19 @@ describe Gitlab::Git::Commit, :seed_helper do describe '#additions' do subject { super().additions } + it { is_expected.to eq(11) } end describe '#deletions' do subject { super().deletions } + it { is_expected.to eq(6) } end describe '#total' do subject { super().total } + it { is_expected.to eq(17) } end end @@ -596,6 +604,7 @@ describe Gitlab::Git::Commit, :seed_helper do describe '#keys' do subject { super().keys.sort } + it { is_expected.to match(sample_commit_hash.keys.sort) } end end diff --git a/spec/lib/gitlab/git/diff_collection_spec.rb b/spec/lib/gitlab/git/diff_collection_spec.rb index ded173c49ef..ce45d6e24ba 100644 --- a/spec/lib/gitlab/git/diff_collection_spec.rb +++ b/spec/lib/gitlab/git/diff_collection_spec.rb @@ -10,6 +10,7 @@ describe Gitlab::Git::DiffCollection, :seed_helper do expanded: expanded ) end + let(:iterator) { MutatingConstantIterator.new(file_count, fake_diff(line_length, line_count)) } let(:file_count) { 0 } let(:line_length) { 1 } @@ -21,6 +22,7 @@ describe Gitlab::Git::DiffCollection, :seed_helper do describe '#to_a' do subject { super().to_a } + it { is_expected.to be_kind_of ::Array } end @@ -52,16 +54,19 @@ describe Gitlab::Git::DiffCollection, :seed_helper do describe '#overflow?' do subject { super().overflow? } + it { is_expected.to be_falsey } end describe '#empty?' do subject { super().empty? } + it { is_expected.to be_falsey } end describe '#real_size' do subject { super().real_size } + it { is_expected.to eq('3') } end @@ -76,6 +81,7 @@ describe Gitlab::Git::DiffCollection, :seed_helper do describe '#line_count' do subject { super().line_count } + it { is_expected.to eq file_count * line_count } end @@ -84,16 +90,19 @@ describe Gitlab::Git::DiffCollection, :seed_helper do describe '#overflow?' do subject { super().overflow? } + it { is_expected.to be_falsey } end describe '#empty?' do subject { super().empty? } + it { is_expected.to be_falsey } end describe '#real_size' do subject { super().real_size } + it { is_expected.to eq('3') } end @@ -108,6 +117,7 @@ describe Gitlab::Git::DiffCollection, :seed_helper do describe '#line_count' do subject { super().line_count } + it { is_expected.to eq file_count * line_count } end end @@ -118,21 +128,25 @@ describe Gitlab::Git::DiffCollection, :seed_helper do describe '#overflow?' do subject { super().overflow? } + it { is_expected.to be_truthy } end describe '#empty?' do subject { super().empty? } + it { is_expected.to be_falsey } end describe '#real_size' do subject { super().real_size } + it { is_expected.to eq('0+') } end describe '#line_count' do subject { super().line_count } + it { is_expected.to eq 1000 } end @@ -143,21 +157,25 @@ describe Gitlab::Git::DiffCollection, :seed_helper do describe '#overflow?' do subject { super().overflow? } + it { is_expected.to be_falsey } end describe '#empty?' do subject { super().empty? } + it { is_expected.to be_falsey } end describe '#real_size' do subject { super().real_size } + it { is_expected.to eq('3') } end describe '#line_count' do subject { super().line_count } + it { is_expected.to eq file_count * line_count } end @@ -174,21 +192,25 @@ describe Gitlab::Git::DiffCollection, :seed_helper do describe '#overflow?' do subject { super().overflow? } + it { is_expected.to be_truthy } end describe '#empty?' do subject { super().empty? } + it { is_expected.to be_falsey } end describe '#real_size' do subject { super().real_size } + it { is_expected.to eq('10+') } end describe '#line_count' do subject { super().line_count } + it { is_expected.to eq 10 } end @@ -199,21 +221,25 @@ describe Gitlab::Git::DiffCollection, :seed_helper do describe '#overflow?' do subject { super().overflow? } + it { is_expected.to be_falsey } end describe '#empty?' do subject { super().empty? } + it { is_expected.to be_falsey } end describe '#real_size' do subject { super().real_size } + it { is_expected.to eq('11') } end describe '#line_count' do subject { super().line_count } + it { is_expected.to eq file_count * line_count } end @@ -226,21 +252,25 @@ describe Gitlab::Git::DiffCollection, :seed_helper do describe '#overflow?' do subject { super().overflow? } + it { is_expected.to be_truthy } end describe '#empty?' do subject { super().empty? } + it { is_expected.to be_falsey } end describe '#real_size' do subject { super().real_size } + it { is_expected.to eq('3+') } end describe '#line_count' do subject { super().line_count } + it { is_expected.to eq 120 } end @@ -251,21 +281,25 @@ describe Gitlab::Git::DiffCollection, :seed_helper do describe '#overflow?' do subject { super().overflow? } + it { is_expected.to be_falsey } end describe '#empty?' do subject { super().empty? } + it { is_expected.to be_falsey } end describe '#real_size' do subject { super().real_size } + it { is_expected.to eq('11') } end describe '#line_count' do subject { super().line_count } + it { is_expected.to eq file_count * line_count } end @@ -282,21 +316,25 @@ describe Gitlab::Git::DiffCollection, :seed_helper do describe '#overflow?' do subject { super().overflow? } + it { is_expected.to be_falsey } end describe '#empty?' do subject { super().empty? } + it { is_expected.to be_falsey } end describe '#real_size' do subject { super().real_size } + it { is_expected.to eq('10') } end describe '#line_count' do subject { super().line_count } + it { is_expected.to eq file_count * line_count } end @@ -310,21 +348,25 @@ describe Gitlab::Git::DiffCollection, :seed_helper do describe '#overflow?' do subject { super().overflow? } + it { is_expected.to be_truthy } end describe '#empty?' do subject { super().empty? } + it { is_expected.to be_falsey } end describe '#real_size' do subject { super().real_size } + it { is_expected.to eq('9+') } end describe '#line_count' do subject { super().line_count } + it { is_expected.to eq file_count * line_count } end @@ -335,21 +377,25 @@ describe Gitlab::Git::DiffCollection, :seed_helper do describe '#overflow?' do subject { super().overflow? } + it { is_expected.to be_falsey } end describe '#empty?' do subject { super().empty? } + it { is_expected.to be_falsey } end describe '#real_size' do subject { super().real_size } + it { is_expected.to eq('10') } end describe '#line_count' do subject { super().line_count } + it { is_expected.to eq file_count * line_count } end @@ -363,26 +409,31 @@ describe Gitlab::Git::DiffCollection, :seed_helper do describe '#overflow?' do subject { super().overflow? } + it { is_expected.to be_falsey } end describe '#empty?' do subject { super().empty? } + it { is_expected.to be_truthy } end describe '#size' do subject { super().size } + it { is_expected.to eq(0) } end describe '#real_size' do subject { super().real_size } + it { is_expected.to eq('0')} end describe '#line_count' do subject { super().line_count } + it { is_expected.to eq 0 } end end diff --git a/spec/lib/gitlab/git/repository_spec.rb b/spec/lib/gitlab/git/repository_spec.rb index 04a648a0da0..44c41da7560 100644 --- a/spec/lib/gitlab/git/repository_spec.rb +++ b/spec/lib/gitlab/git/repository_spec.rb @@ -93,6 +93,7 @@ describe Gitlab::Git::Repository, :seed_helper do describe '#last' do subject { super().last } + it { is_expected.to eq("v1.2.1") } end it { is_expected.to include("v1.0.0") } @@ -215,11 +216,13 @@ describe Gitlab::Git::Repository, :seed_helper do describe '#first' do subject { super().first } + it { is_expected.to eq('feature') } end describe '#last' do subject { super().last } + it { is_expected.to eq('v1.2.1') } end end diff --git a/spec/lib/gitlab/gitlab_import/client_spec.rb b/spec/lib/gitlab/gitlab_import/client_spec.rb index 22ad88e28cb..0f1745fcc02 100644 --- a/spec/lib/gitlab/gitlab_import/client_spec.rb +++ b/spec/lib/gitlab/gitlab_import/client_spec.rb @@ -52,6 +52,7 @@ describe Gitlab::GitlabImport::Client do describe '#projects' do subject(:method) { :projects } + let(:args) { [] } let(:element_list) { build_list(:project, 2) } @@ -67,6 +68,7 @@ describe Gitlab::GitlabImport::Client do describe '#issues' do subject(:method) { :issues } + let(:args) { [1] } let(:element_list) { build_list(:issue, 2) } @@ -82,6 +84,7 @@ describe Gitlab::GitlabImport::Client do describe '#issue_comments' do subject(:method) { :issue_comments } + let(:args) { [1, 1] } let(:element_list) { build_list(:note_on_issue, 2) } diff --git a/spec/lib/gitlab/graphs/commits_spec.rb b/spec/lib/gitlab/graphs/commits_spec.rb index 530d4a981bf..09654e0439e 100644 --- a/spec/lib/gitlab/graphs/commits_spec.rb +++ b/spec/lib/gitlab/graphs/commits_spec.rb @@ -11,12 +11,14 @@ describe Gitlab::Graphs::Commits do describe '#commit_per_day' do context 'when range is only commits from today' do subject { described_class.new([commit2, commit1]).commit_per_day } + it { is_expected.to eq 2 } end end context 'when range is only commits from today' do subject { described_class.new([commit2, commit1]) } + describe '#commit_per_day' do it { expect(subject.commit_per_day).to eq 2 } end @@ -28,6 +30,7 @@ describe Gitlab::Graphs::Commits do context 'with commits from yesterday and today' do subject { described_class.new([commit2, commit1_yesterday]) } + describe '#commit_per_day' do it { expect(subject.commit_per_day).to eq 1.0 } end diff --git a/spec/lib/gitlab/health_checks/gitaly_check_spec.rb b/spec/lib/gitlab/health_checks/gitaly_check_spec.rb index 99d10312c15..36e2fd04aeb 100644 --- a/spec/lib/gitlab/health_checks/gitaly_check_spec.rb +++ b/spec/lib/gitlab/health_checks/gitaly_check_spec.rb @@ -30,6 +30,7 @@ describe Gitlab::HealthChecks::GitalyCheck do describe '#metrics' do subject { described_class.metrics } + let(:server) { double(storage: 'default', read_writeable?: up) } before do diff --git a/spec/lib/gitlab/health_checks/simple_check_shared.rb b/spec/lib/gitlab/health_checks/simple_check_shared.rb index c3d55a11909..03a7cf249cf 100644 --- a/spec/lib/gitlab/health_checks/simple_check_shared.rb +++ b/spec/lib/gitlab/health_checks/simple_check_shared.rb @@ -1,6 +1,7 @@ shared_context 'simple_check' do |metrics_prefix, check_name, success_result| describe '#metrics' do subject { described_class.metrics } + context 'Check is passing' do before do allow(described_class).to receive(:check).and_return success_result @@ -34,6 +35,7 @@ shared_context 'simple_check' do |metrics_prefix, check_name, success_result| describe '#readiness' do subject { described_class.readiness } + context 'Check returns ok' do before do allow(described_class).to receive(:check).and_return success_result diff --git a/spec/lib/gitlab/hook_data/issue_builder_spec.rb b/spec/lib/gitlab/hook_data/issue_builder_spec.rb index 6013fb78bc7..ebd7feb0055 100644 --- a/spec/lib/gitlab/hook_data/issue_builder_spec.rb +++ b/spec/lib/gitlab/hook_data/issue_builder_spec.rb @@ -26,7 +26,7 @@ describe Gitlab::HookData::IssueBuilder do duplicated_to_id project_id relative_position - state + state_id time_estimate title updated_at @@ -41,6 +41,7 @@ describe Gitlab::HookData::IssueBuilder do expect(data).to include(:human_time_estimate) expect(data).to include(:human_total_time_spent) expect(data).to include(:assignee_ids) + expect(data).to include(:state) expect(data).to include('labels' => [label.hook_attrs]) end diff --git a/spec/lib/gitlab/import_export/all_models.yml b/spec/lib/gitlab/import_export/all_models.yml index 1efd7bf5c71..4fd61383c6b 100644 --- a/spec/lib/gitlab/import_export/all_models.yml +++ b/spec/lib/gitlab/import_export/all_models.yml @@ -25,6 +25,7 @@ issues: - epic - designs - design_versions +- description_versions - prometheus_alerts - prometheus_alert_events - self_managed_prometheus_alert_events @@ -132,6 +133,7 @@ merge_requests: - blocks_as_blockee - blocking_merge_requests - blocked_merge_requests +- description_versions external_pull_requests: - project merge_request_diff: diff --git a/spec/lib/gitlab/import_export/project_tree_restorer_spec.rb b/spec/lib/gitlab/import_export/project_tree_restorer_spec.rb index 218031784cb..676973ff5e7 100644 --- a/spec/lib/gitlab/import_export/project_tree_restorer_spec.rb +++ b/spec/lib/gitlab/import_export/project_tree_restorer_spec.rb @@ -434,6 +434,11 @@ describe Gitlab::ImportExport::ProjectTreeRestorer do labels: 0, milestones: 0, first_issue_labels: 1 + + it 'restores issue states' do + expect(project.issues.with_state(:closed).count).to eq(1) + expect(project.issues.with_state(:opened).count).to eq(1) + end end context 'with existing group models' do diff --git a/spec/lib/gitlab/import_export/relation_factory_spec.rb b/spec/lib/gitlab/import_export/relation_factory_spec.rb index 51b2fd06b46..a23e68a8f00 100644 --- a/spec/lib/gitlab/import_export/relation_factory_spec.rb +++ b/spec/lib/gitlab/import_export/relation_factory_spec.rb @@ -85,7 +85,7 @@ describe Gitlab::ImportExport::RelationFactory do class FooModel include ActiveModel::Model - def initialize(params) + def initialize(params = {}) params.each { |key, value| send("#{key}=", value) } end diff --git a/spec/lib/gitlab/metrics/samplers/puma_sampler_spec.rb b/spec/lib/gitlab/metrics/samplers/puma_sampler_spec.rb index b8add3c1324..1097d26c320 100644 --- a/spec/lib/gitlab/metrics/samplers/puma_sampler_spec.rb +++ b/spec/lib/gitlab/metrics/samplers/puma_sampler_spec.rb @@ -4,6 +4,7 @@ require 'spec_helper' describe Gitlab::Metrics::Samplers::PumaSampler do subject { described_class.new(5) } + let(:null_metric) { double('null_metric', set: nil, observe: nil) } before do diff --git a/spec/lib/gitlab/phabricator_import/worker_state_spec.rb b/spec/lib/gitlab/phabricator_import/worker_state_spec.rb index b6f2524a9d0..51514dd0ffd 100644 --- a/spec/lib/gitlab/phabricator_import/worker_state_spec.rb +++ b/spec/lib/gitlab/phabricator_import/worker_state_spec.rb @@ -4,6 +4,7 @@ require 'spec_helper' describe Gitlab::PhabricatorImport::WorkerState, :clean_gitlab_redis_shared_state do subject(:state) { described_class.new('weird-project-id') } + let(:key) { 'phabricator-import/jobs/project-weird-project-id/job-count' } describe '#add_job' do diff --git a/spec/lib/gitlab/reference_extractor_spec.rb b/spec/lib/gitlab/reference_extractor_spec.rb index f6ace0d8bf5..6bc9b6365d1 100644 --- a/spec/lib/gitlab/reference_extractor_spec.rb +++ b/spec/lib/gitlab/reference_extractor_spec.rb @@ -259,6 +259,7 @@ describe Gitlab::ReferenceExtractor do describe '.references_pattern' do subject { described_class.references_pattern } + it { is_expected.to be_kind_of Regexp } end diff --git a/spec/lib/gitlab/request_context_spec.rb b/spec/lib/gitlab/request_context_spec.rb index a744f48da1f..cde12d4b310 100644 --- a/spec/lib/gitlab/request_context_spec.rb +++ b/spec/lib/gitlab/request_context_spec.rb @@ -5,6 +5,7 @@ require 'spec_helper' describe Gitlab::RequestContext do describe '#client_ip' do subject { described_class.client_ip } + let(:app) { -> (env) {} } let(:env) { Hash.new } diff --git a/spec/lib/gitlab/shell_spec.rb b/spec/lib/gitlab/shell_spec.rb index ff9e31ec346..a17e9a31212 100644 --- a/spec/lib/gitlab/shell_spec.rb +++ b/spec/lib/gitlab/shell_spec.rb @@ -396,6 +396,7 @@ describe Gitlab::Shell do describe 'namespace actions' do subject { described_class.new } + let(:storage) { Gitlab.config.repositories.storages.keys.first } describe '#add_namespace' do diff --git a/spec/lib/gitlab/sidekiq_middleware/memory_killer_spec.rb b/spec/lib/gitlab/sidekiq_middleware/memory_killer_spec.rb index bf3bc8e1add..b5be43ec96c 100644 --- a/spec/lib/gitlab/sidekiq_middleware/memory_killer_spec.rb +++ b/spec/lib/gitlab/sidekiq_middleware/memory_killer_spec.rb @@ -4,6 +4,7 @@ require 'spec_helper' describe Gitlab::SidekiqMiddleware::MemoryKiller do subject { described_class.new } + let(:pid) { 999 } let(:worker) { double(:worker, class: ProjectCacheWorker) } diff --git a/spec/lib/gitlab/utils/override_spec.rb b/spec/lib/gitlab/utils/override_spec.rb index 5855c4374a9..e2776efac85 100644 --- a/spec/lib/gitlab/utils/override_spec.rb +++ b/spec/lib/gitlab/utils/override_spec.rb @@ -151,6 +151,7 @@ describe Gitlab::Utils::Override do context 'when subject is a module, and class is prepending it' do subject { extension } + let(:klass) { prepending_class } it_behaves_like 'checking as intended' @@ -158,6 +159,7 @@ describe Gitlab::Utils::Override do context 'when subject is a module, and class is including it' do subject { extension } + let(:klass) { including_class } it_behaves_like 'checking as intended, nothing was overridden' @@ -177,6 +179,7 @@ describe Gitlab::Utils::Override do context 'when subject is a module, and class is prepending it' do subject { extension } + let(:klass) { prepending_class } it_behaves_like 'nothing happened' @@ -184,6 +187,7 @@ describe Gitlab::Utils::Override do context 'when subject is a module, and class is including it' do subject { extension } + let(:klass) { including_class } it 'does not complain when it is overriding something' do @@ -215,6 +219,7 @@ describe Gitlab::Utils::Override do context 'when subject is a module, and class is prepending it' do subject { extension } + let(:klass) { prepending_class_methods } it_behaves_like 'checking as intended' @@ -222,6 +227,7 @@ describe Gitlab::Utils::Override do context 'when subject is a module, and class is extending it' do subject { extension } + let(:klass) { extending_class_methods } it_behaves_like 'checking as intended, nothing was overridden' diff --git a/spec/lib/google_api/cloud_platform/client_spec.rb b/spec/lib/google_api/cloud_platform/client_spec.rb index 91b076c31d6..0f7f57095df 100644 --- a/spec/lib/google_api/cloud_platform/client_spec.rb +++ b/spec/lib/google_api/cloud_platform/client_spec.rb @@ -54,6 +54,7 @@ describe GoogleApi::CloudPlatform::Client do describe '#projects_zones_clusters_get' do subject { client.projects_zones_clusters_get(spy, spy, spy) } + let(:gke_cluster) { double } before do @@ -160,6 +161,7 @@ describe GoogleApi::CloudPlatform::Client do describe '#projects_zones_operations' do subject { client.projects_zones_operations(spy, spy, spy) } + let(:operation) { double } before do diff --git a/spec/lib/json_web_token/token_spec.rb b/spec/lib/json_web_token/token_spec.rb index 916d11ce0ed..ca587a6ebcd 100644 --- a/spec/lib/json_web_token/token_spec.rb +++ b/spec/lib/json_web_token/token_spec.rb @@ -16,6 +16,7 @@ describe JSONWebToken::Token do context 'embeds default payload' do subject { token.payload } + let(:default) { token.send(:default_payload) } it { is_expected.to include(default) } diff --git a/spec/lib/omni_auth/strategies/jwt_spec.rb b/spec/lib/omni_auth/strategies/jwt_spec.rb index bdf3ea6be98..a8c565aa705 100644 --- a/spec/lib/omni_auth/strategies/jwt_spec.rb +++ b/spec/lib/omni_auth/strategies/jwt_spec.rb @@ -8,6 +8,7 @@ describe OmniAuth::Strategies::Jwt do context '#decoded' do subject { described_class.new({}) } + let(:timestamp) { Time.now.to_i } let(:jwt_config) { Devise.omniauth_configs[:jwt] } let(:claims) do diff --git a/spec/lib/uploaded_file_spec.rb b/spec/lib/uploaded_file_spec.rb index 2cb4727bd4b..2bbbd67b13c 100644 --- a/spec/lib/uploaded_file_spec.rb +++ b/spec/lib/uploaded_file_spec.rb @@ -72,16 +72,6 @@ describe UploadedFile do end end - context 'when only remote id is specified' do - let(:params) do - { 'file.remote_id' => 'remote_id' } - end - - it "raises an error" do - expect { subject }.to raise_error(UploadedFile::InvalidPathError, /file is invalid/) - end - end - context 'when verifying allowed paths' do let(:params) do { 'file.path' => temp_file.path } @@ -120,6 +110,52 @@ describe UploadedFile do end end + describe '.initialize' do + context 'when no size is provided' do + it 'determine size from local path' do + file = described_class.new(temp_file.path) + + expect(file.size).to eq(temp_file.size) + end + + it 'raises an exception if is a remote file' do + expect do + described_class.new(nil, remote_id: 'id') + end.to raise_error(UploadedFile::UnknownSizeError, 'Unable to determine file size') + end + end + + context 'when size is a number' do + let_it_be(:size) { 1.gigabyte } + + it 'is overridden by the size of the local file' do + file = described_class.new(temp_file.path, size: size) + + expect(file.size).to eq(temp_file.size) + end + + it 'is respected if is a remote file' do + file = described_class.new(nil, remote_id: 'id', size: size) + + expect(file.size).to eq(size) + end + end + + context 'when size is a string' do + it 'is converted to a number' do + file = described_class.new(nil, remote_id: 'id', size: '1') + + expect(file.size).to eq(1) + end + + it 'raises an exception if does not represent a number' do + expect do + described_class.new(nil, remote_id: 'id', size: 'not a number') + end.to raise_error(UploadedFile::UnknownSizeError, 'Unable to determine file size') + end + end + end + describe '#sanitize_filename' do it { expect(described_class.new(temp_file.path).sanitize_filename('spaced name')).to eq('spaced_name') } it { expect(described_class.new(temp_file.path).sanitize_filename('#$%^&')).to eq('_____') } |