Skip to content

Commit

Permalink
Ownership does not have to generate a token anymore
Browse files Browse the repository at this point in the history
  • Loading branch information
nickrivadeneira committed Jul 12, 2011
1 parent 92fa087 commit 12034a6
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 16 deletions.
6 changes: 0 additions & 6 deletions app/models/ownership.rb
Expand Up @@ -4,13 +4,8 @@ class Ownership < ActiveRecord::Base


validates :user_id, :uniqueness => {:scope => :rubygem_id} validates :user_id, :uniqueness => {:scope => :rubygem_id}


before_create :generate_token
before_destroy :keep_last_owner before_destroy :keep_last_owner


def generate_token
self.token = ActiveSupport::SecureRandom.hex
end

def keep_last_owner def keep_last_owner
if rubygem.owners.count == 1 if rubygem.owners.count == 1
errors[:base] << "Can't delete last owner of a gem." errors[:base] << "Can't delete last owner of a gem."
Expand All @@ -19,5 +14,4 @@ def keep_last_owner
true true
end end
end end

end end
10 changes: 0 additions & 10 deletions test/unit/ownership_test.rb
@@ -1,7 +1,6 @@
require 'test_helper' require 'test_helper'


class OwnershipTest < ActiveSupport::TestCase class OwnershipTest < ActiveSupport::TestCase

should "be valid with factory" do should "be valid with factory" do
assert_valid Factory.build(:ownership) assert_valid Factory.build(:ownership)
end end
Expand All @@ -20,14 +19,6 @@ class OwnershipTest < ActiveSupport::TestCase
subject { @ownership } subject { @ownership }


should validate_uniqueness_of(:user_id).scoped_to(:rubygem_id) should validate_uniqueness_of(:user_id).scoped_to(:rubygem_id)

should "create token" do
assert_not_nil @ownership.token
end

should "have a 32 character hexadecimal api key" do
assert @ownership.token =~ /[a-z0-9]{32}/
end
end end


context "with multiple ownerships on the same rubygem" do context "with multiple ownerships on the same rubygem" do
Expand All @@ -49,5 +40,4 @@ class OwnershipTest < ActiveSupport::TestCase
assert_equal "Can't delete last owner of a gem.", @ownership_two.errors[:base].first assert_equal "Can't delete last owner of a gem.", @ownership_two.errors[:base].first
end end
end end

end end

0 comments on commit 12034a6

Please sign in to comment.