Permalink
Browse files

Merge pull request #467 from rubygems/unyank-by-owner

Allow last version unyanking by original owner
  • Loading branch information...
2 parents ea1d495 + 7a55828 commit 154853efdb9e3956c99ac3e79ff0775a75890e3b @evanphx evanphx committed Jul 13, 2013
@@ -30,7 +30,7 @@ def create
def yank
if @version.indexed?
- @rubygem.yank!(@version)
+ @version.yank!
render :text => "Successfully yanked gem: #{@version.to_title}"
else
render :text => "The version #{params[:version]} has already been yanked.", :status => :unprocessable_entity
View
@@ -113,6 +113,7 @@ def notify(message, code)
end
def update
+ rubygem.disown if rubygem.versions.indexed.count.zero?
rubygem.update_attributes_from_gem_specification!(version, spec)
rubygem.create_ownership(user) unless version.new_record?
true
View
@@ -228,11 +228,8 @@ def reorder_versions
end
end
- def yank!(version)
- version.yank!
- if versions.indexed.count.zero?
- ownerships.each(&:delete)
- end
+ def disown
+ ownerships.each(&:delete)
end
def find_version_from_spec(spec)
View
@@ -95,3 +95,22 @@ Feature: Delete Gems
And I go to the dashboard
And I follow "RGem"
Then I should not see "This gem has been yanked."
+
+ Scenario: User unyanks a gem with no indexed versions
+ Given I am signed up as "email@person.com"
+ And I have an API key for "email@person.com/password"
+ And the following ownership exists:
+ | rubygem | user |
+ | name: RGem | email: email@person.com |
+ And the following versions exist:
+ | rubygem | number |
+ | name: RGem | 1.2.3 |
+ When I yank the gem "RGem" version "1.2.3" with my API key
+ And I go to the dashboard
+ And I go to the "RGem" rubygem page
+ Then I should see "This gem has been yanked"
+
+ When I unyank the gem "RGem" version "1.2.3" with my API key
+ And I go to the dashboard
+ And I follow "RGem"
+ Then I should not see "This gem has been yanked"
@@ -258,10 +258,9 @@ def self.should_respond_to(format)
delete :yank, :gem_name => @rubygem.to_param, :version => @v1.number
end
should respond_with :success
- should "keep the gem, deindex, remove owner" do
+ should "keep the gem, deindex, keep owner" do
assert_equal 1, @rubygem.versions.count
assert @rubygem.versions.indexed.count.zero?
- assert @rubygem.ownerships.count.zero?
end
end
@@ -296,7 +296,7 @@ class RubygemsControllerTest < ActionController::TestCase
setup do
version = create(:version, :created_at => 1.minute.ago)
@rubygem = version.rubygem
- @rubygem.yank!(version)
+ version.yank!
end
context 'when signed out' do
setup { get :show, :id => @rubygem.to_param }
View
@@ -421,17 +421,21 @@ class RubygemTest < ActiveSupport::TestCase
context "when yanking the last version of a gem with an owner" do
setup do
- @rubygem_with_version.yank!(@rubygem_with_version.versions.first)
+ @rubygem_with_version.versions.first.yank!
end
- should "no longer be owned" do
- assert @rubygem_with_version.reload.unowned?
+ should "still be owned" do
+ assert @rubygem_with_version.owned_by?(@owner)
+ end
+
+ should "no longer be indexed" do
+ assert @rubygem_with_version.versions.indexed.count.zero?
end
end
context "when yanking one of many versions of a gem" do
setup do
- @rubygem_with_versions.yank!(@rubygem_with_versions.versions.first)
+ @rubygem_with_versions.versions.first.yank!
end
should "remain owned" do
assert !@rubygem_with_versions.reload.unowned?

0 comments on commit 154853e

Please sign in to comment.