Skip to content
Browse files

Merge pull request #392 from rkneufeld/recent_versions_on_version_show

Resolved Issue #361 by including recent public versions on versions#show
  • Loading branch information...
2 parents f5db270 + 3159cf2 commit 479cd6e10138c0285363bdcfb905a1bf10576338 @cmeiklejohn cmeiklejohn committed Sep 8, 2012
View
2 app/controllers/versions_controller.rb
@@ -7,7 +7,7 @@ def index
def show
@latest_version = Version.find_from_slug!(@rubygem.id, params[:id])
- @versions = [@latest_version]
+ @versions = @rubygem.public_versions_with_extra_version(@latest_version)
render "rubygems/show"
end
View
6 app/models/rubygem.rb
@@ -91,6 +91,12 @@ def public_versions(limit = nil)
versions.published(limit).by_position
end
+ def public_versions_with_extra_version(extra_version)
+ versions = public_versions(5)
+ versions << extra_version
+ versions.uniq.sort_by(&:position)
+ end
+
def hosted?
versions.count.nonzero?
end
View
10 test/functional/versions_controller_test.rb
@@ -40,6 +40,9 @@ class VersionsControllerTest < ActionController::TestCase
setup do
@latest_version = create(:version, :built_at => 1.week.ago, :created_at => 1.day.ago)
@rubygem = @latest_version.rubygem
+ @versions = (1..5).map do |_|
+ Factory(:version, :rubygem => @rubygem)
+ end
get :show, :rubygem_id => @rubygem.name, :id => @latest_version.number
end
@@ -49,7 +52,14 @@ class VersionsControllerTest < ActionController::TestCase
should assign_to(:latest_version) { @latest_version }
should "render info about the gem" do
assert page.has_content?(@rubygem.name)
+ end
+ should "render the specified version" do
assert page.has_content?(@latest_version.number)
end
+ should "render other related versions" do
+ @versions.each do |version|
+ assert page.has_content?(version.number)
+ end
+ end
end
end
View
21 test/unit/rubygem_test.rb
@@ -118,6 +118,27 @@ class RubygemTest < ActiveSupport::TestCase
assert_equal indexed_v1.reload, @rubygem.reload.versions.most_recent
end
+
+ context "#public_versions_with_extra_version" do
+ setup do
+ @first_version = Factory(:version, :rubygem => @rubygem, :number => '1.0.0', :position => 1)
+ @extra_version = Factory(:version, :rubygem => @rubygem, :number => '0.1.0', :position => 2)
+ end
+ should "include public versions" do
+ assert @rubygem.public_versions_with_extra_version(@extra_version).include?(@first_version)
+ end
+ should "include extra version" do
+ assert @rubygem.public_versions_with_extra_version(@extra_version).include?(@extra_version)
+ end
+ should "maintain proper ordering" do
+ versions = @rubygem.public_versions_with_extra_version(@extra_version)
+ assert_equal versions, versions.sort_by(&:position)
+ end
+ should "not duplicate versions" do
+ versions = @rubygem.public_versions_with_extra_version(@first_version)
+ assert_equal versions.count, versions.uniq.count
+ end
+ end
end
context "with a rubygem" do

0 comments on commit 479cd6e

Please sign in to comment.
Something went wrong with that request. Please try again.