To check out this repository please hg clone the following URL, or open the URL using EasyMercurial or your preferred Mercurial client.
root / .svn / pristine / a5 / a5a34b2cada8528aefb674b60eab16486ab7bca6.svn-base @ 1297:0a574315af3e
History | View | Annotate | Download (2.98 KB)
| 1 | 1296:038ba2d95de8 | Chris | require File.expand_path('../../test_helper', __FILE__)
|
|---|---|---|---|
| 2 | |||
| 3 | class FilesControllerTest < ActionController::TestCase |
||
| 4 | fixtures :projects, :trackers, :issue_statuses, :issues, |
||
| 5 | :enumerations, :users, :issue_categories, |
||
| 6 | :projects_trackers, |
||
| 7 | :roles, |
||
| 8 | :member_roles, |
||
| 9 | :members, |
||
| 10 | :enabled_modules, |
||
| 11 | :workflows, |
||
| 12 | :journals, :journal_details, |
||
| 13 | :attachments, |
||
| 14 | :versions |
||
| 15 | |||
| 16 | def setup |
||
| 17 | @controller = FilesController.new |
||
| 18 | @request = ActionController::TestRequest.new |
||
| 19 | @response = ActionController::TestResponse.new |
||
| 20 | @request.session[:user_id] = nil |
||
| 21 | Setting.default_language = 'en' |
||
| 22 | end |
||
| 23 | |||
| 24 | def test_index |
||
| 25 | get :index, :project_id => 1 |
||
| 26 | assert_response :success |
||
| 27 | assert_template 'index' |
||
| 28 | assert_not_nil assigns(:containers) |
||
| 29 | |||
| 30 | # file attached to the project |
||
| 31 | assert_tag :a, :content => 'project_file.zip', |
||
| 32 | :attributes => { :href => '/attachments/download/8/project_file.zip' }
|
||
| 33 | |||
| 34 | # file attached to a project's version |
||
| 35 | assert_tag :a, :content => 'version_file.zip', |
||
| 36 | :attributes => { :href => '/attachments/download/9/version_file.zip' }
|
||
| 37 | end |
||
| 38 | |||
| 39 | def test_new |
||
| 40 | @request.session[:user_id] = 2 |
||
| 41 | get :new, :project_id => 1 |
||
| 42 | assert_response :success |
||
| 43 | assert_template 'new' |
||
| 44 | |||
| 45 | assert_tag 'select', :attributes => {:name => 'version_id'}
|
||
| 46 | end |
||
| 47 | |||
| 48 | def test_new_without_versions |
||
| 49 | Version.delete_all |
||
| 50 | @request.session[:user_id] = 2 |
||
| 51 | get :new, :project_id => 1 |
||
| 52 | assert_response :success |
||
| 53 | assert_template 'new' |
||
| 54 | |||
| 55 | assert_no_tag 'select', :attributes => {:name => 'version_id'}
|
||
| 56 | end |
||
| 57 | |||
| 58 | def test_create_file |
||
| 59 | set_tmp_attachments_directory |
||
| 60 | @request.session[:user_id] = 2 |
||
| 61 | ActionMailer::Base.deliveries.clear |
||
| 62 | |||
| 63 | with_settings :notified_events => %w(file_added) do |
||
| 64 | assert_difference 'Attachment.count' do |
||
| 65 | post :create, :project_id => 1, :version_id => '', |
||
| 66 | :attachments => {'1' => {'file' => uploaded_test_file('testfile.txt', 'text/plain')}}
|
||
| 67 | assert_response :redirect |
||
| 68 | end |
||
| 69 | end |
||
| 70 | assert_redirected_to '/projects/ecookbook/files' |
||
| 71 | a = Attachment.find(:first, :order => 'created_on DESC') |
||
| 72 | assert_equal 'testfile.txt', a.filename |
||
| 73 | assert_equal Project.find(1), a.container |
||
| 74 | |||
| 75 | mail = ActionMailer::Base.deliveries.last |
||
| 76 | assert_not_nil mail |
||
| 77 | assert_equal "[eCookbook] New file", mail.subject |
||
| 78 | assert_mail_body_match 'testfile.txt', mail |
||
| 79 | end |
||
| 80 | |||
| 81 | def test_create_version_file |
||
| 82 | set_tmp_attachments_directory |
||
| 83 | @request.session[:user_id] = 2 |
||
| 84 | |||
| 85 | assert_difference 'Attachment.count' do |
||
| 86 | post :create, :project_id => 1, :version_id => '2', |
||
| 87 | :attachments => {'1' => {'file' => uploaded_test_file('testfile.txt', 'text/plain')}}
|
||
| 88 | assert_response :redirect |
||
| 89 | end |
||
| 90 | assert_redirected_to '/projects/ecookbook/files' |
||
| 91 | a = Attachment.find(:first, :order => 'created_on DESC') |
||
| 92 | assert_equal 'testfile.txt', a.filename |
||
| 93 | assert_equal Version.find(2), a.container |
||
| 94 | end |
||
| 95 | |||
| 96 | end |