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