diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2023-06-15 15:08:47 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2023-06-15 15:08:47 +0300 |
commit | 717436a767395d0ed850a16d07f19cd51c3d4551 (patch) | |
tree | 5c2d69721710081da88c8dcf097813e2f40c062c /spec/models | |
parent | 5a14a0fe63ac7dace9821be554ad3b3951529708 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/models')
-rw-r--r-- | spec/models/release_spec.rb | 90 |
1 files changed, 89 insertions, 1 deletions
diff --git a/spec/models/release_spec.rb b/spec/models/release_spec.rb index 880fb21b7af..863cc11f0b2 100644 --- a/spec/models/release_spec.rb +++ b/spec/models/release_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe Release do +RSpec.describe Release, feature_category: :release_orchestration do let_it_be(:user) { create(:user) } let_it_be(:project) { create(:project, :public, :repository) } @@ -85,6 +85,94 @@ RSpec.describe Release do end end + describe 'latest releases' do + let_it_be(:yesterday) { Time.zone.now - 1.day } + let_it_be(:tomorrow) { Time.zone.now + 1.day } + + let_it_be(:project2) { create(:project) } + + let_it_be(:project_release1) do + create(:release, project: project, released_at: yesterday, created_at: tomorrow) + end + + let_it_be(:project_release2) do + create(:release, project: project, released_at: tomorrow, created_at: yesterday) + end + + let_it_be(:project2_release1) do + create(:release, project: project2, released_at: yesterday, created_at: tomorrow) + end + + let_it_be(:project2_release2) do + create(:release, project: project2, released_at: tomorrow, created_at: yesterday) + end + + let(:args) { {} } + + describe '.latest' do + subject(:latest) { project.releases.latest(**args) } + + context 'without order_by' do + it 'returns the latest release by released date' do + expect(latest).to eq(project_release2) + end + end + + context 'with order_by: created_at' do + let(:args) { { order_by: 'created_at' } } + + it 'returns the latest release by created date' do + expect(latest).to eq(project_release1) + end + end + + context 'when there are no releases' do + it 'returns nil' do + project.releases.delete_all + + expect(latest).to eq(nil) + end + end + end + + describe '.latest_for_projects' do + let(:projects) { [project, project2] } + + subject(:latest_for_projects) { described_class.latest_for_projects(projects, **args) } + + context 'without order_by' do + it 'returns the latest release by released date for each project' do + expect(latest_for_projects).to match_array([project_release2, project2_release2]) + end + end + + context 'with order_by: created_at' do + let(:args) { { order_by: 'created_at' } } + + it 'returns the latest release by created date for each project' do + expect(latest_for_projects).to match_array([project_release1, project2_release1]) + end + end + + context 'when no projects are provided' do + let(:projects) { [] } + + it 'returns empty response' do + expect(latest_for_projects).to be_empty + end + end + + context 'when there are no releases' do + it 'returns empty response' do + project.releases.delete_all + project2.releases.delete_all + + expect(latest_for_projects).to be_empty + end + end + end + end + describe '#assets_count' do subject { Release.find(release.id).assets_count } |