gitlab-org--gitlab-foss/app/models/release.rb
Shinya Maeda 8f1e96c89b Add spec for Release API
Add spec for all release API - GET, POST, PUT, DELETE.
Also, fixes some minior bugs.
2018-12-31 14:35:57 +09:00

40 lines
744 B
Ruby

# frozen_string_literal: true
class Release < ActiveRecord::Base
include CacheMarkdownField
include Gitlab::Utils::StrongMemoize
cache_markdown_field :description
belongs_to :project
# releases prior to 11.7 have no author
belongs_to :author, class_name: 'User'
validates :description, :project, :tag, presence: true
scope :sorted, -> { order(created_at: :desc) }
delegate :repository, to: :project
def commit
strong_memoize(:commit) do
repository.commit(actual_sha)
end
end
def tag_missing?
actual_tag.nil?
end
private
def actual_sha
sha || actual_tag&.dereferenced_target
end
def actual_tag
strong_memoize(:actual_tag) do
repository.find_tag(tag)
end
end
end