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