diff --git a/app/models/profile.rb b/app/models/profile.rb index 66d901a..37be19f 100644 --- a/app/models/profile.rb +++ b/app/models/profile.rb @@ -15,7 +15,6 @@ class Profile < ActiveRecord::Base Comatose::Page.find_by_path(profile.identifier).destroy end - # Valid identifiers must match this format. IDENTIFIER_FORMAT = /^[a-z][a-z0-9_]*[a-z0-9]$/ diff --git a/app/models/user.rb b/app/models/user.rb index e77ffbb..71da3e8 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -8,7 +8,7 @@ class User < ActiveRecord::Base Person.create!(:identifier => user.login, :name => user.login, :user_id => user.id) end - has_one :person + has_one :person, :dependent => :destroy # Virtual attribute for the unencrypted password attr_accessor :password diff --git a/test/unit/user_test.rb b/test/unit/user_test.rb index 5738a71..89b15e0 100644 --- a/test/unit/user_test.rb +++ b/test/unit/user_test.rb @@ -124,6 +124,20 @@ class UserTest < Test::Unit::TestCase assert user.authenticated?('test') end + def test_should_create_person_when_creating_user + count = Person.count + assert !Person.find_by_identifier('lalala') + create_user(:login => 'lalala', :email => 'lalala@example.com') + assert Person.find_by_identifier('lalala') + end + + def test_should_destroy_person_when_destroying_user + user = create_user(:login => 'lalala', :email => 'lalala@example.com') + assert Person.find_by_identifier('lalala') + user.destroy + assert !Person.find_by_identifier('lalala') + end + protected def create_user(options = {}) User.create({ :login => 'quire', :email => 'quire@example.com', :password => 'quire', :password_confirmation => 'quire' }.merge(options)) -- libgit2 0.21.2