Commit 3ad4e8b322f800caea945706abb86b1992bd2079
1 parent
798c80a2
Exists in
master
and in
28 other branches
ActionItem53: removing person when removing user
git-svn-id: https://svn.colivre.coop.br/svn/noosfero/trunk@402 3f533792-8f58-4932-b0fe-aaf55b0a4547
Showing
3 changed files
with
15 additions
and
2 deletions
Show diff stats
app/models/profile.rb
| @@ -15,7 +15,6 @@ class Profile < ActiveRecord::Base | @@ -15,7 +15,6 @@ class Profile < ActiveRecord::Base | ||
| 15 | Comatose::Page.find_by_path(profile.identifier).destroy | 15 | Comatose::Page.find_by_path(profile.identifier).destroy |
| 16 | end | 16 | end |
| 17 | 17 | ||
| 18 | - | ||
| 19 | # Valid identifiers must match this format. | 18 | # Valid identifiers must match this format. |
| 20 | IDENTIFIER_FORMAT = /^[a-z][a-z0-9_]*[a-z0-9]$/ | 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,7 +8,7 @@ class User < ActiveRecord::Base | ||
| 8 | Person.create!(:identifier => user.login, :name => user.login, :user_id => user.id) | 8 | Person.create!(:identifier => user.login, :name => user.login, :user_id => user.id) |
| 9 | end | 9 | end |
| 10 | 10 | ||
| 11 | - has_one :person | 11 | + has_one :person, :dependent => :destroy |
| 12 | 12 | ||
| 13 | # Virtual attribute for the unencrypted password | 13 | # Virtual attribute for the unencrypted password |
| 14 | attr_accessor :password | 14 | attr_accessor :password |
test/unit/user_test.rb
| @@ -124,6 +124,20 @@ class UserTest < Test::Unit::TestCase | @@ -124,6 +124,20 @@ class UserTest < Test::Unit::TestCase | ||
| 124 | assert user.authenticated?('test') | 124 | assert user.authenticated?('test') |
| 125 | end | 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 | protected | 141 | protected |
| 128 | def create_user(options = {}) | 142 | def create_user(options = {}) |
| 129 | User.create({ :login => 'quire', :email => 'quire@example.com', :password => 'quire', :password_confirmation => 'quire' }.merge(options)) | 143 | User.create({ :login => 'quire', :email => 'quire@example.com', :password => 'quire', :password_confirmation => 'quire' }.merge(options)) |