Class | UsersControllerTest
In: | test/functional/users_controller_test.rb
Parent: | Test::Unit::TestCase

### Methods

setup test_account test_cadmin test_edit test_edit_user test_list test_list_admin test_list_cadmin test_list_normaluser test_send_report test_show

### Public Instance methods

setup()

[Source]

        # File test/functional/users_controller_test.rb, line 23
    23:   def setup
    24:     logger.debug "Test Case: #{name}"
    25:     @andy = users(:andy) # admin
    26:     @george = users(:george) #cadmin
    27:     @tony = users(:tony) #user
    28:     @cash = users(:cash) #user
    29:     @controller = UsersController.new
    30:     @request    = ActionController::TestRequest.new
    31:     @response   = ActionController::TestResponse.new
    32:     @emails = ActionMailer::Base::deliveries
    33:     @emails.clear
    34:   end

test_account()

[Source]

         # File test/functional/users_controller_test.rb, line 234
    234:   def test_account
    235:     # TODO implement test
    236:     #assert_tag :tag => 'a', :attributes => {:href => "/users/edit/#{@tony.id.to_s}"}
    237:     #assert_tag :tag => 'a', :attributes => {:href => '/login/change_password'}
    238:
    239:   end

test_cadmin()

Shows:

1. George is central admin, Tony an ordinary user
2. list of users contains links to make other admins the cadmin, and links to make other users admins
3. George can make another Tony the central admin
4. George can make another user cadmin after making Tony the central admin (untill his session expires)
5. Tony can make another user the cadmin after becoming central admin
6. This is all one transaction (we cannot end up with having no cadmin)

[Source]

         # File test/functional/users_controller_test.rb, line 179
    179:   def test_cadmin
    180:     # 1
    181:     assert @george.cadmin?
    182:     assert @tony.user?
    183:     # 2
    184:     get :list
    185:     session['user'] = @george
    186:     get :list
    187:     assert_response :success
    188:     assert_template 'list'
    189:     User.find_all_by_admin('Y').each do |user|
    190:       assert_tag :tag => 'a', :attributes => {:href => "/users/cadmin/#{user.id}"}
    191:       assert_tag :tag => 'a', :attributes => {:href => "/users/admin/#{user.id}?admin=N"}
    192:     end
    193:     User.find_all_by_admin('N').each do |user|
    194:       assert_tag :tag => 'a', :attributes => {:href => "/users/admin/#{user.id}?admin=Y"}
    195:     end
    196:     # 3
    197:     assert_not_nil @george
    198:     assert_not_nil @tony
    199:     get :list
    200:     post :cadmin, :id => @tony.id
    201:     assert_redirected_to :action => 'list'
    202:     assert_equal '', assigns(:cadmin).errors.full_messages.join(", ")
    203:     assert_equal '', assigns(:user).errors.full_messages.join(", ")
    204:     @george.reload
    205:     @tony.reload
    206:     assert !@george.cadmin?
    207:     assert @george.admin?
    208:     assert @tony.cadmin?
    209:     # 4
    210:     post :cadmin, :id => @tony.id
    211:     assert_unot_cadmin_message
    212:     # 5
    213:     session['user'] = @tony
    214:     post :cadmin, :id => @george.id
    215:     assert_redirected_to :action => 'list'
    216:     @george.reload
    217:     @tony.reload
    218:     assert @george.cadmin?
    219:     assert @george.admin?
    220:     assert !@tony.cadmin?
    221:     assert @tony.admin?
    222:     # 6
    223:     @george.name = nil # will cause save of this user to fail
    224:     User.cadmin(@george, @tony)
    225:     @george.reload
    226:     @tony.reload
    227:     assert @george.cadmin?
    228:     assert @george.admin?
    229:     assert !@tony.cadmin?
    230:     assert @tony.admin?
    231:     assert !@george.name.nil?
    232:   end

test_edit()

Shows:

1. user can edit his details
2. user cannot edit another users details
3. admin cannot edit another users details
4. cadmin can edit another users details

[Source]

         # File test/functional/users_controller_test.rb, line 82
     82:   def test_edit
     83:     # 1
     84:     get :index
     85:     session['user'] = @tony
     86:     saved_name = @tony.name
     87:     post :edit, :id => @tony.id, :user => {:name => 'test06_edit'}
     88:     assert_response :success
     89:     @tony.reload
     90:     assert_equal 'test06_edit', @tony.name
     91:     @tony.name = saved_name
     92:     @tony.save!
     93:     # 2
     94:     session['user'] = @cash
     95:     post :edit, :id => @tony.id, :user => {:name => 'test06_edit'}
     96:     assert_response :success
     97:     @tony.reload
     98:     assert_equal saved_name, @tony.name # unchanged
     99:     # 3
    100:     session['user'] = @andy
    101:     post :edit, :id => @tony.id, :user => {:name => 'test06_edit'}
    102:     assert_response :success
    103:     @tony.reload
    104:     assert_equal saved_name, @tony.name # unchanged
    105:     # 4
    106:     session['user'] = @george
    107:     post :edit, :id => @tony.id, :user => {:name => 'test06_edit'}
    108:     assert_response :success
    109:     @tony.reload
    110:     assert_equal 'test06_edit', @tony.name # changed
    111:     @tony.name = saved_name
    112:     @tony.save!
    113:   end

