@@ -1,84 +1,84 | |||
|
1 | 1 | # redMine - project management software |
|
2 | 2 | # Copyright (C) 2006-2007 Jean-Philippe Lang |
|
3 | 3 | # |
|
4 | 4 | # This program is free software; you can redistribute it and/or |
|
5 | 5 | # modify it under the terms of the GNU General Public License |
|
6 | 6 | # as published by the Free Software Foundation; either version 2 |
|
7 | 7 | # of the License, or (at your option) any later version. |
|
8 | 8 | # |
|
9 | 9 | # This program is distributed in the hope that it will be useful, |
|
10 | 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 | 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12 | 12 | # GNU General Public License for more details. |
|
13 | 13 | # |
|
14 | 14 | # You should have received a copy of the GNU General Public License |
|
15 | 15 | # along with this program; if not, write to the Free Software |
|
16 | 16 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
|
17 | 17 | |
|
18 | 18 | require File.dirname(__FILE__) + '/../test_helper' |
|
19 | 19 | require 'account_controller' |
|
20 | 20 | |
|
21 | 21 | # Re-raise errors caught by the controller. |
|
22 | 22 | class AccountController; def rescue_action(e) raise e end; end |
|
23 | 23 | |
|
24 | 24 | class AccountControllerTest < Test::Unit::TestCase |
|
25 | fixtures :users | |
|
25 | fixtures :users, :roles | |
|
26 | 26 | |
|
27 | 27 | def setup |
|
28 | 28 | @controller = AccountController.new |
|
29 | 29 | @request = ActionController::TestRequest.new |
|
30 | 30 | @response = ActionController::TestResponse.new |
|
31 | 31 | User.current = nil |
|
32 | 32 | end |
|
33 | 33 | |
|
34 | 34 | def test_show |
|
35 | 35 | get :show, :id => 2 |
|
36 | 36 | assert_response :success |
|
37 | 37 | assert_template 'show' |
|
38 | 38 | assert_not_nil assigns(:user) |
|
39 | 39 | end |
|
40 | 40 | |
|
41 | 41 | def test_show_inactive |
|
42 | 42 | get :show, :id => 5 |
|
43 | 43 | assert_response 404 |
|
44 | 44 | assert_nil assigns(:user) |
|
45 | 45 | end |
|
46 | 46 | |
|
47 | 47 | def test_login_should_redirect_to_back_url_param |
|
48 | 48 | # request.uri is "test.host" in test environment |
|
49 | 49 | post :login, :username => 'jsmith', :password => 'jsmith', :back_url => 'http%3A%2F%2Ftest.host%2Fissues%2Fshow%2F1' |
|
50 | 50 | assert_redirected_to '/issues/show/1' |
|
51 | 51 | end |
|
52 | 52 | |
|
53 | 53 | def test_login_should_not_redirect_to_another_host |
|
54 | 54 | post :login, :username => 'jsmith', :password => 'jsmith', :back_url => 'http%3A%2F%2Ftest.foo%2Ffake' |
|
55 | 55 | assert_redirected_to '/my/page' |
|
56 | 56 | end |
|
57 | 57 | |
|
58 | 58 | def test_login_with_wrong_password |
|
59 | 59 | post :login, :username => 'admin', :password => 'bad' |
|
60 | 60 | assert_response :success |
|
61 | 61 | assert_template 'login' |
|
62 | 62 | assert_tag 'div', |
|
63 | 63 | :attributes => { :class => "flash error" }, |
|
64 | 64 | :content => /Invalid user or password/ |
|
65 | 65 | end |
|
66 | 66 | |
|
67 | 67 | def test_autologin |
|
68 | 68 | Setting.autologin = "7" |
|
69 | 69 | Token.delete_all |
|
70 | 70 | post :login, :username => 'admin', :password => 'admin', :autologin => 1 |
|
71 | 71 | assert_redirected_to 'my/page' |
|
72 | 72 | token = Token.find :first |
|
73 | 73 | assert_not_nil token |
|
74 | 74 | assert_equal User.find_by_login('admin'), token.user |
|
75 | 75 | assert_equal 'autologin', token.action |
|
76 | 76 | end |
|
77 | 77 | |
|
78 | 78 | def test_logout |
|
79 | 79 | @request.session[:user_id] = 2 |
|
80 | 80 | get :logout |
|
81 | 81 | assert_redirected_to '' |
|
82 | 82 | assert_nil @request.session[:user_id] |
|
83 | 83 | end |
|
84 | 84 | end |
@@ -1,125 +1,126 | |||
|
1 | 1 | # redMine - project management software |
|
2 | 2 | # Copyright (C) 2006-2008 Jean-Philippe Lang |
|
3 | 3 | # |
|
4 | 4 | # This program is free software; you can redistribute it and/or |
|
5 | 5 | # modify it under the terms of the GNU General Public License |
|
6 | 6 | # as published by the Free Software Foundation; either version 2 |
|
7 | 7 | # of the License, or (at your option) any later version. |
|
8 | 8 | # |
|
9 | 9 | # This program is distributed in the hope that it will be useful, |
|
10 | 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 | 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12 | 12 | # GNU General Public License for more details. |
|
13 | 13 | # |
|
14 | 14 | # You should have received a copy of the GNU General Public License |
|
15 | 15 | # along with this program; if not, write to the Free Software |
|
16 | 16 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
|
17 | 17 | |
|
18 | 18 | require File.dirname(__FILE__) + '/../test_helper' |
|
19 | 19 | require 'attachments_controller' |
|
20 | 20 | |
|
21 | 21 | # Re-raise errors caught by the controller. |
|
22 | 22 | class AttachmentsController; def rescue_action(e) raise e end; end |
|
23 | 23 | |
|
24 | 24 | |
|
25 | 25 | class AttachmentsControllerTest < Test::Unit::TestCase |
|
26 | fixtures :users, :projects, :roles, :members, :enabled_modules, :issues, :attachments | |
|
26 | fixtures :users, :projects, :roles, :members, :enabled_modules, :issues, :attachments, | |
|
27 | :versions, :wiki_pages, :wikis | |
|
27 | 28 | |
|
28 | 29 | def setup |
|
29 | 30 | @controller = AttachmentsController.new |
|
30 | 31 | @request = ActionController::TestRequest.new |
|
31 | 32 | @response = ActionController::TestResponse.new |
|
32 | 33 | Attachment.storage_path = "#{RAILS_ROOT}/test/fixtures/files" |
|
33 | 34 | User.current = nil |
|
34 | 35 | end |
|
35 | 36 | |
|
36 | 37 | def test_routing |
|
37 | 38 | assert_routing('/attachments/1', :controller => 'attachments', :action => 'show', :id => '1') |
|
38 | 39 | assert_routing('/attachments/1/filename.ext', :controller => 'attachments', :action => 'show', :id => '1', :filename => 'filename.ext') |
|
39 | 40 | assert_routing('/attachments/download/1', :controller => 'attachments', :action => 'download', :id => '1') |
|
40 | 41 | assert_routing('/attachments/download/1/filename.ext', :controller => 'attachments', :action => 'download', :id => '1', :filename => 'filename.ext') |
|
41 | 42 | end |
|
42 | 43 | |
|
43 | 44 | def test_recognizes |
|
44 | 45 | assert_recognizes({:controller => 'attachments', :action => 'show', :id => '1'}, '/attachments/1') |
|
45 | 46 | assert_recognizes({:controller => 'attachments', :action => 'show', :id => '1'}, '/attachments/show/1') |
|
46 | 47 | assert_recognizes({:controller => 'attachments', :action => 'show', :id => '1', :filename => 'filename.ext'}, '/attachments/1/filename.ext') |
|
47 | 48 | assert_recognizes({:controller => 'attachments', :action => 'download', :id => '1'}, '/attachments/download/1') |
|
48 | 49 | assert_recognizes({:controller => 'attachments', :action => 'download', :id => '1', :filename => 'filename.ext'},'/attachments/download/1/filename.ext') |
|
49 | 50 | end |
|
50 | 51 | |
|
51 | 52 | def test_show_diff |
|
52 | 53 | get :show, :id => 5 |
|
53 | 54 | assert_response :success |
|
54 | 55 | assert_template 'diff' |
|
55 | 56 | end |
|
56 | 57 | |
|
57 | 58 | def test_show_text_file |
|
58 | 59 | get :show, :id => 4 |
|
59 | 60 | assert_response :success |
|
60 | 61 | assert_template 'file' |
|
61 | 62 | end |
|
62 | 63 | |
|
63 | 64 | def test_show_other |
|
64 | 65 | get :show, :id => 6 |
|
65 | 66 | assert_response :success |
|
66 | 67 | assert_equal 'application/octet-stream', @response.content_type |
|
67 | 68 | end |
|
68 | 69 | |
|
69 | 70 | def test_download_text_file |
|
70 | 71 | get :download, :id => 4 |
|
71 | 72 | assert_response :success |
|
72 | 73 | assert_equal 'application/x-ruby', @response.content_type |
|
73 | 74 | end |
|
74 | 75 | |
|
75 | 76 | def test_anonymous_on_private_private |
|
76 | 77 | get :download, :id => 7 |
|
77 | 78 | assert_redirected_to 'account/login' |
|
78 | 79 | end |
|
79 | 80 | |
|
80 | 81 | def test_destroy_issue_attachment |
|
81 | 82 | issue = Issue.find(3) |
|
82 | 83 | @request.session[:user_id] = 2 |
|
83 | 84 | |
|
84 | 85 | assert_difference 'issue.attachments.count', -1 do |
|
85 | 86 | post :destroy, :id => 1 |
|
86 | 87 | end |
|
87 | 88 | # no referrer |
|
88 | 89 | assert_redirected_to 'projects/show/ecookbook' |
|
89 | 90 | assert_nil Attachment.find_by_id(1) |
|
90 | 91 | j = issue.journals.find(:first, :order => 'created_on DESC') |
|
91 | 92 | assert_equal 'attachment', j.details.first.property |
|
92 | 93 | assert_equal '1', j.details.first.prop_key |
|
93 | 94 | assert_equal 'error281.txt', j.details.first.old_value |
|
94 | 95 | end |
|
95 | 96 | |
|
96 | 97 | def test_destroy_wiki_page_attachment |
|
97 | 98 | @request.session[:user_id] = 2 |
|
98 | 99 | assert_difference 'Attachment.count', -1 do |
|
99 | 100 | post :destroy, :id => 3 |
|
100 | 101 | assert_response 302 |
|
101 | 102 | end |
|
102 | 103 | end |
|
103 | 104 | |
|
104 | 105 | def test_destroy_project_attachment |
|
105 | 106 | @request.session[:user_id] = 2 |
|
106 | 107 | assert_difference 'Attachment.count', -1 do |
|
107 | 108 | post :destroy, :id => 8 |
|
108 | 109 | assert_response 302 |
|
109 | 110 | end |
|
110 | 111 | end |
|
111 | 112 | |
|
112 | 113 | def test_destroy_version_attachment |
|
113 | 114 | @request.session[:user_id] = 2 |
|
114 | 115 | assert_difference 'Attachment.count', -1 do |
|
115 | 116 | post :destroy, :id => 9 |
|
116 | 117 | assert_response 302 |
|
117 | 118 | end |
|
118 | 119 | end |
|
119 | 120 | |
|
120 | 121 | def test_destroy_without_permission |
|
121 | 122 | post :destroy, :id => 3 |
|
122 | 123 | assert_redirected_to '/login' |
|
123 | 124 | assert Attachment.find_by_id(3) |
|
124 | 125 | end |
|
125 | 126 | end |
General Comments 0
You need to be logged in to leave comments.
Login now