Mercurial > hg > soundsoftware-site
comparison test/functional/files_controller_test.rb @ 909:cbb26bc654de redmine-1.3
Update to Redmine 1.3-stable branch (Redmine SVN rev 8964)
author | Chris Cannam |
---|---|
date | Fri, 24 Feb 2012 19:09:32 +0000 |
parents | 8661b858af72 |
children | 433d4f72a19b |
comparison
equal
deleted
inserted
replaced
908:c6c2cbd0afee | 909:cbb26bc654de |
---|---|
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 | 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 :attachments, | |
14 :versions | |
15 | |
6 def setup | 16 def setup |
7 @controller = FilesController.new | 17 @controller = FilesController.new |
8 @request = ActionController::TestRequest.new | 18 @request = ActionController::TestRequest.new |
9 @response = ActionController::TestResponse.new | 19 @response = ActionController::TestResponse.new |
10 @request.session[:user_id] = nil | 20 @request.session[:user_id] = nil |
14 def test_index | 24 def test_index |
15 get :index, :project_id => 1 | 25 get :index, :project_id => 1 |
16 assert_response :success | 26 assert_response :success |
17 assert_template 'index' | 27 assert_template 'index' |
18 assert_not_nil assigns(:containers) | 28 assert_not_nil assigns(:containers) |
19 | 29 |
20 # file attached to the project | 30 # file attached to the project |
21 assert_tag :a, :content => 'project_file.zip', | 31 assert_tag :a, :content => 'project_file.zip', |
22 :attributes => { :href => '/attachments/download/8/project_file.zip' } | 32 :attributes => { :href => '/attachments/download/8/project_file.zip' } |
23 | 33 |
24 # file attached to a project's version | 34 # file attached to a project's version |
25 assert_tag :a, :content => 'version_file.zip', | 35 assert_tag :a, :content => 'version_file.zip', |
26 :attributes => { :href => '/attachments/download/9/version_file.zip' } | 36 :attributes => { :href => '/attachments/download/9/version_file.zip' } |
27 end | 37 end |
28 | 38 |
29 def test_create_file | 39 def test_create_file |
30 set_tmp_attachments_directory | 40 set_tmp_attachments_directory |
31 @request.session[:user_id] = 2 | 41 @request.session[:user_id] = 2 |
32 Setting.notified_events = ['file_added'] | 42 Setting.notified_events = ['file_added'] |
33 ActionMailer::Base.deliveries.clear | 43 ActionMailer::Base.deliveries.clear |
34 | 44 |
35 assert_difference 'Attachment.count' do | 45 assert_difference 'Attachment.count' do |
36 post :create, :project_id => 1, :version_id => '', | 46 post :create, :project_id => 1, :version_id => '', |
37 :attachments => {'1' => {'file' => uploaded_test_file('testfile.txt', 'text/plain')}} | 47 :attachments => {'1' => {'file' => uploaded_test_file('testfile.txt', 'text/plain')}} |
38 assert_response :redirect | 48 assert_response :redirect |
39 end | 49 end |
45 mail = ActionMailer::Base.deliveries.last | 55 mail = ActionMailer::Base.deliveries.last |
46 assert_kind_of TMail::Mail, mail | 56 assert_kind_of TMail::Mail, mail |
47 assert_equal "[eCookbook] New file", mail.subject | 57 assert_equal "[eCookbook] New file", mail.subject |
48 assert mail.body.include?('testfile.txt') | 58 assert mail.body.include?('testfile.txt') |
49 end | 59 end |
50 | 60 |
51 def test_create_version_file | 61 def test_create_version_file |
52 set_tmp_attachments_directory | 62 set_tmp_attachments_directory |
53 @request.session[:user_id] = 2 | 63 @request.session[:user_id] = 2 |
54 Setting.notified_events = ['file_added'] | 64 Setting.notified_events = ['file_added'] |
55 | 65 |
56 assert_difference 'Attachment.count' do | 66 assert_difference 'Attachment.count' do |
57 post :create, :project_id => 1, :version_id => '2', | 67 post :create, :project_id => 1, :version_id => '2', |
58 :attachments => {'1' => {'file' => uploaded_test_file('testfile.txt', 'text/plain')}} | 68 :attachments => {'1' => {'file' => uploaded_test_file('testfile.txt', 'text/plain')}} |
59 assert_response :redirect | 69 assert_response :redirect |
60 end | 70 end |
61 assert_redirected_to '/projects/ecookbook/files' | 71 assert_redirected_to '/projects/ecookbook/files' |
62 a = Attachment.find(:first, :order => 'created_on DESC') | 72 a = Attachment.find(:first, :order => 'created_on DESC') |
63 assert_equal 'testfile.txt', a.filename | 73 assert_equal 'testfile.txt', a.filename |
64 assert_equal Version.find(2), a.container | 74 assert_equal Version.find(2), a.container |
65 end | 75 end |
66 | 76 |
67 end | 77 end |