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