Skip to content

Commit

Permalink
Order by version and desc, even when the Range
Browse files Browse the repository at this point in the history
header is not present.
  • Loading branch information
benguillet committed Jul 24, 2015
1 parent 8bb02ba commit abf75f6
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 1 deletion.
2 changes: 2 additions & 0 deletions releases.go
Expand Up @@ -74,6 +74,8 @@ func (q ReleasesQuery) Scope(db *gorm.DB) *gorm.DB {

if r := q.Range; r != nil {
scope = append(scope, Range(r))
} else {
scope = append(scope, Order("version desc"))
}

// Preload all the things.
Expand Down
2 changes: 1 addition & 1 deletion releases_test.go
Expand Up @@ -22,7 +22,7 @@ func TestReleasesQuery(t *testing.T) {
}

tests := scopeTests{
{ReleasesQuery{}, "", []interface{}{}},
{ReleasesQuery{}, "ORDER BY version desc", []interface{}{}},
{ReleasesQuery{Range: rangeHeader}, "ORDER BY version desc LIMIT 20", []interface{}{}},
{ReleasesQuery{App: app, Range: rangeHeader}, "WHERE (app_id = $1) ORDER BY version desc LIMIT 20", []interface{}{"1234"}},
{ReleasesQuery{Version: &version, Range: rangeHeader}, "WHERE (version = $1) ORDER BY version desc LIMIT 20", []interface{}{1}},
Expand Down

0 comments on commit abf75f6

Please sign in to comment.