Skip to content

Resolved Issue #361 by including recent public versions on versions#show #392

Merged
merged 3 commits into from Sep 9, 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
@@ -92,6 +92,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 = Factory(:version, :built_at => 1.week.ago, :created_at => 1.day.ago)
@rubygem = @latest_version.rubygem
+ @versions = (1..5).map do |_|
@qrush
RubyGems member
qrush added a note Jan 26, 2012

Just use times.

@rkneufeld
rkneufeld added a note Jan 26, 2012

Considered that, however n.times returns n and not the array.

@cmeiklejohn
cmeiklejohn added a note Jan 30, 2012

Right, you'd have to do something like n.times.map(&:to_i)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
+ 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
Something went wrong with that request. Please try again.