@@ -1,107 +1,109 | |||||
1 | # Redmine - project management software |
|
1 | # Redmine - project management software | |
2 | # Copyright (C) 2006-2015 Jean-Philippe Lang |
|
2 | # Copyright (C) 2006-2015 Jean-Philippe Lang | |
3 | # |
|
3 | # | |
4 | # This program is free software; you can redistribute it and/or |
|
4 | # This program is free software; you can redistribute it and/or | |
5 | # modify it under the terms of the GNU General Public License |
|
5 | # modify it under the terms of the GNU General Public License | |
6 | # as published by the Free Software Foundation; either version 2 |
|
6 | # as published by the Free Software Foundation; either version 2 | |
7 | # of the License, or (at your option) any later version. |
|
7 | # of the License, or (at your option) any later version. | |
8 | # |
|
8 | # | |
9 | # This program is distributed in the hope that it will be useful, |
|
9 | # This program is distributed in the hope that it will be useful, | |
10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
12 | # GNU General Public License for more details. |
|
12 | # GNU General Public License for more details. | |
13 | # |
|
13 | # | |
14 | # You should have received a copy of the GNU General Public License |
|
14 | # You should have received a copy of the GNU General Public License | |
15 | # along with this program; if not, write to the Free Software |
|
15 | # along with this program; if not, write to the Free Software | |
16 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
|
16 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | |
17 |
|
17 | |||
18 | require File.expand_path('../../test_helper', __FILE__) |
|
18 | require File.expand_path('../../test_helper', __FILE__) | |
19 |
|
19 | |||
20 | class FilesControllerTest < ActionController::TestCase |
|
20 | class FilesControllerTest < ActionController::TestCase | |
21 | fixtures :projects, :trackers, :issue_statuses, :issues, |
|
21 | fixtures :projects, :trackers, :issue_statuses, :issues, | |
22 |
:enumerations, :users, |
|
22 | :enumerations, :users, | |
|
23 | :email_addresses, | |||
|
24 | :issue_categories, | |||
23 | :projects_trackers, |
|
25 | :projects_trackers, | |
24 | :roles, |
|
26 | :roles, | |
25 | :member_roles, |
|
27 | :member_roles, | |
26 | :members, |
|
28 | :members, | |
27 | :enabled_modules, |
|
29 | :enabled_modules, | |
28 | :journals, :journal_details, |
|
30 | :journals, :journal_details, | |
29 | :attachments, |
|
31 | :attachments, | |
30 | :versions |
|
32 | :versions | |
31 |
|
33 | |||
32 | def setup |
|
34 | def setup | |
33 | @request.session[:user_id] = nil |
|
35 | @request.session[:user_id] = nil | |
34 | Setting.default_language = 'en' |
|
36 | Setting.default_language = 'en' | |
35 | end |
|
37 | end | |
36 |
|
38 | |||
37 | def test_index |
|
39 | def test_index | |
38 | get :index, :project_id => 1 |
|
40 | get :index, :project_id => 1 | |
39 | assert_response :success |
|
41 | assert_response :success | |
40 | assert_template 'index' |
|
42 | assert_template 'index' | |
41 | assert_not_nil assigns(:containers) |
|
43 | assert_not_nil assigns(:containers) | |
42 |
|
44 | |||
43 | # file attached to the project |
|
45 | # file attached to the project | |
44 | assert_select 'a[href=?]', '/attachments/download/8/project_file.zip', :text => 'project_file.zip' |
|
46 | assert_select 'a[href=?]', '/attachments/download/8/project_file.zip', :text => 'project_file.zip' | |
45 |
|
47 | |||
46 | # file attached to a project's version |
|
48 | # file attached to a project's version | |
47 | assert_select 'a[href=?]', '/attachments/download/9/version_file.zip', :text => 'version_file.zip' |
|
49 | assert_select 'a[href=?]', '/attachments/download/9/version_file.zip', :text => 'version_file.zip' | |
48 | end |
|
50 | end | |
49 |
|
51 | |||
50 | def test_new |
|
52 | def test_new | |
51 | @request.session[:user_id] = 2 |
|
53 | @request.session[:user_id] = 2 | |
52 | get :new, :project_id => 1 |
|
54 | get :new, :project_id => 1 | |
53 | assert_response :success |
|
55 | assert_response :success | |
54 | assert_template 'new' |
|
56 | assert_template 'new' | |
55 |
|
57 | |||
56 | assert_select 'select[name=?]', 'version_id' |
|
58 | assert_select 'select[name=?]', 'version_id' | |
57 | end |
|
59 | end | |
58 |
|
60 | |||
59 | def test_new_without_versions |
|
61 | def test_new_without_versions | |
60 | Version.delete_all |
|
62 | Version.delete_all | |
61 | @request.session[:user_id] = 2 |
|
63 | @request.session[:user_id] = 2 | |
62 | get :new, :project_id => 1 |
|
64 | get :new, :project_id => 1 | |
63 | assert_response :success |
|
65 | assert_response :success | |
64 | assert_template 'new' |
|
66 | assert_template 'new' | |
65 |
|
67 | |||
66 | assert_select 'select[name=?]', 'version_id', 0 |
|
68 | assert_select 'select[name=?]', 'version_id', 0 | |
67 | end |
|
69 | end | |
68 |
|
70 | |||
69 | def test_create_file |
|
71 | def test_create_file | |
70 | set_tmp_attachments_directory |
|
72 | set_tmp_attachments_directory | |
71 | @request.session[:user_id] = 2 |
|
73 | @request.session[:user_id] = 2 | |
72 | ActionMailer::Base.deliveries.clear |
|
74 | ActionMailer::Base.deliveries.clear | |
73 |
|
75 | |||
74 | with_settings :notified_events => %w(file_added) do |
|
76 | with_settings :notified_events => %w(file_added) do | |
75 | assert_difference 'Attachment.count' do |
|
77 | assert_difference 'Attachment.count' do | |
76 | post :create, :project_id => 1, :version_id => '', |
|
78 | post :create, :project_id => 1, :version_id => '', | |
77 | :attachments => {'1' => {'file' => uploaded_test_file('testfile.txt', 'text/plain')}} |
|
79 | :attachments => {'1' => {'file' => uploaded_test_file('testfile.txt', 'text/plain')}} | |
78 | assert_response :redirect |
|
80 | assert_response :redirect | |
79 | end |
|
81 | end | |
80 | end |
|
82 | end | |
81 | assert_redirected_to '/projects/ecookbook/files' |
|
83 | assert_redirected_to '/projects/ecookbook/files' | |
82 | a = Attachment.order('created_on DESC').first |
|
84 | a = Attachment.order('created_on DESC').first | |
83 | assert_equal 'testfile.txt', a.filename |
|
85 | assert_equal 'testfile.txt', a.filename | |
84 | assert_equal Project.find(1), a.container |
|
86 | assert_equal Project.find(1), a.container | |
85 |
|
87 | |||
86 | mail = ActionMailer::Base.deliveries.last |
|
88 | mail = ActionMailer::Base.deliveries.last | |
87 | assert_not_nil mail |
|
89 | assert_not_nil mail | |
88 | assert_equal "[eCookbook] New file", mail.subject |
|
90 | assert_equal "[eCookbook] New file", mail.subject | |
89 | assert_mail_body_match 'testfile.txt', mail |
|
91 | assert_mail_body_match 'testfile.txt', mail | |
90 | end |
|
92 | end | |
91 |
|
93 | |||
92 | def test_create_version_file |
|
94 | def test_create_version_file | |
93 | set_tmp_attachments_directory |
|
95 | set_tmp_attachments_directory | |
94 | @request.session[:user_id] = 2 |
|
96 | @request.session[:user_id] = 2 | |
95 |
|
97 | |||
96 | assert_difference 'Attachment.count' do |
|
98 | assert_difference 'Attachment.count' do | |
97 | post :create, :project_id => 1, :version_id => '2', |
|
99 | post :create, :project_id => 1, :version_id => '2', | |
98 | :attachments => {'1' => {'file' => uploaded_test_file('testfile.txt', 'text/plain')}} |
|
100 | :attachments => {'1' => {'file' => uploaded_test_file('testfile.txt', 'text/plain')}} | |
99 | assert_response :redirect |
|
101 | assert_response :redirect | |
100 | end |
|
102 | end | |
101 | assert_redirected_to '/projects/ecookbook/files' |
|
103 | assert_redirected_to '/projects/ecookbook/files' | |
102 | a = Attachment.order('created_on DESC').first |
|
104 | a = Attachment.order('created_on DESC').first | |
103 | assert_equal 'testfile.txt', a.filename |
|
105 | assert_equal 'testfile.txt', a.filename | |
104 | assert_equal Version.find(2), a.container |
|
106 | assert_equal Version.find(2), a.container | |
105 | end |
|
107 | end | |
106 |
|
108 | |||
107 | end |
|
109 | end |
General Comments 0
You need to be logged in to leave comments.
Login now