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
31 changes: 30 additions & 1 deletion app/assets/stylesheets/modules/stats.css
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
.stat__count {
font-size: 24px; } }

.stats__graph__heading {
.stats__heading {
margin-bottom: 42px;
font-weight: 600;
font-size: 18px;
Expand Down Expand Up @@ -205,3 +205,32 @@
@-moz-document url-prefix() {
.stats__graph__gem__count {
top: 8px; } }

.stats__table {
width: 100%;
border-collapse: separate;
border-spacing: 30px 15px;
border-left: 3%;
}

.stats__table__row {
height: 30px;
width: 100%; }

.stats__table__column {
/* Size table columns to contents. */
width: 1%;
white-space: nowrap;

font-weight: 400;
text-align: right;
vertical-align: middle; }

@media (max-width: 709px) {
.stats__table__column {
font-size: 13px; } }
@media (min-width: 710px) {
.stats__table__column {
font-size: 15px; } }

.stats__table__column a { color: black; }
1 change: 1 addition & 0 deletions app/controllers/stats_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@ def index
@number_of_downloads = GemDownload.total_count
@most_downloaded = Rubygem.by_downloads.limit(10).includes(:gem_download).to_a
@most_downloaded_count = @most_downloaded.first && @most_downloaded.first.gem_download.count
@recent_uploads = Version.recent_uploads(10)
end
end
7 changes: 7 additions & 0 deletions app/models/version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,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_built_at.limit(limit)
end
Expand Down
44 changes: 33 additions & 11 deletions app/views/stats/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,39 @@
</h2>
</div>

<h2 class="stats__graph__heading">
<%= t('stats.index.all_time_most_downloaded') %>
</h2>
<div class="stats">
<h2 class="stats__heading">
<%= t('stats.index.all_time_most_downloaded') %>
</h2>

<% @most_downloaded.each do |gem| %>
<div class="stats__graph__gem">
<h3 class="stats__graph__gem__name"><%= link_to gem.name, rubygem_path(gem) %></h3>
<div class="stats__graph__gem__meter-wrap">
<div class="stats__graph__gem__meter" style="width: <%= stats_graph_meter(gem, @most_downloaded_count) %>%">
<span class="stats__graph__gem__count"><%= number_to_delimited gem.downloads %></span>
<% @most_downloaded.each do |gem| %>
<div class="stats__graph__gem">
<h3 class="stats__graph__gem__name"><%= link_to gem.name, rubygem_path(gem) %></h3>
<div class="stats__graph__gem__meter-wrap">
<div class="stats__graph__gem__meter" style="width: <%= stats_graph_meter(gem, @most_downloaded_count) %>%">
<span class="stats__graph__gem__count"><%= number_to_delimited gem.downloads %></span>
</div>
</div>
</div>
</div>
<% end %>
<% end %>
</div>

<div class="stats">
<h2 class="stats__heading">
<%= t('stats.index.recent_uploads') %>
</h2>

<table class="stats__table">
<% @recent_uploads.each do |version| %>
<tr class="stats__table__row">
<th class="stats__table__column">
<%= link_to version.rubygem.name, rubygem_path(version.rubygem) %>
</th>
<td class="stats__table__column">
<%= link_to version.number, rubygem_version_path(version.rubygem, version.slug) %>
</td>
<td></td>
</tr>
<% end %>
</table>
</div>
1 change: 1 addition & 0 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,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
3 changes: 3 additions & 0 deletions test/functional/stats_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@ class StatsControllerTest < ActionController::TestCase
@number_of_users = 101
@number_of_downloads = 42
rails_cinco = create(:rubygem, name: 'rails_cinco', number: 1)
@recent_uploads = [create(:version)]

Rubygem.stubs(:total_count).returns @number_of_gems
User.stubs(:count).returns @number_of_users
Version.stubs(:recent_uploads).returns @recent_uploads

create(:gem_download, count: @number_of_downloads)
rails_cinco.gem_download.update(count: 1)
Expand Down Expand Up @@ -39,6 +41,7 @@ class StatsControllerTest < ActionController::TestCase
should "load up the number of gems, users, and downloads" do
assert_received(User, :count)
assert_received(Rubygem, :total_count)
assert_received(Version, :recent_uploads) { |subject| subject.with(10) }
end
end

Expand Down
21 changes: 21 additions & 0 deletions test/unit/version_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,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