Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Move stats from rubygems/versions controller into stats controller

  • Loading branch information...
commit c4c15d50672b0bc68839ccd0b066a49fdaf873a8 1 parent d105374
@qrush qrush authored
View
2  app/controllers/application_controller.rb
@@ -20,7 +20,7 @@ def verify_authenticated_user
end
def find_gem
- @rubygem = Rubygem.find_by_name(params[:id])
+ @rubygem = Rubygem.find_by_name(params[:id] || params[:rubygem_id])
if @rubygem.blank?
respond_to do |format|
format.html do
View
10 app/controllers/rubygems_controller.rb
@@ -1,6 +1,6 @@
class RubygemsController < ApplicationController
before_filter :redirect_to_root, :only => [:edit, :update], :unless => :signed_in?
- before_filter :find_gem, :only => [:edit, :update, :show, :stats]
+ before_filter :find_gem, :only => [:edit, :update, :show]
before_filter :load_gem, :only => [:edit, :update]
def index
@@ -20,14 +20,6 @@ def show
@latest_version = @rubygem.versions.most_recent
end
- def stats
- @versions = @rubygem.versions.limit(5)
- @latest_version = @versions.first
- if @versions.blank?
- render :file => 'public/404.html', :status => :not_found
- end
- end
-
def edit
end
View
20 app/controllers/stats_controller.rb
@@ -1,8 +1,28 @@
class StatsController < ApplicationController
+ before_filter :find_gem, :only => :show
+ before_filter :ensure_hosted, :only => :show
+
+
def index
@number_of_gems = Rubygem.total_count
@number_of_users = User.count
@number_of_downloads = Download.count
@most_downloaded = Rubygem.downloaded(10)
end
+
+ def show
+ if params[:version_id]
+ @version = Version.find_from_slug!(@rubygem.id, params[:version_id])
+ @versions = [@version]
+ else
+ @version = @rubygem.versions.most_recent
+ @versions = @rubygem.versions.limit(5)
+ end
+ end
+
+ private
+
+ def ensure_hosted
+ render :file => 'public/404.html', :status => :not_found if !@rubygem.hosted?
+ end
end
View
8 app/controllers/versions_controller.rb
@@ -11,14 +11,8 @@ def show
render "rubygems/show"
end
- def stats
- @latest_version = @rubygem.versions.most_recent
- @versions = [Version.find_from_slug!(@rubygem.id, params[:id])]
- render "rubygems/stats"
- end
-
protected
-
+
def find_rubygem
@rubygem = Rubygem.find_by_name(params[:rubygem_id])
end
View
4 app/helpers/rubygems_helper.rb
@@ -53,9 +53,9 @@ def documentation_path(version)
def stats_options(rubygem)
[
- ['Overview', stats_rubygem_path(rubygem)],
+ ['Overview', rubygem_stats_path(rubygem)],
*rubygem.versions.sort.reverse.map do |version|
- [version.slug, stats_rubygem_version_path(rubygem, version.slug)]
+ [version.slug, rubygem_version_stats_path(rubygem, version.slug)]
end
]
end
View
2  app/views/rubygems/show.html.erb
@@ -55,7 +55,7 @@
<%= subscribe_link(@rubygem) %>
<%= unsubscribe_link(@rubygem) %>
<% end %>
- <%= link_to "Stats", stats_rubygem_path(@rubygem), :id => "stats" %>
+ <%= link_to "Stats", rubygem_stats_path(@rubygem), :id => "stats" %>
</div>
<% if @latest_version.indexed %>
View
2  app/views/rubygems/stats.html.erb → app/views/stats/show.html.erb
@@ -1,7 +1,7 @@
<% @title, @title_url = @rubygem.name, rubygem_path(@rubygem) %>
<div id="markup">
- <%= simple_markup(@latest_version.info) %>
+ <%= simple_markup(@version.info) %>
</div>
<div class="border">
View
4 config/routes.rb
@@ -71,7 +71,7 @@
constraints :rubygem_id => RUBYGEM_NAME_MATCHER do
resource :subscription, :only => [:create, :destroy]
resources :versions, :only => :index
- member { get :stats }
+ resource :stats, :only => :show
end
end
@@ -80,7 +80,7 @@
constraints :rubygem_id => RUBYGEM_NAME_MATCHER do
resources :versions, :only => :show do
- member { get :stats }
+ resource :stats, :only => :show
end
end
end
View
56 test/functional/rubygems_controller_test.rb
@@ -305,62 +305,6 @@ class RubygemsControllerTest < ActionController::TestCase
should respond_with :not_found
end
- context "On GET to stats" do
- setup do
- @latest_version = Factory(:version)
- @rubygem = @latest_version.rubygem
- @versions = @versions = @rubygem.versions.limit(5)
- get :stats, :id => @rubygem.to_param
- end
-
- should respond_with :success
- should render_template :stats
- should assign_to(:rubygem) { @rubygem }
- should assign_to(:latest_version) { @latest_version }
- should assign_to(:versions) { @versions }
- should "render info about the gem" do
- assert_contain @rubygem.name
- end
- should "display a dropdown to choose the version to show" do
- assert_have_no_selector 'select#version_for_stats'
- end
- end
-
- context "On GET to stats with a gem that has multiple versions" do
- setup do
- @rubygem = Factory(:rubygem)
- @older_version = Factory(:version, :number => "1.0.0", :rubygem => @rubygem)
- @latest_version = Factory(:version, :number => "2.0.0", :rubygem => @rubygem)
- get :stats, :id => @rubygem.to_param
- end
-
- should respond_with :success
- should render_template :stats
- should assign_to(:rubygem) { @rubygem }
- should assign_to(:latest_version) { @latest_version }
- should assign_to(:versions) { [@latest_version, @older_version] }
- should "display a dropdown to choose the version to show" do
- assert_have_selector 'select#version_for_stats'
- end
- end
-
- context "On GET to stats for a gem with no versions" do
- setup do
- @rubygem = Factory(:rubygem)
- get :stats, :id => @rubygem.to_param
- end
-
- should respond_with :not_found
- end
-
- context "On GET to stats for nonexistent gem" do
- setup do
- get :stats, :id => "blahblah"
- end
-
- should respond_with :not_found
- end
-
context "When not logged in" do
context "On GET to show for a gem" do
setup do
View
75 test/functional/stats_controller_test.rb
@@ -42,4 +42,79 @@ class StatsControllerTest < ActionController::TestCase
assert_received(Rubygem) { |subject| subject.downloaded.with(10) }
end
end
+
+ context "On GET to stats" do
+ setup do
+ @version = Factory(:version)
+ @rubygem = @version.rubygem
+ @versions = @versions = @rubygem.versions.limit(5)
+ get :show, :rubygem_id => @rubygem.to_param
+ end
+
+ should respond_with :success
+ should render_template :show
+ should assign_to(:rubygem) { @rubygem }
+ should assign_to(:version) { @version }
+ should assign_to(:versions) { @versions }
+ should "render info about the gem" do
+ assert_contain @rubygem.name
+ end
+ should "display a dropdown to choose the version to show" do
+ assert_have_no_selector 'select#version_for_stats'
+ end
+ end
+
+ context "On GET to stats with a gem that has multiple versions" do
+ setup do
+ @rubygem = Factory(:rubygem)
+ @older_version = Factory(:version, :number => "1.0.0", :rubygem => @rubygem)
+ @latest_version = Factory(:version, :number => "2.0.0", :rubygem => @rubygem)
+ get :show, :rubygem_id => @rubygem.to_param
+ end
+
+ should respond_with :success
+ should render_template :show
+ should assign_to(:rubygem) { @rubygem }
+ should assign_to(:version) { @latest_version }
+ should assign_to(:versions) { [@latest_version, @older_version] }
+ should "display a dropdown to choose the version to show" do
+ assert_have_selector 'select#version_for_stats'
+ end
+ end
+
+ context "On GET to stats for a gem with no versions" do
+ setup do
+ @rubygem = Factory(:rubygem)
+ get :show, :rubygem_id => @rubygem.to_param
+ end
+
+ should respond_with :not_found
+ end
+
+ context "On GET to stats for nonexistent gem" do
+ setup do
+ get :show, :rubygem_id => "blahblah"
+ end
+
+ should respond_with :not_found
+ end
+
+ context "On GET to stats for a specific version" do
+ setup do
+ @version = Factory(:version, :number => "0.0.1")
+ @rubygem = @version.rubygem
+ @latest_version = Factory(:version, :rubygem => @rubygem, :number => "0.0.2")
+
+ get :show, :rubygem_id => @rubygem.name, :version_id => @version.slug
+ end
+
+ should respond_with :success
+ should render_template :show
+ should assign_to(:rubygem) { @rubygem }
+ should assign_to(:version) { @version }
+ should assign_to(:versions) { [@version] }
+ should "render info about the gem" do
+ assert_contain @rubygem.name
+ end
+ end
end
View
19 test/functional/versions_controller_test.rb
@@ -1,7 +1,6 @@
require 'test_helper'
class VersionsControllerTest < ActionController::TestCase
-
context 'GET to index' do
setup do
@rubygem = Factory(:rubygem)
@@ -41,23 +40,5 @@ class VersionsControllerTest < ActionController::TestCase
assert_contain @latest_version.built_at_date
end
end
-
- context "On GET to stats" do
- setup do
- @latest_version = Factory(:version)
- @rubygem = @latest_version.rubygem
- get :stats, :rubygem_id => @rubygem.name, :id => @latest_version.slug
- end
-
- should respond_with :success
- should render_template "rubygems/stats"
- should assign_to(:rubygem) { @rubygem }
- should assign_to(:latest_version) { @latest_version }
- should assign_to(:versions) { [@latest_version] }
- should "render info about the gem" do
- assert_contain @rubygem.name
- end
- end
-
end
View
4 test/unit/helpers/rubygems_helper_test.rb
@@ -58,14 +58,14 @@ class RubygemsHelperTest < ActionView::TestCase
should "show the overview link first" do
overview = stats_options(@rubygem).first
- assert_equal ["Overview", stats_rubygem_path(@rubygem)], overview
+ assert_equal ["Overview", rubygem_stats_path(@rubygem)], overview
end
should "have all the links for the rubygem" do
_, *links = stats_options(@rubygem)
@versions.sort.reverse.each_with_index do |version, index|
- assert_equal [version.slug, stats_rubygem_version_path(@rubygem, version.slug)], links[index]
+ assert_equal [version.slug, rubygem_version_stats_path(@rubygem, version.slug)], links[index]
end
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.