Skip to content

Commit

Permalink
Make create_between consistent for versions with same created_at.
Browse files Browse the repository at this point in the history
  • Loading branch information
simi committed Jun 29, 2023
1 parent ef38deb commit a97e821
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
3 changes: 2 additions & 1 deletion app/models/version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -169,8 +169,9 @@ def self.rubygem_name_for(full_name)
find_by(full_name: full_name)&.rubygem&.name
end

# id is added to ORDER to return stable results for gems pushed at the same time
def self.created_between(start_time, end_time)
where(created_at: start_time..end_time).order(:created_at)
where(created_at: start_time..end_time).order(:created_at, :id)
end

def platformed?
Expand Down
8 changes: 5 additions & 3 deletions test/models/version_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1036,11 +1036,13 @@ class VersionTest < ActiveSupport::TestCase
@end_time = Time.zone.parse("2017-11-10")
end

should "return versions created in the given range" do
@version.created_at = Time.zone.parse("2017-10-20")
should "return versions created in the given range ordered by date and id" do
created_at = Time.zone.parse("2017-10-20")
other_version = create(:version, created_at: created_at)
@version.created_at = created_at
@version.save!

assert_contains Version.created_between(@start_time, @end_time), @version
assert_equal [other_version.id, @version.id], Version.created_between(@start_time, @end_time).map(&:id)
end

should "NOT return versions created before the range begins" do
Expand Down

0 comments on commit a97e821

Please sign in to comment.