test_edit_user()

[Source]

         # File test/functional/users_controller_test.rb, line 162
    162:   def test_edit_user
    163:     get :list
    164:     session['user'] = @tony
    165:     post :edit, :id => session['user'].id, :user => { :name => 'Tony Renamed'}
    166:     assert_response :success
    167:     assert_template 'edit'
    168:     assert_not_nil assigns(:user)
    169:     assert_equal User.find(assigns(:user).id).name, 'Tony Renamed'
    170:   end

test_list()

[Source]

        # File test/functional/users_controller_test.rb, line 36
    36:   def test_list
    37:     get :list
    38:     assert_tologin
    39:     get :index
    40:     assert_tologin
    41:   end

test_list_admin()

[Source]

        # File test/functional/users_controller_test.rb, line 53
    53:   def test_list_admin
    54:     get :index
    55:     session['user'] = @andy
    56:     get :list
    57:     assert_not_nil assigns(:users)
    58:     assert_not_nil assigns(:admins)
    59:     assert_not_nil assigns(:cadmin)
    60:   end

test_list_cadmin()

[Source]

        # File test/functional/users_controller_test.rb, line 43
    43:   def test_list_cadmin
    44:     # get the central admin
    45:     get :list
    46:     session['user'] = @george
    47:     get :list
    48:     assert_not_nil assigns(:users)
    49:     assert_not_nil assigns(:admins)
    50:     assert_not_nil assigns(:cadmin)
    51:   end

test_list_normaluser()

Shows:

1. Only admins can request users list
2. User cannot access account details

[Source]

        # File test/functional/users_controller_test.rb, line 65
    65:   def test_list_normaluser
    66:     # 1
    67:     get :list
    68:     session['user'] = @tony
    69:     get :list
    70:     assert_unot_admin_message
    71:     # 2
    72:     post :account, :id => 1
    73:     assert_equal session['user'], assigns(:user)
    74:     assert_equal LoginController::FLASH_UNOT_ADMIN, flash['notice']
    75:   end

test_send_report()

[Source]

         # File test/functional/users_controller_test.rb, line 115
    115:   def test_send_report
    116:     get :index
    117:     session['user'] = @cash
    118:     post    :send_report, :type => 'M'
    119:     assert_equal UsersController::FLASH_REPORT_SENT, flash['success']
    120:     assert_redirected_to :action => 'account', :id => @cash.id
    121:     assert_equal(1, @emails.size)
    122:     email = @emails.first
    123:     assert email.subject.index('Monthly')
    124:     assert_equal("cash.oshman@epf.eclipse.org", email.bcc[0])
    125:     assert_equal([ENV['EPFWIKI_REPLY_ADDRESS']], email.from)
    126:     post    :send_report, :type => 'D'
    127:     assert_equal UsersController::FLASH_REPORT_SENT, flash['success']
    128:     post    :send_report, :type => 'W'
    129:     assert_equal UsersController::FLASH_REPORT_SENT, flash['success']
    130:   end

test_show()

Show:

1. User can access details
2. Cadmin is shown links ‘list‘
3. User with data (comments, pages, uploads)

[Source]

         # File test/functional/users_controller_test.rb, line 136
    136:   def test_show
    137:     get :index
    138:     # 1
    139:     session['user'] = @tony
    140:     get :show, :id => @tony.id
    141:     assert_response :success
    142:     assert_template 'show'
    143:     assert_not_nil assigns(:user)
    144:     assert_not_nil assigns(:versions)
    145:     assert_not_nil assigns(:comments)
    146:     assert_not_nil assigns(:uploads)
    147:     assert_not_nil assigns(:pages)
    148:     assert_equal @tony.id, assigns(:user).id
    149:     # 2
    150:     session['user'] = @george
    151:     get :show, :id => @tony.id
    152:     assert_equal @tony.id, assigns(:user).id # cadmin sees details of user
    153:     assert_tag :tag => 'a', :attributes => {:href => '/users/list'}
    154:     assert_tag :tag => 'a', :attributes => {:href => '/sites/list'}
    155:     # 3
    156:     create_templates
    157:     p = WikiPage.find(:first)
    158:     create_some_data(p)
    159:     get :show, :id => @andy.id
    160:   end

[Validate]