Commit 3ad4e8b322f800caea945706abb86b1992bd2079

Authored by AntonioTerceiro
1 parent 798c80a2

ActionItem53: removing person when removing user



git-svn-id: https://svn.colivre.coop.br/svn/noosfero/trunk@402 3f533792-8f58-4932-b0fe-aaf55b0a4547
app/models/profile.rb
... ... @@ -15,7 +15,6 @@ class Profile < ActiveRecord::Base
15 15 Comatose::Page.find_by_path(profile.identifier).destroy
16 16 end
17 17  
18   -
19 18 # Valid identifiers must match this format.
20 19 IDENTIFIER_FORMAT = /^[a-z][a-z0-9_]*[a-z0-9]$/
21 20  
... ...
app/models/user.rb
... ... @@ -8,7 +8,7 @@ class User < ActiveRecord::Base
8 8 Person.create!(:identifier => user.login, :name => user.login, :user_id => user.id)
9 9 end
10 10  
11   - has_one :person
  11 + has_one :person, :dependent => :destroy
12 12  
13 13 # Virtual attribute for the unencrypted password
14 14 attr_accessor :password
... ...
test/unit/user_test.rb
... ... @@ -124,6 +124,20 @@ class UserTest < Test::Unit::TestCase
124 124 assert user.authenticated?('test')
125 125 end
126 126  
  127 + def test_should_create_person_when_creating_user
  128 + count = Person.count
  129 + assert !Person.find_by_identifier('lalala')
  130 + create_user(:login => 'lalala', :email => 'lalala@example.com')
  131 + assert Person.find_by_identifier('lalala')
  132 + end
  133 +
  134 + def test_should_destroy_person_when_destroying_user
  135 + user = create_user(:login => 'lalala', :email => 'lalala@example.com')
  136 + assert Person.find_by_identifier('lalala')
  137 + user.destroy
  138 + assert !Person.find_by_identifier('lalala')
  139 + end
  140 +
127 141 protected
128 142 def create_user(options = {})
129 143 User.create({ :login => 'quire', :email => 'quire@example.com', :password => 'quire', :password_confirmation => 'quire' }.merge(options))
... ...