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
|
2019-02-15 15:39:39 +05:30
|
|
|
let(:user) { create(:user) }
|
|
|
|
let(:project) { create(:project, :repository) }
|
2020-05-24 23:13:21 +05:30
|
|
|
let(:params) { {} }
|
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') }
|
2020-05-24 23:13:21 +05:30
|
|
|
let(:finder) { described_class.new(project, user, params) }
|
2019-02-15 15:39:39 +05:30
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
describe '#execute' do
|
2019-12-26 22:10:19 +05:30
|
|
|
subject { finder.execute(**args) }
|
|
|
|
|
|
|
|
let(:args) { {} }
|
|
|
|
|
2019-02-15 15:39:39 +05:30
|
|
|
context 'when the user is not part of the project' do
|
|
|
|
it 'returns no releases' do
|
2019-12-26 22:10:19 +05:30
|
|
|
is_expected.to be_empty
|
2019-02-15 15:39:39 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when the user is a project developer' do
|
|
|
|
before do
|
|
|
|
project.add_developer(user)
|
|
|
|
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
|
|
|
|
|
|
|
|
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 } }
|
|
|
|
|
|
|
|
it 'does not preload associations' do
|
|
|
|
expect(Release).not_to receive(:preloaded)
|
2019-02-15 15:39:39 +05:30
|
|
|
|
2019-12-26 22:10:19 +05:30
|
|
|
subject
|
|
|
|
end
|
2019-02-15 15:39:39 +05:30
|
|
|
end
|
2020-04-22 19:07:51 +05:30
|
|
|
|
|
|
|
# See https://gitlab.com/gitlab-org/gitlab/-/merge_requests/27716
|
|
|
|
context 'when tag is nil' do
|
|
|
|
before do
|
|
|
|
v1_0_0.update_column(:tag, nil)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'ignores rows with a nil tag' do
|
|
|
|
expect(subject.size).to eq(1)
|
|
|
|
expect(subject).to eq([v1_1_0])
|
|
|
|
end
|
|
|
|
end
|
2020-05-24 23:13:21 +05:30
|
|
|
|
|
|
|
context '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
|
2019-02-15 15:39:39 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|