diff options
Diffstat (limited to 'spec/presenters')
8 files changed, 127 insertions, 27 deletions
diff --git a/spec/presenters/ci/build_runner_presenter_spec.rb b/spec/presenters/ci/build_runner_presenter_spec.rb index 1eecc9d1ce6..9cb00781e99 100644 --- a/spec/presenters/ci/build_runner_presenter_spec.rb +++ b/spec/presenters/ci/build_runner_presenter_spec.rb @@ -85,7 +85,7 @@ RSpec.describe Ci::BuildRunnerPresenter do Ci::JobArtifact::DEFAULT_FILE_NAMES.each do |file_type, filename| context file_type.to_s do let(:report) { { "#{file_type}": [filename] } } - let(:build) { create(:ci_build, options: { artifacts: { reports: report } } ) } + let(:build) { create(:ci_build, options: { artifacts: { reports: report } }) } let(:report_expectation) do { @@ -106,7 +106,7 @@ RSpec.describe Ci::BuildRunnerPresenter do context "when option has both archive and reports specification" do let(:report) { { junit: ['junit.xml'] } } - let(:build) { create(:ci_build, options: { script: 'echo', artifacts: { **archive, reports: report } } ) } + let(:build) { create(:ci_build, options: { script: 'echo', artifacts: { **archive, reports: report } }) } let(:report_expectation) do { @@ -223,7 +223,7 @@ RSpec.describe Ci::BuildRunnerPresenter do let(:build) { create(:ci_build, ref: pipeline.ref, pipeline: pipeline) } before do - pipeline.persistent_ref.create + pipeline.persistent_ref.create # rubocop:disable Rails/SaveBang end it 'returns the correct refspecs' do @@ -261,7 +261,7 @@ RSpec.describe Ci::BuildRunnerPresenter do let(:build) { create(:ci_build, pipeline: pipeline) } before do - pipeline.persistent_ref.create + pipeline.persistent_ref.create # rubocop:disable Rails/SaveBang end it 'exposes the persistent pipeline ref' do @@ -272,27 +272,82 @@ RSpec.describe Ci::BuildRunnerPresenter do end end - describe '#variables' do - subject { presenter.variables } + describe '#runner_variables' do + subject { presenter.runner_variables } - let(:build) { create(:ci_build) } + let_it_be(:project_with_flag_disabled) { create(:project, :repository) } + let_it_be(:project_with_flag_enabled) { create(:project, :repository) } + + before do + stub_feature_flags(variable_inside_variable: [project_with_flag_enabled]) + end + + shared_examples 'returns an array with the expected variables' do + it 'returns an array' do + is_expected.to be_an_instance_of(Array) + end + + it 'returns the expected variables' do + is_expected.to eq(presenter.variables.to_runner_variables) + end + end + + context 'when FF :variable_inside_variable is disabled' do + let(:sha) { project_with_flag_disabled.repository.commit.sha } + let(:pipeline) { create(:ci_pipeline, sha: sha, project: project_with_flag_disabled) } + let(:build) { create(:ci_build, pipeline: pipeline) } + + it_behaves_like 'returns an array with the expected variables' + end + + context 'when FF :variable_inside_variable is enabled' do + let(:sha) { project_with_flag_enabled.repository.commit.sha } + let(:pipeline) { create(:ci_pipeline, sha: sha, project: project_with_flag_enabled) } + let(:build) { create(:ci_build, pipeline: pipeline) } - it 'returns a Collection' do - is_expected.to be_an_instance_of(Gitlab::Ci::Variables::Collection) + it_behaves_like 'returns an array with the expected variables' end end - describe '#runner_variables' do - subject { presenter.runner_variables } + describe '#runner_variables subset' do + subject { presenter.runner_variables.select { |v| %w[A B C].include?(v.fetch(:key)) } } let(:build) { create(:ci_build) } - it 'returns an array' do - is_expected.to be_an_instance_of(Array) - end + context 'with references in pipeline variables' do + before do + create(:ci_pipeline_variable, key: 'A', value: 'refA-$B', pipeline: build.pipeline) + create(:ci_pipeline_variable, key: 'B', value: 'refB-$C-$D', pipeline: build.pipeline) + create(:ci_pipeline_variable, key: 'C', value: 'value', pipeline: build.pipeline) + end + + context 'when FF :variable_inside_variable is disabled' do + before do + stub_feature_flags(variable_inside_variable: false) + end - it 'returns the expected variables' do - is_expected.to eq(presenter.variables.to_runner_variables) + it 'returns non-expanded variables' do + is_expected.to eq [ + { key: 'A', value: 'refA-$B', public: false, masked: false }, + { key: 'B', value: 'refB-$C-$D', public: false, masked: false }, + { key: 'C', value: 'value', public: false, masked: false } + ] + end + end + + context 'when FF :variable_inside_variable is enabled' do + before do + stub_feature_flags(variable_inside_variable: [build.project]) + end + + it 'returns expanded and sorted variables' do + is_expected.to eq [ + { key: 'C', value: 'value', public: false, masked: false }, + { key: 'B', value: 'refB-value-$D', public: false, masked: false }, + { key: 'A', value: 'refA-refB-value-$D', public: false, masked: false } + ] + end + end end end end diff --git a/spec/presenters/ci/trigger_presenter_spec.rb b/spec/presenters/ci/trigger_presenter_spec.rb index bac1c94e0b7..b86684707b9 100644 --- a/spec/presenters/ci/trigger_presenter_spec.rb +++ b/spec/presenters/ci/trigger_presenter_spec.rb @@ -35,7 +35,7 @@ RSpec.describe Ci::TriggerPresenter do context 'when user is a trigger owner and builds admin' do before do - trigger.update(owner: user) + trigger.update!(owner: user) end describe '#token' do diff --git a/spec/presenters/clusters/cluster_presenter_spec.rb b/spec/presenters/clusters/cluster_presenter_spec.rb index 2d38c91499a..2e8364b2987 100644 --- a/spec/presenters/clusters/cluster_presenter_spec.rb +++ b/spec/presenters/clusters/cluster_presenter_spec.rb @@ -347,7 +347,7 @@ RSpec.describe Clusters::ClusterPresenter do before do project.add_maintainer(user) - stub_feature_flags(user_mode_in_session: false) + stub_application_setting(admin_mode: false) end context 'user can read logs' do @@ -363,7 +363,7 @@ RSpec.describe Clusters::ClusterPresenter do before do project.add_developer(user) - stub_feature_flags(user_mode_in_session: false) + stub_application_setting(admin_mode: false) end it 'returns nil' do diff --git a/spec/presenters/packages/composer/packages_presenter_spec.rb b/spec/presenters/packages/composer/packages_presenter_spec.rb index d0e3b68fc9f..c1d8c9816a6 100644 --- a/spec/presenters/packages/composer/packages_presenter_spec.rb +++ b/spec/presenters/packages/composer/packages_presenter_spec.rb @@ -9,8 +9,8 @@ RSpec.describe ::Packages::Composer::PackagesPresenter do let_it_be(:json) { { 'name' => package_name } } let_it_be(:group) { create(:group) } let_it_be(:project) { create(:project, :custom_repo, files: { 'composer.json' => json.to_json }, group: group) } - let_it_be(:package1) { create(:composer_package, :with_metadatum, project: project, name: package_name, version: '1.0.0', json: json) } - let_it_be(:package2) { create(:composer_package, :with_metadatum, project: project, name: package_name, version: '2.0.0', json: json) } + let!(:package1) { create(:composer_package, :with_metadatum, project: project, name: package_name, version: '1.0.0', json: json) } + let!(:package2) { create(:composer_package, :with_metadatum, project: project, name: package_name, version: '2.0.0', json: json) } let(:branch) { project.repository.find_branch('master') } @@ -29,6 +29,11 @@ RSpec.describe ::Packages::Composer::PackagesPresenter do 'type' => 'zip', 'url' => "http://localhost/api/v4/projects/#{project.id}/packages/composer/archives/#{package.name}.zip?sha=#{branch.target}" }, + 'source' => { + 'reference' => branch.target, + 'type' => 'git', + 'url' => "http://localhost/#{group.path}/#{project.path}.git" + }, 'name' => package.name, 'uid' => package.id, 'version' => package.version diff --git a/spec/presenters/packages/conan/package_presenter_spec.rb b/spec/presenters/packages/conan/package_presenter_spec.rb index 4e8af752f3e..dad9460c8eb 100644 --- a/spec/presenters/packages/conan/package_presenter_spec.rb +++ b/spec/presenters/packages/conan/package_presenter_spec.rb @@ -146,7 +146,7 @@ RSpec.describe ::Packages::Conan::PackagePresenter do before do [info_file, manifest_file, package_file].each do |file| file.conan_file_metadatum.conan_package_reference = alternative_reference - file.save + file.save! end end diff --git a/spec/presenters/packages/detail/package_presenter_spec.rb b/spec/presenters/packages/detail/package_presenter_spec.rb index 5e20eed877f..4c3e0228583 100644 --- a/spec/presenters/packages/detail/package_presenter_spec.rb +++ b/spec/presenters/packages/detail/package_presenter_spec.rb @@ -31,7 +31,6 @@ RSpec.describe ::Packages::Detail::PackagePresenter do id: pipeline.id, sha: pipeline.sha, ref: pipeline.ref, - git_commit_message: pipeline.git_commit_message, user: user_info, project: { name: pipeline.project.name, diff --git a/spec/presenters/project_hook_presenter_spec.rb b/spec/presenters/project_hook_presenter_spec.rb index 061ec38ae34..2e4bd17bbe1 100644 --- a/spec/presenters/project_hook_presenter_spec.rb +++ b/spec/presenters/project_hook_presenter_spec.rb @@ -11,7 +11,7 @@ RSpec.describe ProjectHookPresenter do subject { web_hook.present.logs_details_path(web_hook_log) } let(:expected_path) do - "/#{project.namespace.path}/#{project.name}/hooks/#{web_hook.id}/hook_logs/#{web_hook_log.id}" + "/#{project.namespace.path}/#{project.name}/-/hooks/#{web_hook.id}/hook_logs/#{web_hook_log.id}" end it { is_expected.to eq(expected_path) } @@ -21,7 +21,7 @@ RSpec.describe ProjectHookPresenter do subject { web_hook.present.logs_details_path(web_hook_log) } let(:expected_path) do - "/#{project.namespace.path}/#{project.name}/hooks/#{web_hook.id}/hook_logs/#{web_hook_log.id}" + "/#{project.namespace.path}/#{project.name}/-/hooks/#{web_hook.id}/hook_logs/#{web_hook_log.id}" end it { is_expected.to eq(expected_path) } diff --git a/spec/presenters/projects/settings/deploy_keys_presenter_spec.rb b/spec/presenters/projects/settings/deploy_keys_presenter_spec.rb index 7a679a03b53..0d340c5e713 100644 --- a/spec/presenters/projects/settings/deploy_keys_presenter_spec.rb +++ b/spec/presenters/projects/settings/deploy_keys_presenter_spec.rb @@ -3,17 +3,58 @@ require 'spec_helper' RSpec.describe Projects::Settings::DeployKeysPresenter do - let(:project) { create(:project) } - let(:user) { create(:user) } + let_it_be(:project, refind: true) { create(:project) } + let_it_be(:other_project) { create(:project) } + let_it_be(:user) { create(:user) } subject(:presenter) do described_class.new(project, current_user: user) end + before_all do + project.add_maintainer(user) + other_project.add_maintainer(user) + end + it 'inherits from Gitlab::View::Presenter::Simple' do expect(described_class.superclass).to eq(Gitlab::View::Presenter::Simple) end + describe 'deploy key groups' do + let_it_be(:deploy_key) { create(:deploy_key, projects: [project]) } + let_it_be(:other_deploy_key) { create(:deploy_key, projects: [other_project]) } + let_it_be(:public_deploy_key) { create(:deploy_key, public: true) } + let_it_be(:unrelated_project) { create(:project, :private) } + let_it_be(:unrelated_deploy_key) { create(:deploy_key, projects: [unrelated_project]) } + + context 'with enabled keys' do + it 'returns correct deploy keys' do + expect(presenter.enabled_keys).to eq([deploy_key]) + expect(presenter.enabled_keys_size).to eq(1) + end + end + + context 'with available keys' do + it 'returns correct deploy keys' do + expect(presenter.available_keys).to eq([other_deploy_key, public_deploy_key]) + end + end + + context 'with available project keys' do + it 'returns correct deploy keys' do + expect(presenter.available_project_keys).to eq([other_deploy_key]) + expect(presenter.available_project_keys_size).to eq(1) + end + end + + context 'with available public keys' do + it 'returns correct deploy keys' do + expect(presenter.available_public_keys).to eq([public_deploy_key]) + expect(presenter.available_public_keys_size).to eq(1) + end + end + end + describe '#enabled_keys' do let!(:deploy_key) { create(:deploy_key, public: true) } |