Commit 654e6447 authored by Markus Koller's avatar Markus Koller

Merge branch 'tags-controller-spec-debug' into 'master'

Fix release evidence sometimes not being collected

See merge request gitlab-org/gitlab!37184
parents 397dd0e8 5df49ebf
......@@ -18,12 +18,10 @@ class Release < ApplicationRecord
has_many :milestones, through: :milestone_releases
has_many :evidences, inverse_of: :release, class_name: 'Releases::Evidence'
default_value_for :released_at, allows_nil: false do
Time.zone.now
end
accepts_nested_attributes_for :links, allow_destroy: true
before_create :set_released_at
validates :project, :tag, presence: true
validates_associated :milestone_releases, message: -> (_, obj) { obj[:value].map(&:errors).map(&:full_messages).join(",") }
......@@ -90,6 +88,10 @@ class Release < ApplicationRecord
repository.find_tag(tag)
end
end
def set_released_at
self.released_at ||= created_at
end
end
Release.prepend_if_ee('EE::Release')
---
title: Fix release evidence sometimes not being collected
merge_request: 37184
author:
type: fixed
......@@ -120,10 +120,14 @@ RSpec.describe Projects::TagsController do
request
release = project.releases.find_by_tag!('1.0')
aggregate_failures do
expect(response).to have_gitlab_http_status(:found)
expect(release).to be_present
expect(release.description).to eq(release_description)
release = project.releases.find_by_tag('1.0')
expect(release).to be_present
expect(release&.description).to eq(release_description)
end
end
end
end
......
......@@ -73,6 +73,22 @@ RSpec.describe Release do
end
end
describe '.create' do
it "fills released_at using created_at if it's not set" do
release = described_class.create(project: project, author: user)
expect(release.released_at).to eq(release.created_at)
end
it "does not change released_at if it's set explicitly" do
released_at = Time.zone.parse('2018-10-20T18:00:00Z')
release = described_class.create(project: project, author: user, released_at: released_at)
expect(release.released_at).to eq(released_at)
end
end
describe '#sources' do
subject { release.sources }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment