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