Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions app/assets/stylesheets/modules/recent.css
Original file line number Diff line number Diff line change
@@ -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; } }
11 changes: 11 additions & 0 deletions app/assets/stylesheets/modules/stats.css
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
5 changes: 5 additions & 0 deletions app/controllers/recent_uploads_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class RecentUploadsController < ApplicationController
def index
@recent_uploads = Version.recent_uploads(25)
end
end
7 changes: 7 additions & 0 deletions app/models/version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
19 changes: 19 additions & 0 deletions app/views/recent_uploads/index.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<% @title = "Recent Uploads" %>

<div class="recent">
<table class="recent__table">
<% @recent_uploads.each do |version| %>
<tr class="recent__table__row">
<th class="recent__table__column">
<%= link_to version.rubygem.name, rubygem_path(version.rubygem), class: 'gems__gem__name' %>
</th>
<td class="recent__table__column">
<%= link_to version.number, rubygem_version_path(version.rubygem, version.slug), class: 'gems__gem__version' %>
</td>
<td class="recent__table__column">
<span class="gem__version__date"><%= nice_date_for(version.rubygem.created_at) %></span>
</td>
</tr>
<% end %>
</table>
</div>
5 changes: 5 additions & 0 deletions app/views/stats/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,9 @@
</div>
</div>
<% end %>

<p class="stats__link">
<%= link_to t('stats.index.recent_uploads'), recent_uploads_path %>
</p>

<%= will_paginate @most_downloaded %>
1 change: 1 addition & 0 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
1 change: 1 addition & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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],
Expand Down
25 changes: 25 additions & 0 deletions test/functional/recent_uploads_controller_test.rb
Original file line number Diff line number Diff line change
@@ -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
21 changes: 21 additions & 0 deletions test/unit/version_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down