Commit b9c58d9486c34810285bd5a30f7aa1b1d760572f

Authored by Moises Machado
1 parent 23335037

ActionItem780: refactoring tests

Squashed commit of the following:

commit ff9310723bc4f768185d4c562f06a99807e00d05
Author: Moises Machado <moises@colivre.coop.br>
Date:   Sat Oct 11 18:34:24 2008 -0300

    fixed the rest of the tests

commit 8fe241dcb67b3928796254e557319da3ec7e9734
Author: Moises Machado <moises@colivre.coop.br>
Date:   Sat Oct 11 17:16:27 2008 -0300

    ActionItem780: refactoring tests and forms
app/models/person.rb
@@ -32,7 +32,7 @@ class Person &lt; Profile @@ -32,7 +32,7 @@ class Person &lt; Profile
32 friends.delete(friend) 32 friends.delete(friend)
33 end 33 end
34 34
35 - N_('Contact information'); N_('Birth date'); N_('City'); N_('State'); N_('Country'); N_('Sex'); 35 + N_('Contact information'); N_('Birth date'); N_('City'); N_('State'); N_('Country'); N_('Sex'); N_('Zip Code')
36 settings_items :photo, :contact_information, :birth_date, :sex, :city, :state, :country, :zip_code 36 settings_items :photo, :contact_information, :birth_date, :sex, :city, :state, :country, :zip_code
37 37
38 def self.conditions_for_profiles(conditions, person) 38 def self.conditions_for_profiles(conditions, person)
app/models/user.rb
@@ -24,7 +24,9 @@ class User &lt; ActiveRecord::Base @@ -24,7 +24,9 @@ class User &lt; ActiveRecord::Base
24 end 24 end
25 25
26 after_create do |user| 26 after_create do |user|
27 - Person.create!(:identifier => user.login, :name => user.login, :user_id => user.id, :environment_id => user.environment_id) 27 + user.person ||= Person.new
  28 + user.person.name ||= user.login
  29 + user.person.update_attributes(:identifier => user.login, :user_id => user.id, :environment_id => user.environment_id)
28 end 30 end
29 31
30 has_one :person, :dependent => :destroy 32 has_one :person, :dependent => :destroy
app/views/account/_signup_form.rhtml
1 <%= error_messages_for :user %> 1 <%= error_messages_for :user %>
2 <% labelled_form_for :user, @user, 2 <% labelled_form_for :user, @user,
3 - :html => { :help=>_('Fill all this fields to join in this environment. <p/> If you forgot your password, do not create a new account, click on the "<b>I forgot my password!</b>" link. ;-)') 3 + :html => { :help=>_('Fill all this fields to join in this environment. <p/> If you forgot your password, do not create a new account, click on the "<b>I forgot my password!</b>" link. ;-)'), :id => 'profile-data'
4 } do |f| -%> 4 } do |f| -%>
5 5
6 <%= f.text_field :login, 6 <%= f.text_field :login,
app/views/profile_editor/_person.rhtml
1 <h2><%= _('Personal information') %></h2> 1 <h2><%= _('Personal information') %></h2>
2 2
  3 + <%= f.text_field(:email)%>
3 4
4 - <%= f.text_field(:nickname, :maxlength => 16, :size => 30) %>  
5 - <div>  
6 - <small><em><%= _('A short name by which you like to be known. Will be used in friends listings, community member listings etc.') %></em></small>  
7 - </div>  
8 -  
9 -  
10 - <%= f.text_field(:name) %>  
11 - <%= labelled_form_field(_('e-Mail'), text_field(:profile_data, :email)) %>  
12 - <%= f.text_field(:contact_information) %>  
13 - <%= f.text_field(:contact_phone) %>  
14 - <%# use :size => 3 if you want 3 radios by line %>  
15 - <%= f.radio_group :profile_data, :sex, [ ['male',_('Male')], ['female',_('Female')] ] %>  
16 - <%= f.text_field(:birth_date) %>  
17 - <%= labelled_form_field(_('Address (street and number)'), text_field(:profile_data, :address)) %>  
18 - <%= labelled_form_field(_('ZIP code'), text_field(:profile_data, :zip_code)) %>  
19 - <%= f.text_field(:city) %>  
20 - <%= f.text_field(:state) %>  
21 - <%= f.text_field(:country) %> 5 + <%= render :partial => 'person_form', :locals => {:f => f} %>
app/views/profile_editor/_person_form.rhtml 0 → 100644
@@ -0,0 +1,16 @@ @@ -0,0 +1,16 @@
  1 +<%= f.text_field(:nickname, :maxlength => 16, :size => 30) %>
  2 +<div>
  3 + <small><em><%= _('A short name by which you like to be known. Will be used in friends listings, community member listings etc.') %></em></small>
  4 +</div>
  5 +
  6 +<%= f.text_field(:name) %>
  7 +<%= f.text_field(:contact_information) %>
  8 +<%= f.text_field(:contact_phone) %>
  9 +<%# use :size => 3 if you want 3 radios by line %>
  10 +<%= f.radio_group :profile_data, :sex, [ ['male',_('Male')], ['female',_('Female')] ] %>
  11 +<%= f.text_field(:birth_date) %>
  12 +<%= labelled_form_field(_('Address (street and number)'), text_field(:profile_data, :address)) %>
  13 +<%= labelled_form_field(_('ZIP code'), text_field(:profile_data, :zip_code)) %>
  14 +<%= f.text_field(:city) %>
  15 +<%= f.text_field(:state) %>
  16 +<%= f.text_field(:country) %>
public/stylesheets/controller_account.css
  1 +@import url(person_data.css);
  2 +
1 .button.disabled { 3 .button.disabled {
2 opacity: 0.5; 4 opacity: 0.5;
3 } 5 }
public/stylesheets/controller_profile_editor.css
1 @import url(controller_cms.css); 1 @import url(controller_cms.css);
  2 +@import url(person_data.css);
