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