Commit 3ad4e8b322f800caea945706abb86b1992bd2079
1 parent
798c80a2
Exists in
master
and in
29 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
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)) | ... | ... |