2 3
3 .profile_info { 4 .profile_info {
4 width: 100%; 5 width: 100%;
@@ -24,7 +25,6 @@ @@ -24,7 +25,6 @@
24 background-color: transparent !important; 25 background-color: transparent !important;
25 } 26 }
26 27
27 -  
28 /* file manager (big) style */ 28 /* file manager (big) style */
29 29
30 .file-manager { 30 .file-manager {
@@ -60,4 +60,3 @@ @@ -60,4 +60,3 @@
60 .file-manager-button span { 60 .file-manager-button span {
61 display: block; 61 display: block;
62 } 62 }
63 -  
test/functional/account_controller_test.rb
@@ -34,7 +34,7 @@ class AccountControllerTest &lt; Test::Unit::TestCase @@ -34,7 +34,7 @@ class AccountControllerTest &lt; Test::Unit::TestCase
34 end 34 end
35 35
36 should 'redirect to user control panel on login' do 36 should 'redirect to user control panel on login' do
37 - u = create_user 37 + u = new_user
38 post :login, :user => {:login => 'quire', :password => 'quire'} 38 post :login, :user => {:login => 'quire', :password => 'quire'}
39 39
40 assert_redirected_to :controller => 'profile_editor', :action => 'index', :profile => 'quire' 40 assert_redirected_to :controller => 'profile_editor', :action => 'index', :profile => 'quire'
@@ -49,14 +49,14 @@ class AccountControllerTest &lt; Test::Unit::TestCase @@ -49,14 +49,14 @@ class AccountControllerTest &lt; Test::Unit::TestCase
49 49
50 def test_should_allow_signup 50 def test_should_allow_signup
51 assert_difference User, :count do 51 assert_difference User, :count do
52 - create_user 52 + new_user
53 assert_response :redirect 53 assert_response :redirect
54 end 54 end
55 end 55 end
56 56
57 def test_should_require_login_on_signup 57 def test_should_require_login_on_signup
58 assert_no_difference User, :count do 58 assert_no_difference User, :count do
59 - create_user(:login => nil) 59 + new_user(:login => nil)
60 assert assigns(:user).errors.on(:login) 60 assert assigns(:user).errors.on(:login)
61 assert_response :success 61 assert_response :success
62 end 62 end
@@ -64,7 +64,7 @@ class AccountControllerTest &lt; Test::Unit::TestCase @@ -64,7 +64,7 @@ class AccountControllerTest &lt; Test::Unit::TestCase
64 64
65 def test_should_require_password_on_signup 65 def test_should_require_password_on_signup
66 assert_no_difference User, :count do 66 assert_no_difference User, :count do
67 - create_user(:password => nil) 67 + new_user(:password => nil)
68 assert assigns(:user).errors.on(:password) 68 assert assigns(:user).errors.on(:password)
69 assert_response :success 69 assert_response :success
70 end 70 end
@@ -72,7 +72,7 @@ class AccountControllerTest &lt; Test::Unit::TestCase @@ -72,7 +72,7 @@ class AccountControllerTest &lt; Test::Unit::TestCase
72 72
73 def test_should_require_password_confirmation_on_signup 73 def test_should_require_password_confirmation_on_signup
74 assert_no_difference User, :count do 74 assert_no_difference User, :count do
75 - create_user(:password_confirmation => nil) 75 + new_user(:password_confirmation => nil)
76 assert assigns(:user).errors.on(:password_confirmation) 76 assert assigns(:user).errors.on(:password_confirmation)
77 assert_response :success 77 assert_response :success
78 end 78 end
@@ -80,7 +80,7 @@ class AccountControllerTest &lt; Test::Unit::TestCase @@ -80,7 +80,7 @@ class AccountControllerTest &lt; Test::Unit::TestCase
80 80
81 def test_should_require_email_on_signup 81 def test_should_require_email_on_signup
82 assert_no_difference User, :count do 82 assert_no_difference User, :count do
83 - create_user(:email => nil) 83 + new_user(:email => nil)
84 assert assigns(:user).errors.on(:email) 84 assert assigns(:user).errors.on(:email)
85 assert_response :success 85 assert_response :success
86 end 86 end
@@ -89,7 +89,7 @@ class AccountControllerTest &lt; Test::Unit::TestCase @@ -89,7 +89,7 @@ class AccountControllerTest &lt; Test::Unit::TestCase
89 def test_shoud_not_save_without_acceptance_of_terms_of_use_on_signup 89 def test_shoud_not_save_without_acceptance_of_terms_of_use_on_signup
90 assert_no_difference User, :count do 90 assert_no_difference User, :count do
91 Environment.default.update_attributes(:terms_of_use => 'some terms ...') 91 Environment.default.update_attributes(:terms_of_use => 'some terms ...')
92 - create_user 92 + new_user
93 assert_response :success 93 assert_response :success
94 end 94 end
95 end 95 end
@@ -97,7 +97,7 @@ class AccountControllerTest &lt; Test::Unit::TestCase @@ -97,7 +97,7 @@ class AccountControllerTest &lt; Test::Unit::TestCase
97 def test_shoud_save_with_acceptance_of_terms_of_use_on_signup 97 def test_shoud_save_with_acceptance_of_terms_of_use_on_signup
98 assert_difference User, :count do 98 assert_difference User, :count do
99 Environment.default.update_attributes(:terms_of_use => 'some terms ...') 99 Environment.default.update_attributes(:terms_of_use => 'some terms ...')
100 - create_user(:terms_accepted => '1') 100 + new_user(:terms_accepted => '1')
101 assert_response :redirect 101 assert_response :redirect
102 end 102 end
103 end 103 end
@@ -243,7 +243,7 @@ class AccountControllerTest &lt; Test::Unit::TestCase @@ -243,7 +243,7 @@ class AccountControllerTest &lt; Test::Unit::TestCase
243 end 243 end
244 244
245 should 'require password confirmation correctly to enter new pasword' do 245 should 'require password confirmation correctly to enter new pasword' do
246 - user = User.create!(:login => 'testuser', :email => 'testuser@example.com', :password => 'test', :password_confirmation => 'test') 246 + user = create_user('testuser', :email => 'testuser@example.com', :password => 'test', :password_confirmation => 'test')
247 change = ChangePassword.create!(:login => 'testuser', :email => 'testuser@example.com') 247 change = ChangePassword.create!(:login => 'testuser', :email => 'testuser@example.com')
248 248
249 post :new_password, :code => change.code, :change_password => { :password => 'onepass', :password_confirmation => 'another_pass' } 249 post :new_password, :code => change.code, :change_password => { :password => 'onepass', :password_confirmation => 'another_pass' }
@@ -267,9 +267,9 @@ class AccountControllerTest &lt; Test::Unit::TestCase @@ -267,9 +267,9 @@ class AccountControllerTest &lt; Test::Unit::TestCase
267 267
268 should 'restrict multiple users with the same e-mail' do 268 should 'restrict multiple users with the same e-mail' do
269 assert_difference User, :count do 269 assert_difference User, :count do
270 - create_user(:login => 'user1', :email => 'user@example.com') 270 + new_user(:login => 'user1', :email => 'user@example.com')
271 assert assigns(:user).valid? 271 assert assigns(:user).valid?
272 - create_user(:login => 'user2', :email => 'user@example.com') 272 + new_user(:login => 'user2', :email => 'user@example.com')
273 assert assigns(:user).errors.on(:email) 273 assert assigns(:user).errors.on(:email)
274 end 274 end
275 end 275 end
@@ -398,7 +398,7 @@ class AccountControllerTest &lt; Test::Unit::TestCase @@ -398,7 +398,7 @@ class AccountControllerTest &lt; Test::Unit::TestCase
398 398
399 should 'not activate if user does not accept terms' do 399 should 'not activate if user does not accept terms' do
400 ent = Enterprise.create!(:name => 'test enterprise', :identifier => 'test_ent', :foundation_year => 1998, :enabled => false) 400 ent = Enterprise.create!(:name => 'test enterprise', :identifier => 'test_ent', :foundation_year => 1998, :enabled => false)
401 - p = User.create!(:login => 'test_user', :password => 'blih', :password_confirmation => 'blih', :email => 'test@noosfero.com').person 401 + p = create_user('test_user', :password => 'blih', :password_confirmation => 'blih', :email => 'test@noosfero.com').person
402 login_as(p.identifier) 402 login_as(p.identifier)
403 403
404 task = EnterpriseActivation.create!(:enterprise => ent) 404 task = EnterpriseActivation.create!(:enterprise => ent)
@@ -423,7 +423,7 @@ class AccountControllerTest &lt; Test::Unit::TestCase @@ -423,7 +423,7 @@ class AccountControllerTest &lt; Test::Unit::TestCase
423 423
424 should 'activate enterprise and make logged user admin' do 424 should 'activate enterprise and make logged user admin' do
425 ent = Enterprise.create!(:name => 'test enterprise', :identifier => 'test_ent', :foundation_year => 1998, :enabled => false) 425 ent = Enterprise.create!(:name => 'test enterprise', :identifier => 'test_ent', :foundation_year => 1998, :enabled => false)
426 - p = User.create!(:login => 'test_user', :password => 'blih', :password_confirmation => 'blih', :email => 'test@noosfero.com').person 426 + p = create_user('test_user', :password => 'blih', :password_confirmation => 'blih', :email => 'test@noosfero.com').person
427 login_as(p.identifier) 427 login_as(p.identifier)
428 428
429 task = EnterpriseActivation.create!(:enterprise => ent) 429 task = EnterpriseActivation.create!(:enterprise => ent)
@@ -449,7 +449,7 @@ class AccountControllerTest &lt; Test::Unit::TestCase @@ -449,7 +449,7 @@ class AccountControllerTest &lt; Test::Unit::TestCase
449 449
450 should 'activate enterprise and make unlogged user admin' do 450 should 'activate enterprise and make unlogged user admin' do
451 ent = Enterprise.create!(:name => 'test enterprise', :identifier => 'test_ent', :foundation_year => 1998, :enabled => false) 451 ent = Enterprise.create!(:name => 'test enterprise', :identifier => 'test_ent', :foundation_year => 1998, :enabled => false)
452 - p = User.create!(:login => 'test_user', :password => 'blih', :password_confirmation => 'blih', :email => 'test@noosfero.com').person 452 + p = create_user('test_user', :password => 'blih', :password_confirmation => 'blih', :email => 'test@noosfero.com').person
453 453
454 task = EnterpriseActivation.create!(:enterprise => ent) 454 task = EnterpriseActivation.create!(:enterprise => ent)
455 EnterpriseActivation.expects(:find_by_code).with('0123456789').returns(task).at_least_once 455 EnterpriseActivation.expects(:find_by_code).with('0123456789').returns(task).at_least_once
@@ -467,7 +467,7 @@ class AccountControllerTest &lt; Test::Unit::TestCase @@ -467,7 +467,7 @@ class AccountControllerTest &lt; Test::Unit::TestCase
467 task = EnterpriseActivation.create!(:enterprise => ent) 467 task = EnterpriseActivation.create!(:enterprise => ent)
468 EnterpriseActivation.expects(:find_by_code).with('0123456789').returns(task).at_least_once 468 EnterpriseActivation.expects(:find_by_code).with('0123456789').returns(task).at_least_once
469 469
470 - post :activate_enterprise, :enterprise_code => '0123456789', :answer => '1998', :terms_accepted => true, :new_user => true, :user => { :login => 'test_user', :password => 'blih', :password_confirmation => 'blih', :email => 'test@noosfero.com' } 470 + post :activate_enterprise, :enterprise_code => '0123456789', :answer => '1998', :terms_accepted => true, :new_user => true, :user => { :login => 'test_user', :password => 'blih', :password_confirmation => 'blih', :email => 'test@noosfero.com' }, :profile_data => person_data
471 ent.reload 471 ent.reload
472 472
473 assert ent.enabled 473 assert ent.enabled
@@ -517,7 +517,7 @@ class AccountControllerTest &lt; Test::Unit::TestCase @@ -517,7 +517,7 @@ class AccountControllerTest &lt; Test::Unit::TestCase
517 517
518 should 'not be able to signup while inverse captcha field filled' do 518 should 'not be able to signup while inverse captcha field filled' do
519 assert_no_difference User, :count do 519 assert_no_difference User, :count do
520 - create_user({}, @controller.icaptcha_field => 'bli@bla.email.foo') 520 + new_user({}, @controller.icaptcha_field => 'bli@bla.email.foo')
521 end 521 end
522 end 522 end
523 523
@@ -527,7 +527,7 @@ class AccountControllerTest &lt; Test::Unit::TestCase @@ -527,7 +527,7 @@ class AccountControllerTest &lt; Test::Unit::TestCase
527 end 527 end
528 528
529 should 'use the current environment for the template of user' do 529 should 'use the current environment for the template of user' do
530 - template = User.create!(:login => 'test_template', :email => 'test@bli.com', :password => 'pass', :password_confirmation => 'pass').person 530 + template = create_user('test_template', :email => 'test@bli.com', :password => 'pass', :password_confirmation => 'pass').person
531 template.boxes.destroy_all 531 template.boxes.destroy_all
532 template.boxes << Box.new 532 template.boxes << Box.new
533 template.boxes[0].blocks << Block.new 533 template.boxes[0].blocks << Block.new
@@ -538,7 +538,7 @@ class AccountControllerTest &lt; Test::Unit::TestCase @@ -538,7 +538,7 @@ class AccountControllerTest &lt; Test::Unit::TestCase
538 538
539 @controller.stubs(:environment).returns(env) 539 @controller.stubs(:environment).returns(env)
540 540
541 - create_user 541 + new_user
542 542
543 assert_equal 1, assigns(:user).person.boxes.size 543 assert_equal 1, assigns(:user).person.boxes.size
544 assert_equal 1, assigns(:user).person.boxes[0].blocks.size 544 assert_equal 1, assigns(:user).person.boxes[0].blocks.size
@@ -574,13 +574,19 @@ class AccountControllerTest &lt; Test::Unit::TestCase @@ -574,13 +574,19 @@ class AccountControllerTest &lt; Test::Unit::TestCase
574 end 574 end
575 575
576 protected 576 protected
577 - def create_user(options = {}, extra_options ={})  
578 - post :signup, { :user => { :login => 'quire', 577 + def new_user(options = {}, extra_options ={})
  578 + data = {:profile_data => person_data}
  579 + if extra_options[:profile_data]
  580 + data[:profile_data].merge! extra_options.delete(:profile_data)
  581 + end
  582 + data.merge! extra_options
  583 +
  584 + post :signup, { :user => { :login => 'quire',
579 :email => 'quire@example.com', 585 :email => 'quire@example.com',
580 :password => 'quire', 586 :password => 'quire',
581 :password_confirmation => 'quire' 587 :password_confirmation => 'quire'
582 }.merge(options) 588 }.merge(options)
583 - }.merge(extra_options) 589 + }.merge(data)
584 end 590 end
585 591
586 def auth_token(token) 592 def auth_token(token)
test/functional/cms_controller_test.rb
@@ -107,7 +107,7 @@ class CmsControllerTest &lt; Test::Unit::TestCase @@ -107,7 +107,7 @@ class CmsControllerTest &lt; Test::Unit::TestCase
107 107
108 assert_redirected_to :action => 'view', :id => a.id 108 assert_redirected_to :action => 'view', :id => a.id
109 109
110 - profile.reload 110 + profile = Profile.find(@profile.id)
111 assert_equal a, profile.home_page 111 assert_equal a, profile.home_page
112 end 112 end
113 113
test/functional/memberships_controller_test.rb
@@ -49,7 +49,7 @@ class MembershipsControllerTest &lt; Test::Unit::TestCase @@ -49,7 +49,7 @@ class MembershipsControllerTest &lt; Test::Unit::TestCase
49 assert_response :redirect 49 assert_response :redirect
50 assert_redirected_to community.url 50 assert_redirected_to community.url
51 51
52 - profile.reload 52 + profile = Profile.find(@profile.id)
53 assert profile.memberships.include?(community), 'profile should be actually added to the community' 53 assert profile.memberships.include?(community), 'profile should be actually added to the community'
54 end 54 end
55 55
@@ -139,7 +139,7 @@ class MembershipsControllerTest &lt; Test::Unit::TestCase @@ -139,7 +139,7 @@ class MembershipsControllerTest &lt; Test::Unit::TestCase
139 assert_response :redirect 139 assert_response :redirect
140 assert_redirected_to :action => 'index' 140 assert_redirected_to :action => 'index'
141 141
142 - profile.reload 142 + profile = Profile.find(@profile.id)
143 assert_not_includes profile.memberships, community 143 assert_not_includes profile.memberships, community
144 end 144 end
145 145
@@ -239,7 +239,7 @@ class MembershipsControllerTest &lt; Test::Unit::TestCase @@ -239,7 +239,7 @@ class MembershipsControllerTest &lt; Test::Unit::TestCase
239 community.affiliate(profile, Profile::Roles.all_roles) 239 community.affiliate(profile, Profile::Roles.all_roles)
240 post :leave, :profile => profile.identifier, :id => community.id, :confirmation => true 240 post :leave, :profile => profile.identifier, :id => community.id, :confirmation => true
241 241
242 - profile.reload 242 + profile = Profile.find(@profile.id)
243 assert_not_includes profile.memberships, community 243 assert_not_includes profile.memberships, community
244 end 244 end
245 245
test/functional/profile_editor_controller_test.rb
@@ -12,13 +12,14 @@ class ProfileEditorControllerTest &lt; Test::Unit::TestCase @@ -12,13 +12,14 @@ class ProfileEditorControllerTest &lt; Test::Unit::TestCase
12 @request = ActionController::TestRequest.new 12 @request = ActionController::TestRequest.new
13 @request.stubs(:ssl?).returns(true) 13 @request.stubs(:ssl?).returns(true)
14 @response = ActionController::TestResponse.new 14 @response = ActionController::TestResponse.new
15 - login_as('ze')  
16 - @profile = Person['ze'] 15 + @profile = create_user('default_user').person
  16 + Environment.default.affiliate(@profile, [Environment::Roles.admin] + Profile::Roles.all_roles)
  17 + login_as('default_user')
17 end 18 end
18 attr_reader :profile 19 attr_reader :profile
19 20
20 def test_local_files_reference 21 def test_local_files_reference
21 - assert_local_files_reference :get, :index, :profile => 'ze' 22 + assert_local_files_reference :get, :index, :profile => profile.identifier
22 end 23 end
23 24
24 def test_valid_xhtml 25 def test_valid_xhtml
@@ -26,7 +27,7 @@ class ProfileEditorControllerTest &lt; Test::Unit::TestCase @@ -26,7 +27,7 @@ class ProfileEditorControllerTest &lt; Test::Unit::TestCase
26 end 27 end
27 28
28 def test_index 29 def test_index
29 - person = User.create(:login => 'test_profile', :email => 'test@noosfero.org', :password => 'test', :password_confirmation => 'test').person 30 + person = create_user('test_profile').person
30 person.name = 'a test profile' 31 person.name = 'a test profile'
31 person.address = 'my address' 32 person.address = 'my address'
32 person.contact_information = 'my contact information' 33 person.contact_information = 'my contact information'
@@ -53,8 +54,7 @@ class ProfileEditorControllerTest &lt; Test::Unit::TestCase @@ -53,8 +54,7 @@ class ProfileEditorControllerTest &lt; Test::Unit::TestCase
53 end 54 end
54 55
55 def test_edit_person_info 56 def test_edit_person_info
56 - person = User.create(:login => 'test_profile', :email => 'test@noosfero.org', :password => 'test', :password_confirmation => 'test').person  
57 - assert person.valid? 57 + person = create_user('test_profile', :email => 'test@noosfero.org', :password => 'test', :password_confirmation => 'test').person
58 get :edit, :profile => person.identifier 58 get :edit, :profile => person.identifier
59 assert_response :success 59 assert_response :success
60 assert_template 'edit' 60 assert_template 'edit'
@@ -64,7 +64,7 @@ class ProfileEditorControllerTest &lt; Test::Unit::TestCase @@ -64,7 +64,7 @@ class ProfileEditorControllerTest &lt; Test::Unit::TestCase
64 person = create_user('test_profile').person 64 person = create_user('test_profile').person
65 post :edit, :profile => 'test_profile', :profile_data => { 'name' => 'new person', 'contact_information' => 'new contact information', 'address' => 'new address', 'sex' => 'female' } 65 post :edit, :profile => 'test_profile', :profile_data => { 'name' => 'new person', 'contact_information' => 'new contact information', 'address' => 'new address', 'sex' => 'female' }
66 assert_redirected_to :action => 'index' 66 assert_redirected_to :action => 'index'
67 - person.reload 67 + person = Person.find(person.id)
68 assert_equal 'new person', person.name 68 assert_equal 'new person', person.name
69 assert_equal 'new contact information', person.contact_information 69 assert_equal 'new contact information', person.contact_information
70 assert_equal 'new address', person.address 70 assert_equal 'new address', person.address
@@ -190,28 +190,27 @@ class ProfileEditorControllerTest &lt; Test::Unit::TestCase @@ -190,28 +190,27 @@ class ProfileEditorControllerTest &lt; Test::Unit::TestCase
190 end 190 end
191 191
192 should 'display profile publication option in edit profile screen' do 192 should 'display profile publication option in edit profile screen' do
193 - profile = Profile['ze']  
194 - get :edit, :profile => 'ze' 193 + get :edit, :profile => profile.identifier
195 assert_tag :tag => 'input', :attributes => { :type => 'radio', :checked => 'checked', :name => 'profile_data[public_profile]', :value => 'true' } 194 assert_tag :tag => 'input', :attributes => { :type => 'radio', :checked => 'checked', :name => 'profile_data[public_profile]', :value => 'true' }
196 assert_tag :tag => 'input', :attributes => { :type => 'radio', :name => 'profile_data[public_profile]', :value => 'false' } 195 assert_tag :tag => 'input', :attributes => { :type => 'radio', :name => 'profile_data[public_profile]', :value => 'false' }
197 end 196 end
198 197
199 should 'display properly that the profile is non-public' do 198 should 'display properly that the profile is non-public' do
200 - profile = Profile['ze']  
201 profile.update_attributes!(:public_profile => false) 199 profile.update_attributes!(:public_profile => false)
202 - get :edit, :profile => 'ze' 200 + get :edit, :profile => profile.identifier
203 assert_tag :tag => 'input', :attributes => { :type => 'radio', :checked => 'checked', :name => 'profile_data[public_profile]', :value => 'false' } 201 assert_tag :tag => 'input', :attributes => { :type => 'radio', :checked => 'checked', :name => 'profile_data[public_profile]', :value => 'false' }
204 assert_tag :tag => 'input', :attributes => { :type => 'radio', :name => 'profile_data[public_profile]', :value => 'true' } 202 assert_tag :tag => 'input', :attributes => { :type => 'radio', :name => 'profile_data[public_profile]', :value => 'true' }
205 end 203 end
206 204
207 should 'save profile publication option set to true' do 205 should 'save profile publication option set to true' do
208 - post :edit, :profile => 'ze', :profile_data => { :public_profile => 'true' }  
209 - assert_equal true, Profile['ze'].public_profile 206 + post :edit, :profile => profile.identifier, :profile_data => { :public_profile => 'true' }
  207 + assert_equal true, profile.public_profile
210 end 208 end
211 209
212 should 'save profile publication option set to false' do 210 should 'save profile publication option set to false' do
213 - post :edit, :profile => 'ze', :profile_data => { :public_profile => 'false' }  
214 - assert_equal false, Profile['ze'].public_profile 211 + post :edit, :profile => profile.identifier, :profile_data => { :public_profile => 'false' }
  212 + profile = Person.find(@profile.id)
  213 + assert_equal false, profile.public_profile
215 end 214 end
216 215
217 should 'show error messages for invalid foundation_year' do 216 should 'show error messages for invalid foundation_year' do
@@ -368,8 +367,8 @@ class ProfileEditorControllerTest &lt; Test::Unit::TestCase @@ -368,8 +367,8 @@ class ProfileEditorControllerTest &lt; Test::Unit::TestCase
368 367
369 should 'link to mailconf' do 368 should 'link to mailconf' do
370 MailConf.expects(:enabled?).returns(true).at_least_once 369 MailConf.expects(:enabled?).returns(true).at_least_once
371 - get :index, :profile => 'ze'  
372 - assert_tag :tag => 'a', :attributes => { :href => '/myprofile/ze/mailconf' } 370 + get :index, :profile => profile.identifier
  371 + assert_tag :tag => 'a', :attributes => { :href => "/myprofile/#{profile.identifier}/mailconf" }
373 end 372 end
374 373
375 should 'not link to mailconf for organizations' do 374 should 'not link to mailconf for organizations' do
@@ -381,8 +380,8 @@ class ProfileEditorControllerTest &lt; Test::Unit::TestCase @@ -381,8 +380,8 @@ class ProfileEditorControllerTest &lt; Test::Unit::TestCase
381 380
382 should 'not link to mailconf if mail not enabled' do 381 should 'not link to mailconf if mail not enabled' do
383 MailConf.expects(:enabled?).returns(false).at_least_once 382 MailConf.expects(:enabled?).returns(false).at_least_once
384 - get :index, :profile => 'ze'  
385 - assert_no_tag :tag => 'a', :attributes => { :href => '/myprofile/ze/mailconf' } 383 + get :index, :profile => profile.identifier
  384 + assert_no_tag :tag => 'a', :attributes => { :href => "/myprofile/#{profile.identifier}/mailconf" }
386 end 385 end
387 386
388 should 'link to enable enterprise' do 387 should 'link to enable enterprise' do
@@ -465,7 +464,7 @@ class ProfileEditorControllerTest &lt; Test::Unit::TestCase @@ -465,7 +464,7 @@ class ProfileEditorControllerTest &lt; Test::Unit::TestCase
465 should 'save footer and header' do 464 should 'save footer and header' do
466 person = create_user('designtestuser').person 465 person = create_user('designtestuser').person
467 post :header_footer, :profile => 'designtestuser', :custom_header => 'new header', :custom_footer => 'new footer' 466 post :header_footer, :profile => 'designtestuser', :custom_header => 'new header', :custom_footer => 'new footer'
468 - person.reload 467 + person = Person.find(person.id)
469 assert_equal 'new header', person.custom_header 468 assert_equal 'new header', person.custom_header
470 assert_equal 'new footer', person.custom_footer 469 assert_equal 'new footer', person.custom_footer
471 end 470 end
@@ -477,8 +476,8 @@ class ProfileEditorControllerTest &lt; Test::Unit::TestCase @@ -477,8 +476,8 @@ class ProfileEditorControllerTest &lt; Test::Unit::TestCase
477 end 476 end
478 477
479 should 'point to header/footer editing in control panel' do 478 should 'point to header/footer editing in control panel' do
480 - get :index, :profile => 'ze'  
481 - assert_tag :tag => 'a', :attributes => { :href => '/myprofile/ze/profile_editor/header_footer' } 479 + get :index, :profile => profile.identifier
  480 + assert_tag :tag => 'a', :attributes => { :href => "/myprofile/#{profile.identifier}/profile_editor/header_footer" }
482 end 481 end
483 482
484 should 'not list the manage products button if the environment disabled it' do 483 should 'not list the manage products button if the environment disabled it' do
@@ -497,14 +496,14 @@ class ProfileEditorControllerTest &lt; Test::Unit::TestCase @@ -497,14 +496,14 @@ class ProfileEditorControllerTest &lt; Test::Unit::TestCase
497 496
498 should 'display categories if environment disable_categories disabled' do 497 should 'display categories if environment disable_categories disabled' do
499 Environment.any_instance.stubs(:enabled?).with(anything).returns(false) 498 Environment.any_instance.stubs(:enabled?).with(anything).returns(false)
500 - person = User.create(:login => 'test_profile', :email => 'test@noosfero.org', :password => 'test', :password_confirmation => 'test').person 499 + person = create_user('test_profile', :email => 'test@noosfero.org', :password => 'test', :password_confirmation => 'test').person
501 get :edit, :profile => person.identifier 500 get :edit, :profile => person.identifier
502 assert_tag :tag => 'div', :descendant => { :tag => 'h2', :content => 'Select the categories of your interest' } 501 assert_tag :tag => 'div', :descendant => { :tag => 'h2', :content => 'Select the categories of your interest' }
503 end 502 end
504 503
505 should 'not display categories if environment disable_categories enabled' do 504 should 'not display categories if environment disable_categories enabled' do
506 Environment.any_instance.stubs(:enabled?).with(anything).returns(true) 505 Environment.any_instance.stubs(:enabled?).with(anything).returns(true)
507 - person = User.create(:login => 'test_profile', :email => 'test@noosfero.org', :password => 'test', :password_confirmation => 'test').person 506 + person = create_user('test_profile', :email => 'test@noosfero.org', :password => 'test', :password_confirmation => 'test').person
508 get :edit, :profile => person.identifier 507 get :edit, :profile => person.identifier
509 assert_no_tag :tag => 'div', :descendant => { :tag => 'h2', :content => 'Select the categories of your interest' } 508 assert_no_tag :tag => 'div', :descendant => { :tag => 'h2', :content => 'Select the categories of your interest' }
510 end 509 end
test/functional/profile_members_controller_test.rb
@@ -74,7 +74,7 @@ class ProfileMembersControllerTest &lt; Test::Unit::TestCase @@ -74,7 +74,7 @@ class ProfileMembersControllerTest &lt; Test::Unit::TestCase
74 post 'update_roles', :profile => 'test_enterprise', :roles => [role2.id], :person => member 74 post 'update_roles', :profile => 'test_enterprise', :roles => [role2.id], :person => member
75 75
76 assert_response :redirect 76 assert_response :redirect
77 - member.reload 77 + member = Person.find(member.id)
78 roles = member.find_roles(ent).map(&:role) 78 roles = member.find_roles(ent).map(&:role)
79 assert_includes roles, role2 79 assert_includes roles, role2
80 assert_not_includes roles, role1 80 assert_not_includes roles, role1
test/functional/tasks_controller_test.rb
@@ -67,7 +67,7 @@ class TasksControllerTest &lt; Test::Unit::TestCase @@ -67,7 +67,7 @@ class TasksControllerTest &lt; Test::Unit::TestCase
67 t = AddMember.create!(:person => profile, :community => profile) 67 t = AddMember.create!(:person => profile, :community => profile)
68 count = profile.members.size 68 count = profile.members.size
69 post :close, :decision => 'finish', :id => t.id 69 post :close, :decision => 'finish', :id => t.id
70 - profile.reload 70 + profile = Profile.find(@profile.id)
71 assert_equal count + 1, profile.members.size 71 assert_equal count + 1, profile.members.size
72 end 72 end
73 73
test/functional/themes_controller_test.rb
@@ -55,7 +55,7 @@ class ThemesControllerTest &lt; Test::Unit::TestCase @@ -55,7 +55,7 @@ class ThemesControllerTest &lt; Test::Unit::TestCase
55 55
56 should 'save selection of theme' do 56 should 'save selection of theme' do
57 get :set, :profile => 'testinguser', :id => 'onetheme' 57 get :set, :profile => 'testinguser', :id => 'onetheme'
58 - profile.reload 58 + profile = Profile.find(@profile.id)
59 assert_equal 'onetheme', profile.theme 59 assert_equal 'onetheme', profile.theme
60 end 60 end
61 61
@@ -234,7 +234,7 @@ class ThemesControllerTest &lt; Test::Unit::TestCase @@ -234,7 +234,7 @@ class ThemesControllerTest &lt; Test::Unit::TestCase
234 234
235 should 'set template' do 235 should 'set template' do
236 post :set_layout_template, :profile => 'testinguser', :id => 'leftbar' 236 post :set_layout_template, :profile => 'testinguser', :id => 'leftbar'
237 - profile.reload 237 + profile = Profile.find(@profile.id)
238 assert_equal 'leftbar', profile.layout_template 238 assert_equal 'leftbar', profile.layout_template
239 assert_redirected_to :action => 'index' 239 assert_redirected_to :action => 'index'
240 end 240 end
test/integration/editing_person_info_test.rb
@@ -6,19 +6,19 @@ class EditingPersonInfoTest &lt; ActionController::IntegrationTest @@ -6,19 +6,19 @@ class EditingPersonInfoTest &lt; ActionController::IntegrationTest
6 6
7 should 'allow to edit person info' do 7 should 'allow to edit person info' do
8 8
9 - profile = Profile.find_by_identifier('ze') 9 + profile = create_user('user_ze', :password => 'test', :password_confirmation => 'test').person
10 10
11 - login('ze', 'test') 11 + login(profile.identifier, 'test')
12 12
13 - get '/myprofile/ze' 13 + get "/myprofile/#{profile.identifier}"
14 assert_response :success 14 assert_response :success
15 15
16 assert_tag :tag => 'a', :content => 'Profile settings' 16 assert_tag :tag => 'a', :content => 'Profile settings'
17 17
18 - get '/myprofile/ze/profile_editor/edit' 18 + get "/myprofile/#{profile.identifier}/profile_editor/edit"
19 assert_response :success 19 assert_response :success
20 20
21 - post '/myprofile/ze/profile_editor/edit', :profile_data => { :address => 'a new address', :contact_information => 'a new contact information' } 21 + post "/myprofile/#{profile.identifier}/profile_editor/edit", :profile_data => { :address => 'a new address', :contact_information => 'a new contact information' }
22 assert_response :redirect 22 assert_response :redirect
23 23
24 end 24 end
test/integration/forgot_password_test.rb
@@ -12,7 +12,7 @@ class ForgotPasswordTest &lt; ActionController::IntegrationTest @@ -12,7 +12,7 @@ class ForgotPasswordTest &lt; ActionController::IntegrationTest
12 Profile.destroy_all 12 Profile.destroy_all
13 ChangePassword.destroy_all 13 ChangePassword.destroy_all
14 14
15 - User.create!(:login => 'forgotten', :password => 'test', :password_confirmation => 'test', :email => 'forgotten@localhost.localdomain') 15 + create_user('forgotten', :password => 'test', :password_confirmation => 'test', :email => 'forgotten@localhost.localdomain')
16 16
17 get '/account/forgot_password' 17 get '/account/forgot_password'
18 18
test/integration/signup_test.rb
@@ -21,7 +21,7 @@ class SignupTest &lt; ActionController::IntegrationTest @@ -21,7 +21,7 @@ class SignupTest &lt; ActionController::IntegrationTest
21 assert_template 'signup' 21 assert_template 'signup'
22 assert_equal count, User.count 22 assert_equal count, User.count
23 23
24 - post '/account/signup', :user => { :login => 'shouldaccepterms', :password => 'test', :password_confirmation => 'test', :email => 'shouldaccepterms@example.com', :terms_accepted => '1' } 24 + post '/account/signup', :user => { :login => 'shouldaccepterms', :password => 'test', :password_confirmation => 'test', :email => 'shouldaccepterms@example.com', :terms_accepted => '1' }, :profile_data => person_data
25 assert_response :redirect 25 assert_response :redirect
26 26
27 follow_redirect! 27 follow_redirect!
test/test_helper.rb
@@ -66,7 +66,7 @@ class Test::Unit::TestCase @@ -66,7 +66,7 @@ class Test::Unit::TestCase
66 end 66 end
67 67
68 def create_admin_user(env) 68 def create_admin_user(env)
69 - admin_user = User.find_by_login('adminuser') || User.create!(:login => 'adminuser', :email => 'adminuser@noosfero.org', :password => 'adminuser', :password_confirmation => 'adminuser') 69 + admin_user = User.find_by_login('adminuser') || create_user('adminuser', :email => 'adminuser@noosfero.org', :password => 'adminuser', :password_confirmation => 'adminuser')
70 admin_role = Role.find_by_name('admin_role') || Role.create!(:name => 'admin_role', :permissions => ['view_environment_admin_panel','edit_environment_features', 'edit_environment_design', 'manage_environment_categories', 'manage_environment_roles', 'manage_environment_validators']) 70 admin_role = Role.find_by_name('admin_role') || Role.create!(:name => 'admin_role', :permissions => ['view_environment_admin_panel','edit_environment_features', 'edit_environment_design', 'manage_environment_categories', 'manage_environment_roles', 'manage_environment_validators'])
71 RoleAssignment.create!(:accessor => admin_user.person, :role => admin_role, :resource => env) unless admin_user.person.role_assignments.map{|ra|[ra.role, ra.accessor, ra.resource]}.include?([admin_role, admin_user, env]) 71 RoleAssignment.create!(:accessor => admin_user.person, :role => admin_role, :resource => env) unless admin_user.person.role_assignments.map{|ra|[ra.role, ra.accessor, ra.resource]}.include?([admin_role, admin_user, env])
72 admin_user.login 72 admin_user.login
@@ -79,14 +79,21 @@ class Test::Unit::TestCase @@ -79,14 +79,21 @@ class Test::Unit::TestCase
79 env 79 env
80 end 80 end
81 81
82 - def create_user(name, options = {}) 82 + def create_user(name, options = {}, person_options = {})
83 data = { 83 data = {
84 :login => name, 84 :login => name,
85 :email => name + '@noosfero.org', 85 :email => name + '@noosfero.org',
86 :password => name.underscore, 86 :password => name.underscore,
87 :password_confirmation => name.underscore 87 :password_confirmation => name.underscore
88 }.merge(options) 88 }.merge(options)
89 - User.create!(data) 89 + user = User.new(data)
  90 + user.build_person(person_data.merge(person_options))
  91 + user.save!
  92 + user
  93 + end
  94 +
  95 + def person_data
  96 + {}
90 end 97 end
91 98
92 def give_permission(user, permission, target) 99 def give_permission(user, permission, target)
test/unit/article_test.rb
@@ -477,6 +477,7 @@ class ArticleTest &lt; Test::Unit::TestCase @@ -477,6 +477,7 @@ class ArticleTest &lt; Test::Unit::TestCase
477 a = p1.articles.create!(:name => 'test article', :body => 'some text') 477 a = p1.articles.create!(:name => 'test article', :body => 'some text')
478 b = a.copy(:parent => a, :profile => p2) 478 b = a.copy(:parent => a, :profile => p2)
479 479
  480 + p2 = Person.find(p2.id)
480 assert_includes p2.articles, b 481 assert_includes p2.articles, b
481 assert_equal 'some text', b.body 482 assert_equal 'some text', b.body
482 end 483 end
test/unit/change_password_test.rb
@@ -20,7 +20,7 @@ class ChangePasswordTest &lt; Test::Unit::TestCase @@ -20,7 +20,7 @@ class ChangePasswordTest &lt; Test::Unit::TestCase
20 20
21 should 'require a valid username' do 21 should 'require a valid username' do
22 User.destroy_all 22 User.destroy_all
23 - User.create!(:login => 'testuser', :password => 'test', :password_confirmation => 'test', :email => 'test@example.com') 23 + create_user('testuser', :password => 'test', :password_confirmation => 'test', :email => 'test@example.com')
24 24
25 data = ChangePassword.new 25 data = ChangePassword.new
26 data.login = 'testuser' 26 data.login = 'testuser'
@@ -30,7 +30,7 @@ class ChangePasswordTest &lt; Test::Unit::TestCase @@ -30,7 +30,7 @@ class ChangePasswordTest &lt; Test::Unit::TestCase
30 30
31 should 'refuse incorrect e-mail address' do 31 should 'refuse incorrect e-mail address' do
32 User.destroy_all 32 User.destroy_all
33 - User.create!(:login => 'testuser', :password => 'test', :password_confirmation => 'test', :email => 'test@example.com') 33 + create_user('testuser', :password => 'test', :password_confirmation => 'test', :email => 'test@example.com')
34 34
35 data = ChangePassword.new 35 data = ChangePassword.new
36 data.login = 'testuser' 36 data.login = 'testuser'
@@ -43,7 +43,7 @@ class ChangePasswordTest &lt; Test::Unit::TestCase @@ -43,7 +43,7 @@ class ChangePasswordTest &lt; Test::Unit::TestCase
43 43
44 should 'require the correct e-mail address' do 44 should 'require the correct e-mail address' do
45 User.destroy_all 45 User.destroy_all
46 - User.create!(:login => 'testuser', :password => 'test', :password_confirmation => 'test', :email => 'test@example.com') 46 + create_user('testuser', :password => 'test', :password_confirmation => 'test', :email => 'test@example.com')
47 47
48 data = ChangePassword.new 48 data = ChangePassword.new
49 data.login = 'testuser' 49 data.login = 'testuser'
@@ -55,7 +55,7 @@ class ChangePasswordTest &lt; Test::Unit::TestCase @@ -55,7 +55,7 @@ class ChangePasswordTest &lt; Test::Unit::TestCase
55 end 55 end
56 56
57 should 'require correct passsword confirmation' do 57 should 'require correct passsword confirmation' do
58 - User.create!(:login => 'testuser', :password => 'test', :password_confirmation => 'test', :email => 'test@example.com') 58 + create_user('testuser', :password => 'test', :password_confirmation => 'test', :email => 'test@example.com')
59 59
60 change = ChangePassword.new 60 change = ChangePassword.new
61 change.login = 'testuser' 61 change.login = 'testuser'
@@ -75,7 +75,7 @@ class ChangePasswordTest &lt; Test::Unit::TestCase @@ -75,7 +75,7 @@ class ChangePasswordTest &lt; Test::Unit::TestCase
75 75
76 should 'actually change password' do 76 should 'actually change password' do
77 User.destroy_all 77 User.destroy_all
78 - person = User.create!(:login => 'testuser', :password => 'test', :password_confirmation => 'test', :email => 'test@example.com').person 78 + person = create_user('testuser', :password => 'test', :password_confirmation => 'test', :email => 'test@example.com').person
79 79
80 change = ChangePassword.new 80 change = ChangePassword.new
81 change.login = 'testuser' 81 change.login = 'testuser'
@@ -93,7 +93,7 @@ class ChangePasswordTest &lt; Test::Unit::TestCase @@ -93,7 +93,7 @@ class ChangePasswordTest &lt; Test::Unit::TestCase
93 93
94 should 'not require password and password confirmation when cancelling' do 94 should 'not require password and password confirmation when cancelling' do
95 User.destroy_all 95 User.destroy_all
96 - person = User.create!(:login => 'testuser', :password => 'test', :password_confirmation => 'test', :email => 'test@example.com').person 96 + person = create_user('testuser', :password => 'test', :password_confirmation => 'test', :email => 'test@example.com').person
97 97
98 change = ChangePassword.new 98 change = ChangePassword.new
99 change.login = 'testuser' 99 change.login = 'testuser'
test/unit/create_enterprise_test.rb
@@ -28,7 +28,7 @@ class CreateEnterpriseTest &lt; Test::Unit::TestCase @@ -28,7 +28,7 @@ class CreateEnterpriseTest &lt; Test::Unit::TestCase
28 task.valid? 28 task.valid?
29 29
30 assert task.errors.invalid?(:requestor_id) 30 assert task.errors.invalid?(:requestor_id)
31 - task.requestor = User.create!(:login => 'testuser', :password => 'test', :password_confirmation => 'test', :email => 'testuser@localhost.localdomain').person 31 + task.requestor = create_user('testuser', :password => 'test', :password_confirmation => 'test', :email => 'testuser@localhost.localdomain').person
32 task.valid? 32 task.valid?
33 assert !task.errors.invalid?(:requestor_id) 33 assert !task.errors.invalid?(:requestor_id)
34 end 34 end
@@ -98,7 +98,7 @@ class CreateEnterpriseTest &lt; Test::Unit::TestCase @@ -98,7 +98,7 @@ class CreateEnterpriseTest &lt; Test::Unit::TestCase
98 region = Region.create!(:name => 'My region', :environment_id => environment.id) 98 region = Region.create!(:name => 'My region', :environment_id => environment.id)
99 validator = Organization.create!(:name => "My organization", :identifier => 'myorg', :environment_id => environment.id) 99 validator = Organization.create!(:name => "My organization", :identifier => 'myorg', :environment_id => environment.id)
100 region.validators << validator 100 region.validators << validator
101 - person = User.create!(:login => 'testuser', :password => 'test', :password_confirmation => 'test', :email => 'testuser@localhost.localdomain').person 101 + person = create_user('testuser', :password => 'test', :password_confirmation => 'test', :email => 'testuser@localhost.localdomain').person
102 102
103 task = CreateEnterprise.create!({ 103 task = CreateEnterprise.create!({
104 :name => 'My new enterprise', 104 :name => 'My new enterprise',
@@ -132,7 +132,7 @@ class CreateEnterpriseTest &lt; Test::Unit::TestCase @@ -132,7 +132,7 @@ class CreateEnterpriseTest &lt; Test::Unit::TestCase
132 region = Region.create!(:name => 'My region', :environment_id => environment.id) 132 region = Region.create!(:name => 'My region', :environment_id => environment.id)
133 validator = Organization.create!(:name => "My organization", :identifier => 'myorg', :environment_id => environment.id) 133 validator = Organization.create!(:name => "My organization", :identifier => 'myorg', :environment_id => environment.id)
134 region.validators << validator 134 region.validators << validator
135 - person = User.create!(:login => 'testuser', :password => 'test', :password_confirmation => 'test', :email => 'testuser@localhost.localdomain').person 135 + person = create_user('testuser', :password => 'test', :password_confirmation => 'test', :email => 'testuser@localhost.localdomain').person
136 136
137 task = CreateEnterprise.create!({ 137 task = CreateEnterprise.create!({
138 :name => 'My new enterprise', 138 :name => 'My new enterprise',
@@ -174,7 +174,7 @@ class CreateEnterpriseTest &lt; Test::Unit::TestCase @@ -174,7 +174,7 @@ class CreateEnterpriseTest &lt; Test::Unit::TestCase
174 region = Region.create!(:name => 'My region', :environment_id => environment.id) 174 region = Region.create!(:name => 'My region', :environment_id => environment.id)
175 validator = Organization.create!(:name => "My organization", :identifier => 'myorg', :environment_id => environment.id) 175 validator = Organization.create!(:name => "My organization", :identifier => 'myorg', :environment_id => environment.id)
176 region.validators << validator 176 region.validators << validator
177 - person = User.create!(:login => 'testuser', :password => 'test', :password_confirmation => 'test', :email => 'testuser@localhost.localdomain').person 177 + person = create_user('testuser', :password => 'test', :password_confirmation => 'test', :email => 'testuser@localhost.localdomain').person
178 task = CreateEnterprise.new({ 178 task = CreateEnterprise.new({
179 :name => 'My new enterprise', 179 :name => 'My new enterprise',
180 :identifier => 'mynewenterprise', 180 :identifier => 'mynewenterprise',
test/unit/person_test.rb
@@ -6,16 +6,16 @@ class PersonTest &lt; Test::Unit::TestCase @@ -6,16 +6,16 @@ class PersonTest &lt; Test::Unit::TestCase
6 def test_person_must_come_form_the_cration_of_an_user 6 def test_person_must_come_form_the_cration_of_an_user
7 p = Person.new(:name => 'John', :identifier => 'john') 7 p = Person.new(:name => 'John', :identifier => 'john')
8 assert !p.valid? 8 assert !p.valid?
9 - p.user = User.create(:login => 'john', :email => 'john@doe.org', :password => 'dhoe', :password_confirmation => 'dhoe') 9 + p.user = create_user('john', :email => 'john@doe.org', :password => 'dhoe', :password_confirmation => 'dhoe')
10 assert !p.valid? 10 assert !p.valid?
11 - p = User.create(:login => 'johnz', :email => 'johnz@doe.org', :password => 'dhoe', :password_confirmation => 'dhoe').person 11 + p = create_user('johnz', :email => 'johnz@doe.org', :password => 'dhoe', :password_confirmation => 'dhoe').person
12 assert p.valid? 12 assert p.valid?
13 end 13 end
14 14
15 def test_can_associate_to_a_profile 15 def test_can_associate_to_a_profile
16 pr = Profile.new(:identifier => 'mytestprofile', :name => 'My test profile') 16 pr = Profile.new(:identifier => 'mytestprofile', :name => 'My test profile')
17 pr.save! 17 pr.save!
18 - pe = User.create(:login => 'person', :email => 'person@test.net', :password => 'dhoe', :password_confirmation => 'dhoe').person 18 + pe = create_user('person', :email => 'person@test.net', :password => 'dhoe', :password_confirmation => 'dhoe').person
19 pe.save! 19 pe.save!
20 member_role = Role.create(:name => 'somerandomrole') 20 member_role = Role.create(:name => 'somerandomrole')
21 pr.affiliate(pe, member_role) 21 pr.affiliate(pe, member_role)
@@ -26,7 +26,7 @@ class PersonTest &lt; Test::Unit::TestCase @@ -26,7 +26,7 @@ class PersonTest &lt; Test::Unit::TestCase
26 def test_can_belong_to_an_enterprise 26 def test_can_belong_to_an_enterprise
27 e = Enterprise.new(:identifier => 'enterprise', :name => 'enterprise') 27 e = Enterprise.new(:identifier => 'enterprise', :name => 'enterprise')
28 e.save! 28 e.save!
29 - p = User.create(:login => 'person', :email => 'person@test.net', :password => 'dhoe', :password_confirmation => 'dhoe').person 29 + p = create_user('person', :email => 'person@test.net', :password => 'dhoe', :password_confirmation => 'dhoe').person
30 p.save! 30 p.save!
31 member_role = Role.create(:name => 'somerandomrole') 31 member_role = Role.create(:name => 'somerandomrole')
32 e.affiliate(p, member_role) 32 e.affiliate(p, member_role)
@@ -46,7 +46,7 @@ class PersonTest &lt; Test::Unit::TestCase @@ -46,7 +46,7 @@ class PersonTest &lt; Test::Unit::TestCase
46 46
47 should 'can have user' do 47 should 'can have user' do
48 u = User.new(:login => 'john', :email => 'john@doe.org', :password => 'dhoe', :password_confirmation => 'dhoe') 48 u = User.new(:login => 'john', :email => 'john@doe.org', :password => 'dhoe', :password_confirmation => 'dhoe')
49 - p = Person.new(:name => 'John', :identifier => 'john') 49 + p = Person.new(person_data.merge(:name => 'John', :identifier => 'john'))
50 u.person = p 50 u.person = p
51 assert u.save 51 assert u.save
52 assert_kind_of User, p.user 52 assert_kind_of User, p.user
@@ -54,8 +54,7 @@ class PersonTest &lt; Test::Unit::TestCase @@ -54,8 +54,7 @@ class PersonTest &lt; Test::Unit::TestCase
54 end 54 end
55 55
56 should 'only one person per user' do 56 should 'only one person per user' do
57 - u = User.new(:login => 'john', :email => 'john@doe.org', :password => 'dhoe', :password_confirmation => 'dhoe')  
58 - assert u.save 57 + u = create_user('john', :email => 'john@doe.org', :password => 'dhoe', :password_confirmation => 'dhoe')
59 58
60 p1 = u.person 59 p1 = u.person
61 assert_equal u, p1.user 60 assert_equal u, p1.user
@@ -81,30 +80,30 @@ class PersonTest &lt; Test::Unit::TestCase @@ -81,30 +80,30 @@ class PersonTest &lt; Test::Unit::TestCase
81 end 80 end
82 81
83 should 'change the roles of the user' do 82 should 'change the roles of the user' do
84 - p = User.create(:login => 'jonh', :email => 'john@doe.org', :password => 'dhoe', :password_confirmation => 'dhoe').person 83 + p = create_user('jonh', :email => 'john@doe.org', :password => 'dhoe', :password_confirmation => 'dhoe').person
85 e = Enterprise.create(:identifier => 'enter', :name => 'Enter') 84 e = Enterprise.create(:identifier => 'enter', :name => 'Enter')
86 r1 = Role.create(:name => 'associate') 85 r1 = Role.create(:name => 'associate')
87 assert e.affiliate(p, r1) 86 assert e.affiliate(p, r1)
88 r2 = Role.create(:name => 'partner') 87 r2 = Role.create(:name => 'partner')
89 assert p.define_roles([r2], e) 88 assert p.define_roles([r2], e)
90 - p.reload 89 + p = Person.find(p.id)
91 assert p.role_assignments.any? {|ra| ra.role == r2} 90 assert p.role_assignments.any? {|ra| ra.role == r2}
92 assert !p.role_assignments.any? {|ra| ra.role == r1} 91 assert !p.role_assignments.any? {|ra| ra.role == r1}
93 end 92 end
94 93
95 should 'report that the user has the permission' do 94 should 'report that the user has the permission' do
96 - p = User.create(:login => 'jonh', :email => 'john@doe.org', :password => 'dhoe', :password_confirmation => 'dhoe').person 95 + p = create_user('john', :email => 'john@doe.org', :password => 'dhoe', :password_confirmation => 'dhoe').person
97 r = Role.create(:name => 'associate', :permissions => ['edit_profile']) 96 r = Role.create(:name => 'associate', :permissions => ['edit_profile'])
98 e = Enterprise.create(:identifier => 'enterpri', :name => 'Enterpri') 97 e = Enterprise.create(:identifier => 'enterpri', :name => 'Enterpri')
99 assert e.affiliate(p, r) 98 assert e.affiliate(p, r)
100 - assert p.reload 99 + p = Person.find(p.id)
101 assert e.reload 100 assert e.reload
102 assert p.has_permission?('edit_profile', e) 101 assert p.has_permission?('edit_profile', e)
103 assert !p.has_permission?('destroy_profile', e) 102 assert !p.has_permission?('destroy_profile', e)
104 end 103 end
105 104
106 should 'get an email address from the associated user instance' do 105 should 'get an email address from the associated user instance' do
107 - p = User.create!(:login => 'jonh', :email => 'john@doe.org', :password => 'dhoe', :password_confirmation => 'dhoe').person 106 + p = create_user('jonh', :email => 'john@doe.org', :password => 'dhoe', :password_confirmation => 'dhoe').person
108 assert_equal 'john@doe.org', p.email 107 assert_equal 'john@doe.org', p.email
109 end 108 end
110 109
@@ -131,7 +130,7 @@ class PersonTest &lt; Test::Unit::TestCase @@ -131,7 +130,7 @@ class PersonTest &lt; Test::Unit::TestCase
131 env.affiliate(person, role) 130 env.affiliate(person, role)
132 assert ! person.is_admin? 131 assert ! person.is_admin?
133 role.update_attributes(:permissions => ['view_environment_admin_panel']) 132 role.update_attributes(:permissions => ['view_environment_admin_panel'])
134 - person.reload 133 + person = Person.find(person.id)
135 assert person.is_admin? 134 assert person.is_admin?
136 end 135 end
137 136
test/unit/profile_test.rb
@@ -60,7 +60,16 @@ class ProfileTest &lt; Test::Unit::TestCase @@ -60,7 +60,16 @@ class ProfileTest &lt; Test::Unit::TestCase
60 end 60 end
61 61
62 should 'set default environment for users created' do 62 should 'set default environment for users created' do
63 - assert_equal Environment.default, create_user('mytestuser').person.environment 63 + user = create_user 'mytestuser'
  64 + assert_equal 'mytestuser', user.login
  65 + assert !user.new_record?
  66 +
  67 + p = user.person
  68 +
  69 + assert !p.new_record?
  70 + assert_equal 'mytestuser', p.identifier
  71 + e = p.environment
  72 + assert_equal Environment.default, e
64 end 73 end
65 74
66 def test_cannot_rename 75 def test_cannot_rename
@@ -86,7 +95,7 @@ class ProfileTest &lt; Test::Unit::TestCase @@ -86,7 +95,7 @@ class ProfileTest &lt; Test::Unit::TestCase
86 95
87 def test_can_have_affiliated_people 96 def test_can_have_affiliated_people
88 pr = Profile.create(:name => 'composite_profile', :identifier => 'composite') 97 pr = Profile.create(:name => 'composite_profile', :identifier => 'composite')
89 - pe = User.create(:login => 'aff', :email => 'aff@pr.coop', :password => 'blih', :password_confirmation => 'blih').person 98 + pe = create_user('aff', :email => 'aff@pr.coop', :password => 'blih', :password_confirmation => 'blih').person
90 99
91 member_role = Role.new(:name => 'new_member_role') 100 member_role = Role.new(:name => 'new_member_role')
92 assert member_role.save 101 assert member_role.save
@@ -817,7 +826,6 @@ class ProfileTest &lt; Test::Unit::TestCase @@ -817,7 +826,6 @@ class ProfileTest &lt; Test::Unit::TestCase
817 826
818 community.remove_member(person) 827 community.remove_member(person)
819 828
820 - person.reload  
821 assert_not_includes person.memberships, community 829 assert_not_includes person.memberships, community
822 end 830 end
823 831
test/unit/task_test.rb
@@ -194,7 +194,10 @@ class TaskTest &lt; Test::Unit::TestCase @@ -194,7 +194,10 @@ class TaskTest &lt; Test::Unit::TestCase
194 protected 194 protected
195 195
196 def sample_user 196 def sample_user
197 - User.create(:login => 'testfindinactivetask', :password => 'test', :password_confirmation => 'test', :email => 'testfindinactivetask@localhost.localdomain').person 197 + user = User.new(:login => 'testfindinactivetask', :password => 'test', :password_confirmation => 'test', :email => 'testfindinactivetask@localhost.localdomain')
  198 + user.build_person(person_data)
  199 + user.save
  200 + user.person
198 end 201 end
199 202
200 end 203 end
test/unit/user_test.rb
@@ -8,35 +8,35 @@ class UserTest &lt; Test::Unit::TestCase @@ -8,35 +8,35 @@ class UserTest &lt; Test::Unit::TestCase
8 8
9 def test_should_create_user 9 def test_should_create_user
10 assert_difference User, :count do 10 assert_difference User, :count do
11 - user = create_user 11 + user = new_user
12 assert !user.new_record?, "#{user.errors.full_messages.to_sentence}" 12 assert !user.new_record?, "#{user.errors.full_messages.to_sentence}"
13 end 13 end
14 end 14 end
15 15
16 def test_should_require_login 16 def test_should_require_login
17 assert_no_difference User, :count do 17 assert_no_difference User, :count do
18 - u = create_user(:login => nil) 18 + u = new_user(:login => nil)
19 assert u.errors.on(:login) 19 assert u.errors.on(:login)
20 end 20 end
21 end 21 end
22 22
23 def test_should_require_password 23 def test_should_require_password
24 assert_no_difference User, :count do 24 assert_no_difference User, :count do
25 - u = create_user(:password => nil) 25 + u = new_user(:password => nil)
26 assert u.errors.on(:password) 26 assert u.errors.on(:password)
27 end 27 end
28 end 28 end
29 29
30 def test_should_require_password_confirmation 30 def test_should_require_password_confirmation
31 assert_no_difference User, :count do 31 assert_no_difference User, :count do
32 - u = create_user(:password_confirmation => nil) 32 + u = new_user(:password_confirmation => nil)
33 assert u.errors.on(:password_confirmation) 33 assert u.errors.on(:password_confirmation)
34 end 34 end
35 end 35 end
36 36
37 def test_should_require_email 37 def test_should_require_email
38 assert_no_difference User, :count do 38 assert_no_difference User, :count do
39 - u = create_user(:email => nil) 39 + u = new_user(:email => nil)
40 assert u.errors.on(:email) 40 assert u.errors.on(:email)
41 end 41 end
42 end 42 end
@@ -72,7 +72,7 @@ class UserTest &lt; Test::Unit::TestCase @@ -72,7 +72,7 @@ class UserTest &lt; Test::Unit::TestCase
72 users_count = User.count 72 users_count = User.count
73 person_count = Person.count 73 person_count = Person.count
74 74
75 - user = User.create!(:login => 'new_user', :email => 'new_user@example.com', :password => 'test', :password_confirmation => 'test') 75 + user = create_user('new_user', :email => 'new_user@example.com', :password => 'test', :password_confirmation => 'test')
76 76
77 assert Person.exists?(['user_id = ?', user.id]) 77 assert Person.exists?(['user_id = ?', user.id])
78 78
@@ -107,7 +107,7 @@ class UserTest &lt; Test::Unit::TestCase @@ -107,7 +107,7 @@ class UserTest &lt; Test::Unit::TestCase
107 end 107 end
108 108
109 def test_should_change_password 109 def test_should_change_password
110 - user = User.create!(:login => 'changetest', :password => 'test', :password_confirmation => 'test', :email => 'changetest@example.com') 110 + user = create_user('changetest', :password => 'test', :password_confirmation => 'test', :email => 'changetest@example.com')
111 assert_nothing_raised do 111 assert_nothing_raised do
112 user.change_password!('test', 'newpass', 'newpass') 112 user.change_password!('test', 'newpass', 'newpass')
113 end 113 end
@@ -116,7 +116,7 @@ class UserTest &lt; Test::Unit::TestCase @@ -116,7 +116,7 @@ class UserTest &lt; Test::Unit::TestCase
116 end 116 end
117 117
118 def test_should_give_correct_current_password_for_changing_password 118 def test_should_give_correct_current_password_for_changing_password
119 - user = User.create!(:login => 'changetest', :password => 'test', :password_confirmation => 'test', :email => 'changetest@example.com') 119 + user = create_user('changetest', :password => 'test', :password_confirmation => 'test', :email => 'changetest@example.com')
120 assert_raise User::IncorrectPassword do 120 assert_raise User::IncorrectPassword do
121 user.change_password!('wrong', 'newpass', 'newpass') 121 user.change_password!('wrong', 'newpass', 'newpass')
122 end 122 end
@@ -125,7 +125,7 @@ class UserTest &lt; Test::Unit::TestCase @@ -125,7 +125,7 @@ class UserTest &lt; Test::Unit::TestCase
125 end 125 end
126 126
127 should 'require matching confirmation when changing password by force' do 127 should 'require matching confirmation when changing password by force' do
128 - user = User.create!(:login => 'changetest', :password => 'test', :password_confirmation => 'test', :email => 'changetest@example.com') 128 + user = create_user('changetest', :password => 'test', :password_confirmation => 'test', :email => 'changetest@example.com')
129 assert_raise ActiveRecord::RecordInvalid do 129 assert_raise ActiveRecord::RecordInvalid do
130 user.force_change_password!('newpass', 'newpasswrong') 130 user.force_change_password!('newpass', 'newpasswrong')
131 end 131 end
@@ -134,7 +134,7 @@ class UserTest &lt; Test::Unit::TestCase @@ -134,7 +134,7 @@ class UserTest &lt; Test::Unit::TestCase
134 end 134 end
135 135
136 should 'be able to force password change' do 136 should 'be able to force password change' do
137 - user = User.create!(:login => 'changetest', :password => 'test', :password_confirmation => 'test', :email => 'changetest@example.com') 137 + user = create_user('changetest', :password => 'test', :password_confirmation => 'test', :email => 'changetest@example.com')
138 assert_nothing_raised do 138 assert_nothing_raised do
139 user.force_change_password!('newpass', 'newpass') 139 user.force_change_password!('newpass', 'newpass')
140 end 140 end
@@ -144,19 +144,19 @@ class UserTest &lt; Test::Unit::TestCase @@ -144,19 +144,19 @@ class UserTest &lt; Test::Unit::TestCase
144 def test_should_create_person_when_creating_user 144 def test_should_create_person_when_creating_user
145 count = Person.count 145 count = Person.count
146 assert !Person.find_by_identifier('lalala') 146 assert !Person.find_by_identifier('lalala')
147 - create_user(:login => 'lalala', :email => 'lalala@example.com') 147 + new_user(:login => 'lalala', :email => 'lalala@example.com')
148 assert Person.find_by_identifier('lalala') 148 assert Person.find_by_identifier('lalala')
149 end 149 end
150 150
151 should 'set the same environment for user and person objects' do 151 should 'set the same environment for user and person objects' do
152 env = Environment.create!(:name => 'my test environment') 152 env = Environment.create!(:name => 'my test environment')
153 - user = create_user(:environment_id => env.id) 153 + user = new_user(:environment_id => env.id)
154 assert_equal env, user.environment 154 assert_equal env, user.environment
155 assert_equal env, user.person.environment 155 assert_equal env, user.person.environment
156 end 156 end
157 157
158 def test_should_destroy_person_when_destroying_user 158 def test_should_destroy_person_when_destroying_user
159 - user = create_user(:login => 'lalala', :email => 'lalala@example.com') 159 + user = new_user(:login => 'lalala', :email => 'lalala@example.com')
160 assert Person.find_by_identifier('lalala') 160 assert Person.find_by_identifier('lalala')
161 user.destroy 161 user.destroy
162 assert !Person.find_by_identifier('lalala') 162 assert !Person.find_by_identifier('lalala')
@@ -164,6 +164,7 @@ class UserTest &lt; Test::Unit::TestCase @@ -164,6 +164,7 @@ class UserTest &lt; Test::Unit::TestCase
164 164
165 def test_should_encrypt_password_with_salted_sha1 165 def test_should_encrypt_password_with_salted_sha1
166 user = User.new(:login => 'lalala', :email => 'lalala@example.com', :password => 'test', :password_confirmation => 'test') 166 user = User.new(:login => 'lalala', :email => 'lalala@example.com', :password => 'test', :password_confirmation => 'test')
  167 + user.build_person(person_data)
167 user.expects(:salt).returns('testsalt') 168 user.expects(:salt).returns('testsalt')
168 user.save! 169 user.save!
169 170
@@ -177,12 +178,12 @@ class UserTest &lt; Test::Unit::TestCase @@ -177,12 +178,12 @@ class UserTest &lt; Test::Unit::TestCase
177 def test_should_support_md5_passwords 178 def test_should_support_md5_passwords
178 # ATTENTION this test explicitly exposes the crypted form of 'test'. This 179 # ATTENTION this test explicitly exposes the crypted form of 'test'. This
179 # makes 'test' a terrible password. :) 180 # makes 'test' a terrible password. :)
180 - user = create_user(:login => 'lalala', :email => 'lalala@example.com', :password => 'test', :password_confirmation => 'test', :password_type => 'md5') 181 + user = new_user(:login => 'lalala', :email => 'lalala@example.com', :password => 'test', :password_confirmation => 'test', :password_type => 'md5')
181 assert_equal '098f6bcd4621d373cade4e832627b4f6', user.crypted_password 182 assert_equal '098f6bcd4621d373cade4e832627b4f6', user.crypted_password
182 end 183 end
183 184
184 def test_should_support_clear_passwords 185 def test_should_support_clear_passwords
185 - assert_equal 'test', create_user(:password => 'test', :password_confirmation => 'test', :password_type => 'clear').crypted_password 186 + assert_equal 'test', new_user(:password => 'test', :password_confirmation => 'test', :password_type => 'clear').crypted_password
186 end 187 end
187 188
188 def test_should_only_allow_know_encryption_methods 189 def test_should_only_allow_know_encryption_methods
@@ -214,14 +215,14 @@ class UserTest &lt; Test::Unit::TestCase @@ -214,14 +215,14 @@ class UserTest &lt; Test::Unit::TestCase
214 215
215 def test_new_instances_should_use_system_encryption_method 216 def test_new_instances_should_use_system_encryption_method
216 User.expects(:system_encryption_method).returns(:clear) 217 User.expects(:system_encryption_method).returns(:clear)
217 - assert_equal 'clear', create_user.password_type 218 + assert_equal 'clear', new_user.password_type
218 end 219 end
219 220
220 def test_should_reencrypt_password_when_using_different_encryption_method_from_the_system_default 221 def test_should_reencrypt_password_when_using_different_encryption_method_from_the_system_default
221 User.stubs(:system_encryption_method).returns(:salted_sha1) 222 User.stubs(:system_encryption_method).returns(:salted_sha1)
222 223
223 # a user was created ... 224 # a user was created ...
224 - user = create_user(:login => 'lalala', :email => 'lalala@example.com', :password => 'test', :password_confirmation => 'test', :password_type => 'salted_sha1') 225 + user = new_user(:login => 'lalala', :email => 'lalala@example.com', :password => 'test', :password_confirmation => 'test', :password_type => 'salted_sha1')
225 226
226 # then the sysadmin decided to change the encryption method 227 # then the sysadmin decided to change the encryption method
227 User.expects(:system_encryption_method).returns(:md5).at_least_once 228 User.expects(:system_encryption_method).returns(:md5).at_least_once
@@ -238,7 +239,7 @@ class UserTest &lt; Test::Unit::TestCase @@ -238,7 +239,7 @@ class UserTest &lt; Test::Unit::TestCase
238 def test_should_not_update_encryption_if_password_incorrect 239 def test_should_not_update_encryption_if_password_incorrect
239 # a user was created 240 # a user was created
240 User.stubs(:system_encryption_method).returns(:salted_sha1) 241 User.stubs(:system_encryption_method).returns(:salted_sha1)
241 - user = create_user(:login => 'lalala', :email => 'lalala@example.com', :password => 'test', :password_confirmation => 'test', :password_type => 'salted_sha1') 242 + user = new_user(:login => 'lalala', :email => 'lalala@example.com', :password => 'test', :password_confirmation => 'test', :password_type => 'salted_sha1')
242 crypted_password = user.crypted_password 243 crypted_password = user.crypted_password
243 244
244 # then the sysadmin deciced to change the encryption method 245 # then the sysadmin deciced to change the encryption method
@@ -262,7 +263,10 @@ class UserTest &lt; Test::Unit::TestCase @@ -262,7 +263,10 @@ class UserTest &lt; Test::Unit::TestCase
262 end 263 end
263 264
264 protected 265 protected
265 - def create_user(options = {})  
266 - User.create({ :login => 'quire', :email => 'quire@example.com', :password => 'quire', :password_confirmation => 'quire' }.merge(options)) 266 + def new_user(options = {})
  267 + user = User.new({ :login => 'quire', :email => 'quire@example.com', :password => 'quire', :password_confirmation => 'quire' }.merge(options))
  268 + user.build_person(person_data)
  269 + user.save
  270 + user
267 end 271 end
268 end 272 end