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