Class | UploadsControllerTest
In: | test/functional/uploads_controller_test.rb
Parent: | Test::Unit::TestCase

### Methods

setup test_new

### Public Instance methods

setup()

[Source]

        # File test/functional/uploads_controller_test.rb, line 24
    24:   def setup
    25:     logger.debug "Test Case: #{name}"
    26:     @controller = UploadsController.new
    27:     @request    = ActionController::TestRequest.new
    28:     @response   = ActionController::TestResponse.new
    29:     @andy = users(:andy) # admin
    30:     @george = users(:george) # central admin
    31:     @tony = users(:tony) # user
    32:   end

test_new()

Shows:

1. Logon
2. Logged in user can upload image
3. User cannot update upload of another user
4. Admin can update upload of another user
5. Admin cannot destroy upload of another user
6. User cannot destroy own upload
7. Cadmin can destroy upload of another user

[Source]

        # File test/functional/uploads_controller_test.rb, line 42
    42:   def test_new
    43:     assert_equal 0, Upload.count
    44:     # 1
    45:     post :new
    46:     assert_redirected_to :controller => 'login'
    47:     # 2
    48:     session['user'] = @andy
    49:     post :new, :upload => {:upload_type => 'Image', :description => 'OpenUP PT image', :file => upload_file("#{ENV['EPFWIKI_ROOT_DIR']}test/functional/uploads_controller_test/openup_pt.jpg", 'image/jpeg')}
    50:     assert_redirected_to :action => 'list'
    51:     assert_equal 1, Upload.count
    52:     assert_not_nil assigns(:upload)
    53:     assert File.exists?(assigns(:upload).path)
    54:
    55:     # 4
    56:     get :index
    57:     session['user'] = @tony
    58:     upload = Upload.find(:first)
    59:     post :update, :id => upload.id, :upload => {:description => 'image'}
    60:     assert_equal ::FLASH_NOT_OWNER, flash['error']
    61:     upload.reload
    62:     assert_equal 'OpenUP PT image', upload.description
    63:     # 5
    64:     upload.user = @tony
    65:     assert upload.save
    66:     session['user'] = @andy
    67:     post :update, :id => upload.id, :upload => {:description => 'image'}
    68:     assert_equal nil, flash['error']
    69:     upload.reload
    70:     assert_equal 'image', upload.description
    71:     # 6
    72:     get :index
    73:     session['user'] = @andy
    74:     upload = Upload.find(:first)
    75:     assert session['user'] != upload.user
    76:     post :destroy, :id => upload
    77:     assert_equal LoginController::FLASH_UNOT_CADMIN, flash['error']
    78:     assert Upload.exists?(upload.id)
    79:     upload2 = Upload.new(:filename => upload.filename, :upload_type => upload.upload_type,
    80:     :content_type => upload.content_type, :description => upload.description,
    81:     :user_id => upload.user_id, :rel_path => upload.rel_path)
    82:     assert upload2.save
    83:     # 7
    84:     session['user'] = @tony
    85:     assert session['user'], upload.user
    86:     post :destroy, :id => upload
    87:     assert Upload.exists?(upload)
    88:     # 8 # TODO test this, currently we cannot test this because use of request.referer causes errors: "The error occurred while evaluating nil.[]"
    89:     #session['user'] = @george
    90:     #assert session['user'], upload2.user
    91:     #post :destroy, :id => upload2
    92:     #assert !Upload.exists?(upload2)
    93:     #assert_equal 0, Upload.count
    94:   end

[Validate]