ReleasesFinder will always return a relation
This commit is contained in:
parent
b9aac409a5
commit
a7aaad96f3
4 changed files with 9 additions and 10 deletions
|
@ -6,11 +6,9 @@ class ReleasesFinder
|
|||
@current_user = current_user
|
||||
end
|
||||
|
||||
# rubocop: disable CodeReuse/ActiveRecord
|
||||
def execute
|
||||
return [] unless Ability.allowed?(@current_user, :read_release, @project)
|
||||
return Release.none unless Ability.allowed?(@current_user, :read_release, @project)
|
||||
|
||||
@project.releases.order('created_at DESC')
|
||||
@project.releases.sorted
|
||||
end
|
||||
# rubocop: enable CodeReuse/ActiveRecord
|
||||
end
|
||||
|
|
|
@ -11,6 +11,8 @@ class Release < ActiveRecord::Base
|
|||
|
||||
validates :description, :project, :tag, presence: true
|
||||
|
||||
scope :sorted, -> { order(created_at: :desc) }
|
||||
|
||||
delegate :repository, to: :project
|
||||
|
||||
def commit
|
||||
|
|
|
@ -21,7 +21,7 @@ module API
|
|||
use :pagination
|
||||
end
|
||||
get ':id/releases' do
|
||||
releases = ::Kaminari.paginate_array(::ReleasesFinder.new(user_project, current_user).execute)
|
||||
releases = ::ReleasesFinder.new(user_project, current_user).execute
|
||||
|
||||
present paginate(releases), with: Entities::Release
|
||||
end
|
||||
|
|
|
@ -12,9 +12,8 @@ describe ReleasesFinder do
|
|||
subject { described_class.new(project, user)}
|
||||
|
||||
before do
|
||||
now = Time.now
|
||||
v1_0_0.update_attribute(:created_at, now - 2.days)
|
||||
v1_1_0.update_attribute(:created_at, now - 1.day)
|
||||
v1_0_0.update_attribute(:created_at, 2.days.ago)
|
||||
v1_1_0.update_attribute(:created_at, 1.day.ago)
|
||||
end
|
||||
|
||||
describe '#execute' do
|
||||
|
|
Loading…
Reference in a new issue