@@ -1,77 +1,96 | |||||
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 :projects, :trackers, :issue_statuses, :issues, |
|
4 | fixtures :projects, :trackers, :issue_statuses, :issues, | |
5 | :enumerations, :users, :issue_categories, |
|
5 | :enumerations, :users, :issue_categories, | |
6 | :projects_trackers, |
|
6 | :projects_trackers, | |
7 | :roles, |
|
7 | :roles, | |
8 | :member_roles, |
|
8 | :member_roles, | |
9 | :members, |
|
9 | :members, | |
10 | :enabled_modules, |
|
10 | :enabled_modules, | |
11 | :workflows, |
|
11 | :workflows, | |
12 | :journals, :journal_details, |
|
12 | :journals, :journal_details, | |
13 | :attachments, |
|
13 | :attachments, | |
14 | :versions |
|
14 | :versions | |
15 |
|
15 | |||
16 | def setup |
|
16 | def setup | |
17 | @controller = FilesController.new |
|
17 | @controller = FilesController.new | |
18 | @request = ActionController::TestRequest.new |
|
18 | @request = ActionController::TestRequest.new | |
19 | @response = ActionController::TestResponse.new |
|
19 | @response = ActionController::TestResponse.new | |
20 | @request.session[:user_id] = nil |
|
20 | @request.session[:user_id] = nil | |
21 | Setting.default_language = 'en' |
|
21 | Setting.default_language = 'en' | |
22 | end |
|
22 | end | |
23 |
|
23 | |||
24 | def test_index |
|
24 | def test_index | |
25 | get :index, :project_id => 1 |
|
25 | get :index, :project_id => 1 | |
26 | assert_response :success |
|
26 | assert_response :success | |
27 | assert_template 'index' |
|
27 | assert_template 'index' | |
28 | assert_not_nil assigns(:containers) |
|
28 | assert_not_nil assigns(:containers) | |
29 |
|
29 | |||
30 | # file attached to the project |
|
30 | # file attached to the project | |
31 | assert_tag :a, :content => 'project_file.zip', |
|
31 | assert_tag :a, :content => 'project_file.zip', | |
32 | :attributes => { :href => '/attachments/download/8/project_file.zip' } |
|
32 | :attributes => { :href => '/attachments/download/8/project_file.zip' } | |
33 |
|
33 | |||
34 | # file attached to a project's version |
|
34 | # file attached to a project's version | |
35 | assert_tag :a, :content => 'version_file.zip', |
|
35 | assert_tag :a, :content => 'version_file.zip', | |
36 | :attributes => { :href => '/attachments/download/9/version_file.zip' } |
|
36 | :attributes => { :href => '/attachments/download/9/version_file.zip' } | |
37 | end |
|
37 | end | |
38 |
|
38 | |||
|
39 | def test_new | |||
|
40 | @request.session[:user_id] = 2 | |||
|
41 | get :new, :project_id => 1 | |||
|
42 | assert_response :success | |||
|
43 | assert_template 'new' | |||
|
44 | ||||
|
45 | assert_tag 'select', :attributes => {:name => 'version_id'} | |||
|
46 | end | |||
|
47 | ||||
|
48 | def test_new_without_versions | |||
|
49 | Version.delete_all | |||
|
50 | @request.session[:user_id] = 2 | |||
|
51 | get :new, :project_id => 1 | |||
|
52 | assert_response :success | |||
|
53 | assert_template 'new' | |||
|
54 | ||||
|
55 | assert_no_tag 'select', :attributes => {:name => 'version_id'} | |||
|
56 | end | |||
|
57 | ||||
39 | def test_create_file |
|
58 | def test_create_file | |
40 | set_tmp_attachments_directory |
|
59 | set_tmp_attachments_directory | |
41 | @request.session[:user_id] = 2 |
|
60 | @request.session[:user_id] = 2 | |
42 | Setting.notified_events = ['file_added'] |
|
61 | Setting.notified_events = ['file_added'] | |
43 | ActionMailer::Base.deliveries.clear |
|
62 | ActionMailer::Base.deliveries.clear | |
44 |
|
63 | |||
45 | assert_difference 'Attachment.count' do |
|
64 | assert_difference 'Attachment.count' do | |
46 | post :create, :project_id => 1, :version_id => '', |
|
65 | post :create, :project_id => 1, :version_id => '', | |
47 | :attachments => {'1' => {'file' => uploaded_test_file('testfile.txt', 'text/plain')}} |
|
66 | :attachments => {'1' => {'file' => uploaded_test_file('testfile.txt', 'text/plain')}} | |
48 | assert_response :redirect |
|
67 | assert_response :redirect | |
49 | end |
|
68 | end | |
50 | assert_redirected_to '/projects/ecookbook/files' |
|
69 | assert_redirected_to '/projects/ecookbook/files' | |
51 | a = Attachment.find(:first, :order => 'created_on DESC') |
|
70 | a = Attachment.find(:first, :order => 'created_on DESC') | |
52 | assert_equal 'testfile.txt', a.filename |
|
71 | assert_equal 'testfile.txt', a.filename | |
53 | assert_equal Project.find(1), a.container |
|
72 | assert_equal Project.find(1), a.container | |
54 |
|
73 | |||
55 | mail = ActionMailer::Base.deliveries.last |
|
74 | mail = ActionMailer::Base.deliveries.last | |
56 | assert_kind_of TMail::Mail, mail |
|
75 | assert_kind_of TMail::Mail, mail | |
57 | assert_equal "[eCookbook] New file", mail.subject |
|
76 | assert_equal "[eCookbook] New file", mail.subject | |
58 | assert mail.body.include?('testfile.txt') |
|
77 | assert mail.body.include?('testfile.txt') | |
59 | end |
|
78 | end | |
60 |
|
79 | |||
61 | def test_create_version_file |
|
80 | def test_create_version_file | |
62 | set_tmp_attachments_directory |
|
81 | set_tmp_attachments_directory | |
63 | @request.session[:user_id] = 2 |
|
82 | @request.session[:user_id] = 2 | |
64 | Setting.notified_events = ['file_added'] |
|
83 | Setting.notified_events = ['file_added'] | |
65 |
|
84 | |||
66 | assert_difference 'Attachment.count' do |
|
85 | assert_difference 'Attachment.count' do | |
67 | post :create, :project_id => 1, :version_id => '2', |
|
86 | post :create, :project_id => 1, :version_id => '2', | |
68 | :attachments => {'1' => {'file' => uploaded_test_file('testfile.txt', 'text/plain')}} |
|
87 | :attachments => {'1' => {'file' => uploaded_test_file('testfile.txt', 'text/plain')}} | |
69 | assert_response :redirect |
|
88 | assert_response :redirect | |
70 | end |
|
89 | end | |
71 | assert_redirected_to '/projects/ecookbook/files' |
|
90 | assert_redirected_to '/projects/ecookbook/files' | |
72 | a = Attachment.find(:first, :order => 'created_on DESC') |
|
91 | a = Attachment.find(:first, :order => 'created_on DESC') | |
73 | assert_equal 'testfile.txt', a.filename |
|
92 | assert_equal 'testfile.txt', a.filename | |
74 | assert_equal Version.find(2), a.container |
|
93 | assert_equal Version.find(2), a.container | |
75 | end |
|
94 | end | |
76 |
|
95 | |||
77 | end |
|
96 | end |
General Comments 0
You need to be logged in to leave comments.
Login now