diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2022-12-20 14:22:11 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2022-12-20 14:22:11 +0000 |
commit | 0c872e02b2c822e3397515ec324051ff540f0cd5 (patch) | |
tree | ce2fb6ce7030e4dad0f4118d21ab6453e5938cdd /spec/presenters | |
parent | f7e05a6853b12f02911494c4b3fe53d9540d74fc (diff) | |
download | gitlab-ce-f7d6ced4f57b4920a666336f5a44d098faade2ea.tar.gz |
Add latest changes from gitlab-org/gitlab@15-7-stable-eev15.7.0-rc42
Diffstat (limited to 'spec/presenters')
-rw-r--r-- | spec/presenters/blob_presenter_spec.rb | 2 | ||||
-rw-r--r-- | spec/presenters/ci/freeze_period_presenter_spec.rb | 37 | ||||
-rw-r--r-- | spec/presenters/group_member_presenter_spec.rb | 18 | ||||
-rw-r--r-- | spec/presenters/member_presenter_spec.rb | 14 | ||||
-rw-r--r-- | spec/presenters/packages/pypi/simple_package_versions_presenter_spec.rb | 8 | ||||
-rw-r--r-- | spec/presenters/project_member_presenter_spec.rb | 18 | ||||
-rw-r--r-- | spec/presenters/project_presenter_spec.rb | 22 | ||||
-rw-r--r-- | spec/presenters/projects/security/configuration_presenter_spec.rb | 2 | ||||
-rw-r--r-- | spec/presenters/search_service_presenter_spec.rb | 8 |
9 files changed, 111 insertions, 18 deletions
diff --git a/spec/presenters/blob_presenter_spec.rb b/spec/presenters/blob_presenter_spec.rb index 88dafb7ea1f..f8cba8e9203 100644 --- a/spec/presenters/blob_presenter_spec.rb +++ b/spec/presenters/blob_presenter_spec.rb @@ -118,7 +118,7 @@ RSpec.describe BlobPresenter do end describe '#permalink_path' do - it { expect(presenter.permalink_path).to eq("/#{project.full_path}/-/blob/#{project.repository.commit.sha}/files/ruby/regex.rb") } + it { expect(presenter.permalink_path).to eq("/#{project.full_path}/-/blob/#{project.repository.commit(blob.commit_id).sha}/files/ruby/regex.rb") } end context 'environment has been deployed' do diff --git a/spec/presenters/ci/freeze_period_presenter_spec.rb b/spec/presenters/ci/freeze_period_presenter_spec.rb new file mode 100644 index 00000000000..e9959540b8d --- /dev/null +++ b/spec/presenters/ci/freeze_period_presenter_spec.rb @@ -0,0 +1,37 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe Ci::FreezePeriodPresenter, feature_category: :release_orchestration do + let_it_be(:project) { build_stubbed(:project) } + + let(:presenter) { described_class.new(freeze_period) } + + describe '#start_time' do + let(:freeze_period) { build_stubbed(:ci_freeze_period, project: project) } + + context 'when active' do + # Default freeze period factory is on a weekend, so let's travel in time to a Saturday! + let(:time) { Time.utc(2022, 12, 3, 6) } + let(:previous_start) { Time.utc(2022, 12, 2, 23) } + + it 'returns the previous time of the freeze period start' do + travel_to(time) do + expect(presenter.start_time).to eq(previous_start) + end + end + end + + context 'when inactive' do + # Default freeze period factory is on a weekend, so we travel back a couple of days earlier. + let(:time) { Time.utc(2022, 11, 30, 6) } + let(:next_start) { Time.utc(2022, 12, 2, 23) } + + it 'returns the next time of the freeze period start' do + travel_to(time) do + expect(presenter.start_time).to eq(next_start) + end + end + end + end +end diff --git a/spec/presenters/group_member_presenter_spec.rb b/spec/presenters/group_member_presenter_spec.rb index 352f81356e0..25992871160 100644 --- a/spec/presenters/group_member_presenter_spec.rb +++ b/spec/presenters/group_member_presenter_spec.rb @@ -54,6 +54,24 @@ RSpec.describe GroupMemberPresenter do end end + describe '#last_owner?' do + context 'when member is the last owner of the group' do + before do + allow(group_member).to receive(:last_owner_of_the_group?).and_return(true) + end + + it { expect(presenter.last_owner?).to eq(true) } + end + + context 'when member is not the last owner of the group' do + before do + allow(group_member).to receive(:last_owner_of_the_group?).and_return(false) + end + + it { expect(presenter.last_owner?).to eq(false) } + end + end + describe '#can_update?' do context 'when user can update_group_member' do before do diff --git a/spec/presenters/member_presenter_spec.rb b/spec/presenters/member_presenter_spec.rb new file mode 100644 index 00000000000..65e23d20051 --- /dev/null +++ b/spec/presenters/member_presenter_spec.rb @@ -0,0 +1,14 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe MemberPresenter, feature_category: :subgroups do + let_it_be(:member) { build(:group_member) } + let(:presenter) { described_class.new(member) } + + describe '#last_owner?' do + it 'raises `NotImplementedError`' do + expect { presenter.last_owner? }.to raise_error(NotImplementedError) + end + 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 c966b1fc8e1..50a5cb631f9 100644 --- a/spec/presenters/packages/pypi/simple_package_versions_presenter_spec.rb +++ b/spec/presenters/packages/pypi/simple_package_versions_presenter_spec.rb @@ -36,6 +36,14 @@ RSpec.describe ::Packages::Pypi::SimplePackageVersionsPresenter, :aggregate_fail it { is_expected.to include expected_link } end + + it 'avoids N+1 database queries' do + control = ActiveRecord::QueryRecorder.new { subject } + + create(:pypi_package, project: project, name: package_name) + + expect { described_class.new(project.packages, project_or_group).body }.not_to exceed_query_limit(control) + end end context 'for project' do diff --git a/spec/presenters/project_member_presenter_spec.rb b/spec/presenters/project_member_presenter_spec.rb index 1cfc8cfb53b..28afb78cdce 100644 --- a/spec/presenters/project_member_presenter_spec.rb +++ b/spec/presenters/project_member_presenter_spec.rb @@ -54,6 +54,24 @@ RSpec.describe ProjectMemberPresenter do end end + describe '#last_owner?' do + context 'when member is the holder of the personal namespace' do + before do + allow(project_member).to receive(:holder_of_the_personal_namespace?).and_return(true) + end + + it { expect(presenter.last_owner?).to eq(true) } + end + + context 'when member is not the holder of the personal namespace' do + before do + allow(project_member).to receive(:holder_of_the_personal_namespace?).and_return(false) + end + + it { expect(presenter.last_owner?).to eq(false) } + end + end + describe '#can_update?' do context 'when user is NOT attempting to update an Owner' do before do diff --git a/spec/presenters/project_presenter_spec.rb b/spec/presenters/project_presenter_spec.rb index c32cc87afbb..4c2b87f34a1 100644 --- a/spec/presenters/project_presenter_spec.rb +++ b/spec/presenters/project_presenter_spec.rb @@ -76,21 +76,21 @@ RSpec.describe ProjectPresenter do let_it_be(:project) { create(:project, :public, :repository) } it 'returns files and readme if user has repository access' do - allow(presenter).to receive(:can?).with(nil, :download_code, project).and_return(true) + allow(presenter).to receive(:can?).with(nil, :read_code, project).and_return(true) expect(presenter.default_view).to eq('files') end it 'returns wiki if user does not have repository access and can read wiki, which exists' do allow(project).to receive(:wiki_repository_exists?).and_return(true) - allow(presenter).to receive(:can?).with(nil, :download_code, project).and_return(false) + allow(presenter).to receive(:can?).with(nil, :read_code, project).and_return(false) allow(presenter).to receive(:can?).with(nil, :read_wiki, project).and_return(true) expect(presenter.default_view).to eq('wiki') end it 'returns activity if user does not have repository or wiki access' do - allow(presenter).to receive(:can?).with(nil, :download_code, project).and_return(false) + allow(presenter).to receive(:can?).with(nil, :read_code, project).and_return(false) allow(presenter).to receive(:can?).with(nil, :read_issue, project).and_return(false) allow(presenter).to receive(:can?).with(nil, :read_wiki, project).and_return(false) @@ -117,7 +117,7 @@ RSpec.describe ProjectPresenter do context 'when the user is allowed to see the code' do it 'returns the project view' do - allow(presenter).to receive(:can?).with(user, :download_code, project).and_return(true) + allow(presenter).to receive(:can?).with(user, :read_code, project).and_return(true) expect(presenter.default_view).to eq('readme') end @@ -126,7 +126,7 @@ RSpec.describe ProjectPresenter do context 'with wikis enabled and the right policy for the user' do before do project.project_feature.update_attribute(:issues_access_level, 0) - allow(presenter).to receive(:can?).with(user, :download_code, project).and_return(false) + allow(presenter).to receive(:can?).with(user, :read_code, project).and_return(false) end it 'returns wiki if the user has the right policy and the wiki exists' do @@ -146,7 +146,7 @@ RSpec.describe ProjectPresenter do context 'with issues as a feature available' do it 'return issues' do - allow(presenter).to receive(:can?).with(user, :download_code, project).and_return(false) + allow(presenter).to receive(:can?).with(user, :read_code, project).and_return(false) allow(presenter).to receive(:can?).with(user, :read_issue, project).and_return(true) allow(presenter).to receive(:can?).with(user, :read_wiki, project).and_return(false) @@ -157,7 +157,7 @@ RSpec.describe ProjectPresenter do context 'with no activity, no wikies and no issues' do it 'returns activity as default' do project.project_feature.update_attribute(:issues_access_level, 0) - allow(presenter).to receive(:can?).with(user, :download_code, project).and_return(false) + allow(presenter).to receive(:can?).with(user, :read_code, project).and_return(false) allow(presenter).to receive(:can?).with(user, :read_wiki, project).and_return(false) allow(presenter).to receive(:can?).with(user, :read_issue, project).and_return(false) @@ -623,14 +623,6 @@ RSpec.describe ProjectPresenter do context 'empty repo' do let(:project) { create(:project, :stubbed_repository) } - context 'for a guest user' do - it 'orders the items correctly' do - expect(empty_repo_statistics_buttons.map(&:label)).to start_with( - a_string_including('No license') - ) - end - end - it 'includes a button to configure integrations for maintainers' do project.add_maintainer(user) diff --git a/spec/presenters/projects/security/configuration_presenter_spec.rb b/spec/presenters/projects/security/configuration_presenter_spec.rb index ca7f96b567d..4fe459a798a 100644 --- a/spec/presenters/projects/security/configuration_presenter_spec.rb +++ b/spec/presenters/projects/security/configuration_presenter_spec.rb @@ -11,7 +11,7 @@ RSpec.describe Projects::Security::ConfigurationPresenter do let(:presenter) { described_class.new(project, current_user: current_user) } before do - stub_licensed_features(licensed_scan_types.to_h { |type| [type, true] }) + stub_licensed_features(licensed_scan_types.index_with { true }) end describe '#to_html_data_attribute' do diff --git a/spec/presenters/search_service_presenter_spec.rb b/spec/presenters/search_service_presenter_spec.rb index af9fee8cfd9..a235f954366 100644 --- a/spec/presenters/search_service_presenter_spec.rb +++ b/spec/presenters/search_service_presenter_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe SearchServicePresenter do +RSpec.describe SearchServicePresenter, feature_category: :global_search do let(:user) { create(:user) } let(:search) { '' } let(:search_service) { SearchService.new(user, search: search, scope: scope) } @@ -51,4 +51,10 @@ RSpec.describe SearchServicePresenter do it { expect(presenter.show_results_status?).to eq(result) } end end + + describe '#advanced_search_enabled?' do + let(:scope) { nil } + + it { expect(presenter.advanced_search_enabled?).to eq(false) } + end end |