2019-02-15 15:39:39 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'spec_helper'
|
|
|
|
|
2020-06-23 00:09:42 +05:30
|
|
|
RSpec.describe ReleasesFinder do
|
2020-10-24 23:57:45 +05:30
|
|
|
let(:user) { create(:user) }
|
|
|
|
let(:group) { create :group }
|
|
|
|
let(:project) { create(:project, :repository, group: group) }
|
|
|
|
let(:params) { {} }
|
|
|
|
let(:args) { {} }
|
2019-02-15 15:39:39 +05:30
|
|
|
let(:repository) { project.repository }
|
|
|
|
let(:v1_0_0) { create(:release, project: project, tag: 'v1.0.0') }
|
|
|
|
let(:v1_1_0) { create(:release, project: project, tag: 'v1.1.0') }
|
|
|
|
|
|
|
|
before do
|
2019-09-30 21:07:59 +05:30
|
|
|
v1_0_0.update_attribute(:released_at, 2.days.ago)
|
|
|
|
v1_1_0.update_attribute(:released_at, 1.day.ago)
|
2019-02-15 15:39:39 +05:30
|
|
|
end
|
|
|
|
|
2020-10-24 23:57:45 +05:30
|
|
|
shared_examples_for 'when the user is not part of the project' do
|
|
|
|
it 'returns no releases' do
|
|
|
|
is_expected.to be_empty
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2022-04-04 11:22:00 +05:30
|
|
|
shared_examples_for 'when the user is not part of the group' do
|
|
|
|
before do
|
|
|
|
allow(Ability).to receive(:allowed?).with(user, :read_release, group).and_return(false)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns no releases' do
|
|
|
|
is_expected.to be_empty
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-10-24 23:57:45 +05:30
|
|
|
shared_examples_for 'when a tag parameter is passed' do
|
|
|
|
let(:params) { { tag: 'v1.0.0' } }
|
|
|
|
|
|
|
|
it 'only returns the release with the matching tag' do
|
|
|
|
expect(subject).to eq([v1_0_0])
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
shared_examples_for 'preload' do
|
|
|
|
it 'preloads associations' do
|
|
|
|
expect(Release).to receive(:preloaded).once.and_call_original
|
|
|
|
|
|
|
|
subject
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when preload is false' do
|
|
|
|
let(:args) { { preload: false } }
|
2019-12-26 22:10:19 +05:30
|
|
|
|
2020-10-24 23:57:45 +05:30
|
|
|
it 'does not preload associations' do
|
|
|
|
expect(Release).not_to receive(:preloaded)
|
2019-12-26 22:10:19 +05:30
|
|
|
|
2020-10-24 23:57:45 +05:30
|
|
|
subject
|
2019-02-15 15:39:39 +05:30
|
|
|
end
|
|
|
|
end
|
2020-10-24 23:57:45 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
describe 'when parent is a project' do
|
|
|
|
subject { described_class.new(project, user, params).execute(**args) }
|
|
|
|
|
|
|
|
it_behaves_like 'when the user is not part of the project'
|
2019-02-15 15:39:39 +05:30
|
|
|
|
2022-04-04 11:22:00 +05:30
|
|
|
context 'when the user is a project guest' do
|
2019-02-15 15:39:39 +05:30
|
|
|
before do
|
2022-04-04 11:22:00 +05:30
|
|
|
project.add_guest(user)
|
2019-02-15 15:39:39 +05:30
|
|
|
end
|
|
|
|
|
2019-09-30 21:07:59 +05:30
|
|
|
it 'sorts by release date' do
|
2019-12-26 22:10:19 +05:30
|
|
|
is_expected.to be_present
|
|
|
|
expect(subject.size).to eq(2)
|
|
|
|
expect(subject).to eq([v1_1_0, v1_0_0])
|
|
|
|
end
|
|
|
|
|
2021-01-03 14:25:43 +05:30
|
|
|
context 'with sorting parameters' do
|
|
|
|
before do
|
|
|
|
v1_1_0.update_attribute(:created_at, 3.days.ago)
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'by default is released_at in descending order' do
|
|
|
|
it { is_expected.to eq([v1_1_0, v1_0_0]) }
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'released_at in ascending order' do
|
|
|
|
let(:params) { { sort: 'asc' } }
|
|
|
|
|
|
|
|
it { is_expected.to eq([v1_0_0, v1_1_0]) }
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'order by created_at in descending order' do
|
|
|
|
let(:params) { { order_by: 'created_at' } }
|
|
|
|
|
|
|
|
it { is_expected.to eq([v1_0_0, v1_1_0]) }
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'order by created_at in ascending order' do
|
|
|
|
let(:params) { { order_by: 'created_at', sort: 'asc' } }
|
|
|
|
|
|
|
|
it { is_expected.to eq([v1_1_0, v1_0_0]) }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-10-24 23:57:45 +05:30
|
|
|
it_behaves_like 'preload'
|
|
|
|
it_behaves_like 'when a tag parameter is passed'
|
|
|
|
end
|
|
|
|
end
|
2019-12-26 22:10:19 +05:30
|
|
|
|
2020-10-24 23:57:45 +05:30
|
|
|
describe 'when parent is a group' do
|
|
|
|
context 'without subgroups' do
|
|
|
|
let(:project2) { create(:project, :repository, namespace: group) }
|
|
|
|
let!(:v6) { create(:release, project: project2, tag: 'v6') }
|
2019-12-26 22:10:19 +05:30
|
|
|
|
2020-10-24 23:57:45 +05:30
|
|
|
subject { described_class.new(group, user, params).execute(**args) }
|
2019-12-26 22:10:19 +05:30
|
|
|
|
2022-04-04 11:22:00 +05:30
|
|
|
it_behaves_like 'when the user is not part of the group'
|
2020-10-24 23:57:45 +05:30
|
|
|
|
2022-04-04 11:22:00 +05:30
|
|
|
context 'when the user is a project guest on one sibling project' do
|
2020-10-24 23:57:45 +05:30
|
|
|
before do
|
2022-04-04 11:22:00 +05:30
|
|
|
project.add_guest(user)
|
2020-10-24 23:57:45 +05:30
|
|
|
v1_0_0.update_attribute(:released_at, 3.days.ago)
|
|
|
|
v1_1_0.update_attribute(:released_at, 1.day.ago)
|
|
|
|
end
|
2019-02-15 15:39:39 +05:30
|
|
|
|
2022-04-04 11:22:00 +05:30
|
|
|
it 'does not return any releases' do
|
|
|
|
expect(subject.size).to eq(0)
|
|
|
|
expect(subject).to eq([])
|
2019-12-26 22:10:19 +05:30
|
|
|
end
|
2019-02-15 15:39:39 +05:30
|
|
|
end
|
2020-04-22 19:07:51 +05:30
|
|
|
|
2022-04-04 11:22:00 +05:30
|
|
|
context 'when the user is a guest on the group' do
|
2020-04-22 19:07:51 +05:30
|
|
|
before do
|
2022-04-04 11:22:00 +05:30
|
|
|
group.add_guest(user)
|
2020-10-24 23:57:45 +05:30
|
|
|
v1_0_0.update_attribute(:released_at, 3.days.ago)
|
|
|
|
v6.update_attribute(:released_at, 2.days.ago)
|
|
|
|
v1_1_0.update_attribute(:released_at, 1.day.ago)
|
2020-04-22 19:07:51 +05:30
|
|
|
end
|
|
|
|
|
2020-10-24 23:57:45 +05:30
|
|
|
it 'sorts by release date' do
|
|
|
|
expect(subject.size).to eq(3)
|
|
|
|
expect(subject).to eq([v1_1_0, v6, v1_0_0])
|
|
|
|
end
|
|
|
|
|
|
|
|
it_behaves_like 'when a tag parameter is passed'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'with subgroups' do
|
|
|
|
let(:params) { { include_subgroups: true } }
|
|
|
|
|
|
|
|
subject { described_class.new(group, user, params).execute(**args) }
|
|
|
|
|
|
|
|
context 'with a single-level subgroup' do
|
|
|
|
let(:subgroup) { create :group, parent: group }
|
|
|
|
let(:project2) { create(:project, :repository, namespace: subgroup) }
|
|
|
|
let!(:v6) { create(:release, project: project2, tag: 'v6') }
|
|
|
|
|
2022-04-04 11:22:00 +05:30
|
|
|
it_behaves_like 'when the user is not part of the group'
|
2020-10-24 23:57:45 +05:30
|
|
|
|
2022-04-04 11:22:00 +05:30
|
|
|
context 'when the user a project guest in the subgroup project' do
|
2020-10-24 23:57:45 +05:30
|
|
|
before do
|
2022-04-04 11:22:00 +05:30
|
|
|
project2.add_guest(user)
|
2020-10-24 23:57:45 +05:30
|
|
|
end
|
|
|
|
|
2022-04-04 11:22:00 +05:30
|
|
|
it 'does not return any releases' do
|
|
|
|
expect(subject).to match_array([])
|
2020-10-24 23:57:45 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2022-04-04 11:22:00 +05:30
|
|
|
context 'when the user is a guest on the group' do
|
2020-10-24 23:57:45 +05:30
|
|
|
before do
|
2022-04-04 11:22:00 +05:30
|
|
|
group.add_guest(user)
|
2020-10-24 23:57:45 +05:30
|
|
|
v6.update_attribute(:released_at, 2.days.ago)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns all releases' do
|
|
|
|
expect(subject).to match_array([v1_1_0, v1_0_0, v6])
|
|
|
|
end
|
|
|
|
|
|
|
|
it_behaves_like 'when a tag parameter is passed'
|
2020-04-22 19:07:51 +05:30
|
|
|
end
|
|
|
|
end
|
2020-05-24 23:13:21 +05:30
|
|
|
|
2020-10-24 23:57:45 +05:30
|
|
|
context 'with a multi-level subgroup' do
|
|
|
|
let(:subgroup) { create :group, parent: group }
|
|
|
|
let(:subsubgroup) { create :group, parent: subgroup }
|
|
|
|
let(:project2) { create(:project, :repository, namespace: subgroup) }
|
|
|
|
let(:project3) { create(:project, :repository, namespace: subsubgroup) }
|
|
|
|
let!(:v6) { create(:release, project: project2, tag: 'v6') }
|
|
|
|
let!(:p3) { create(:release, project: project3, tag: 'p3') }
|
|
|
|
|
|
|
|
before do
|
|
|
|
v6.update_attribute(:released_at, 2.days.ago)
|
|
|
|
p3.update_attribute(:released_at, 3.days.ago)
|
|
|
|
end
|
|
|
|
|
2022-04-04 11:22:00 +05:30
|
|
|
it_behaves_like 'when the user is not part of the group'
|
2020-10-24 23:57:45 +05:30
|
|
|
|
2022-04-04 11:22:00 +05:30
|
|
|
context 'when the user a project guest in the subgroup and subsubgroup project' do
|
2020-10-24 23:57:45 +05:30
|
|
|
before do
|
2022-04-04 11:22:00 +05:30
|
|
|
project2.add_guest(user)
|
|
|
|
project3.add_guest(user)
|
2020-10-24 23:57:45 +05:30
|
|
|
end
|
|
|
|
|
2022-04-04 11:22:00 +05:30
|
|
|
it 'does not return any releases' do
|
|
|
|
expect(subject).to match_array([])
|
2020-10-24 23:57:45 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2022-04-04 11:22:00 +05:30
|
|
|
context 'when the user a project guest in the subsubgroup project' do
|
2020-10-24 23:57:45 +05:30
|
|
|
before do
|
2022-04-04 11:22:00 +05:30
|
|
|
project3.add_guest(user)
|
2020-10-24 23:57:45 +05:30
|
|
|
end
|
|
|
|
|
2022-04-04 11:22:00 +05:30
|
|
|
it 'does not return any releases' do
|
|
|
|
expect(subject).to match_array([])
|
2020-10-24 23:57:45 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2022-04-04 11:22:00 +05:30
|
|
|
context 'when the user a guest on the group' do
|
2020-10-24 23:57:45 +05:30
|
|
|
before do
|
2022-04-04 11:22:00 +05:30
|
|
|
group.add_guest(user)
|
2020-10-24 23:57:45 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns all releases' do
|
|
|
|
expect(subject).to match_array([v1_1_0, v6, v1_0_0, p3])
|
|
|
|
end
|
2020-05-24 23:13:21 +05:30
|
|
|
|
2020-10-24 23:57:45 +05:30
|
|
|
it_behaves_like 'when a tag parameter is passed'
|
2020-05-24 23:13:21 +05:30
|
|
|
end
|
|
|
|
end
|
2019-02-15 15:39:39 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|