@@ -1,67 +1,78 | |||
|
1 | 1 | require File.expand_path('../../test_helper', __FILE__) |
|
2 | 2 | |
|
3 | 3 | class FilesControllerTest < ActionController::TestCase |
|
4 | fixtures :all | |
|
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 | :issues, :issue_statuses, :issue_categories, | |
|
14 | :attachments, | |
|
15 | :versions | |
|
5 | 16 | |
|
6 | 17 | def setup |
|
7 | 18 | @controller = FilesController.new |
|
8 | 19 | @request = ActionController::TestRequest.new |
|
9 | 20 | @response = ActionController::TestResponse.new |
|
10 | 21 | @request.session[:user_id] = nil |
|
11 | 22 | Setting.default_language = 'en' |
|
12 | 23 | end |
|
13 | 24 | |
|
14 | 25 | def test_index |
|
15 | 26 | get :index, :project_id => 1 |
|
16 | 27 | assert_response :success |
|
17 | 28 | assert_template 'index' |
|
18 | 29 | assert_not_nil assigns(:containers) |
|
19 | 30 | |
|
20 | 31 | # file attached to the project |
|
21 | 32 | assert_tag :a, :content => 'project_file.zip', |
|
22 | 33 | :attributes => { :href => '/attachments/download/8/project_file.zip' } |
|
23 | 34 | |
|
24 | 35 | # file attached to a project's version |
|
25 | 36 | assert_tag :a, :content => 'version_file.zip', |
|
26 | 37 | :attributes => { :href => '/attachments/download/9/version_file.zip' } |
|
27 | 38 | end |
|
28 | 39 | |
|
29 | 40 | def test_create_file |
|
30 | 41 | set_tmp_attachments_directory |
|
31 | 42 | @request.session[:user_id] = 2 |
|
32 | 43 | Setting.notified_events = ['file_added'] |
|
33 | 44 | ActionMailer::Base.deliveries.clear |
|
34 | 45 | |
|
35 | 46 | assert_difference 'Attachment.count' do |
|
36 | 47 | post :create, :project_id => 1, :version_id => '', |
|
37 | 48 | :attachments => {'1' => {'file' => uploaded_test_file('testfile.txt', 'text/plain')}} |
|
38 | 49 | assert_response :redirect |
|
39 | 50 | end |
|
40 | 51 | assert_redirected_to '/projects/ecookbook/files' |
|
41 | 52 | a = Attachment.find(:first, :order => 'created_on DESC') |
|
42 | 53 | assert_equal 'testfile.txt', a.filename |
|
43 | 54 | assert_equal Project.find(1), a.container |
|
44 | 55 | |
|
45 | 56 | mail = ActionMailer::Base.deliveries.last |
|
46 | 57 | assert_kind_of TMail::Mail, mail |
|
47 | 58 | assert_equal "[eCookbook] New file", mail.subject |
|
48 | 59 | assert mail.body.include?('testfile.txt') |
|
49 | 60 | end |
|
50 | 61 | |
|
51 | 62 | def test_create_version_file |
|
52 | 63 | set_tmp_attachments_directory |
|
53 | 64 | @request.session[:user_id] = 2 |
|
54 | 65 | Setting.notified_events = ['file_added'] |
|
55 | 66 | |
|
56 | 67 | assert_difference 'Attachment.count' do |
|
57 | 68 | post :create, :project_id => 1, :version_id => '2', |
|
58 | 69 | :attachments => {'1' => {'file' => uploaded_test_file('testfile.txt', 'text/plain')}} |
|
59 | 70 | assert_response :redirect |
|
60 | 71 | end |
|
61 | 72 | assert_redirected_to '/projects/ecookbook/files' |
|
62 | 73 | a = Attachment.find(:first, :order => 'created_on DESC') |
|
63 | 74 | assert_equal 'testfile.txt', a.filename |
|
64 | 75 | assert_equal Version.find(2), a.container |
|
65 | 76 | end |
|
66 | 77 | |
|
67 | 78 | end |
General Comments 0
You need to be logged in to leave comments.
Login now