diff --git a/app/assets/stylesheets/modules/recent.css b/app/assets/stylesheets/modules/recent.css new file mode 100644 index 00000000000..458483318a7 --- /dev/null +++ b/app/assets/stylesheets/modules/recent.css @@ -0,0 +1,38 @@ +.recent { + margin-top: -15px; + overflow: auto; + border-bottom: 1px solid #c1c4ca; } + @media (max-width: 709px) { + .stats { + margin-bottom: 24px; + padding-bottom: 12px; } } + @media (min-width: 710px) { + .stats { + margin-bottom: 60px; + padding-bottom: 10px; } } + +.recent__table { + width: 100%; + border-collapse: separate; + border-spacing: 30px 15px; + border-left: 3%; } + +.recent__table__row { + height: 30px; + width: 100%; } + +.recent__table__column { + /* Size table columns to contents. */ + width: 1%; + white-space: nowrap; + + font-weight: 400; + text-align: left; + vertical-align: middle; } + + @media (max-width: 709px) { + .recent__table__column { + font-size: 13px; } } + @media (min-width: 710px) { + .recent__table__column { + font-size: 15px; } } diff --git a/app/assets/stylesheets/modules/stats.css b/app/assets/stylesheets/modules/stats.css index b2bdbd1fe2f..5c6437402e4 100644 --- a/app/assets/stylesheets/modules/stats.css +++ b/app/assets/stylesheets/modules/stats.css @@ -47,6 +47,17 @@ .stat__count { font-size: 24px; } } +.stats__link { + margin-top: 81px; +} + +.stats__link a { + font-weight: 600; + font-size: 20px; + color: #000000; } + +.stats__link a:focus, .stats__link a:hover { color: #e9573f; } + .stats__graph__heading { margin-bottom: 42px; font-weight: 600; diff --git a/app/controllers/recent_uploads_controller.rb b/app/controllers/recent_uploads_controller.rb new file mode 100644 index 00000000000..0e1a6623eb4 --- /dev/null +++ b/app/controllers/recent_uploads_controller.rb @@ -0,0 +1,5 @@ +class RecentUploadsController < ApplicationController + def index + @recent_uploads = Version.recent_uploads(25) + end +end diff --git a/app/models/version.rb b/app/models/version.rb index eec8217c64e..2fbd2a9126d 100644 --- a/app/models/version.rb +++ b/app/models/version.rb @@ -152,6 +152,13 @@ def self.just_updated(limit = 5) .limit(limit) end + def self.recent_uploads(limit) + joins(:rubygem) + .indexed + .by_created_at + .limit(limit) + end + def self.published(limit) indexed.by_created_at.limit(limit) end diff --git a/app/views/recent_uploads/index.html.erb b/app/views/recent_uploads/index.html.erb new file mode 100644 index 00000000000..504cf3c4395 --- /dev/null +++ b/app/views/recent_uploads/index.html.erb @@ -0,0 +1,19 @@ +<% @title = "Recent Uploads" %> + +
+ + <% @recent_uploads.each do |version| %> + + + + + + <% end %> +
+ <%= link_to version.rubygem.name, rubygem_path(version.rubygem), class: 'gems__gem__name' %> + + <%= link_to version.number, rubygem_version_path(version.rubygem, version.slug), class: 'gems__gem__version' %> + + <%= nice_date_for(version.rubygem.created_at) %> +
+
diff --git a/app/views/stats/index.html.erb b/app/views/stats/index.html.erb index 9f700ccde62..7ce4179afff 100644 --- a/app/views/stats/index.html.erb +++ b/app/views/stats/index.html.erb @@ -33,4 +33,9 @@ <% end %> + + + <%= will_paginate @most_downloaded %> diff --git a/config/locales/en.yml b/config/locales/en.yml index d9a746c1c0a..619d616c6e0 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -165,6 +165,7 @@ en: total_gems: Total gems total_users: Total users all_time_most_downloaded: All Time Most Downloaded + recent_uploads: Recent Uploads users: new: diff --git a/config/routes.rb b/config/routes.rb index 2e6fce4b3b8..10896bb34a0 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -128,6 +128,7 @@ resources :profiles, only: :show resource :profile, only: [:edit, :update] resources :stats, only: :index + resources :recent_uploads, only: :index resources :rubygems, only: [:index, :show, :edit, :update], diff --git a/test/functional/recent_uploads_controller_test.rb b/test/functional/recent_uploads_controller_test.rb new file mode 100644 index 00000000000..85c38e9298b --- /dev/null +++ b/test/functional/recent_uploads_controller_test.rb @@ -0,0 +1,25 @@ +require 'test_helper' + +class RecentUploadsControllerTest < ActionController::TestCase + context "on GET to index" do + setup do + @recent_uploads = [create(:version)] + + Version.stubs(:recent_uploads).returns @recent_uploads + + get :index + end + + should "display 25 recently uploaded gems" do + assert_received(Version, :recent_uploads) { |subject| subject.with(25) } + end + end + + context "on GET to index with no data" do + setup do + get :index + end + + should respond_with :success + end +end diff --git a/test/unit/version_test.rb b/test/unit/version_test.rb index 486674f19d5..f3a7f8aa49b 100644 --- a/test/unit/version_test.rb +++ b/test/unit/version_test.rb @@ -136,6 +136,27 @@ class VersionTest < ActiveSupport::TestCase end end + context "recent uploads" do + setup do + @gem_1 = create(:rubygem) + @second = create(:version, rubygem: @gem_1, created_at: 1.day.ago) + @fourth = create(:version, rubygem: @gem_1, created_at: 4.days.ago) + + @gem_2 = create(:rubygem) + @first = create(:version, rubygem: @gem_2, created_at: 1.minute.ago) + @not_included_fifth = create(:version, rubygem: @gem_2, created_at: 10.days.ago) + + @gem_3 = create(:rubygem) + @third = create(:version, rubygem: @gem_3, created_at: 3.days.ago) + end + + should "include specified number of versions ordered by created at" do + versions = Version.recent_uploads(4) + assert_equal 4, versions.size + assert_equal [@first, @second, @third, @fourth], versions + end + end + context "with a rubygem" do setup do @rubygem = create(:rubygem)