diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2019-10-01 12:05:59 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2019-10-01 12:05:59 +0000 |
commit | 9e27f0d920cc3891fa7644c5cc0bc280c519fb20 (patch) | |
tree | 9784dd99270f2009159b19077412bf83d13123a4 /spec | |
parent | 1bab0ba591263cd739af2d2c7c3f1b03678a59b6 (diff) | |
download | gitlab-ce-9e27f0d920cc3891fa7644c5cc0bc280c519fb20.tar.gz |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec')
20 files changed, 406 insertions, 120 deletions
diff --git a/spec/features/projects/jobs/user_browses_job_spec.rb b/spec/features/projects/jobs/user_browses_job_spec.rb index 4d8a4812123..82ad08d0ff2 100644 --- a/spec/features/projects/jobs/user_browses_job_spec.rb +++ b/spec/features/projects/jobs/user_browses_job_spec.rb @@ -104,20 +104,20 @@ describe 'User browses a job', :js do it 'displays the failure reason' do wait_for_all_requests within('.builds-container') do - build_link = first('.build-job > a') - expect(build_link['data-original-title']).to eq('test - failed - (unknown failure)') + expect(page).to have_selector( + ".build-job > a[data-original-title='test - failed - (unknown failure)']") end end end context 'when a failed job has been retried' do - let!(:build) { create(:ci_build, :failed, :retried, :trace_artifact, pipeline: pipeline) } + let!(:build_retried) { create(:ci_build, :failed, :retried, :trace_artifact, pipeline: pipeline) } it 'displays the failure reason and retried label' do wait_for_all_requests within('.builds-container') do - build_link = first('.build-job > a') - expect(build_link['data-original-title']).to eq('test - failed - (unknown failure) (retried)') + expect(page).to have_selector( + ".build-job > a[data-original-title='test - failed - (unknown failure) (retried)']") end end end diff --git a/spec/fixtures/lib/gitlab/import_export/project.json b/spec/fixtures/lib/gitlab/import_export/project.json index 4544c38f39a..7d9c8cdef8f 100644 --- a/spec/fixtures/lib/gitlab/import_export/project.json +++ b/spec/fixtures/lib/gitlab/import_export/project.json @@ -6175,6 +6175,8 @@ "finished_at": null, "user_id": 9999, "duration": null, + "source": "push", + "merge_request_id": null, "notes": [ { "id": 999, diff --git a/spec/javascripts/boards/issue_card_spec.js b/spec/javascripts/boards/issue_card_spec.js index 9b5e8afa4ef..9e99f961797 100644 --- a/spec/javascripts/boards/issue_card_spec.js +++ b/spec/javascripts/boards/issue_card_spec.js @@ -286,19 +286,4 @@ describe('Issue card component', () => { .catch(done.fail); }); }); - - describe('weights', () => { - it('shows weight component is greater than 0', () => { - expect(component.$el.querySelector('.board-card-weight')).not.toBeNull(); - }); - - it('shows weight component when weight is 0', done => { - component.issue.weight = 0; - - Vue.nextTick(() => { - expect(component.$el.querySelector('.board-card-weight')).not.toBeNull(); - done(); - }); - }); - }); }); diff --git a/spec/lib/api/helpers/graphql_helpers_spec.rb b/spec/lib/api/helpers/graphql_helpers_spec.rb new file mode 100644 index 00000000000..c775ba6d5e8 --- /dev/null +++ b/spec/lib/api/helpers/graphql_helpers_spec.rb @@ -0,0 +1,44 @@ +# frozen_string_literal: true + +require 'spec_helper' + +describe API::Helpers::GraphqlHelpers do + describe 'run_graphql!' do + let(:query) { '{ metadata { version } }' } + + let(:graphql_helper) do + Class.new do + include API::Helpers::GraphqlHelpers + end.new + end + + context 'when transform function is provided' do + let(:result) { { 'data' => { 'metadata' => { 'version' => '1.0.0' } } } } + + before do + allow(GitlabSchema).to receive(:execute).and_return(result) + end + + it 'returns the expected result' do + expect( + graphql_helper.run_graphql!( + query: query, + transform: ->(result) { result.dig('data', 'metadata') } + ) + ).to eq({ 'version' => '1.0.0' }) + end + end + + context 'when a transform function is not provided' do + let(:result) { double('result') } + + before do + allow(GitlabSchema).to receive(:execute).and_return(result) + end + + it 'returns the expected result' do + expect(graphql_helper.run_graphql!(query: query)).to eq(result) + end + end + end +end diff --git a/spec/lib/banzai/filter/video_link_filter_spec.rb b/spec/lib/banzai/filter/video_link_filter_spec.rb index afcc846ba05..b5be204d680 100644 --- a/spec/lib/banzai/filter/video_link_filter_spec.rb +++ b/spec/lib/banzai/filter/video_link_filter_spec.rb @@ -17,32 +17,27 @@ describe Banzai::Filter::VideoLinkFilter do let(:project) { create(:project, :repository) } - shared_examples 'replaces the image tag with a video tag' do |ext| - it "replaces the image tag 'path/video.#{ext}' with a video tag" do - container = filter(link_to_image("/path/video.#{ext}")).children.first - - expect(container.name).to eq 'div' - expect(container['class']).to eq 'video-container' + context 'when the element src has a video extension' do + UploaderHelper::SAFE_VIDEO_EXT.each do |ext| + it "replaces the image tag 'path/video.#{ext}' with a video tag" do + container = filter(link_to_image("/path/video.#{ext}")).children.first - video, paragraph = container.children + expect(container.name).to eq 'div' + expect(container['class']).to eq 'video-container' - expect(video.name).to eq 'video' - expect(video['src']).to eq "/path/video.#{ext}" + video, paragraph = container.children - expect(paragraph.name).to eq 'p' + expect(video.name).to eq 'video' + expect(video['src']).to eq "/path/video.#{ext}" - link = paragraph.children.first + expect(paragraph.name).to eq 'p' - expect(link.name).to eq 'a' - expect(link['href']).to eq "/path/video.#{ext}" - expect(link['target']).to eq '_blank' - end - end + link = paragraph.children.first - context 'when the element src has a video extension' do - UploaderHelper::SAFE_VIDEO_EXT.each do |ext| - it_behaves_like 'replaces the image tag with a video tag', ext - it_behaves_like 'replaces the image tag with a video tag', ext.upcase + expect(link.name).to eq 'a' + expect(link['href']).to eq "/path/video.#{ext}" + expect(link['target']).to eq '_blank' + end end end diff --git a/spec/lib/gitlab/background_migration/migrate_pages_metadata_spec.rb b/spec/lib/gitlab/background_migration/migrate_pages_metadata_spec.rb new file mode 100644 index 00000000000..d94a312f605 --- /dev/null +++ b/spec/lib/gitlab/background_migration/migrate_pages_metadata_spec.rb @@ -0,0 +1,44 @@ +# frozen_string_literal: true + +require 'spec_helper' + +describe Gitlab::BackgroundMigration::MigratePagesMetadata, :migration, schema: 20190919040324 do + let(:projects) { table(:projects) } + + subject(:migrate_pages_metadata) { described_class.new } + + describe '#perform_on_relation' do + let(:namespaces) { table(:namespaces) } + let(:builds) { table(:ci_builds) } + let(:pages_metadata) { table(:project_pages_metadata) } + + it 'marks specified projects with successful pages deployment' do + namespace = namespaces.create!(name: 'gitlab', path: 'gitlab-org') + not_migrated_with_pages = projects.create!(namespace_id: namespace.id, name: 'Not Migrated With Pages') + builds.create!(project_id: not_migrated_with_pages.id, type: 'GenericCommitStatus', status: 'success', stage: 'deploy', name: 'pages:deploy') + + migrated = projects.create!(namespace_id: namespace.id, name: 'Migrated') + pages_metadata.create!(project_id: migrated.id, deployed: true) + + not_migrated_no_pages = projects.create!(namespace_id: namespace.id, name: 'Not Migrated No Pages') + project_not_in_relation_scope = projects.create!(namespace_id: namespace.id, name: 'Other') + + projects_relation = projects.where(id: [not_migrated_with_pages, not_migrated_no_pages, migrated]) + + migrate_pages_metadata.perform_on_relation(projects_relation) + + expect(pages_metadata.find_by_project_id(not_migrated_with_pages.id).deployed).to eq(true) + expect(pages_metadata.find_by_project_id(not_migrated_no_pages.id).deployed).to eq(false) + expect(pages_metadata.find_by_project_id(migrated.id).deployed).to eq(true) + expect(pages_metadata.find_by_project_id(project_not_in_relation_scope.id)).to be_nil + end + end + + describe '#perform' do + it 'creates relation and delegates to #perform_on_relation' do + expect(migrate_pages_metadata).to receive(:perform_on_relation).with(projects.where(id: 3..5)) + + migrate_pages_metadata.perform(3, 5) + end + end +end diff --git a/spec/lib/gitlab/ci/status/composite_spec.rb b/spec/lib/gitlab/ci/status/composite_spec.rb new file mode 100644 index 00000000000..1725d954b92 --- /dev/null +++ b/spec/lib/gitlab/ci/status/composite_spec.rb @@ -0,0 +1,61 @@ +require 'spec_helper' + +describe Gitlab::Ci::Status::Composite do + set(:pipeline) { create(:ci_pipeline) } + + before(:all) do + @statuses = HasStatus::STATUSES_ENUM.map do |status, idx| + [status, create(:ci_build, pipeline: pipeline, status: status, importing: true)] + end.to_h + + @statuses_with_allow_failure = HasStatus::STATUSES_ENUM.map do |status, idx| + [status, create(:ci_build, pipeline: pipeline, status: status, allow_failure: true, importing: true)] + end.to_h + end + + describe '#status' do + shared_examples 'compares composite with SQL status' do + it 'returns exactly the same result' do + builds = Ci::Build.where(id: all_statuses) + + expect(composite_status.status).to eq(builds.legacy_status) + expect(composite_status.warnings?).to eq(builds.failed_but_allowed.any?) + end + end + + shared_examples 'validate all combinations' do |perms| + HasStatus::STATUSES_ENUM.keys.combination(perms).each do |statuses| + context "with #{statuses.join(",")}" do + it_behaves_like 'compares composite with SQL status' do + let(:all_statuses) do + statuses.map { |status| @statuses[status] } + end + + let(:composite_status) do + described_class.new(all_statuses) + end + end + + HasStatus::STATUSES_ENUM.each do |allow_failure_status, _| + context "and allow_failure #{allow_failure_status}" do + it_behaves_like 'compares composite with SQL status' do + let(:all_statuses) do + statuses.map { |status| @statuses[status] } + + [@statuses_with_allow_failure[allow_failure_status]] + end + + let(:composite_status) do + described_class.new(all_statuses) + end + end + end + end + end + end + end + + it_behaves_like 'validate all combinations', 0 + it_behaves_like 'validate all combinations', 1 + it_behaves_like 'validate all combinations', 2 + end +end 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 fcc79279b6f..c619a2ab237 100644 --- a/spec/lib/gitlab/import_export/project_tree_restorer_spec.rb +++ b/spec/lib/gitlab/import_export/project_tree_restorer_spec.rb @@ -96,6 +96,17 @@ describe Gitlab::ImportExport::ProjectTreeRestorer do expect(Ci::Pipeline.where(ref: nil)).not_to be_empty end + it 'restores pipeline for merge request' do + pipeline = Ci::Pipeline.find_by_sha('048721d90c449b244b7b4c53a9186b04330174ec') + + expect(pipeline).to be_valid + expect(pipeline.tag).to be_falsey + expect(pipeline.source).to eq('merge_request_event') + expect(pipeline.merge_request.id).to be > 0 + expect(pipeline.merge_request.target_branch).to eq('feature') + expect(pipeline.merge_request.source_branch).to eq('feature_conflict') + end + it 'preserves updated_at on issues' do issue = Issue.where(description: 'Aliquam enim illo et possimus.').first diff --git a/spec/lib/gitlab/import_export/relation_factory_spec.rb b/spec/lib/gitlab/import_export/relation_factory_spec.rb index a31f77484d8..51b2fd06b46 100644 --- a/spec/lib/gitlab/import_export/relation_factory_spec.rb +++ b/spec/lib/gitlab/import_export/relation_factory_spec.rb @@ -3,12 +3,14 @@ require 'spec_helper' describe Gitlab::ImportExport::RelationFactory do let(:project) { create(:project) } let(:members_mapper) { double('members_mapper').as_null_object } + let(:merge_requests_mapping) { {} } let(:user) { create(:admin) } let(:excluded_keys) { [] } let(:created_object) do described_class.create(relation_sym: relation_sym, relation_hash: relation_hash, members_mapper: members_mapper, + merge_requests_mapping: merge_requests_mapping, user: user, project: project, excluded_keys: excluded_keys) diff --git a/spec/models/ci/group_spec.rb b/spec/models/ci/group_spec.rb index 36c65d92840..b3b158a111e 100644 --- a/spec/models/ci/group_spec.rb +++ b/spec/models/ci/group_spec.rb @@ -22,6 +22,32 @@ describe Ci::Group do end end + describe '#status' do + let(:jobs) do + [create(:ci_build, :failed)] + end + + context 'when ci_composite_status is enabled' do + before do + stub_feature_flags(ci_composite_status: true) + end + + it 'returns a failed status' do + expect(subject.status).to eq('failed') + end + end + + context 'when ci_composite_status is disabled' do + before do + stub_feature_flags(ci_composite_status: false) + end + + it 'returns a failed status' do + expect(subject.status).to eq('failed') + end + end + end + describe '#detailed_status' do context 'when there is only one item in the group' do it 'calls the status from the object itself' do diff --git a/spec/models/ci/legacy_stage_spec.rb b/spec/models/ci/legacy_stage_spec.rb index bb812cc0533..477f4036218 100644 --- a/spec/models/ci/legacy_stage_spec.rb +++ b/spec/models/ci/legacy_stage_spec.rb @@ -216,7 +216,7 @@ describe Ci::LegacyStage do context 'when stage has warnings' do context 'when using memoized warnings flag' do context 'when there are warnings' do - let(:stage) { build(:ci_stage, warnings: 2) } + let(:stage) { build(:ci_stage, warnings: true) } it 'returns true using memoized value' do expect(stage).not_to receive(:statuses) @@ -225,22 +225,13 @@ describe Ci::LegacyStage do end context 'when there are no warnings' do - let(:stage) { build(:ci_stage, warnings: 0) } + let(:stage) { build(:ci_stage, warnings: false) } it 'returns false using memoized value' do expect(stage).not_to receive(:statuses) expect(stage).not_to have_warnings end end - - context 'when number of warnings is not a valid value' do - let(:stage) { build(:ci_stage, warnings: true) } - - it 'calculates statuses using database queries' do - expect(stage).to receive(:statuses).and_call_original - expect(stage).not_to have_warnings - end - end end context 'when calculating warnings from statuses' do diff --git a/spec/models/ci/pipeline_spec.rb b/spec/models/ci/pipeline_spec.rb index 3c625784132..0e11c595388 100644 --- a/spec/models/ci/pipeline_spec.rb +++ b/spec/models/ci/pipeline_spec.rb @@ -1136,59 +1136,71 @@ describe Ci::Pipeline, :mailer do end describe '#legacy_stages' do + using RSpec::Parameterized::TableSyntax + subject { pipeline.legacy_stages } - context 'stages list' do - it 'returns ordered list of stages' do - expect(subject.map(&:name)).to eq(%w[build test deploy]) - end + where(:ci_composite_status) do + [false, true] end - context 'stages with statuses' do - let(:statuses) do - subject.map { |stage| [stage.name, stage.status] } + with_them do + before do + stub_feature_flags(ci_composite_status: ci_composite_status) end - it 'returns list of stages with correct statuses' do - expect(statuses).to eq([%w(build failed), - %w(test success), - %w(deploy running)]) + context 'stages list' do + it 'returns ordered list of stages' do + expect(subject.map(&:name)).to eq(%w[build test deploy]) + end end - context 'when commit status is retried' do - before do - create(:commit_status, pipeline: pipeline, - stage: 'build', - name: 'mac', - stage_idx: 0, - status: 'success') - - pipeline.process! + context 'stages with statuses' do + let(:statuses) do + subject.map { |stage| [stage.name, stage.status] } end - it 'ignores the previous state' do - expect(statuses).to eq([%w(build success), + it 'returns list of stages with correct statuses' do + expect(statuses).to eq([%w(build failed), %w(test success), %w(deploy running)]) end - end - end - context 'when there is a stage with warnings' do - before do - create(:commit_status, pipeline: pipeline, - stage: 'deploy', - name: 'prod:2', - stage_idx: 2, - status: 'failed', - allow_failure: true) + context 'when commit status is retried' do + before do + create(:commit_status, pipeline: pipeline, + stage: 'build', + name: 'mac', + stage_idx: 0, + status: 'success') + + pipeline.process! + end + + it 'ignores the previous state' do + expect(statuses).to eq([%w(build success), + %w(test success), + %w(deploy running)]) + end + end end - it 'populates stage with correct number of warnings' do - deploy_stage = pipeline.legacy_stages.third + context 'when there is a stage with warnings' do + before do + create(:commit_status, pipeline: pipeline, + stage: 'deploy', + name: 'prod:2', + stage_idx: 2, + status: 'failed', + allow_failure: true) + end - expect(deploy_stage).not_to receive(:statuses) - expect(deploy_stage).to have_warnings + it 'populates stage with correct number of warnings' do + deploy_stage = pipeline.legacy_stages.third + + expect(deploy_stage).not_to receive(:statuses) + expect(deploy_stage).to have_warnings + end end end end @@ -2326,36 +2338,38 @@ describe Ci::Pipeline, :mailer do describe '#update_status' do context 'when pipeline is empty' do it 'updates does not change pipeline status' do - expect(pipeline.statuses.latest.status).to be_nil + expect(pipeline.statuses.latest.slow_composite_status).to be_nil expect { pipeline.update_status } - .to change { pipeline.reload.status }.to 'skipped' + .to change { pipeline.reload.status } + .from('created') + .to('skipped') end end context 'when updating status to pending' do before do - allow(pipeline) - .to receive_message_chain(:statuses, :latest, :status) - .and_return(:running) + create(:ci_build, pipeline: pipeline, status: :running) end it 'updates pipeline status to running' do expect { pipeline.update_status } - .to change { pipeline.reload.status }.to 'running' + .to change { pipeline.reload.status } + .from('created') + .to('running') end end context 'when updating status to scheduled' do before do - allow(pipeline) - .to receive_message_chain(:statuses, :latest, :status) - .and_return(:scheduled) + create(:ci_build, pipeline: pipeline, status: :scheduled) end it 'updates pipeline status to scheduled' do expect { pipeline.update_status } - .to change { pipeline.reload.status }.to 'scheduled' + .to change { pipeline.reload.status } + .from('created') + .to('scheduled') end end diff --git a/spec/models/ci/stage_spec.rb b/spec/models/ci/stage_spec.rb index 85cd32fb03a..8827509edda 100644 --- a/spec/models/ci/stage_spec.rb +++ b/spec/models/ci/stage_spec.rb @@ -130,7 +130,7 @@ describe Ci::Stage, :models do context 'when statuses status was not recognized' do before do allow(stage) - .to receive_message_chain(:statuses, :latest, :status) + .to receive(:latest_stage_status) .and_return(:unknown) end diff --git a/spec/models/commit_status_spec.rb b/spec/models/commit_status_spec.rb index 017cca0541e..95e9b0d0f92 100644 --- a/spec/models/commit_status_spec.rb +++ b/spec/models/commit_status_spec.rb @@ -321,7 +321,7 @@ describe CommitStatus do end it 'returns a correct compound status' do - expect(described_class.all.status).to eq 'running' + expect(described_class.all.slow_composite_status).to eq 'running' end end @@ -331,7 +331,7 @@ describe CommitStatus do end it 'returns status that indicates success' do - expect(described_class.all.status).to eq 'success' + expect(described_class.all.slow_composite_status).to eq 'success' end end @@ -342,7 +342,7 @@ describe CommitStatus do end it 'returns status according to the scope' do - expect(described_class.latest.status).to eq 'success' + expect(described_class.latest.slow_composite_status).to eq 'success' end end end diff --git a/spec/models/concerns/has_status_spec.rb b/spec/models/concerns/has_status_spec.rb index 09fb2fff521..21e4dda6dab 100644 --- a/spec/models/concerns/has_status_spec.rb +++ b/spec/models/concerns/has_status_spec.rb @@ -3,12 +3,15 @@ require 'spec_helper' describe HasStatus do - describe '.status' do - subject { CommitStatus.status } + describe '.slow_composite_status' do + using RSpec::Parameterized::TableSyntax + + subject { CommitStatus.slow_composite_status } shared_examples 'build status summary' do context 'all successful' do let!(:statuses) { Array.new(2) { create(type, status: :success) } } + it { is_expected.to eq 'success' } end @@ -165,16 +168,26 @@ describe HasStatus do end end - context 'ci build statuses' do - let(:type) { :ci_build } - - it_behaves_like 'build status summary' + where(:ci_composite_status) do + [false, true] end - context 'generic commit statuses' do - let(:type) { :generic_commit_status } + with_them do + before do + stub_feature_flags(ci_composite_status: ci_composite_status) + end + + context 'ci build statuses' do + let(:type) { :ci_build } - it_behaves_like 'build status summary' + it_behaves_like 'build status summary' + end + + context 'generic commit statuses' do + let(:type) { :generic_commit_status } + + it_behaves_like 'build status summary' + end end end @@ -372,8 +385,8 @@ describe HasStatus do end end - describe '.status_sql' do - subject { Ci::Build.status_sql } + describe '.legacy_status_sql' do + subject { Ci::Build.legacy_status_sql } it 'returns SQL' do puts subject diff --git a/spec/models/namespace_spec.rb b/spec/models/namespace_spec.rb index e72e272f4d2..a4d60467071 100644 --- a/spec/models/namespace_spec.rb +++ b/spec/models/namespace_spec.rb @@ -928,12 +928,34 @@ describe Namespace do let(:project) { create(:project, namespace: namespace) } context 'when there are pages deployed for the project' do - before do - project.mark_pages_as_deployed + context 'but pages metadata is not migrated' do + before do + generic_commit_status = create(:generic_commit_status, :success, stage: 'deploy', name: 'pages:deploy') + generic_commit_status.update!(project: project) + project.pages_metadatum.destroy! + end + + it 'migrates pages metadata and returns the virual domain' do + virtual_domain = namespace.pages_virtual_domain + + expect(project.reload.pages_metadatum.deployed).to eq(true) + + expect(virtual_domain).to be_an_instance_of(Pages::VirtualDomain) + expect(virtual_domain.lookup_paths).not_to be_empty + end end - it 'returns the virual domain' do - expect(namespace.pages_virtual_domain).to be_an_instance_of(Pages::VirtualDomain) + context 'and pages metadata is migrated' do + before do + project.mark_pages_as_deployed + end + + it 'returns the virual domain' do + virtual_domain = namespace.pages_virtual_domain + + expect(virtual_domain).to be_an_instance_of(Pages::VirtualDomain) + expect(virtual_domain.lookup_paths).not_to be_empty + end end end end diff --git a/spec/models/pages_domain_spec.rb b/spec/models/pages_domain_spec.rb index 9ac80f8b795..2e7b2b88432 100644 --- a/spec/models/pages_domain_spec.rb +++ b/spec/models/pages_domain_spec.rb @@ -569,7 +569,9 @@ describe PagesDomain do context 'when there are pages deployed for the project' do before do - project.mark_pages_as_deployed + generic_commit_status = create(:generic_commit_status, :success, stage: 'deploy', name: 'pages:deploy') + generic_commit_status.update!(project: project) + project.pages_metadatum.destroy! project.reload end @@ -578,6 +580,12 @@ describe PagesDomain do expect(pages_domain.pages_virtual_domain).to be_an_instance_of(Pages::VirtualDomain) end + + it 'migrates project pages metadata' do + expect { pages_domain.pages_virtual_domain }.to change { + project.reload.pages_metadatum&.deployed + }.from(nil).to(true) + end end end end diff --git a/spec/models/project_services/jira_service_spec.rb b/spec/models/project_services/jira_service_spec.rb index 39c1176f238..c3b2e52848c 100644 --- a/spec/models/project_services/jira_service_spec.rb +++ b/spec/models/project_services/jira_service_spec.rb @@ -282,7 +282,7 @@ describe JiraService do context 'when data are stored in properties' do let(:properties) { data_params.merge(title: title, description: description) } let!(:service) do - create(:jira_service, :without_properties_callback, properties: properties) + create(:jira_service, :without_properties_callback, properties: properties.merge(additional: 'something')) end it_behaves_like 'issue tracker fields' diff --git a/spec/models/project_spec.rb b/spec/models/project_spec.rb index e97e8c58bbd..daccd143b6d 100644 --- a/spec/models/project_spec.rb +++ b/spec/models/project_spec.rb @@ -5107,6 +5107,16 @@ describe Project do end end + describe '.pages_metadata_not_migrated' do + it 'returns only projects that have pages deployed' do + _project_with_pages_metadata_migrated = create(:project) + project_with_pages_metadata_not_migrated = create(:project) + project_with_pages_metadata_not_migrated.pages_metadatum.destroy! + + expect(described_class.pages_metadata_not_migrated).to contain_exactly(project_with_pages_metadata_not_migrated) + end + end + describe '#pages_group_root?' do it 'returns returns true if pages_url is same as pages_group_url' do project = build(:project) diff --git a/spec/models/service_spec.rb b/spec/models/service_spec.rb index d96e1398677..4049ddcff7f 100644 --- a/spec/models/service_spec.rb +++ b/spec/models/service_spec.rb @@ -78,10 +78,11 @@ describe Service do end describe "Template" do + let(:project) { create(:project) } + describe '.build_from_template' do context 'when template is invalid' do it 'sets service template to inactive when template is invalid' do - project = create(:project) template = build(:prometheus_service, template: true, active: true, properties: {}) template.save(validate: false) @@ -91,6 +92,64 @@ describe Service do expect(service.active).to be false end end + + describe 'build issue tracker from a template' do + let(:title) { 'custom title' } + let(:description) { 'custom description' } + let(:url) { 'http://jira.example.com' } + let(:api_url) { 'http://api-jira.example.com' } + let(:username) { 'jira-username' } + let(:password) { 'jira-password' } + let(:data_params) do + { + url: url, api_url: api_url, + username: username, password: password + } + end + + shared_examples 'service creation from a template' do + it 'creates a correct service' do + service = described_class.build_from_template(project.id, template) + + expect(service).to be_active + expect(service.title).to eq(title) + expect(service.description).to eq(description) + expect(service.url).to eq(url) + expect(service.api_url).to eq(api_url) + expect(service.username).to eq(username) + expect(service.password).to eq(password) + end + end + + # this will be removed as part of https://gitlab.com/gitlab-org/gitlab-foss/issues/63084 + context 'when data are stored in properties' do + let(:properties) { data_params.merge(title: title, description: description) } + let!(:template) do + create(:jira_service, :without_properties_callback, template: true, properties: properties.merge(additional: 'something')) + end + + it_behaves_like 'service creation from a template' + end + + context 'when data are stored in separated fields' do + let(:template) do + create(:jira_service, data_params.merge(properties: {}, title: title, description: description, template: true)) + end + + it_behaves_like 'service creation from a template' + end + + context 'when data are stored in both properties and separated fields' do + let(:properties) { data_params.merge(title: title, description: description) } + let(:template) do + create(:jira_service, :without_properties_callback, active: true, template: true, properties: properties).tap do |service| + create(:jira_tracker_data, data_params.merge(service: service)) + end + end + + it_behaves_like 'service creation from a template' + end + end end describe "for pushover service" do @@ -104,7 +163,6 @@ describe Service do api_key: '123456789' }) end - let(:project) { create(:project) } describe 'is prefilled for projects pushover service' do it "has all fields prefilled" do |