summaryrefslogtreecommitdiff
path: root/spec/presenters
diff options
context:
space:
mode:
Diffstat (limited to 'spec/presenters')
-rw-r--r--spec/presenters/alert_management/alert_presenter_spec.rb2
-rw-r--r--spec/presenters/ci/build_runner_presenter_spec.rb61
-rw-r--r--spec/presenters/merge_request_presenter_spec.rb25
-rw-r--r--spec/presenters/packages/pypi/simple_package_versions_presenter_spec.rb2
-rw-r--r--spec/presenters/project_hook_presenter_spec.rb4
-rw-r--r--spec/presenters/project_member_presenter_spec.rb118
6 files changed, 154 insertions, 58 deletions
diff --git a/spec/presenters/alert_management/alert_presenter_spec.rb b/spec/presenters/alert_management/alert_presenter_spec.rb
index 21c0cb3fead..fe228f174fe 100644
--- a/spec/presenters/alert_management/alert_presenter_spec.rb
+++ b/spec/presenters/alert_management/alert_presenter_spec.rb
@@ -115,7 +115,7 @@ RSpec.describe AlertManagement::AlertPresenter do
it 'formats the start time of the alert' do
alert.started_at = Time.utc(2019, 5, 5)
- expect(presenter.start_time). to eq('05 May 2019, 12:00AM (UTC)')
+ expect(presenter.start_time).to eq('05 May 2019, 12:00AM (UTC)')
end
end
diff --git a/spec/presenters/ci/build_runner_presenter_spec.rb b/spec/presenters/ci/build_runner_presenter_spec.rb
index ace65307321..fe2d8f0f670 100644
--- a/spec/presenters/ci/build_runner_presenter_spec.rb
+++ b/spec/presenters/ci/build_runner_presenter_spec.rb
@@ -309,25 +309,64 @@ RSpec.describe Ci::BuildRunnerPresenter do
end
describe '#runner_variables' do
- subject { presenter.runner_variables }
+ subject(:runner_variables) { presenter.runner_variables }
let_it_be(:project) { create(:project, :repository) }
- shared_examples 'returns an array with the expected variables' do
- it 'returns an array' do
- is_expected.to be_an_instance_of(Array)
+ let(:sha) { project.repository.commit.sha }
+ let(:pipeline) { create(:ci_pipeline, sha: sha, project: project) }
+ let(:build) { create(:ci_build, pipeline: pipeline) }
+
+ 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
+
+ context 'when there are variables to expand' do
+ before_all do
+ create(:ci_variable, project: project,
+ key: 'regular_var',
+ value: 'value 1')
+ create(:ci_variable, project: project,
+ key: 'file_var',
+ value: 'value 2',
+ variable_type: :file)
+ create(:ci_variable, project: project,
+ key: 'var_with_variables',
+ value: 'value 3 and $regular_var and $file_var and $undefined_var')
end
- it 'returns the expected variables' do
- is_expected.to eq(presenter.variables.to_runner_variables)
+ it 'returns variables with expanded' do
+ expect(runner_variables).to include(
+ { key: 'regular_var', value: 'value 1',
+ public: false, masked: false },
+ { key: 'file_var', value: 'value 2',
+ public: false, masked: false, file: true },
+ { key: 'var_with_variables', value: 'value 3 and value 1 and $file_var and $undefined_var',
+ public: false, masked: false }
+ )
end
- end
- let(:sha) { project.repository.commit.sha }
- let(:pipeline) { create(:ci_pipeline, sha: sha, project: project) }
- let(:build) { create(:ci_build, pipeline: pipeline) }
+ context 'when the FF ci_stop_expanding_file_vars_for_runners is disabled' do
+ before do
+ stub_feature_flags(ci_stop_expanding_file_vars_for_runners: false)
+ end
- it_behaves_like 'returns an array with the expected variables'
+ it 'returns variables with expanded' do
+ expect(runner_variables).to include(
+ { key: 'regular_var', value: 'value 1',
+ public: false, masked: false },
+ { key: 'file_var', value: 'value 2',
+ public: false, masked: false, file: true },
+ { key: 'var_with_variables', value: 'value 3 and value 1 and value 2 and $undefined_var',
+ public: false, masked: false }
+ )
+ end
+ end
+ end
end
describe '#runner_variables subset' do
diff --git a/spec/presenters/merge_request_presenter_spec.rb b/spec/presenters/merge_request_presenter_spec.rb
index 798bee70e42..31aa4778d3c 100644
--- a/spec/presenters/merge_request_presenter_spec.rb
+++ b/spec/presenters/merge_request_presenter_spec.rb
@@ -17,29 +17,8 @@ RSpec.describe MergeRequestPresenter do
allow(resource).to receive(:mergeable_discussions_state?).and_return(discussions_state)
end
- context 'when change_response_code_merge_status is enabled' do
- it 'returns the mergeable_discussions_state' do
- is_expected.to eq(discussions_state)
- end
- end
-
- context 'when change_response_code_merge_status is disabled' do
- before do
- stub_feature_flags(change_response_code_merge_status: false)
- end
-
- context 'when it is not mergeable' do
- it 'returns false' do
- resource.close!
- is_expected.to eq(false)
- end
- end
-
- context 'when it is mergeable' do
- it 'returns the mergeable_discussions_state' do
- is_expected.to eq(discussions_state)
- end
- end
+ it 'returns the mergeable_discussions_state' do
+ is_expected.to eq(discussions_state)
end
end
diff --git a/spec/presenters/packages/pypi/simple_package_versions_presenter_spec.rb b/spec/presenters/packages/pypi/simple_package_versions_presenter_spec.rb
index be454e5168c..c966b1fc8e1 100644
--- a/spec/presenters/packages/pypi/simple_package_versions_presenter_spec.rb
+++ b/spec/presenters/packages/pypi/simple_package_versions_presenter_spec.rb
@@ -59,7 +59,7 @@ RSpec.describe ::Packages::Pypi::SimplePackageVersionsPresenter, :aggregate_fail
let(:project_or_group) { project }
- it { is_expected.not_to include(package_file_pending_destruction.file_name)}
+ it { is_expected.not_to include(package_file_pending_destruction.file_name) }
end
end
end
diff --git a/spec/presenters/project_hook_presenter_spec.rb b/spec/presenters/project_hook_presenter_spec.rb
index 2e4bd17bbe1..a85865652d8 100644
--- a/spec/presenters/project_hook_presenter_spec.rb
+++ b/spec/presenters/project_hook_presenter_spec.rb
@@ -18,10 +18,10 @@ RSpec.describe ProjectHookPresenter do
end
describe '#logs_retry_path' do
- subject { web_hook.present.logs_details_path(web_hook_log) }
+ subject { web_hook.present.logs_retry_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}/retry"
end
it { is_expected.to eq(expected_path) }
diff --git a/spec/presenters/project_member_presenter_spec.rb b/spec/presenters/project_member_presenter_spec.rb
index ad45a23c183..1cfc8cfb53b 100644
--- a/spec/presenters/project_member_presenter_spec.rb
+++ b/spec/presenters/project_member_presenter_spec.rb
@@ -55,39 +55,95 @@ RSpec.describe ProjectMemberPresenter do
end
describe '#can_update?' do
- context 'when user can update_project_member' do
+ context 'when user is NOT attempting to update an Owner' do
before do
- allow(presenter).to receive(:can?).with(user, :update_project_member, presenter).and_return(true)
+ allow(project_member).to receive(:owner?).and_return(false)
end
- it { expect(presenter.can_update?).to eq(true) }
+ context 'when user can update_project_member' do
+ before do
+ allow(presenter).to receive(:can?).with(user, :update_project_member, presenter).and_return(true)
+ end
+
+ specify { expect(presenter.can_update?).to eq(true) }
+ end
+
+ context 'when user cannot update_project_member' do
+ before do
+ allow(presenter).to receive(:can?).with(user, :update_project_member, presenter).and_return(false)
+ allow(presenter).to receive(:can?).with(user, :override_project_member, presenter).and_return(false)
+ end
+
+ specify { expect(presenter.can_update?).to eq(false) }
+ end
end
- context 'when user cannot update_project_member' do
+ context 'when user is attempting to update an Owner' do
before do
- allow(presenter).to receive(:can?).with(user, :update_project_member, presenter).and_return(false)
- allow(presenter).to receive(:can?).with(user, :override_project_member, presenter).and_return(false)
+ allow(project_member).to receive(:owner?).and_return(true)
+ end
+
+ context 'when user can manage owners' do
+ before do
+ allow(presenter).to receive(:can?).with(user, :manage_owners, project).and_return(true)
+ end
+
+ specify { expect(presenter.can_update?).to eq(true) }
end
- it { expect(presenter.can_update?).to eq(false) }
+ context 'when user cannot manage owners' do
+ before do
+ allow(presenter).to receive(:can?).with(user, :manage_owners, project).and_return(false)
+ end
+
+ specify { expect(presenter.can_update?).to eq(false) }
+ end
end
end
describe '#can_remove?' do
- context 'when user can destroy_project_member' do
+ context 'when user is NOT attempting to remove an Owner' do
before do
- allow(presenter).to receive(:can?).with(user, :destroy_project_member, presenter).and_return(true)
+ allow(project_member).to receive(:owner?).and_return(false)
end
- it { expect(presenter.can_remove?).to eq(true) }
+ context 'when user can destroy_project_member' do
+ before do
+ allow(presenter).to receive(:can?).with(user, :destroy_project_member, presenter).and_return(true)
+ end
+
+ specify { expect(presenter.can_remove?).to eq(true) }
+ end
+
+ context 'when user cannot destroy_project_member' do
+ before do
+ allow(presenter).to receive(:can?).with(user, :destroy_project_member, presenter).and_return(false)
+ end
+
+ specify { expect(presenter.can_remove?).to eq(false) }
+ end
end
- context 'when user cannot destroy_project_member' do
+ context 'when user is attempting to remove an Owner' do
before do
- allow(presenter).to receive(:can?).with(user, :destroy_project_member, presenter).and_return(false)
+ allow(project_member).to receive(:owner?).and_return(true)
+ end
+
+ context 'when user can manage owners' do
+ before do
+ allow(presenter).to receive(:can?).with(user, :manage_owners, project).and_return(true)
+ end
+
+ specify { expect(presenter.can_remove?).to eq(true) }
end
- it { expect(presenter.can_remove?).to eq(false) }
+ context 'when user cannot manage owners' do
+ before do
+ allow(presenter).to receive(:can?).with(user, :manage_owners, project).and_return(false)
+ end
+
+ specify { expect(presenter.can_remove?).to eq(false) }
+ end
end
end
@@ -99,7 +155,7 @@ RSpec.describe ProjectMemberPresenter do
context 'and user can update_project_member' do
before do
- allow(presenter).to receive(:can?).with(user, :update_project_member, presenter).and_return(true)
+ allow(presenter).to receive(:can_update?).and_return(true)
end
it { expect(presenter.can_approve?).to eq(true) }
@@ -107,8 +163,7 @@ RSpec.describe ProjectMemberPresenter do
context 'and user cannot update_project_member' do
before do
- allow(presenter).to receive(:can?).with(user, :update_project_member, presenter).and_return(false)
- allow(presenter).to receive(:can?).with(user, :override_project_member, presenter).and_return(false)
+ allow(presenter).to receive(:can_update?).and_return(false)
end
it { expect(presenter.can_approve?).to eq(false) }
@@ -122,7 +177,7 @@ RSpec.describe ProjectMemberPresenter do
context 'and user can update_project_member' do
before do
- allow(presenter).to receive(:can?).with(user, :update_project_member, presenter).and_return(true)
+ allow(presenter).to receive(:can_update?).and_return(true)
end
it { expect(presenter.can_approve?).to eq(false) }
@@ -130,7 +185,7 @@ RSpec.describe ProjectMemberPresenter do
context 'and user cannot update_project_member' do
before do
- allow(presenter).to receive(:can?).with(user, :update_project_member, presenter).and_return(false)
+ allow(presenter).to receive(:can_update?).and_return(false)
end
it { expect(presenter.can_approve?).to eq(false) }
@@ -138,9 +193,32 @@ RSpec.describe ProjectMemberPresenter do
end
end
- it_behaves_like '#valid_level_roles', :project do
+ describe 'valid level roles' do
before do
- entity.group = group
+ allow(Ability).to receive(:allowed?).and_call_original
+ allow(Ability).to receive(:allowed?).with(member_user, :manage_owners, entity).and_return(can_manage_owners)
+ end
+
+ context 'when user cannot manage owners' do
+ it_behaves_like '#valid_level_roles', :project do
+ let(:expected_roles) { { 'Developer' => 30, 'Maintainer' => 40, 'Reporter' => 20 } }
+ let(:can_manage_owners) { false }
+
+ before do
+ entity.group = group
+ end
+ end
+ end
+
+ context 'when user can manage owners' do
+ it_behaves_like '#valid_level_roles', :project do
+ let(:expected_roles) { { 'Developer' => 30, 'Maintainer' => 40, 'Owner' => 50, 'Reporter' => 20 } }
+ let(:can_manage_owners) { true }
+
+ before do
+ entity.group = group
+ end
+ end
end
end
end