diff options
author | Douwe Maan <douwe@gitlab.com> | 2018-05-09 17:09:25 +0000 |
---|---|---|
committer | Douwe Maan <douwe@gitlab.com> | 2018-05-09 17:09:25 +0000 |
commit | c4957ea958bbc9fcf30d59c8319ef5bf71d01219 (patch) | |
tree | 4a64ef11c29e74924e931142029060a3822dddc9 /spec | |
parent | 0135ea6db4c1cc3968691343c6b7cac191502cb8 (diff) | |
parent | 96b9c070ad102ec1004921ff318e2a0a591a5a9c (diff) | |
download | gitlab-ce-c4957ea958bbc9fcf30d59c8319ef5bf71d01219.tar.gz |
Merge branch 'master' into 'fix-project-mirror-data-schema'
# Conflicts:
# db/schema.rb
Diffstat (limited to 'spec')
-rw-r--r-- | spec/factories/ci/runners.rb | 2 | ||||
-rw-r--r-- | spec/factories/merge_requests.rb | 5 | ||||
-rw-r--r-- | spec/features/projects/merge_requests/user_merges_merge_request_spec.rb | 43 | ||||
-rw-r--r-- | spec/features/projects/merge_requests/user_rebases_merge_request_spec.rb | 34 | ||||
-rw-r--r-- | spec/helpers/projects_helper_spec.rb | 2 | ||||
-rw-r--r-- | spec/javascripts/ide/lib/common/model_spec.js | 4 | ||||
-rw-r--r-- | spec/javascripts/ide/stores/actions/file_spec.js | 16 | ||||
-rw-r--r-- | spec/lib/gitlab/git/repository_spec.rb | 17 | ||||
-rw-r--r-- | spec/migrations/add_pipeline_build_foreign_key_spec.rb | 32 | ||||
-rw-r--r-- | spec/models/ci/runner_spec.rb | 3 | ||||
-rw-r--r-- | spec/models/clusters/applications/runner_spec.rb | 3 | ||||
-rw-r--r-- | spec/models/project_spec.rb | 50 | ||||
-rw-r--r-- | spec/requests/api/runner_spec.rb | 23 | ||||
-rw-r--r-- | spec/support/helpers/migrations_helpers.rb | 10 | ||||
-rw-r--r-- | spec/support/services/migrate_to_ghost_user_service_shared_examples.rb | 2 |
15 files changed, 214 insertions, 32 deletions
diff --git a/spec/factories/ci/runners.rb b/spec/factories/ci/runners.rb index 34b8b246d0f..cdc170b9ccb 100644 --- a/spec/factories/ci/runners.rb +++ b/spec/factories/ci/runners.rb @@ -6,6 +6,7 @@ FactoryBot.define do is_shared false active true access_level :not_protected + runner_type :project_type trait :online do contacted_at Time.now @@ -13,6 +14,7 @@ FactoryBot.define do trait :shared do is_shared true + runner_type :instance_type end trait :specific do diff --git a/spec/factories/merge_requests.rb b/spec/factories/merge_requests.rb index d26cb0c3417..fab0ec22450 100644 --- a/spec/factories/merge_requests.rb +++ b/spec/factories/merge_requests.rb @@ -41,6 +41,11 @@ FactoryBot.define do state :merged end + trait :merged_target do + source_branch "merged-target" + target_branch "improve/awesome" + end + trait :closed do state :closed end diff --git a/spec/features/projects/merge_requests/user_merges_merge_request_spec.rb b/spec/features/projects/merge_requests/user_merges_merge_request_spec.rb new file mode 100644 index 00000000000..6539e6e9208 --- /dev/null +++ b/spec/features/projects/merge_requests/user_merges_merge_request_spec.rb @@ -0,0 +1,43 @@ +require "spec_helper" + +describe "User merges a merge request", :js do + let(:user) { project.owner } + + before do + sign_in(user) + end + + shared_examples "fast forward merge a merge request" do + it "merges a merge request" do + expect(page).to have_content("Fast-forward merge without a merge commit").and have_button("Merge") + + page.within(".mr-state-widget") do + click_button("Merge") + end + + page.within(".status-box") do + expect(page).to have_content("Merged") + end + end + end + + context "ff-only merge" do + let(:project) { create(:project, :public, :repository, merge_requests_ff_only_enabled: true) } + + before do + visit(merge_request_path(merge_request)) + end + + context "when branch is rebased" do + let!(:merge_request) { create(:merge_request, :rebased, source_project: project) } + + it_behaves_like "fast forward merge a merge request" + end + + context "when branch is merged" do + let!(:merge_request) { create(:merge_request, :merged_target, source_project: project) } + + it_behaves_like "fast forward merge a merge request" + end + end +end diff --git a/spec/features/projects/merge_requests/user_rebases_merge_request_spec.rb b/spec/features/projects/merge_requests/user_rebases_merge_request_spec.rb new file mode 100644 index 00000000000..92e1c9942b1 --- /dev/null +++ b/spec/features/projects/merge_requests/user_rebases_merge_request_spec.rb @@ -0,0 +1,34 @@ +require "spec_helper" + +describe "User rebases a merge request", :js do + let(:merge_request) { create(:merge_request, :simple, source_project: project) } + let(:user) { project.owner } + + before do + sign_in(user) + end + + shared_examples "rebases" do + it "rebases" do + visit(merge_request_path(merge_request)) + + expect(page).to have_button("Rebase") + + click_button("Rebase") + + expect(page).to have_content("Rebase in progress") + end + end + + context "when merge is regular" do + let(:project) { create(:project, :public, :repository, merge_requests_rebase_enabled: true) } + + it_behaves_like "rebases" + end + + context "when merge is ff-only" do + let(:project) { create(:project, :public, :repository, merge_requests_ff_only_enabled: true) } + + it_behaves_like "rebases" + end +end diff --git a/spec/helpers/projects_helper_spec.rb b/spec/helpers/projects_helper_spec.rb index 8fcb175416f..f8877b6d1aa 100644 --- a/spec/helpers/projects_helper_spec.rb +++ b/spec/helpers/projects_helper_spec.rb @@ -283,7 +283,7 @@ describe ProjectsHelper do end it 'removes the repo path' do - repo = "#{storage_path}/namespace/test.git" + repo = File.join(storage_path, 'namespace/test.git') import_error = "Could not clone #{repo}\n" expect(sanitize_repo_path(project, import_error)).to eq('Could not clone [REPOS PATH]/namespace/test.git') diff --git a/spec/javascripts/ide/lib/common/model_spec.js b/spec/javascripts/ide/lib/common/model_spec.js index 7a6c22b6d27..c278bf92b08 100644 --- a/spec/javascripts/ide/lib/common/model_spec.js +++ b/spec/javascripts/ide/lib/common/model_spec.js @@ -28,6 +28,10 @@ describe('Multi-file editor library model', () => { expect(model.originalModel).not.toBeNull(); expect(model.model).not.toBeNull(); expect(model.baseModel).not.toBeNull(); + + expect(model.originalModel.uri.path).toBe('original/path--path'); + expect(model.model.uri.path).toBe('path--path'); + expect(model.baseModel.uri.path).toBe('target/path--path'); }); it('creates model with head file to compare against', () => { diff --git a/spec/javascripts/ide/stores/actions/file_spec.js b/spec/javascripts/ide/stores/actions/file_spec.js index 3ef5a859001..7bebc2288e3 100644 --- a/spec/javascripts/ide/stores/actions/file_spec.js +++ b/spec/javascripts/ide/stores/actions/file_spec.js @@ -569,6 +569,22 @@ describe('IDE store file actions', () => { .catch(done.fail); }); + it('returns false when already opened', done => { + store.state.openFiles.push({ + ...f, + active: true, + key: `pending-${f.key}`, + }); + + store + .dispatch('openPendingTab', { file: f, keyPrefix: 'pending' }) + .then(added => { + expect(added).toBe(false); + }) + .then(done) + .catch(done.fail); + }); + it('pushes router URL when added', done => { store.state.currentBranchId = 'master'; diff --git a/spec/lib/gitlab/git/repository_spec.rb b/spec/lib/gitlab/git/repository_spec.rb index 9f091975959..cce84276fe3 100644 --- a/spec/lib/gitlab/git/repository_spec.rb +++ b/spec/lib/gitlab/git/repository_spec.rb @@ -2275,7 +2275,22 @@ describe Gitlab::Git::Repository, seed_helper: true do expect(empty_repo.checksum).to eq '0000000000000000000000000000000000000000' end - it 'raises a no repository exception when there is no repo' do + it 'raises Gitlab::Git::Repository::InvalidRepository error for non-valid git repo' do + FileUtils.rm_rf(File.join(storage_path, 'non-valid.git')) + + system(git_env, *%W(#{Gitlab.config.git.bin_path} clone --bare #{TEST_REPO_PATH} non-valid.git), + chdir: SEED_STORAGE_PATH, + out: '/dev/null', + err: '/dev/null') + + File.truncate(File.join(storage_path, 'non-valid.git/HEAD'), 0) + + non_valid = described_class.new('default', 'non-valid.git', '') + + expect { non_valid.checksum }.to raise_error(Gitlab::Git::Repository::InvalidRepository) + end + + it 'raises Gitlab::Git::Repository::NoRepository error when there is no repo' do broken_repo = described_class.new('default', 'a/path.git', '') expect { broken_repo.checksum }.to raise_error(Gitlab::Git::Repository::NoRepository) diff --git a/spec/migrations/add_pipeline_build_foreign_key_spec.rb b/spec/migrations/add_pipeline_build_foreign_key_spec.rb new file mode 100644 index 00000000000..e9413f52f19 --- /dev/null +++ b/spec/migrations/add_pipeline_build_foreign_key_spec.rb @@ -0,0 +1,32 @@ +require 'spec_helper' +require Rails.root.join('db', 'migrate', '20180420010016_add_pipeline_build_foreign_key.rb') + +describe AddPipelineBuildForeignKey, :migration do + let(:namespaces) { table(:namespaces) } + let(:projects) { table(:projects) } + let(:pipelines) { table(:ci_pipelines) } + let(:builds) { table(:ci_builds) } + + before do + namespaces.create(id: 10, name: 'gitlab-org', path: 'gitlab-org') + projects.create!(id: 11, namespace_id: 10, name: 'gitlab', path: 'gitlab') + pipelines.create!(id: 12, project_id: 11, ref: 'master', sha: 'adf43c3a') + + builds.create!(id: 101, commit_id: 12, project_id: 11) + builds.create!(id: 102, commit_id: 222, project_id: 11) + builds.create!(id: 103, commit_id: 333, project_id: 11) + builds.create!(id: 104, commit_id: 12, project_id: 11) + builds.create!(id: 106, commit_id: nil, project_id: 11) + builds.create!(id: 107, commit_id: 12, project_id: nil) + end + + it 'adds foreign key after removing orphans' do + expect(builds.all.count).to eq 6 + expect(foreign_key_exists?(:ci_builds, :ci_pipelines, column: :commit_id)).to be_falsey + + migrate! + + expect(builds.all.pluck(:id)).to eq [101, 104] + expect(foreign_key_exists?(:ci_builds, :ci_pipelines, column: :commit_id)).to be_truthy + end +end diff --git a/spec/models/ci/runner_spec.rb b/spec/models/ci/runner_spec.rb index cc4d4e5e4ae..eb59ba7cbe9 100644 --- a/spec/models/ci/runner_spec.rb +++ b/spec/models/ci/runner_spec.rb @@ -3,6 +3,7 @@ require 'spec_helper' describe Ci::Runner do describe 'validation' do it { is_expected.to validate_presence_of(:access_level) } + it { is_expected.to validate_presence_of(:runner_type) } context 'when runner is not allowed to pick untagged jobs' do context 'when runner does not have tags' do @@ -198,7 +199,7 @@ describe Ci::Runner do end describe '#assign_to' do - let!(:project) { FactoryBot.create :project } + let!(:project) { FactoryBot.create(:project) } let!(:shared_runner) { FactoryBot.create(:ci_runner, :shared) } before do diff --git a/spec/models/clusters/applications/runner_spec.rb b/spec/models/clusters/applications/runner_spec.rb index 64d995a73c1..5f2c723d483 100644 --- a/spec/models/clusters/applications/runner_spec.rb +++ b/spec/models/clusters/applications/runner_spec.rb @@ -74,9 +74,8 @@ describe Clusters::Applications::Runner do it 'assigns the new runner to runner' do subject - gitlab_runner.reload - expect(gitlab_runner.runner).not_to be_nil + expect(gitlab_runner.reload.runner).to be_project_type end end diff --git a/spec/models/project_spec.rb b/spec/models/project_spec.rb index 41622fbbb6f..5b452f17979 100644 --- a/spec/models/project_spec.rb +++ b/spec/models/project_spec.rb @@ -309,12 +309,12 @@ describe Project do describe 'project token' do it 'sets an random token if none provided' do - project = FactoryBot.create :project, runners_token: '' + project = FactoryBot.create(:project, runners_token: '') expect(project.runners_token).not_to eq('') end it 'does not set an random token if one provided' do - project = FactoryBot.create :project, runners_token: 'my-token' + project = FactoryBot.create(:project, runners_token: 'my-token') expect(project.runners_token).to eq('my-token') end end @@ -639,7 +639,7 @@ describe Project do describe '#to_param' do context 'with namespace' do before do - @group = create :group, name: 'gitlab' + @group = create(:group, name: 'gitlab') @project = create(:project, name: 'gitlabhq', namespace: @group) end @@ -866,8 +866,8 @@ describe Project do describe '#star_count' do it 'counts stars from multiple users' do - user1 = create :user - user2 = create :user + user1 = create(:user) + user2 = create(:user) project = create(:project, :public) expect(project.star_count).to eq(0) @@ -889,7 +889,7 @@ describe Project do end it 'counts stars on the right project' do - user = create :user + user = create(:user) project1 = create(:project, :public) project2 = create(:project, :public) @@ -1148,9 +1148,9 @@ describe Project do describe '#any_runners?' do context 'shared runners' do - let(:project) { create :project, shared_runners_enabled: shared_runners_enabled } - let(:specific_runner) { create :ci_runner } - let(:shared_runner) { create :ci_runner, :shared } + let(:project) { create(:project, shared_runners_enabled: shared_runners_enabled) } + let(:specific_runner) { create(:ci_runner) } + let(:shared_runner) { create(:ci_runner, :shared) } context 'for shared runners disabled' do let(:shared_runners_enabled) { false } @@ -1208,9 +1208,9 @@ describe Project do end context 'group runners' do - let(:project) { create :project, group_runners_enabled: group_runners_enabled } - let(:group) { create :group, projects: [project] } - let(:group_runner) { create :ci_runner, groups: [group] } + let(:project) { create(:project, group_runners_enabled: group_runners_enabled) } + let(:group) { create(:group, projects: [project]) } + let(:group_runner) { create(:ci_runner, groups: [group]) } context 'for group runners disabled' do let(:group_runners_enabled) { false } @@ -1292,7 +1292,7 @@ describe Project do end describe '#pages_deployed?' do - let(:project) { create :project } + let(:project) { create(:project) } subject { project.pages_deployed? } @@ -1310,8 +1310,8 @@ describe Project do end describe '#pages_url' do - let(:group) { create :group, name: group_name } - let(:project) { create :project, namespace: group, name: project_name } + let(:group) { create(:group, name: group_name) } + let(:project) { create(:project, namespace: group, name: project_name) } let(:domain) { 'Example.com' } subject { project.pages_url } @@ -1337,8 +1337,8 @@ describe Project do end describe '#pages_group_url' do - let(:group) { create :group, name: group_name } - let(:project) { create :project, namespace: group, name: project_name } + let(:group) { create(:group, name: group_name) } + let(:project) { create(:project, namespace: group, name: project_name) } let(:domain) { 'Example.com' } let(:port) { 1234 } @@ -1455,8 +1455,8 @@ describe Project do let(:private_group) { create(:group, visibility_level: 0) } let(:internal_group) { create(:group, visibility_level: 10) } - let(:private_project) { create :project, :private, group: private_group } - let(:internal_project) { create :project, :internal, group: internal_group } + let(:private_project) { create(:project, :private, group: private_group) } + let(:internal_project) { create(:project, :internal, group: internal_group) } context 'when group is private project can not be internal' do it { expect(private_project.visibility_level_allowed?(Gitlab::VisibilityLevel::INTERNAL)).to be_falsey } @@ -1885,8 +1885,6 @@ describe Project do update_remote_mirrors end - # TODO: study if remote_mirror_available_overridden is still a necessary attribute considering that - # it is no longer under any license it 'does nothing when remote mirror is disabled globally and not overridden' do stub_application_setting(mirror_available: false) project.remote_mirror_available_overridden = false @@ -2452,8 +2450,8 @@ describe Project do end describe '#pages_url' do - let(:group) { create :group, name: 'Group' } - let(:nested_group) { create :group, parent: group } + let(:group) { create(:group, name: 'Group') } + let(:nested_group) { create(:group, parent: group) } let(:domain) { 'Example.com' } subject { project.pages_url } @@ -2464,7 +2462,7 @@ describe Project do end context 'top-level group' do - let(:project) { create :project, namespace: group, name: project_name } + let(:project) { create(:project, namespace: group, name: project_name) } context 'group page' do let(:project_name) { 'group.example.com' } @@ -2480,7 +2478,7 @@ describe Project do end context 'nested group' do - let(:project) { create :project, namespace: nested_group, name: project_name } + let(:project) { create(:project, namespace: nested_group, name: project_name) } let(:expected_url) { "http://group.example.com/#{nested_group.path}/#{project.path}" } context 'group page' do @@ -2498,7 +2496,7 @@ describe Project do end describe '#http_url_to_repo' do - let(:project) { create :project } + let(:project) { create(:project) } it 'returns the url to the repo without a username' do expect(project.http_url_to_repo).to eq("#{project.web_url}.git") diff --git a/spec/requests/api/runner_spec.rb b/spec/requests/api/runner_spec.rb index 082605827b7..da392c5ab81 100644 --- a/spec/requests/api/runner_spec.rb +++ b/spec/requests/api/runner_spec.rb @@ -41,6 +41,7 @@ describe API::Runner, :clean_gitlab_redis_shared_state do expect(json_response['id']).to eq(runner.id) expect(json_response['token']).to eq(runner.token) expect(runner.run_untagged).to be true + expect(runner.active).to be true expect(runner.token).not_to eq(registration_token) expect(runner).to be_instance_type end @@ -129,6 +130,28 @@ describe API::Runner, :clean_gitlab_redis_shared_state do end end + context 'when option for activating a Runner is provided' do + context 'when active is set to true' do + it 'creates runner' do + post api('/runners'), token: registration_token, + active: true + + expect(response).to have_gitlab_http_status 201 + expect(Ci::Runner.first.active).to be true + end + end + + context 'when active is set to false' do + it 'creates runner' do + post api('/runners'), token: registration_token, + active: false + + expect(response).to have_gitlab_http_status 201 + expect(Ci::Runner.first.active).to be false + end + end + end + context 'when maximum job timeout is specified' do it 'creates runner' do post api('/runners'), token: registration_token, diff --git a/spec/support/helpers/migrations_helpers.rb b/spec/support/helpers/migrations_helpers.rb index 5d6f662e8fe..84abec75c26 100644 --- a/spec/support/helpers/migrations_helpers.rb +++ b/spec/support/helpers/migrations_helpers.rb @@ -24,6 +24,16 @@ module MigrationsHelpers end end + def foreign_key_exists?(source, target = nil, column: nil) + ActiveRecord::Base.connection.foreign_keys(source).any? do |key| + if column + key.options[:column].to_s == column.to_s + else + key.to_table.to_s == target.to_s + end + end + end + def reset_column_in_all_models clear_schema_cache! diff --git a/spec/support/services/migrate_to_ghost_user_service_shared_examples.rb b/spec/support/services/migrate_to_ghost_user_service_shared_examples.rb index adfd256dff1..1478c6b5a47 100644 --- a/spec/support/services/migrate_to_ghost_user_service_shared_examples.rb +++ b/spec/support/services/migrate_to_ghost_user_service_shared_examples.rb @@ -86,7 +86,7 @@ shared_examples "migrating a deleted user's associated records to the ghost user end it "blocks the user before #{record_class_name} migration begins" do - expect(service).to receive("migrate_#{record_class_name.parameterize('_')}s".to_sym) do + expect(service).to receive("migrate_#{record_class_name.parameterize('_').pluralize}".to_sym) do expect(user.reload).to be_blocked end |