comparison .svn/pristine/ef/ef01ace269b8f950664d9b52e99400c8a56e9cdf.svn-base @ 1298:4f746d8966dd redmine_2.3_integration

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