diff --git a/app/controllers/versions_controller.rb b/app/controllers/versions_controller.rb
index e5bdfe34f84..597afd6e51c 100644
--- a/app/controllers/versions_controller.rb
+++ b/app/controllers/versions_controller.rb
@@ -3,6 +3,7 @@ class VersionsController < ApplicationController
def index
set_page
+ @oldest_version_date = @rubygem.versions.oldest_authored_at
@versions = @rubygem.versions.by_position.page(@page).per(Gemcutter::VERSIONS_PER_PAGE)
end
diff --git a/app/models/version.rb b/app/models/version.rb
index 32e61390acc..5e9bc1abe29 100644
--- a/app/models/version.rb
+++ b/app/models/version.rb
@@ -212,6 +212,19 @@ def rely_on_built_at?
built_at && built_at <= RUBYGEMS_IMPORT_DATE
end
+ def self.oldest_authored_at
+ minimum(
+ <<~SQL.squish
+ CASE WHEN DATE(created_at) = '#{RUBYGEMS_IMPORT_DATE}'
+ AND built_at <= created_at THEN
+ built_at
+ ELSE
+ created_at
+ END
+ SQL
+ )
+ end
+
def refresh_rubygem_indexed
rubygem.refresh_indexed!
end
diff --git a/app/views/versions/index.html.erb b/app/views/versions/index.html.erb
index 94620b1f37d..3a8a919d373 100644
--- a/app/views/versions/index.html.erb
+++ b/app/views/versions/index.html.erb
@@ -4,7 +4,7 @@
<%= t('.not_hosted_notice') %>
<% else %>
- <%= t('.versions_since', :count => @versions.total_count, :since => nice_date_for(@versions.map(&:authored_at).min)) %>:
+ <%= t('.versions_since', :count => @versions.total_count, :since => nice_date_for(@oldest_version_date)) %>:
<%= render @versions %>
diff --git a/test/functional/versions_controller_test.rb b/test/functional/versions_controller_test.rb
index b7308c1912b..c9b2879644f 100644
--- a/test/functional/versions_controller_test.rb
+++ b/test/functional/versions_controller_test.rb
@@ -114,27 +114,37 @@ class VersionsControllerTest < ActionController::TestCase
end
assert_select ".gem__version__date sup", text: "*", count: 1
+
+ assert_select ".t-list__heading", text: /1 version since January 01, 2000/, count: 1
end
end
context "on GET to index" do
setup do
@rubygem = create(:rubygem)
- create(:version, number: "1.1.2", rubygem: @rubygem)
+ @oldest_created_at = Date.parse("2010-01-01")
+ create(:version, number: "1.1.2", rubygem: @rubygem, position: 0)
+ create(:version, number: "1.1.1", rubygem: @rubygem, position: 1, created_at: @oldest_created_at)
end
should "get paginated result" do
- # first page includes the only version
- get :index, params: { rubygem_id: @rubygem.name }
-
- assert_response :success
- assert page.has_content?("1.1.2")
-
- # second page does not include the only version
- get :index, params: { rubygem_id: @rubygem.name, page: 2 }
-
- assert_response :success
- refute page.has_content?("1.1.2")
+ stub_const(Gemcutter, :VERSIONS_PER_PAGE, 1) do
+ # first page only includes the version at position 0
+ get :index, params: { rubygem_id: @rubygem.name }
+
+ assert_response :success
+ assert page.has_content?("1.1.2")
+ refute page.has_content?("1.1.1")
+ assert_select ".t-list__heading", text: /2 versions since January 01, 2010/, count: 1
+
+ # second page only includes the version at position 1
+ get :index, params: { rubygem_id: @rubygem.name, page: 2 }
+
+ assert_response :success
+ refute page.has_content?("1.1.2")
+ assert page.has_content?("1.1.1")
+ assert_select ".t-list__heading", text: /2 versions since January 01, 2010/, count: 1
+ end
end
end
diff --git a/test/models/version_test.rb b/test/models/version_test.rb
index 11bad71a8bb..d332ad8b174 100644
--- a/test/models/version_test.rb
+++ b/test/models/version_test.rb
@@ -242,6 +242,25 @@ class VersionTest < ActiveSupport::TestCase
end
end
+ context ".oldest_authored_at scope" do
+ setup do
+ @built_at = Version::RUBYGEMS_IMPORT_DATE - 60.days
+ @version.update(built_at: @built_at, created_at: Version::RUBYGEMS_IMPORT_DATE)
+ _newer_version = create(:version, rubygem: @version.rubygem)
+ end
+
+ should "return the built_at of the oldest version when created_at is the same as RUBYGEMS_IMPORT_DATE" do
+ assert_equal @built_at, Version.oldest_authored_at
+ end
+
+ should "return the created_at of the oldest version when created_at is not the same as RUBYGEMS_IMPORT_DATE" do
+ created_at = Version::RUBYGEMS_IMPORT_DATE + 1.day
+ @version.update(created_at: created_at)
+
+ assert_equal created_at, Version.oldest_authored_at
+ end
+ end
+
should "have a rubygems version" do
@version.update(required_rubygems_version: @required_rubygems_version)
new_version = Version.find(@version.id)