@@ -1,67 +1,67 | |||
|
1 | 1 | require File.expand_path('../../test_helper', __FILE__) |
|
2 | 2 | |
|
3 | 3 | class FilesControllerTest < ActionController::TestCase |
|
4 | 4 | fixtures :all |
|
5 | ||
|
5 | ||
|
6 | 6 | def setup |
|
7 | 7 | @controller = FilesController.new |
|
8 | 8 | @request = ActionController::TestRequest.new |
|
9 | 9 | @response = ActionController::TestResponse.new |
|
10 | 10 | @request.session[:user_id] = nil |
|
11 | 11 | Setting.default_language = 'en' |
|
12 | 12 | end |
|
13 | 13 | |
|
14 | 14 | def test_index |
|
15 | 15 | get :index, :project_id => 1 |
|
16 | 16 | assert_response :success |
|
17 | 17 | assert_template 'index' |
|
18 | 18 | assert_not_nil assigns(:containers) |
|
19 | ||
|
19 | ||
|
20 | 20 | # file attached to the project |
|
21 | 21 | assert_tag :a, :content => 'project_file.zip', |
|
22 | 22 | :attributes => { :href => '/attachments/download/8/project_file.zip' } |
|
23 | ||
|
23 | ||
|
24 | 24 | # file attached to a project's version |
|
25 | 25 | assert_tag :a, :content => 'version_file.zip', |
|
26 | 26 | :attributes => { :href => '/attachments/download/9/version_file.zip' } |
|
27 | 27 | end |
|
28 | 28 | |
|
29 | 29 | def test_create_file |
|
30 | 30 | set_tmp_attachments_directory |
|
31 | 31 | @request.session[:user_id] = 2 |
|
32 | 32 | Setting.notified_events = ['file_added'] |
|
33 | 33 | ActionMailer::Base.deliveries.clear |
|
34 | ||
|
34 | ||
|
35 | 35 | assert_difference 'Attachment.count' do |
|
36 | 36 | post :create, :project_id => 1, :version_id => '', |
|
37 | 37 | :attachments => {'1' => {'file' => uploaded_test_file('testfile.txt', 'text/plain')}} |
|
38 | 38 | assert_response :redirect |
|
39 | 39 | end |
|
40 | 40 | assert_redirected_to '/projects/ecookbook/files' |
|
41 | 41 | a = Attachment.find(:first, :order => 'created_on DESC') |
|
42 | 42 | assert_equal 'testfile.txt', a.filename |
|
43 | 43 | assert_equal Project.find(1), a.container |
|
44 | 44 | |
|
45 | 45 | mail = ActionMailer::Base.deliveries.last |
|
46 | 46 | assert_kind_of TMail::Mail, mail |
|
47 | 47 | assert_equal "[eCookbook] New file", mail.subject |
|
48 | 48 | assert mail.body.include?('testfile.txt') |
|
49 | 49 | end |
|
50 | ||
|
50 | ||
|
51 | 51 | def test_create_version_file |
|
52 | 52 | set_tmp_attachments_directory |
|
53 | 53 | @request.session[:user_id] = 2 |
|
54 | 54 | Setting.notified_events = ['file_added'] |
|
55 | ||
|
55 | ||
|
56 | 56 | assert_difference 'Attachment.count' do |
|
57 | 57 | post :create, :project_id => 1, :version_id => '2', |
|
58 | 58 | :attachments => {'1' => {'file' => uploaded_test_file('testfile.txt', 'text/plain')}} |
|
59 | 59 | assert_response :redirect |
|
60 | 60 | end |
|
61 | 61 | assert_redirected_to '/projects/ecookbook/files' |
|
62 | 62 | a = Attachment.find(:first, :order => 'created_on DESC') |
|
63 | 63 | assert_equal 'testfile.txt', a.filename |
|
64 | 64 | assert_equal Version.find(2), a.container |
|
65 | 65 | end |
|
66 | ||
|
66 | ||
|
67 | 67 | end |
General Comments 0
You need to be logged in to leave comments.
Login now