diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2019-12-03 13:28:37 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2019-12-03 13:28:37 +0300 |
commit | 662bb2b6f1f5b5730a0d1eaa66238e718468645d (patch) | |
tree | c1ca759e7d2c96e9c2023bbcf946f79e423473a5 /spec | |
parent | ed8af41027110fdad8f7bb4d53329eb73417fb8d (diff) |
Add latest changes from gitlab-org/gitlab@12-5-stable-ee
Diffstat (limited to 'spec')
-rw-r--r-- | spec/fixtures/lib/gitlab/import_export/complex/project.json | 13 | ||||
-rw-r--r-- | spec/helpers/projects/error_tracking_helper_spec.rb | 17 | ||||
-rw-r--r-- | spec/initializers/lograge_spec.rb | 6 | ||||
-rw-r--r-- | spec/lib/gitlab/grape_logging/loggers/exception_logger_spec.rb | 8 | ||||
-rw-r--r-- | spec/lib/gitlab/import_export/project_tree_restorer_spec.rb | 14 | ||||
-rw-r--r-- | spec/lib/quality/test_level_spec.rb | 26 | ||||
-rw-r--r-- | spec/services/merge_requests/push_options_handler_service_spec.rb | 8 | ||||
-rw-r--r-- | spec/support/database_cleaner.rb | 33 |
8 files changed, 102 insertions, 23 deletions
diff --git a/spec/fixtures/lib/gitlab/import_export/complex/project.json b/spec/fixtures/lib/gitlab/import_export/complex/project.json index 31805a54f2f..8dc91b05f4d 100644 --- a/spec/fixtures/lib/gitlab/import_export/complex/project.json +++ b/spec/fixtures/lib/gitlab/import_export/complex/project.json @@ -7209,15 +7209,15 @@ } ], "project_feature": { - "builds_access_level": 0, + "builds_access_level": 10, "created_at": "2014-12-26T09:26:45.000Z", "id": 2, - "issues_access_level": 0, - "merge_requests_access_level": 20, + "issues_access_level": 10, + "merge_requests_access_level": 10, "project_id": 4, - "snippets_access_level": 20, + "snippets_access_level": 10, "updated_at": "2016-09-23T11:58:28.000Z", - "wiki_access_level": 20 + "wiki_access_level": 10 }, "custom_attributes": [ { @@ -7257,6 +7257,9 @@ "image_url": "http://www.example.com" } ], + "ci_cd_settings": { + "group_runners_enabled": false + }, "boards": [ { "id": 29, diff --git a/spec/helpers/projects/error_tracking_helper_spec.rb b/spec/helpers/projects/error_tracking_helper_spec.rb index 064b3ad21cb..5e7449e21b7 100644 --- a/spec/helpers/projects/error_tracking_helper_spec.rb +++ b/spec/helpers/projects/error_tracking_helper_spec.rb @@ -75,4 +75,21 @@ describe Projects::ErrorTrackingHelper do end end end + + describe '#error_details_data' do + let(:issue_id) { 1234 } + let(:route_params) { [project.owner, project, issue_id, { format: :json }] } + let(:details_path) { details_namespace_project_error_tracking_index_path(*route_params) } + let(:stack_trace_path) { stack_trace_namespace_project_error_tracking_index_path(*route_params) } + + let(:result) { helper.error_details_data(project, issue_id) } + + it 'returns the correct details path' do + expect(result['issue-details-path']).to eq details_path + end + + it 'returns the correct stack trace path' do + expect(result['issue-stack-trace-path']).to eq stack_trace_path + end + end end diff --git a/spec/initializers/lograge_spec.rb b/spec/initializers/lograge_spec.rb index 9267231390d..5dd296b6040 100644 --- a/spec/initializers/lograge_spec.rb +++ b/spec/initializers/lograge_spec.rb @@ -110,9 +110,9 @@ describe 'lograge', type: :request do log_data = JSON.parse(log_output.string) - expect(log_data['exception']['class']).to eq('RuntimeError') - expect(log_data['exception']['message']).to eq('bad request') - expect(log_data['exception']['backtrace']).to eq(Gitlab::Profiler.clean_backtrace(backtrace)) + expect(log_data['exception.class']).to eq('RuntimeError') + expect(log_data['exception.message']).to eq('bad request') + expect(log_data['exception.backtrace']).to eq(Gitlab::Profiler.clean_backtrace(backtrace)) end end end diff --git a/spec/lib/gitlab/grape_logging/loggers/exception_logger_spec.rb b/spec/lib/gitlab/grape_logging/loggers/exception_logger_spec.rb index 8d7826c0a56..e21af023bb8 100644 --- a/spec/lib/gitlab/grape_logging/loggers/exception_logger_spec.rb +++ b/spec/lib/gitlab/grape_logging/loggers/exception_logger_spec.rb @@ -24,10 +24,8 @@ describe Gitlab::GrapeLogging::Loggers::ExceptionLogger do let(:expected) do { - exception: { - class: 'RuntimeError', - message: 'This is a test' - } + 'exception.class' => 'RuntimeError', + 'exception.message' => 'This is a test' } end @@ -39,7 +37,7 @@ describe Gitlab::GrapeLogging::Loggers::ExceptionLogger do before do current_backtrace = caller allow(exception).to receive(:backtrace).and_return(current_backtrace) - expected[:exception][:backtrace] = Gitlab::Profiler.clean_backtrace(current_backtrace) + expected['exception.backtrace'] = Gitlab::Profiler.clean_backtrace(current_backtrace) end it 'includes the backtrace' do 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 459b1eed1a7..64a648ca1f8 100644 --- a/spec/lib/gitlab/import_export/project_tree_restorer_spec.rb +++ b/spec/lib/gitlab/import_export/project_tree_restorer_spec.rb @@ -48,11 +48,11 @@ describe Gitlab::ImportExport::ProjectTreeRestorer do it 'restore correct project features' do project = Project.find_by_path('project') - expect(project.project_feature.issues_access_level).to eq(ProjectFeature::DISABLED) - expect(project.project_feature.builds_access_level).to eq(ProjectFeature::ENABLED) - expect(project.project_feature.snippets_access_level).to eq(ProjectFeature::ENABLED) - expect(project.project_feature.wiki_access_level).to eq(ProjectFeature::ENABLED) - expect(project.project_feature.merge_requests_access_level).to eq(ProjectFeature::ENABLED) + expect(project.project_feature.issues_access_level).to eq(ProjectFeature::PRIVATE) + expect(project.project_feature.builds_access_level).to eq(ProjectFeature::PRIVATE) + expect(project.project_feature.snippets_access_level).to eq(ProjectFeature::PRIVATE) + expect(project.project_feature.wiki_access_level).to eq(ProjectFeature::PRIVATE) + expect(project.project_feature.merge_requests_access_level).to eq(ProjectFeature::PRIVATE) end it 'has the project description' do @@ -220,6 +220,10 @@ describe Gitlab::ImportExport::ProjectTreeRestorer do expect(award_emoji.map(&:name)).to contain_exactly('thumbsup', 'coffee') end + it 'restores `ci_cd_settings` : `group_runners_enabled` setting' do + expect(@project.ci_cd_settings.group_runners_enabled?).to eq(false) + end + it 'restores the correct service' do expect(CustomIssueTrackerService.first).not_to be_nil end diff --git a/spec/lib/quality/test_level_spec.rb b/spec/lib/quality/test_level_spec.rb index 4db188bd8f2..c85994402dd 100644 --- a/spec/lib/quality/test_level_spec.rb +++ b/spec/lib/quality/test_level_spec.rb @@ -25,6 +25,13 @@ RSpec.describe Quality::TestLevel do end end + context 'when level is migration' do + it 'returns a pattern' do + expect(subject.pattern(:migration)) + .to eq("spec/{migrations,lib/gitlab/background_migration}{,/**/}*_spec.rb") + end + end + context 'when level is integration' do it 'returns a pattern' do expect(subject.pattern(:integration)) @@ -79,6 +86,13 @@ RSpec.describe Quality::TestLevel do end end + context 'when level is migration' do + it 'returns a regexp' do + expect(subject.regexp(:migration)) + .to eq(%r{spec/(migrations|lib/gitlab/background_migration)}) + end + end + context 'when level is integration' do it 'returns a regexp' do expect(subject.regexp(:integration)) @@ -116,6 +130,18 @@ RSpec.describe Quality::TestLevel do expect(subject.level_for('spec/models/abuse_report_spec.rb')).to eq(:unit) end + it 'returns the correct level for a migration test' do + expect(subject.level_for('spec/migrations/add_default_and_free_plans_spec.rb')).to eq(:migration) + end + + it 'returns the correct level for a background_migration test' do + expect(subject.level_for('spec/lib/gitlab/background_migration/archive_legacy_traces_spec.rb')).to eq(:migration) + end + + it 'returns the correct level for a geo migration test' do + expect(described_class.new('ee/').level_for('ee/spec/migrations/geo/migrate_ci_job_artifacts_to_separate_registry_spec.rb')).to eq(:migration) + end + it 'returns the correct level for an integration test' do expect(subject.level_for('spec/mailers/abuse_report_mailer_spec.rb')).to eq(:integration) end diff --git a/spec/services/merge_requests/push_options_handler_service_spec.rb b/spec/services/merge_requests/push_options_handler_service_spec.rb index 75b9c2304a6..7f9c47d8670 100644 --- a/spec/services/merge_requests/push_options_handler_service_spec.rb +++ b/spec/services/merge_requests/push_options_handler_service_spec.rb @@ -101,17 +101,15 @@ describe MergeRequests::PushOptionsHandlerService do shared_examples_for 'a service that can set the merge request to merge when pipeline succeeds' do subject(:last_mr) { MergeRequest.last } + let(:change) { Gitlab::ChangesList.new(changes).changes.first } + it 'sets auto_merge_enabled' do service.execute expect(last_mr.auto_merge_enabled).to eq(true) expect(last_mr.auto_merge_strategy).to eq(AutoMergeService::STRATEGY_MERGE_WHEN_PIPELINE_SUCCEEDS) - end - - it 'sets merge_user to the user' do - service.execute - expect(last_mr.merge_user).to eq(user) + expect(last_mr.merge_params['sha']).to eq(change[:newrev]) end end diff --git a/spec/support/database_cleaner.rb b/spec/support/database_cleaner.rb index f0dd6c52b74..25260a56578 100644 --- a/spec/support/database_cleaner.rb +++ b/spec/support/database_cleaner.rb @@ -29,6 +29,39 @@ RSpec.configure do |config| delete_from_all_tables! end + config.append_after(:context, :migration) do + delete_from_all_tables! + + # Postgres maximum number of columns in a table is 1600 (https://github.com/postgres/postgres/blob/de41869b64d57160f58852eab20a27f248188135/src/include/access/htup_details.h#L23-L47). + # And since: + # "The DROP COLUMN form does not physically remove the column, but simply makes + # it invisible to SQL operations. Subsequent insert and update operations in the + # table will store a null value for the column. Thus, dropping a column is quick + # but it will not immediately reduce the on-disk size of your table, as the space + # occupied by the dropped column is not reclaimed. + # The space will be reclaimed over time as existing rows are updated." + # according to https://www.postgresql.org/docs/current/sql-altertable.html. + # We drop and recreate the database if any table has more than 1200 columns, just to be safe. + max_allowed_columns = 1200 + tables_with_more_than_allowed_columns = + ApplicationRecord.connection.execute("SELECT attrelid::regclass::text AS table, COUNT(*) AS column_count FROM pg_attribute GROUP BY attrelid HAVING COUNT(*) > #{max_allowed_columns}") + + if tables_with_more_than_allowed_columns.any? + tables_with_more_than_allowed_columns.each do |result| + puts "The #{result['table']} table has #{result['column_count']} columns." + end + puts "Recreating the database" + start = Gitlab::Metrics::System.monotonic_time + + ActiveRecord::Tasks::DatabaseTasks.drop_current + ActiveRecord::Tasks::DatabaseTasks.create_current + ActiveRecord::Tasks::DatabaseTasks.load_schema_current + ActiveRecord::Tasks::DatabaseTasks.migrate + + puts "Database re-creation done in #{Gitlab::Metrics::System.monotonic_time - start}" + end + end + config.around(:each, :delete) do |example| self.class.use_transactional_tests = false |