Skip to content
Browse files

fix build history sort order

  • Loading branch information...
1 parent 30e57f0 commit 366bc59c02f052c4b195c09ad3f4cb79be07b466 @svenfuchs svenfuchs committed
Showing with 11 additions and 8 deletions.
  1. +10 −7 lib/travis/model/build.rb
  2. +1 −1 lib/travis/services/builds/all.rb
View
17 lib/travis/model/build.rb
@@ -96,8 +96,12 @@ def last_finished_on_branch(branches)
finished.on_branch(branches).descending.first
end
- def descending
- order(arel_table[:id].desc)
+ def descending(column = :id)
+ if column == :number
+ order('number::int DESC')
+ else
+ order(arel_table[column].desc)
+ end
end
def paged(options)
@@ -106,13 +110,12 @@ def paged(options)
end
def older_than(build = nil)
- criteria = if build
- number = build.is_a?(Build) ? build.number : build
- where('number::integer < ?', number.to_i)
+ scope = if build
+ where('number::integer < ?', (build.is_a?(Build) ? build.number : build).to_i)
else
- Build
+ Build # TODO in which case we'd call older_than without an argument?
end
- criteria.includes(:commit).order('number::int DESC').limit(per_page)
+ scope.includes(:commit).descending(:number).limit(per_page)
end
def next_number
View
2 lib/travis/services/builds/all.rb
@@ -7,7 +7,7 @@ class All < Base
def run
# TODO :after_number seems like a bizarre api
# why not just pass an id? pagination style?
- builds = repository(params).builds.order(params[:order_by] || 'number DESC')
+ builds = repository(params).builds.descending(:number)
builds = builds.by_event_type(params) if params[:event_type]
params[:after_number] ? builds.older_than(params[:after_number]) : builds.recent
rescue ActiveRecord::RecordNotFound

0 comments on commit 366bc59

Please sign in to comment.
Something went wrong with that request. Please try again.