diff options
author | James Lopez <james@jameslopez.es> | 2016-06-16 12:59:07 +0200 |
---|---|---|
committer | James Lopez <james@jameslopez.es> | 2016-06-16 12:59:07 +0200 |
commit | 452c076a34cc11cc97f4b1c3113e86ce4367e055 (patch) | |
tree | a503b33dc6dd181e2cf56d5965fc1eb822b4d9f9 /spec/lib | |
parent | 13e37a3ee5c943525a99481b855d654e97e8597c (diff) | |
download | gitlab-ce-452c076a34cc11cc97f4b1c3113e86ce4367e055.tar.gz |
Revert "squashed merge and fixed conflicts"
This reverts commit 13e37a3ee5c943525a99481b855d654e97e8597c.
Diffstat (limited to 'spec/lib')
-rw-r--r-- | spec/lib/banzai/filter/redactor_filter_spec.rb | 12 | ||||
-rw-r--r-- | spec/lib/ci/gitlab_ci_yaml_processor_spec.rb | 115 | ||||
-rw-r--r-- | spec/lib/container_registry/tag_spec.rb | 89 | ||||
-rw-r--r-- | spec/lib/gitlab/auth_spec.rb | 26 | ||||
-rw-r--r-- | spec/lib/gitlab/ci/config/node/configurable_spec.rb | 35 | ||||
-rw-r--r-- | spec/lib/gitlab/ci/config/node/factory_spec.rb | 49 | ||||
-rw-r--r-- | spec/lib/gitlab/ci/config/node/global_spec.rb | 104 | ||||
-rw-r--r-- | spec/lib/gitlab/ci/config/node/null_spec.rb | 23 | ||||
-rw-r--r-- | spec/lib/gitlab/ci/config/node/script_spec.rb | 48 | ||||
-rw-r--r-- | spec/lib/gitlab/ci/config_spec.rb | 42 | ||||
-rw-r--r-- | spec/lib/gitlab/database/migration_helpers_spec.rb | 13 | ||||
-rw-r--r-- | spec/lib/gitlab/metrics/instrumentation_spec.rb | 60 | ||||
-rw-r--r-- | spec/lib/gitlab/metrics/rack_middleware_spec.rb | 29 | ||||
-rw-r--r-- | spec/lib/gitlab/metrics/sampler_spec.rb | 25 | ||||
-rw-r--r-- | spec/lib/gitlab/project_search_results_spec.rb | 12 | ||||
-rw-r--r-- | spec/lib/gitlab/search_results_spec.rb | 16 |
16 files changed, 66 insertions, 632 deletions
diff --git a/spec/lib/banzai/filter/redactor_filter_spec.rb b/spec/lib/banzai/filter/redactor_filter_spec.rb index f181125156b..697d10bbf70 100644 --- a/spec/lib/banzai/filter/redactor_filter_spec.rb +++ b/spec/lib/banzai/filter/redactor_filter_spec.rb @@ -69,18 +69,6 @@ describe Banzai::Filter::RedactorFilter, lib: true do expect(doc.css('a').length).to eq 0 end - it 'removes references for project members with guest role' do - member = create(:user) - project = create(:empty_project, :public) - project.team << [member, :guest] - issue = create(:issue, :confidential, project: project) - - link = reference_link(project: project.id, issue: issue.id, reference_type: 'issue') - doc = filter(link, current_user: member) - - expect(doc.css('a').length).to eq 0 - end - it 'allows references for author' do author = create(:user) project = create(:empty_project, :public) diff --git a/spec/lib/ci/gitlab_ci_yaml_processor_spec.rb b/spec/lib/ci/gitlab_ci_yaml_processor_spec.rb index 143e2e6d238..7375539cf17 100644 --- a/spec/lib/ci/gitlab_ci_yaml_processor_spec.rb +++ b/spec/lib/ci/gitlab_ci_yaml_processor_spec.rb @@ -26,8 +26,7 @@ module Ci tag_list: [], options: {}, allow_failure: false, - when: "on_success", - environment: nil, + when: "on_success" }) end @@ -388,8 +387,7 @@ module Ci services: ["mysql"] }, allow_failure: false, - when: "on_success", - environment: nil, + when: "on_success" }) end @@ -417,8 +415,7 @@ module Ci services: ["postgresql"] }, allow_failure: false, - when: "on_success", - environment: nil, + when: "on_success" }) end end @@ -504,7 +501,6 @@ module Ci }) config_processor = GitlabCiYamlProcessor.new(config, path) - builds = config_processor.builds_for_stage_and_ref("test", "master") expect(builds.size).to eq(1) expect(builds.first[:when]).to eq(when_state) @@ -576,12 +572,7 @@ module Ci services: ["mysql"], before_script: ["pwd"], rspec: { - artifacts: { - paths: ["logs/", "binaries/"], - untracked: true, - name: "custom_name", - expire_in: "7d" - }, + artifacts: { paths: ["logs/", "binaries/"], untracked: true, name: "custom_name" }, script: "rspec" } }) @@ -603,77 +594,13 @@ module Ci artifacts: { name: "custom_name", paths: ["logs/", "binaries/"], - untracked: true, - expire_in: "7d" + untracked: true } }, when: "on_success", - allow_failure: false, - environment: nil, + allow_failure: false }) end - - %w[on_success on_failure always].each do |when_state| - it "returns artifacts for when #{when_state} defined" do - config = YAML.dump({ - rspec: { - script: "rspec", - artifacts: { paths: ["logs/", "binaries/"], when: when_state } - } - }) - - config_processor = GitlabCiYamlProcessor.new(config, path) - - builds = config_processor.builds_for_stage_and_ref("test", "master") - expect(builds.size).to eq(1) - expect(builds.first[:options][:artifacts][:when]).to eq(when_state) - end - end - end - - describe '#environment' do - let(:config) do - { - deploy_to_production: { stage: 'deploy', script: 'test', environment: environment } - } - end - - let(:processor) { GitlabCiYamlProcessor.new(YAML.dump(config)) } - let(:builds) { processor.builds_for_stage_and_ref('deploy', 'master') } - - context 'when a production environment is specified' do - let(:environment) { 'production' } - - it 'does return production' do - expect(builds.size).to eq(1) - expect(builds.first[:environment]).to eq(environment) - end - end - - context 'when no environment is specified' do - let(:environment) { nil } - - it 'does return nil environment' do - expect(builds.size).to eq(1) - expect(builds.first[:environment]).to be_nil - end - end - - context 'is not a string' do - let(:environment) { 1 } - - it 'raises error' do - expect { builds }.to raise_error("deploy_to_production job: environment parameter #{Gitlab::Regex.environment_name_regex_message}") - end - end - - context 'is not a valid string' do - let(:environment) { 'production staging' } - - it 'raises error' do - expect { builds }.to raise_error("deploy_to_production job: environment parameter #{Gitlab::Regex.environment_name_regex_message}") - end - end end describe "Dependencies" do @@ -737,8 +664,7 @@ module Ci tag_list: [], options: {}, when: "on_success", - allow_failure: false, - environment: nil, + allow_failure: false }) end end @@ -783,8 +709,7 @@ module Ci tag_list: [], options: {}, when: "on_success", - allow_failure: false, - environment: nil, + allow_failure: false }) expect(subject.second).to eq({ except: nil, @@ -796,8 +721,7 @@ module Ci tag_list: [], options: {}, when: "on_success", - allow_failure: false, - environment: nil, + allow_failure: false }) end end @@ -1043,27 +967,6 @@ EOT end.to raise_error(GitlabCiYamlProcessor::ValidationError, "rspec job: artifacts:name parameter should be a string") end - it "returns errors if job artifacts:when is not an a predefined value" do - config = YAML.dump({ types: ["build", "test"], rspec: { script: "test", artifacts: { when: 1 } } }) - expect do - GitlabCiYamlProcessor.new(config) - end.to raise_error(GitlabCiYamlProcessor::ValidationError, "rspec job: artifacts:when parameter should be on_success, on_failure or always") - end - - it "returns errors if job artifacts:expire_in is not an a string" do - config = YAML.dump({ types: ["build", "test"], rspec: { script: "test", artifacts: { expire_in: 1 } } }) - expect do - GitlabCiYamlProcessor.new(config) - end.to raise_error(GitlabCiYamlProcessor::ValidationError, "rspec job: artifacts:expire_in parameter should be a duration") - end - - it "returns errors if job artifacts:expire_in is not an a valid duration" do - config = YAML.dump({ types: ["build", "test"], rspec: { script: "test", artifacts: { expire_in: "7 elephants" } } }) - expect do - GitlabCiYamlProcessor.new(config) - end.to raise_error(GitlabCiYamlProcessor::ValidationError, "rspec job: artifacts:expire_in parameter should be a duration") - end - it "returns errors if job artifacts:untracked is not an array of strings" do config = YAML.dump({ types: ["build", "test"], rspec: { script: "test", artifacts: { untracked: "string" } } }) expect do diff --git a/spec/lib/container_registry/tag_spec.rb b/spec/lib/container_registry/tag_spec.rb index c7324c2bf77..858cb0bb134 100644 --- a/spec/lib/container_registry/tag_spec.rb +++ b/spec/lib/container_registry/tag_spec.rb @@ -17,85 +17,46 @@ describe ContainerRegistry::Tag do end context 'manifest processing' do - context 'schema v1' do - before do - stub_request(:get, 'http://example.com/v2/group/test/manifests/tag'). - with(headers: headers). - to_return( - status: 200, - body: File.read(Rails.root + 'spec/fixtures/container_registry/tag_manifest_1.json'), - headers: { 'Content-Type' => 'application/vnd.docker.distribution.manifest.v1+prettyjws' }) - end - - context '#layers' do - subject { tag.layers } - - it { expect(subject.length).to eq(1) } - end - - context '#total_size' do - subject { tag.total_size } - - it { is_expected.to be_nil } - end + before do + stub_request(:get, 'http://example.com/v2/group/test/manifests/tag'). + with(headers: headers). + to_return( + status: 200, + body: File.read(Rails.root + 'spec/fixtures/container_registry/tag_manifest.json'), + headers: { 'Content-Type' => 'application/vnd.docker.distribution.manifest.v2+json' }) + end - context 'config processing' do - context '#config' do - subject { tag.config } + context '#layers' do + subject { tag.layers } - it { is_expected.to be_nil } - end + it { expect(subject.length).to eq(1) } + end - context '#created_at' do - subject { tag.created_at } + context '#total_size' do + subject { tag.total_size } - it { is_expected.to be_nil } - end - end + it { is_expected.to eq(2319870) } end - context 'schema v2' do + context 'config processing' do before do - stub_request(:get, 'http://example.com/v2/group/test/manifests/tag'). - with(headers: headers). + stub_request(:get, 'http://example.com/v2/group/test/blobs/sha256:d7a513a663c1a6dcdba9ed832ca53c02ac2af0c333322cd6ca92936d1d9917ac'). + with(headers: { 'Accept' => 'application/octet-stream' }). to_return( status: 200, - body: File.read(Rails.root + 'spec/fixtures/container_registry/tag_manifest.json'), - headers: { 'Content-Type' => 'application/vnd.docker.distribution.manifest.v2+json' }) + body: File.read(Rails.root + 'spec/fixtures/container_registry/config_blob.json')) end - context '#layers' do - subject { tag.layers } + context '#config' do + subject { tag.config } - it { expect(subject.length).to eq(1) } + it { is_expected.not_to be_nil } end - context '#total_size' do - subject { tag.total_size } - - it { is_expected.to eq(2319870) } - end - - context 'config processing' do - before do - stub_request(:get, 'http://example.com/v2/group/test/blobs/sha256:d7a513a663c1a6dcdba9ed832ca53c02ac2af0c333322cd6ca92936d1d9917ac'). - with(headers: { 'Accept' => 'application/octet-stream' }). - to_return( - status: 200, - body: File.read(Rails.root + 'spec/fixtures/container_registry/config_blob.json')) - end - - context '#config' do - subject { tag.config } - - it { is_expected.not_to be_nil } - end - - context '#created_at' do - subject { tag.created_at } + context '#created_at' do + subject { tag.created_at } - it { is_expected.not_to be_nil } - end + it { is_expected.not_to be_nil } end end end diff --git a/spec/lib/gitlab/auth_spec.rb b/spec/lib/gitlab/auth_spec.rb index 7bec1367156..a814ad2a4e7 100644 --- a/spec/lib/gitlab/auth_spec.rb +++ b/spec/lib/gitlab/auth_spec.rb @@ -3,7 +3,7 @@ require 'spec_helper' describe Gitlab::Auth, lib: true do let(:gl_auth) { described_class } - describe 'find_for_git_client' do + describe 'find' do it 'recognizes CI' do token = '123' project = create(:empty_project) @@ -11,7 +11,7 @@ describe Gitlab::Auth, lib: true do ip = 'ip' expect(gl_auth).to receive(:rate_limit!).with(ip, success: true, login: 'gitlab-ci-token') - expect(gl_auth.find_for_git_client('gitlab-ci-token', token, project: project, ip: ip)).to eq(Gitlab::Auth::Result.new(nil, :ci)) + expect(gl_auth.find('gitlab-ci-token', token, project: project, ip: ip)).to eq(Gitlab::Auth::Result.new(nil, :ci)) end it 'recognizes master passwords' do @@ -19,7 +19,7 @@ describe Gitlab::Auth, lib: true do ip = 'ip' expect(gl_auth).to receive(:rate_limit!).with(ip, success: true, login: user.username) - expect(gl_auth.find_for_git_client(user.username, 'password', project: nil, ip: ip)).to eq(Gitlab::Auth::Result.new(user, :gitlab_or_ldap)) + expect(gl_auth.find(user.username, 'password', project: nil, ip: ip)).to eq(Gitlab::Auth::Result.new(user, :gitlab_or_ldap)) end it 'recognizes OAuth tokens' do @@ -29,7 +29,7 @@ describe Gitlab::Auth, lib: true do ip = 'ip' expect(gl_auth).to receive(:rate_limit!).with(ip, success: true, login: 'oauth2') - expect(gl_auth.find_for_git_client("oauth2", token.token, project: nil, ip: ip)).to eq(Gitlab::Auth::Result.new(user, :oauth)) + expect(gl_auth.find("oauth2", token.token, project: nil, ip: ip)).to eq(Gitlab::Auth::Result.new(user, :oauth)) end it 'returns double nil for invalid credentials' do @@ -37,11 +37,11 @@ describe Gitlab::Auth, lib: true do ip = 'ip' expect(gl_auth).to receive(:rate_limit!).with(ip, success: false, login: login) - expect(gl_auth.find_for_git_client(login, 'bar', project: nil, ip: ip)).to eq(Gitlab::Auth::Result.new) + expect(gl_auth.find(login, 'bar', project: nil, ip: ip)).to eq(Gitlab::Auth::Result.new) end end - describe 'find_with_user_password' do + describe 'find_in_gitlab_or_ldap' do let!(:user) do create(:user, username: username, @@ -52,25 +52,25 @@ describe Gitlab::Auth, lib: true do let(:password) { 'my-secret' } it "should find user by valid login/password" do - expect( gl_auth.find_with_user_password(username, password) ).to eql user + expect( gl_auth.find_in_gitlab_or_ldap(username, password) ).to eql user end it 'should find user by valid email/password with case-insensitive email' do - expect(gl_auth.find_with_user_password(user.email.upcase, password)).to eql user + expect(gl_auth.find_in_gitlab_or_ldap(user.email.upcase, password)).to eql user end it 'should find user by valid username/password with case-insensitive username' do - expect(gl_auth.find_with_user_password(username.upcase, password)).to eql user + expect(gl_auth.find_in_gitlab_or_ldap(username.upcase, password)).to eql user end it "should not find user with invalid password" do password = 'wrong' - expect( gl_auth.find_with_user_password(username, password) ).not_to eql user + expect( gl_auth.find_in_gitlab_or_ldap(username, password) ).not_to eql user end it "should not find user with invalid login" do user = 'wrong' - expect( gl_auth.find_with_user_password(username, password) ).not_to eql user + expect( gl_auth.find_in_gitlab_or_ldap(username, password) ).not_to eql user end context "with ldap enabled" do @@ -81,13 +81,13 @@ describe Gitlab::Auth, lib: true do it "tries to autheticate with db before ldap" do expect(Gitlab::LDAP::Authentication).not_to receive(:login) - gl_auth.find_with_user_password(username, password) + gl_auth.find_in_gitlab_or_ldap(username, password) end it "uses ldap as fallback to for authentication" do expect(Gitlab::LDAP::Authentication).to receive(:login) - gl_auth.find_with_user_password('ldap_user', 'password') + gl_auth.find_in_gitlab_or_ldap('ldap_user', 'password') end end end diff --git a/spec/lib/gitlab/ci/config/node/configurable_spec.rb b/spec/lib/gitlab/ci/config/node/configurable_spec.rb deleted file mode 100644 index 47c68f96dc8..00000000000 --- a/spec/lib/gitlab/ci/config/node/configurable_spec.rb +++ /dev/null @@ -1,35 +0,0 @@ -require 'spec_helper' - -describe Gitlab::Ci::Config::Node::Configurable do - let(:node) { Class.new } - - before do - node.include(described_class) - end - - describe 'allowed nodes' do - before do - node.class_eval do - allow_node :object, Object, description: 'test object' - end - end - - describe '#allowed_nodes' do - it 'has valid allowed nodes' do - expect(node.allowed_nodes).to include :object - end - - it 'creates a node factory' do - expect(node.allowed_nodes[:object]) - .to be_an_instance_of Gitlab::Ci::Config::Node::Factory - end - - it 'returns a duplicated factory object' do - first_factory = node.allowed_nodes[:object] - second_factory = node.allowed_nodes[:object] - - expect(first_factory).not_to be_equal(second_factory) - end - end - end -end diff --git a/spec/lib/gitlab/ci/config/node/factory_spec.rb b/spec/lib/gitlab/ci/config/node/factory_spec.rb deleted file mode 100644 index d681aa32456..00000000000 --- a/spec/lib/gitlab/ci/config/node/factory_spec.rb +++ /dev/null @@ -1,49 +0,0 @@ -require 'spec_helper' - -describe Gitlab::Ci::Config::Node::Factory do - describe '#create!' do - let(:factory) { described_class.new(entry_class) } - let(:entry_class) { Gitlab::Ci::Config::Node::Script } - - context 'when value setting value' do - it 'creates entry with valid value' do - entry = factory - .with(value: ['ls', 'pwd']) - .create! - - expect(entry.value).to eq "ls\npwd" - end - - context 'when setting description' do - it 'creates entry with description' do - entry = factory - .with(value: ['ls', 'pwd']) - .with(description: 'test description') - .create! - - expect(entry.value).to eq "ls\npwd" - expect(entry.description).to eq 'test description' - end - end - end - - context 'when not setting value' do - it 'raises error' do - expect { factory.create! }.to raise_error( - Gitlab::Ci::Config::Node::Factory::InvalidFactory - ) - end - end - - context 'when creating a null entry' do - it 'creates a null entry' do - entry = factory - .with(value: nil) - .nullify! - .create! - - expect(entry).to be_an_instance_of Gitlab::Ci::Config::Node::Null - end - end - end -end diff --git a/spec/lib/gitlab/ci/config/node/global_spec.rb b/spec/lib/gitlab/ci/config/node/global_spec.rb deleted file mode 100644 index b1972172435..00000000000 --- a/spec/lib/gitlab/ci/config/node/global_spec.rb +++ /dev/null @@ -1,104 +0,0 @@ -require 'spec_helper' - -describe Gitlab::Ci::Config::Node::Global do - let(:global) { described_class.new(hash) } - - describe '#allowed_nodes' do - it 'can contain global config keys' do - expect(global.allowed_nodes).to include :before_script - end - - it 'returns a hash' do - expect(global.allowed_nodes).to be_a Hash - end - end - - context 'when hash is valid' do - let(:hash) do - { before_script: ['ls', 'pwd'] } - end - - describe '#process!' do - before { global.process! } - - it 'creates nodes hash' do - expect(global.nodes).to be_an Array - end - - it 'creates node object for each entry' do - expect(global.nodes.count).to eq 1 - end - - it 'creates node object using valid class' do - expect(global.nodes.first) - .to be_an_instance_of Gitlab::Ci::Config::Node::Script - end - - it 'sets correct description for nodes' do - expect(global.nodes.first.description) - .to eq 'Script that will be executed before each job.' - end - end - - describe '#leaf?' do - it 'is not leaf' do - expect(global).not_to be_leaf - end - end - - describe '#before_script' do - context 'when processed' do - before { global.process! } - - it 'returns correct script' do - expect(global.before_script).to eq "ls\npwd" - end - end - - context 'when not processed' do - it 'returns nil' do - expect(global.before_script).to be nil - end - end - end - end - - context 'when hash is not valid' do - before { global.process! } - - let(:hash) do - { before_script: 'ls' } - end - - describe '#valid?' do - it 'is not valid' do - expect(global).not_to be_valid - end - end - - describe '#errors' do - it 'reports errors from child nodes' do - expect(global.errors) - .to include 'before_script should be an array of strings' - end - end - - describe '#before_script' do - it 'raises error' do - expect { global.before_script }.to raise_error( - Gitlab::Ci::Config::Node::Entry::InvalidError - ) - end - end - end - - context 'when value is not a hash' do - let(:hash) { [] } - - describe '#valid?' do - it 'is not valid' do - expect(global).not_to be_valid - end - end - end -end diff --git a/spec/lib/gitlab/ci/config/node/null_spec.rb b/spec/lib/gitlab/ci/config/node/null_spec.rb deleted file mode 100644 index 36101c62462..00000000000 --- a/spec/lib/gitlab/ci/config/node/null_spec.rb +++ /dev/null @@ -1,23 +0,0 @@ -require 'spec_helper' - -describe Gitlab::Ci::Config::Node::Null do - let(:entry) { described_class.new(nil) } - - describe '#leaf?' do - it 'is leaf node' do - expect(entry).to be_leaf - end - end - - describe '#any_method' do - it 'responds with nil' do - expect(entry.any_method).to be nil - end - end - - describe '#value' do - it 'returns nil' do - expect(entry.value).to be nil - end - end -end diff --git a/spec/lib/gitlab/ci/config/node/script_spec.rb b/spec/lib/gitlab/ci/config/node/script_spec.rb deleted file mode 100644 index e4d6481f8a5..00000000000 --- a/spec/lib/gitlab/ci/config/node/script_spec.rb +++ /dev/null @@ -1,48 +0,0 @@ -require 'spec_helper' - -describe Gitlab::Ci::Config::Node::Script do - let(:entry) { described_class.new(value) } - - describe '#validate!' do - before { entry.validate! } - - context 'when entry value is correct' do - let(:value) { ['ls', 'pwd'] } - - describe '#value' do - it 'returns concatenated command' do - expect(entry.value).to eq "ls\npwd" - end - end - - describe '#errors' do - it 'does not append errors' do - expect(entry.errors).to be_empty - end - end - - describe '#valid?' do - it 'is valid' do - expect(entry).to be_valid - end - end - end - - context 'when entry value is not correct' do - let(:value) { 'ls' } - - describe '#errors' do - it 'saves errors' do - expect(entry.errors) - .to include /should be an array of strings/ - end - end - - describe '#valid?' do - it 'is not valid' do - expect(entry).not_to be_valid - end - end - end - end -end diff --git a/spec/lib/gitlab/ci/config_spec.rb b/spec/lib/gitlab/ci/config_spec.rb index 3871d939feb..4d46abe520f 100644 --- a/spec/lib/gitlab/ci/config_spec.rb +++ b/spec/lib/gitlab/ci/config_spec.rb @@ -29,43 +29,17 @@ describe Gitlab::Ci::Config do expect(config.to_hash).to eq hash end - - describe '#valid?' do - it 'is valid' do - expect(config).to be_valid - end - - it 'has no errors' do - expect(config.errors).to be_empty - end - end end context 'when config is invalid' do - context 'when yml is incorrect' do - let(:yml) { '// invalid' } - - describe '.new' do - it 'raises error' do - expect { config }.to raise_error( - Gitlab::Ci::Config::Loader::FormatError, - /Invalid configuration format/ - ) - end - end - end - - context 'when config logic is incorrect' do - let(:yml) { 'before_script: "ls"' } - - describe '#valid?' do - it 'is not valid' do - expect(config).not_to be_valid - end - - it 'has errors' do - expect(config.errors).not_to be_empty - end + let(:yml) { '// invalid' } + + describe '.new' do + it 'raises error' do + expect { config }.to raise_error( + Gitlab::Ci::Config::Loader::FormatError, + /Invalid configuration format/ + ) end end end diff --git a/spec/lib/gitlab/database/migration_helpers_spec.rb b/spec/lib/gitlab/database/migration_helpers_spec.rb index 1ec539066a7..83ddabe6b0b 100644 --- a/spec/lib/gitlab/database/migration_helpers_spec.rb +++ b/spec/lib/gitlab/database/migration_helpers_spec.rb @@ -120,19 +120,6 @@ describe Gitlab::Database::MigrationHelpers, lib: true do model.add_column_with_default(:projects, :foo, :integer, default: 10) end.to raise_error(RuntimeError) end - - it 'removes the added column whenever changing a column NULL constraint fails' do - expect(model).to receive(:change_column_null). - with(:projects, :foo, false). - and_raise(RuntimeError) - - expect(model).to receive(:remove_column). - with(:projects, :foo) - - expect do - model.add_column_with_default(:projects, :foo, :integer, default: 10) - end.to raise_error(RuntimeError) - end end context 'inside a transaction' do diff --git a/spec/lib/gitlab/metrics/instrumentation_spec.rb b/spec/lib/gitlab/metrics/instrumentation_spec.rb index cdf641341cb..220e86924a2 100644 --- a/spec/lib/gitlab/metrics/instrumentation_spec.rb +++ b/spec/lib/gitlab/metrics/instrumentation_spec.rb @@ -9,31 +9,9 @@ describe Gitlab::Metrics::Instrumentation do text end - class << self - def buzz(text = 'buzz') - text - end - private :buzz - - def flaky(text = 'flaky') - text - end - protected :flaky - end - def bar(text = 'bar') text end - - def wadus(text = 'wadus') - text - end - private :wadus - - def chaf(text = 'chaf') - text - end - protected :chaf end allow(@dummy).to receive(:name).and_return('Dummy') @@ -79,7 +57,7 @@ describe Gitlab::Metrics::Instrumentation do and_return(transaction) expect(transaction).to receive(:add_metric). - with(described_class::SERIES, hash_including(:duration, :cpu_duration), + with(described_class::SERIES, an_instance_of(Hash), method: 'Dummy.foo') @dummy.foo @@ -159,7 +137,7 @@ describe Gitlab::Metrics::Instrumentation do and_return(transaction) expect(transaction).to receive(:add_metric). - with(described_class::SERIES, hash_including(:duration, :cpu_duration), + with(described_class::SERIES, an_instance_of(Hash), method: 'Dummy#bar') @dummy.new.bar @@ -230,21 +208,6 @@ describe Gitlab::Metrics::Instrumentation do described_class.instrument_methods(@dummy) expect(described_class.instrumented?(@dummy.singleton_class)).to eq(true) - expect(@dummy.method(:foo).source_location.first).to match(/instrumentation\.rb/) - end - - it 'instruments all protected class methods' do - described_class.instrument_methods(@dummy) - - expect(described_class.instrumented?(@dummy.singleton_class)).to eq(true) - expect(@dummy.method(:flaky).source_location.first).to match(/instrumentation\.rb/) - end - - it 'instruments all private instance methods' do - described_class.instrument_methods(@dummy) - - expect(described_class.instrumented?(@dummy.singleton_class)).to eq(true) - expect(@dummy.method(:buzz).source_location.first).to match(/instrumentation\.rb/) end it 'only instruments methods directly defined in the module' do @@ -278,21 +241,6 @@ describe Gitlab::Metrics::Instrumentation do described_class.instrument_instance_methods(@dummy) expect(described_class.instrumented?(@dummy)).to eq(true) - expect(@dummy.new.method(:bar).source_location.first).to match(/instrumentation\.rb/) - end - - it 'instruments all protected instance methods' do - described_class.instrument_instance_methods(@dummy) - - expect(described_class.instrumented?(@dummy)).to eq(true) - expect(@dummy.new.method(:chaf).source_location.first).to match(/instrumentation\.rb/) - end - - it 'instruments all private instance methods' do - described_class.instrument_instance_methods(@dummy) - - expect(described_class.instrumented?(@dummy)).to eq(true) - expect(@dummy.new.method(:wadus).source_location.first).to match(/instrumentation\.rb/) end it 'only instruments methods directly defined in the module' do @@ -305,7 +253,7 @@ describe Gitlab::Metrics::Instrumentation do described_class.instrument_instance_methods(@dummy) - expect(@dummy.new.method(:kittens).source_location.first).not_to match(/instrumentation\.rb/) + expect(@dummy.method_defined?(:_original_kittens)).to eq(false) end it 'can take a block to determine if a method should be instrumented' do @@ -313,7 +261,7 @@ describe Gitlab::Metrics::Instrumentation do false end - expect(@dummy.new.method(:bar).source_location.first).not_to match(/instrumentation\.rb/) + expect(@dummy.method_defined?(:_original_bar)).to eq(false) end end end diff --git a/spec/lib/gitlab/metrics/rack_middleware_spec.rb b/spec/lib/gitlab/metrics/rack_middleware_spec.rb index 40289f8b972..b99be4e1060 100644 --- a/spec/lib/gitlab/metrics/rack_middleware_spec.rb +++ b/spec/lib/gitlab/metrics/rack_middleware_spec.rb @@ -31,20 +31,6 @@ describe Gitlab::Metrics::RackMiddleware do middleware.call(env) end - - it 'tags a transaction with the method andpath of the route in the grape endpoint' do - route = double(:route, route_method: "GET", route_path: "/:version/projects/:id/archive(.:format)") - endpoint = double(:endpoint, route: route) - - env['api.endpoint'] = endpoint - - allow(app).to receive(:call).with(env) - - expect(middleware).to receive(:tag_endpoint). - with(an_instance_of(Gitlab::Metrics::Transaction), env) - - middleware.call(env) - end end describe '#transaction_from_env' do @@ -74,19 +60,4 @@ describe Gitlab::Metrics::RackMiddleware do expect(transaction.action).to eq('TestController#show') end end - - describe '#tag_endpoint' do - let(:transaction) { middleware.transaction_from_env(env) } - - it 'tags a transaction with the method and path of the route in the grape endpount' do - route = double(:route, route_method: "GET", route_path: "/:version/projects/:id/archive(.:format)") - endpoint = double(:endpoint, route: route) - - env['api.endpoint'] = endpoint - - middleware.tag_endpoint(transaction, env) - - expect(transaction.action).to eq('Grape#GET /projects/:id/archive') - end - end end diff --git a/spec/lib/gitlab/metrics/sampler_spec.rb b/spec/lib/gitlab/metrics/sampler_spec.rb index 1ab923b58cf..59db127674a 100644 --- a/spec/lib/gitlab/metrics/sampler_spec.rb +++ b/spec/lib/gitlab/metrics/sampler_spec.rb @@ -72,25 +72,14 @@ describe Gitlab::Metrics::Sampler do end end - if Gitlab::Metrics.mri? - describe '#sample_objects' do - it 'adds a metric containing the amount of allocated objects' do - expect(sampler).to receive(:add_metric). - with(/object_counts/, an_instance_of(Hash), an_instance_of(Hash)). - at_least(:once). - and_call_original - - sampler.sample_objects - end - - it 'ignores classes without a name' do - expect(Allocations).to receive(:to_hash).and_return({ Class.new => 4 }) - - expect(sampler).not_to receive(:add_metric). - with('object_counts', an_instance_of(Hash), type: nil) + describe '#sample_objects' do + it 'adds a metric containing the amount of allocated objects' do + expect(sampler).to receive(:add_metric). + with(/object_counts/, an_instance_of(Hash), an_instance_of(Hash)). + at_least(:once). + and_call_original - sampler.sample_objects - end + sampler.sample_objects end end diff --git a/spec/lib/gitlab/project_search_results_spec.rb b/spec/lib/gitlab/project_search_results_spec.rb index 270b89972d7..db0ff95b4f5 100644 --- a/spec/lib/gitlab/project_search_results_spec.rb +++ b/spec/lib/gitlab/project_search_results_spec.rb @@ -43,18 +43,6 @@ describe Gitlab::ProjectSearchResults, lib: true do expect(results.issues_count).to eq 1 end - it 'should not list project confidential issues for project members with guest role' do - project.team << [member, :guest] - - results = described_class.new(member, project, query) - issues = results.objects('issues') - - expect(issues).to include issue - expect(issues).not_to include security_issue_1 - expect(issues).not_to include security_issue_2 - expect(results.issues_count).to eq 1 - end - it 'should list project confidential issues for author' do results = described_class.new(author, project, query) issues = results.objects('issues') diff --git a/spec/lib/gitlab/search_results_spec.rb b/spec/lib/gitlab/search_results_spec.rb index 1bb444bf34f..f4afe597e8d 100644 --- a/spec/lib/gitlab/search_results_spec.rb +++ b/spec/lib/gitlab/search_results_spec.rb @@ -86,22 +86,6 @@ describe Gitlab::SearchResults do expect(results.issues_count).to eq 1 end - it 'should not list confidential issues for project members with guest role' do - project_1.team << [member, :guest] - project_2.team << [member, :guest] - - results = described_class.new(member, limit_projects, query) - issues = results.objects('issues') - - expect(issues).to include issue - expect(issues).not_to include security_issue_1 - expect(issues).not_to include security_issue_2 - expect(issues).not_to include security_issue_3 - expect(issues).not_to include security_issue_4 - expect(issues).not_to include security_issue_5 - expect(results.issues_count).to eq 1 - end - it 'should list confidential issues for author' do results = described_class.new(author, limit_projects, query) issues = results.objects('issues') |