##// END OF EJS Templates
Refactor: Move the rest of the routing tests to RoutingTest....
Eric Davis -
r3573:9b595c689d06
parent child
Show More
@@ -1,150 +1,135
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 < ActionController::TestCase
25 class AttachmentsControllerTest < ActionController::TestCase
26 fixtures :users, :projects, :roles, :members, :member_roles, :enabled_modules, :issues, :trackers, :attachments,
26 fixtures :users, :projects, :roles, :members, :member_roles, :enabled_modules, :issues, :trackers, :attachments,
27 :versions, :wiki_pages, :wikis, :documents
27 :versions, :wiki_pages, :wikis, :documents
28
28
29 def setup
29 def setup
30 @controller = AttachmentsController.new
30 @controller = AttachmentsController.new
31 @request = ActionController::TestRequest.new
31 @request = ActionController::TestRequest.new
32 @response = ActionController::TestResponse.new
32 @response = ActionController::TestResponse.new
33 Attachment.storage_path = "#{RAILS_ROOT}/test/fixtures/files"
33 Attachment.storage_path = "#{RAILS_ROOT}/test/fixtures/files"
34 User.current = nil
34 User.current = nil
35 end
35 end
36
36
37 def test_routing
38 assert_routing('/attachments/1', :controller => 'attachments', :action => 'show', :id => '1')
39 assert_routing('/attachments/1/filename.ext', :controller => 'attachments', :action => 'show', :id => '1', :filename => 'filename.ext')
40 assert_routing('/attachments/download/1', :controller => 'attachments', :action => 'download', :id => '1')
41 assert_routing('/attachments/download/1/filename.ext', :controller => 'attachments', :action => 'download', :id => '1', :filename => 'filename.ext')
42 end
43
44 def test_recognizes
45 assert_recognizes({:controller => 'attachments', :action => 'show', :id => '1'}, '/attachments/1')
46 assert_recognizes({:controller => 'attachments', :action => 'show', :id => '1'}, '/attachments/show/1')
47 assert_recognizes({:controller => 'attachments', :action => 'show', :id => '1', :filename => 'filename.ext'}, '/attachments/1/filename.ext')
48 assert_recognizes({:controller => 'attachments', :action => 'download', :id => '1'}, '/attachments/download/1')
49 assert_recognizes({:controller => 'attachments', :action => 'download', :id => '1', :filename => 'filename.ext'},'/attachments/download/1/filename.ext')
50 end
51
52 def test_show_diff
37 def test_show_diff
53 get :show, :id => 5
38 get :show, :id => 5
54 assert_response :success
39 assert_response :success
55 assert_template 'diff'
40 assert_template 'diff'
56 assert_equal 'text/html', @response.content_type
41 assert_equal 'text/html', @response.content_type
57 end
42 end
58
43
59 def test_show_text_file
44 def test_show_text_file
60 get :show, :id => 4
45 get :show, :id => 4
61 assert_response :success
46 assert_response :success
62 assert_template 'file'
47 assert_template 'file'
63 assert_equal 'text/html', @response.content_type
48 assert_equal 'text/html', @response.content_type
64 end
49 end
65
50
66 def test_show_text_file_should_send_if_too_big
51 def test_show_text_file_should_send_if_too_big
67 Setting.file_max_size_displayed = 512
52 Setting.file_max_size_displayed = 512
68 Attachment.find(4).update_attribute :filesize, 754.kilobyte
53 Attachment.find(4).update_attribute :filesize, 754.kilobyte
69
54
70 get :show, :id => 4
55 get :show, :id => 4
71 assert_response :success
56 assert_response :success
72 assert_equal 'application/x-ruby', @response.content_type
57 assert_equal 'application/x-ruby', @response.content_type
73 end
58 end
74
59
75 def test_show_other
60 def test_show_other
76 get :show, :id => 6
61 get :show, :id => 6
77 assert_response :success
62 assert_response :success
78 assert_equal 'application/octet-stream', @response.content_type
63 assert_equal 'application/octet-stream', @response.content_type
79 end
64 end
80
65
81 def test_download_text_file
66 def test_download_text_file
82 get :download, :id => 4
67 get :download, :id => 4
83 assert_response :success
68 assert_response :success
84 assert_equal 'application/x-ruby', @response.content_type
69 assert_equal 'application/x-ruby', @response.content_type
85 end
70 end
86
71
87 def test_download_should_assign_content_type_if_blank
72 def test_download_should_assign_content_type_if_blank
88 Attachment.find(4).update_attribute(:content_type, '')
73 Attachment.find(4).update_attribute(:content_type, '')
89
74
90 get :download, :id => 4
75 get :download, :id => 4
91 assert_response :success
76 assert_response :success
92 assert_equal 'text/x-ruby', @response.content_type
77 assert_equal 'text/x-ruby', @response.content_type
93 end
78 end
94
79
95 def test_download_missing_file
80 def test_download_missing_file
96 get :download, :id => 2
81 get :download, :id => 2
97 assert_response 404
82 assert_response 404
98 end
83 end
99
84
100 def test_anonymous_on_private_private
85 def test_anonymous_on_private_private
101 get :download, :id => 7
86 get :download, :id => 7
102 assert_redirected_to '/login?back_url=http%3A%2F%2Ftest.host%2Fattachments%2Fdownload%2F7'
87 assert_redirected_to '/login?back_url=http%3A%2F%2Ftest.host%2Fattachments%2Fdownload%2F7'
103 end
88 end
104
89
105 def test_destroy_issue_attachment
90 def test_destroy_issue_attachment
106 issue = Issue.find(3)
91 issue = Issue.find(3)
107 @request.session[:user_id] = 2
92 @request.session[:user_id] = 2
108
93
109 assert_difference 'issue.attachments.count', -1 do
94 assert_difference 'issue.attachments.count', -1 do
110 post :destroy, :id => 1
95 post :destroy, :id => 1
111 end
96 end
112 # no referrer
97 # no referrer
113 assert_redirected_to 'projects/ecookbook'
98 assert_redirected_to 'projects/ecookbook'
114 assert_nil Attachment.find_by_id(1)
99 assert_nil Attachment.find_by_id(1)
115 j = issue.journals.find(:first, :order => 'created_on DESC')
100 j = issue.journals.find(:first, :order => 'created_on DESC')
116 assert_equal 'attachment', j.details.first.property
101 assert_equal 'attachment', j.details.first.property
117 assert_equal '1', j.details.first.prop_key
102 assert_equal '1', j.details.first.prop_key
118 assert_equal 'error281.txt', j.details.first.old_value
103 assert_equal 'error281.txt', j.details.first.old_value
119 end
104 end
120
105
121 def test_destroy_wiki_page_attachment
106 def test_destroy_wiki_page_attachment
122 @request.session[:user_id] = 2
107 @request.session[:user_id] = 2
123 assert_difference 'Attachment.count', -1 do
108 assert_difference 'Attachment.count', -1 do
124 post :destroy, :id => 3
109 post :destroy, :id => 3
125 assert_response 302
110 assert_response 302
126 end
111 end
127 end
112 end
128
113
129 def test_destroy_project_attachment
114 def test_destroy_project_attachment
130 @request.session[:user_id] = 2
115 @request.session[:user_id] = 2
131 assert_difference 'Attachment.count', -1 do
116 assert_difference 'Attachment.count', -1 do
132 post :destroy, :id => 8
117 post :destroy, :id => 8
133 assert_response 302
118 assert_response 302
134 end
119 end
135 end
120 end
136
121
137 def test_destroy_version_attachment
122 def test_destroy_version_attachment
138 @request.session[:user_id] = 2
123 @request.session[:user_id] = 2
139 assert_difference 'Attachment.count', -1 do
124 assert_difference 'Attachment.count', -1 do
140 post :destroy, :id => 9
125 post :destroy, :id => 9
141 assert_response 302
126 assert_response 302
142 end
127 end
143 end
128 end
144
129
145 def test_destroy_without_permission
130 def test_destroy_without_permission
146 post :destroy, :id => 3
131 post :destroy, :id => 3
147 assert_redirected_to '/login?back_url=http%3A%2F%2Ftest.host%2Fattachments%2Fdestroy%2F3'
132 assert_redirected_to '/login?back_url=http%3A%2F%2Ftest.host%2Fattachments%2Fdestroy%2F3'
148 assert Attachment.find_by_id(3)
133 assert Attachment.find_by_id(3)
149 end
134 end
150 end
135 end
@@ -1,146 +1,99
1 # Redmine - project management software
1 # Redmine - project management software
2 # Copyright (C) 2006-2009 Jean-Philippe Lang
2 # Copyright (C) 2006-2009 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 'boards_controller'
19 require 'boards_controller'
20
20
21 # Re-raise errors caught by the controller.
21 # Re-raise errors caught by the controller.
22 class BoardsController; def rescue_action(e) raise e end; end
22 class BoardsController; def rescue_action(e) raise e end; end
23
23
24 class BoardsControllerTest < ActionController::TestCase
24 class BoardsControllerTest < ActionController::TestCase
25 fixtures :projects, :users, :members, :member_roles, :roles, :boards, :messages, :enabled_modules
25 fixtures :projects, :users, :members, :member_roles, :roles, :boards, :messages, :enabled_modules
26
26
27 def setup
27 def setup
28 @controller = BoardsController.new
28 @controller = BoardsController.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_index_routing
35 assert_routing(
36 {:method => :get, :path => '/projects/world_domination/boards'},
37 :controller => 'boards', :action => 'index', :project_id => 'world_domination'
38 )
39 end
40
41 def test_index
34 def test_index
42 get :index, :project_id => 1
35 get :index, :project_id => 1
43 assert_response :success
36 assert_response :success
44 assert_template 'index'
37 assert_template 'index'
45 assert_not_nil assigns(:boards)
38 assert_not_nil assigns(:boards)
46 assert_not_nil assigns(:project)
39 assert_not_nil assigns(:project)
47 end
40 end
48
41
49 def test_index_not_found
42 def test_index_not_found
50 get :index, :project_id => 97
43 get :index, :project_id => 97
51 assert_response 404
44 assert_response 404
52 end
45 end
53
46
54 def test_index_should_show_messages_if_only_one_board
47 def test_index_should_show_messages_if_only_one_board
55 Project.find(1).boards.slice(1..-1).each(&:destroy)
48 Project.find(1).boards.slice(1..-1).each(&:destroy)
56
49
57 get :index, :project_id => 1
50 get :index, :project_id => 1
58 assert_response :success
51 assert_response :success
59 assert_template 'show'
52 assert_template 'show'
60 assert_not_nil assigns(:topics)
53 assert_not_nil assigns(:topics)
61 end
54 end
62
55
63 def test_new_routing
64 assert_routing(
65 {:method => :get, :path => '/projects/world_domination/boards/new'},
66 :controller => 'boards', :action => 'new', :project_id => 'world_domination'
67 )
68 assert_recognizes(
69 {:controller => 'boards', :action => 'new', :project_id => 'world_domination'},
70 {:method => :post, :path => '/projects/world_domination/boards'}
71 )
72 end
73
74 def test_post_new
56 def test_post_new
75 @request.session[:user_id] = 2
57 @request.session[:user_id] = 2
76 assert_difference 'Board.count' do
58 assert_difference 'Board.count' do
77 post :new, :project_id => 1, :board => { :name => 'Testing', :description => 'Testing board creation'}
59 post :new, :project_id => 1, :board => { :name => 'Testing', :description => 'Testing board creation'}
78 end
60 end
79 assert_redirected_to '/projects/ecookbook/settings/boards'
61 assert_redirected_to '/projects/ecookbook/settings/boards'
80 end
62 end
81
63
82 def test_show_routing
83 assert_routing(
84 {:method => :get, :path => '/projects/world_domination/boards/44'},
85 :controller => 'boards', :action => 'show', :id => '44', :project_id => 'world_domination'
86 )
87 assert_routing(
88 {:method => :get, :path => '/projects/world_domination/boards/44.atom'},
89 :controller => 'boards', :action => 'show', :id => '44', :project_id => 'world_domination', :format => 'atom'
90 )
91 end
92
93 def test_show
64 def test_show
94 get :show, :project_id => 1, :id => 1
65 get :show, :project_id => 1, :id => 1
95 assert_response :success
66 assert_response :success
96 assert_template 'show'
67 assert_template 'show'
97 assert_not_nil assigns(:board)
68 assert_not_nil assigns(:board)
98 assert_not_nil assigns(:project)
69 assert_not_nil assigns(:project)
99 assert_not_nil assigns(:topics)
70 assert_not_nil assigns(:topics)
100 end
71 end
101
72
102 def test_show_atom
73 def test_show_atom
103 get :show, :project_id => 1, :id => 1, :format => 'atom'
74 get :show, :project_id => 1, :id => 1, :format => 'atom'
104 assert_response :success
75 assert_response :success
105 assert_template 'common/feed.atom'
76 assert_template 'common/feed.atom'
106 assert_not_nil assigns(:board)
77 assert_not_nil assigns(:board)
107 assert_not_nil assigns(:project)
78 assert_not_nil assigns(:project)
108 assert_not_nil assigns(:messages)
79 assert_not_nil assigns(:messages)
109 end
80 end
110
81
111 def test_edit_routing
112 assert_routing(
113 {:method => :get, :path => '/projects/world_domination/boards/44/edit'},
114 :controller => 'boards', :action => 'edit', :id => '44', :project_id => 'world_domination'
115 )
116 assert_recognizes(#TODO: use PUT method to board_path, modify form accordingly
117 {:controller => 'boards', :action => 'edit', :id => '44', :project_id => 'world_domination'},
118 {:method => :post, :path => '/projects/world_domination/boards/44/edit'}
119 )
120 end
121
122 def test_post_edit
82 def test_post_edit
123 @request.session[:user_id] = 2
83 @request.session[:user_id] = 2
124 assert_no_difference 'Board.count' do
84 assert_no_difference 'Board.count' do
125 post :edit, :project_id => 1, :id => 2, :board => { :name => 'Testing', :description => 'Testing board update'}
85 post :edit, :project_id => 1, :id => 2, :board => { :name => 'Testing', :description => 'Testing board update'}
126 end
86 end
127 assert_redirected_to '/projects/ecookbook/settings/boards'
87 assert_redirected_to '/projects/ecookbook/settings/boards'
128 assert_equal 'Testing', Board.find(2).name
88 assert_equal 'Testing', Board.find(2).name
129 end
89 end
130
90
131 def test_destroy_routing
132 assert_routing(#TODO: use DELETE method to board_path, modify form accoringly
133 {:method => :post, :path => '/projects/world_domination/boards/44/destroy'},
134 :controller => 'boards', :action => 'destroy', :id => '44', :project_id => 'world_domination'
135 )
136 end
137
138 def test_post_destroy
91 def test_post_destroy
139 @request.session[:user_id] = 2
92 @request.session[:user_id] = 2
140 assert_difference 'Board.count', -1 do
93 assert_difference 'Board.count', -1 do
141 post :destroy, :project_id => 1, :id => 2
94 post :destroy, :project_id => 1, :id => 2
142 end
95 end
143 assert_redirected_to '/projects/ecookbook/settings/boards'
96 assert_redirected_to '/projects/ecookbook/settings/boards'
144 assert_nil Board.find_by_id(2)
97 assert_nil Board.find_by_id(2)
145 end
98 end
146 end
99 end
@@ -1,121 +1,78
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 'documents_controller'
19 require 'documents_controller'
20
20
21 # Re-raise errors caught by the controller.
21 # Re-raise errors caught by the controller.
22 class DocumentsController; def rescue_action(e) raise e end; end
22 class DocumentsController; def rescue_action(e) raise e end; end
23
23
24 class DocumentsControllerTest < ActionController::TestCase
24 class DocumentsControllerTest < ActionController::TestCase
25 fixtures :projects, :users, :roles, :members, :member_roles, :enabled_modules, :documents, :enumerations
25 fixtures :projects, :users, :roles, :members, :member_roles, :enabled_modules, :documents, :enumerations
26
26
27 def setup
27 def setup
28 @controller = DocumentsController.new
28 @controller = DocumentsController.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_index_routing
35 assert_routing(
36 {:method => :get, :path => '/projects/567/documents'},
37 :controller => 'documents', :action => 'index', :project_id => '567'
38 )
39 end
40
41 def test_index
34 def test_index
42 # Sets a default category
35 # Sets a default category
43 e = Enumeration.find_by_name('Technical documentation')
36 e = Enumeration.find_by_name('Technical documentation')
44 e.update_attributes(:is_default => true)
37 e.update_attributes(:is_default => true)
45
38
46 get :index, :project_id => 'ecookbook'
39 get :index, :project_id => 'ecookbook'
47 assert_response :success
40 assert_response :success
48 assert_template 'index'
41 assert_template 'index'
49 assert_not_nil assigns(:grouped)
42 assert_not_nil assigns(:grouped)
50
43
51 # Default category selected in the new document form
44 # Default category selected in the new document form
52 assert_tag :select, :attributes => {:name => 'document[category_id]'},
45 assert_tag :select, :attributes => {:name => 'document[category_id]'},
53 :child => {:tag => 'option', :attributes => {:selected => 'selected'},
46 :child => {:tag => 'option', :attributes => {:selected => 'selected'},
54 :content => 'Technical documentation'}
47 :content => 'Technical documentation'}
55 end
48 end
56
49
57 def test_new_routing
58 assert_routing(
59 {:method => :get, :path => '/projects/567/documents/new'},
60 :controller => 'documents', :action => 'new', :project_id => '567'
61 )
62 assert_recognizes(
63 {:controller => 'documents', :action => 'new', :project_id => '567'},
64 {:method => :post, :path => '/projects/567/documents'}
65 )
66 end
67
68 def test_new_with_one_attachment
50 def test_new_with_one_attachment
69 ActionMailer::Base.deliveries.clear
51 ActionMailer::Base.deliveries.clear
70 Setting.notified_events << 'document_added'
52 Setting.notified_events << 'document_added'
71 @request.session[:user_id] = 2
53 @request.session[:user_id] = 2
72 set_tmp_attachments_directory
54 set_tmp_attachments_directory
73
55
74 post :new, :project_id => 'ecookbook',
56 post :new, :project_id => 'ecookbook',
75 :document => { :title => 'DocumentsControllerTest#test_post_new',
57 :document => { :title => 'DocumentsControllerTest#test_post_new',
76 :description => 'This is a new document',
58 :description => 'This is a new document',
77 :category_id => 2},
59 :category_id => 2},
78 :attachments => {'1' => {'file' => uploaded_test_file('testfile.txt', 'text/plain')}}
60 :attachments => {'1' => {'file' => uploaded_test_file('testfile.txt', 'text/plain')}}
79
61
80 assert_redirected_to 'projects/ecookbook/documents'
62 assert_redirected_to 'projects/ecookbook/documents'
81
63
82 document = Document.find_by_title('DocumentsControllerTest#test_post_new')
64 document = Document.find_by_title('DocumentsControllerTest#test_post_new')
83 assert_not_nil document
65 assert_not_nil document
84 assert_equal Enumeration.find(2), document.category
66 assert_equal Enumeration.find(2), document.category
85 assert_equal 1, document.attachments.size
67 assert_equal 1, document.attachments.size
86 assert_equal 'testfile.txt', document.attachments.first.filename
68 assert_equal 'testfile.txt', document.attachments.first.filename
87 assert_equal 1, ActionMailer::Base.deliveries.size
69 assert_equal 1, ActionMailer::Base.deliveries.size
88 end
70 end
89
71
90 def test_edit_routing
91 assert_routing(
92 {:method => :get, :path => '/documents/22/edit'},
93 :controller => 'documents', :action => 'edit', :id => '22'
94 )
95 assert_recognizes(#TODO: should be using PUT on document URI
96 {:controller => 'documents', :action => 'edit', :id => '567'},
97 {:method => :post, :path => '/documents/567/edit'}
98 )
99 end
100
101 def test_show_routing
102 assert_routing(
103 {:method => :get, :path => '/documents/22'},
104 :controller => 'documents', :action => 'show', :id => '22'
105 )
106 end
107
108 def test_destroy_routing
109 assert_recognizes(#TODO: should be using DELETE on document URI
110 {:controller => 'documents', :action => 'destroy', :id => '567'},
111 {:method => :post, :path => '/documents/567/destroy'}
112 )
113 end
114
115 def test_destroy
72 def test_destroy
116 @request.session[:user_id] = 2
73 @request.session[:user_id] = 2
117 post :destroy, :id => 1
74 post :destroy, :id => 1
118 assert_redirected_to 'projects/ecookbook/documents'
75 assert_redirected_to 'projects/ecookbook/documents'
119 assert_nil Document.find_by_id(1)
76 assert_nil Document.find_by_id(1)
120 end
77 end
121 end
78 end
@@ -1,107 +1,96
1 # Redmine - project management software
1 # Redmine - project management software
2 # Copyright (C) 2006-2009 Jean-Philippe Lang
2 # Copyright (C) 2006-2009 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 'issue_categories_controller'
19 require 'issue_categories_controller'
20
20
21 # Re-raise errors caught by the controller.
21 # Re-raise errors caught by the controller.
22 class IssueCategoriesController; def rescue_action(e) raise e end; end
22 class IssueCategoriesController; def rescue_action(e) raise e end; end
23
23
24 class IssueCategoriesControllerTest < ActionController::TestCase
24 class IssueCategoriesControllerTest < ActionController::TestCase
25 fixtures :projects, :users, :members, :member_roles, :roles, :enabled_modules, :issue_categories
25 fixtures :projects, :users, :members, :member_roles, :roles, :enabled_modules, :issue_categories
26
26
27 def setup
27 def setup
28 @controller = IssueCategoriesController.new
28 @controller = IssueCategoriesController.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 @request.session[:user_id] = 2
32 @request.session[:user_id] = 2
33 end
33 end
34
34
35 def test_new_routing
36 assert_routing(
37 {:method => :get, :path => 'projects/test/issue_categories/new'},
38 :controller => 'issue_categories', :action => 'new', :project_id => 'test'
39 )
40 assert_routing(
41 {:method => :post, :path => 'projects/test/issue_categories/new'},
42 :controller => 'issue_categories', :action => 'new', :project_id => 'test'
43 )
44 end
45
46 def test_get_new
35 def test_get_new
47 @request.session[:user_id] = 2 # manager
36 @request.session[:user_id] = 2 # manager
48 get :new, :project_id => '1'
37 get :new, :project_id => '1'
49 assert_response :success
38 assert_response :success
50 assert_template 'new'
39 assert_template 'new'
51 end
40 end
52
41
53 def test_post_new
42 def test_post_new
54 @request.session[:user_id] = 2 # manager
43 @request.session[:user_id] = 2 # manager
55 assert_difference 'IssueCategory.count' do
44 assert_difference 'IssueCategory.count' do
56 post :new, :project_id => '1', :category => {:name => 'New category'}
45 post :new, :project_id => '1', :category => {:name => 'New category'}
57 end
46 end
58 assert_redirected_to '/projects/ecookbook/settings/categories'
47 assert_redirected_to '/projects/ecookbook/settings/categories'
59 category = IssueCategory.find_by_name('New category')
48 category = IssueCategory.find_by_name('New category')
60 assert_not_nil category
49 assert_not_nil category
61 assert_equal 1, category.project_id
50 assert_equal 1, category.project_id
62 end
51 end
63
52
64 def test_post_edit
53 def test_post_edit
65 assert_no_difference 'IssueCategory.count' do
54 assert_no_difference 'IssueCategory.count' do
66 post :edit, :id => 2, :category => { :name => 'Testing' }
55 post :edit, :id => 2, :category => { :name => 'Testing' }
67 end
56 end
68 assert_redirected_to '/projects/ecookbook/settings/categories'
57 assert_redirected_to '/projects/ecookbook/settings/categories'
69 assert_equal 'Testing', IssueCategory.find(2).name
58 assert_equal 'Testing', IssueCategory.find(2).name
70 end
59 end
71
60
72 def test_edit_not_found
61 def test_edit_not_found
73 post :edit, :id => 97, :category => { :name => 'Testing' }
62 post :edit, :id => 97, :category => { :name => 'Testing' }
74 assert_response 404
63 assert_response 404
75 end
64 end
76
65
77 def test_destroy_category_not_in_use
66 def test_destroy_category_not_in_use
78 post :destroy, :id => 2
67 post :destroy, :id => 2
79 assert_redirected_to '/projects/ecookbook/settings/categories'
68 assert_redirected_to '/projects/ecookbook/settings/categories'
80 assert_nil IssueCategory.find_by_id(2)
69 assert_nil IssueCategory.find_by_id(2)
81 end
70 end
82
71
83 def test_destroy_category_in_use
72 def test_destroy_category_in_use
84 post :destroy, :id => 1
73 post :destroy, :id => 1
85 assert_response :success
74 assert_response :success
86 assert_template 'destroy'
75 assert_template 'destroy'
87 assert_not_nil IssueCategory.find_by_id(1)
76 assert_not_nil IssueCategory.find_by_id(1)
88 end
77 end
89
78
90 def test_destroy_category_in_use_with_reassignment
79 def test_destroy_category_in_use_with_reassignment
91 issue = Issue.find(:first, :conditions => {:category_id => 1})
80 issue = Issue.find(:first, :conditions => {:category_id => 1})
92 post :destroy, :id => 1, :todo => 'reassign', :reassign_to_id => 2
81 post :destroy, :id => 1, :todo => 'reassign', :reassign_to_id => 2
93 assert_redirected_to '/projects/ecookbook/settings/categories'
82 assert_redirected_to '/projects/ecookbook/settings/categories'
94 assert_nil IssueCategory.find_by_id(1)
83 assert_nil IssueCategory.find_by_id(1)
95 # check that the issue was reassign
84 # check that the issue was reassign
96 assert_equal 2, issue.reload.category_id
85 assert_equal 2, issue.reload.category_id
97 end
86 end
98
87
99 def test_destroy_category_in_use_without_reassignment
88 def test_destroy_category_in_use_without_reassignment
100 issue = Issue.find(:first, :conditions => {:category_id => 1})
89 issue = Issue.find(:first, :conditions => {:category_id => 1})
101 post :destroy, :id => 1, :todo => 'nullify'
90 post :destroy, :id => 1, :todo => 'nullify'
102 assert_redirected_to '/projects/ecookbook/settings/categories'
91 assert_redirected_to '/projects/ecookbook/settings/categories'
103 assert_nil IssueCategory.find_by_id(1)
92 assert_nil IssueCategory.find_by_id(1)
104 # check that the issue category was nullified
93 # check that the issue category was nullified
105 assert_nil issue.reload.category_id
94 assert_nil issue.reload.category_id
106 end
95 end
107 end
96 end
@@ -1,85 +1,71
1 require File.dirname(__FILE__) + '/../test_helper'
1 require File.dirname(__FILE__) + '/../test_helper'
2 require 'issue_relations_controller'
2 require 'issue_relations_controller'
3
3
4 # Re-raise errors caught by the controller.
4 # Re-raise errors caught by the controller.
5 class IssueRelationsController; def rescue_action(e) raise e end; end
5 class IssueRelationsController; def rescue_action(e) raise e end; end
6
6
7
7
8 class IssueRelationsControllerTest < ActionController::TestCase
8 class IssueRelationsControllerTest < ActionController::TestCase
9 fixtures :projects,
9 fixtures :projects,
10 :users,
10 :users,
11 :roles,
11 :roles,
12 :members,
12 :members,
13 :member_roles,
13 :member_roles,
14 :issues,
14 :issues,
15 :issue_statuses,
15 :issue_statuses,
16 :issue_relations,
16 :issue_relations,
17 :enabled_modules,
17 :enabled_modules,
18 :enumerations,
18 :enumerations,
19 :trackers
19 :trackers
20
20
21 def setup
21 def setup
22 @controller = IssueRelationsController.new
22 @controller = IssueRelationsController.new
23 @request = ActionController::TestRequest.new
23 @request = ActionController::TestRequest.new
24 @response = ActionController::TestResponse.new
24 @response = ActionController::TestResponse.new
25 User.current = nil
25 User.current = nil
26 end
26 end
27
27
28 def test_new_routing
29 assert_routing(
30 {:method => :post, :path => '/issues/1/relations'},
31 {:controller => 'issue_relations', :action => 'new', :issue_id => '1'}
32 )
33 end
34
35 def test_new
28 def test_new
36 assert_difference 'IssueRelation.count' do
29 assert_difference 'IssueRelation.count' do
37 @request.session[:user_id] = 3
30 @request.session[:user_id] = 3
38 post :new, :issue_id => 1,
31 post :new, :issue_id => 1,
39 :relation => {:issue_to_id => '2', :relation_type => 'relates', :delay => ''}
32 :relation => {:issue_to_id => '2', :relation_type => 'relates', :delay => ''}
40 end
33 end
41 end
34 end
42
35
43 def test_new_should_accept_id_with_hash
36 def test_new_should_accept_id_with_hash
44 assert_difference 'IssueRelation.count' do
37 assert_difference 'IssueRelation.count' do
45 @request.session[:user_id] = 3
38 @request.session[:user_id] = 3
46 post :new, :issue_id => 1,
39 post :new, :issue_id => 1,
47 :relation => {:issue_to_id => '#2', :relation_type => 'relates', :delay => ''}
40 :relation => {:issue_to_id => '#2', :relation_type => 'relates', :delay => ''}
48 end
41 end
49 end
42 end
50
43
51 def test_new_should_not_break_with_non_numerical_id
44 def test_new_should_not_break_with_non_numerical_id
52 assert_no_difference 'IssueRelation.count' do
45 assert_no_difference 'IssueRelation.count' do
53 assert_nothing_raised do
46 assert_nothing_raised do
54 @request.session[:user_id] = 3
47 @request.session[:user_id] = 3
55 post :new, :issue_id => 1,
48 post :new, :issue_id => 1,
56 :relation => {:issue_to_id => 'foo', :relation_type => 'relates', :delay => ''}
49 :relation => {:issue_to_id => 'foo', :relation_type => 'relates', :delay => ''}
57 end
50 end
58 end
51 end
59 end
52 end
60
53
61 def test_should_create_relations_with_visible_issues_only
54 def test_should_create_relations_with_visible_issues_only
62 Setting.cross_project_issue_relations = '1'
55 Setting.cross_project_issue_relations = '1'
63 assert_nil Issue.visible(User.find(3)).find_by_id(4)
56 assert_nil Issue.visible(User.find(3)).find_by_id(4)
64
57
65 assert_no_difference 'IssueRelation.count' do
58 assert_no_difference 'IssueRelation.count' do
66 @request.session[:user_id] = 3
59 @request.session[:user_id] = 3
67 post :new, :issue_id => 1,
60 post :new, :issue_id => 1,
68 :relation => {:issue_to_id => '4', :relation_type => 'relates', :delay => ''}
61 :relation => {:issue_to_id => '4', :relation_type => 'relates', :delay => ''}
69 end
62 end
70 end
63 end
71
64
72 def test_destroy_routing
73 assert_recognizes( #TODO: use DELETE on issue URI
74 {:controller => 'issue_relations', :action => 'destroy', :issue_id => '1', :id => '23'},
75 {:method => :post, :path => '/issues/1/relations/23/destroy'}
76 )
77 end
78
79 def test_destroy
65 def test_destroy
80 assert_difference 'IssueRelation.count', -1 do
66 assert_difference 'IssueRelation.count', -1 do
81 @request.session[:user_id] = 3
67 @request.session[:user_id] = 3
82 post :destroy, :id => '2', :issue_id => '3'
68 post :destroy, :id => '2', :issue_id => '3'
83 end
69 end
84 end
70 end
85 end
71 end
@@ -1,82 +1,75
1 # Redmine - project management software
1 # Redmine - project management software
2 # Copyright (C) 2006-2009 Jean-Philippe Lang
2 # Copyright (C) 2006-2009 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 'members_controller'
19 require 'members_controller'
20
20
21 # Re-raise errors caught by the controller.
21 # Re-raise errors caught by the controller.
22 class MembersController; def rescue_action(e) raise e end; end
22 class MembersController; def rescue_action(e) raise e end; end
23
23
24
24
25 class MembersControllerTest < ActionController::TestCase
25 class MembersControllerTest < ActionController::TestCase
26 fixtures :projects, :members, :member_roles, :roles, :users
26 fixtures :projects, :members, :member_roles, :roles, :users
27
27
28 def setup
28 def setup
29 @controller = MembersController.new
29 @controller = MembersController.new
30 @request = ActionController::TestRequest.new
30 @request = ActionController::TestRequest.new
31 @response = ActionController::TestResponse.new
31 @response = ActionController::TestResponse.new
32 User.current = nil
32 User.current = nil
33 @request.session[:user_id] = 2
33 @request.session[:user_id] = 2
34 end
34 end
35
35
36 def test_members_routing
37 assert_routing(
38 {:method => :post, :path => 'projects/5234/members/new'},
39 :controller => 'members', :action => 'new', :id => '5234'
40 )
41 end
42
43 def test_create
36 def test_create
44 assert_difference 'Member.count' do
37 assert_difference 'Member.count' do
45 post :new, :id => 1, :member => {:role_ids => [1], :user_id => 7}
38 post :new, :id => 1, :member => {:role_ids => [1], :user_id => 7}
46 end
39 end
47 assert_redirected_to '/projects/ecookbook/settings/members'
40 assert_redirected_to '/projects/ecookbook/settings/members'
48 assert User.find(7).member_of?(Project.find(1))
41 assert User.find(7).member_of?(Project.find(1))
49 end
42 end
50
43
51 def test_create_multiple
44 def test_create_multiple
52 assert_difference 'Member.count', 3 do
45 assert_difference 'Member.count', 3 do
53 post :new, :id => 1, :member => {:role_ids => [1], :user_ids => [7, 8, 9]}
46 post :new, :id => 1, :member => {:role_ids => [1], :user_ids => [7, 8, 9]}
54 end
47 end
55 assert_redirected_to '/projects/ecookbook/settings/members'
48 assert_redirected_to '/projects/ecookbook/settings/members'
56 assert User.find(7).member_of?(Project.find(1))
49 assert User.find(7).member_of?(Project.find(1))
57 end
50 end
58
51
59 def test_edit
52 def test_edit
60 assert_no_difference 'Member.count' do
53 assert_no_difference 'Member.count' do
61 post :edit, :id => 2, :member => {:role_ids => [1], :user_id => 3}
54 post :edit, :id => 2, :member => {:role_ids => [1], :user_id => 3}
62 end
55 end
63 assert_redirected_to '/projects/ecookbook/settings/members'
56 assert_redirected_to '/projects/ecookbook/settings/members'
64 end
57 end
65
58
66 def test_destroy
59 def test_destroy
67 assert_difference 'Member.count', -1 do
60 assert_difference 'Member.count', -1 do
68 post :destroy, :id => 2
61 post :destroy, :id => 2
69 end
62 end
70 assert_redirected_to '/projects/ecookbook/settings/members'
63 assert_redirected_to '/projects/ecookbook/settings/members'
71 assert !User.find(3).member_of?(Project.find(1))
64 assert !User.find(3).member_of?(Project.find(1))
72 end
65 end
73
66
74 def test_autocomplete_for_member
67 def test_autocomplete_for_member
75 get :autocomplete_for_member, :id => 1, :q => 'mis'
68 get :autocomplete_for_member, :id => 1, :q => 'mis'
76 assert_response :success
69 assert_response :success
77 assert_template 'autocomplete_for_member'
70 assert_template 'autocomplete_for_member'
78
71
79 assert_tag :label, :content => /User Misc/,
72 assert_tag :label, :content => /User Misc/,
80 :child => { :tag => 'input', :attributes => { :name => 'member[user_ids][]', :value => '8' } }
73 :child => { :tag => 'input', :attributes => { :name => 'member[user_ids][]', :value => '8' } }
81 end
74 end
82 end
75 end
@@ -1,187 +1,144
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 'messages_controller'
19 require 'messages_controller'
20
20
21 # Re-raise errors caught by the controller.
21 # Re-raise errors caught by the controller.
22 class MessagesController; def rescue_action(e) raise e end; end
22 class MessagesController; def rescue_action(e) raise e end; end
23
23
24 class MessagesControllerTest < ActionController::TestCase
24 class MessagesControllerTest < ActionController::TestCase
25 fixtures :projects, :users, :members, :member_roles, :roles, :boards, :messages, :enabled_modules
25 fixtures :projects, :users, :members, :member_roles, :roles, :boards, :messages, :enabled_modules
26
26
27 def setup
27 def setup
28 @controller = MessagesController.new
28 @controller = MessagesController.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_routing
35 assert_routing(
36 {:method => :get, :path => '/boards/22/topics/2'},
37 :controller => 'messages', :action => 'show', :id => '2', :board_id => '22'
38 )
39 end
40
41 def test_show
34 def test_show
42 get :show, :board_id => 1, :id => 1
35 get :show, :board_id => 1, :id => 1
43 assert_response :success
36 assert_response :success
44 assert_template 'show'
37 assert_template 'show'
45 assert_not_nil assigns(:board)
38 assert_not_nil assigns(:board)
46 assert_not_nil assigns(:project)
39 assert_not_nil assigns(:project)
47 assert_not_nil assigns(:topic)
40 assert_not_nil assigns(:topic)
48 end
41 end
49
42
50 def test_show_with_pagination
43 def test_show_with_pagination
51 message = Message.find(1)
44 message = Message.find(1)
52 assert_difference 'Message.count', 30 do
45 assert_difference 'Message.count', 30 do
53 30.times do
46 30.times do
54 message.children << Message.new(:subject => 'Reply', :content => 'Reply body', :author_id => 2, :board_id => 1)
47 message.children << Message.new(:subject => 'Reply', :content => 'Reply body', :author_id => 2, :board_id => 1)
55 end
48 end
56 end
49 end
57 get :show, :board_id => 1, :id => 1, :r => message.children.last(:order => 'id').id
50 get :show, :board_id => 1, :id => 1, :r => message.children.last(:order => 'id').id
58 assert_response :success
51 assert_response :success
59 assert_template 'show'
52 assert_template 'show'
60 replies = assigns(:replies)
53 replies = assigns(:replies)
61 assert_not_nil replies
54 assert_not_nil replies
62 assert !replies.include?(message.children.first(:order => 'id'))
55 assert !replies.include?(message.children.first(:order => 'id'))
63 assert replies.include?(message.children.last(:order => 'id'))
56 assert replies.include?(message.children.last(:order => 'id'))
64 end
57 end
65
58
66 def test_show_with_reply_permission
59 def test_show_with_reply_permission
67 @request.session[:user_id] = 2
60 @request.session[:user_id] = 2
68 get :show, :board_id => 1, :id => 1
61 get :show, :board_id => 1, :id => 1
69 assert_response :success
62 assert_response :success
70 assert_template 'show'
63 assert_template 'show'
71 assert_tag :div, :attributes => { :id => 'reply' },
64 assert_tag :div, :attributes => { :id => 'reply' },
72 :descendant => { :tag => 'textarea', :attributes => { :id => 'message_content' } }
65 :descendant => { :tag => 'textarea', :attributes => { :id => 'message_content' } }
73 end
66 end
74
67
75 def test_show_message_not_found
68 def test_show_message_not_found
76 get :show, :board_id => 1, :id => 99999
69 get :show, :board_id => 1, :id => 99999
77 assert_response 404
70 assert_response 404
78 end
71 end
79
72
80 def test_new_routing
81 assert_routing(
82 {:method => :get, :path => '/boards/lala/topics/new'},
83 :controller => 'messages', :action => 'new', :board_id => 'lala'
84 )
85 assert_recognizes(#TODO: POST to collection, need to adjust form accordingly
86 {:controller => 'messages', :action => 'new', :board_id => 'lala'},
87 {:method => :post, :path => '/boards/lala/topics/new'}
88 )
89 end
90
91 def test_get_new
73 def test_get_new
92 @request.session[:user_id] = 2
74 @request.session[:user_id] = 2
93 get :new, :board_id => 1
75 get :new, :board_id => 1
94 assert_response :success
76 assert_response :success
95 assert_template 'new'
77 assert_template 'new'
96 end
78 end
97
79
98 def test_post_new
80 def test_post_new
99 @request.session[:user_id] = 2
81 @request.session[:user_id] = 2
100 ActionMailer::Base.deliveries.clear
82 ActionMailer::Base.deliveries.clear
101 Setting.notified_events = ['message_posted']
83 Setting.notified_events = ['message_posted']
102
84
103 post :new, :board_id => 1,
85 post :new, :board_id => 1,
104 :message => { :subject => 'Test created message',
86 :message => { :subject => 'Test created message',
105 :content => 'Message body'}
87 :content => 'Message body'}
106 message = Message.find_by_subject('Test created message')
88 message = Message.find_by_subject('Test created message')
107 assert_not_nil message
89 assert_not_nil message
108 assert_redirected_to "boards/1/topics/#{message.to_param}"
90 assert_redirected_to "boards/1/topics/#{message.to_param}"
109 assert_equal 'Message body', message.content
91 assert_equal 'Message body', message.content
110 assert_equal 2, message.author_id
92 assert_equal 2, message.author_id
111 assert_equal 1, message.board_id
93 assert_equal 1, message.board_id
112
94
113 mail = ActionMailer::Base.deliveries.last
95 mail = ActionMailer::Base.deliveries.last
114 assert_kind_of TMail::Mail, mail
96 assert_kind_of TMail::Mail, mail
115 assert_equal "[#{message.board.project.name} - #{message.board.name} - msg#{message.root.id}] Test created message", mail.subject
97 assert_equal "[#{message.board.project.name} - #{message.board.name} - msg#{message.root.id}] Test created message", mail.subject
116 assert mail.body.include?('Message body')
98 assert mail.body.include?('Message body')
117 # author
99 # author
118 assert mail.bcc.include?('jsmith@somenet.foo')
100 assert mail.bcc.include?('jsmith@somenet.foo')
119 # project member
101 # project member
120 assert mail.bcc.include?('dlopper@somenet.foo')
102 assert mail.bcc.include?('dlopper@somenet.foo')
121 end
103 end
122
104
123 def test_edit_routing
124 assert_routing(
125 {:method => :get, :path => '/boards/lala/topics/22/edit'},
126 :controller => 'messages', :action => 'edit', :board_id => 'lala', :id => '22'
127 )
128 assert_recognizes( #TODO: use PUT to topic_path, modify form accordingly
129 {:controller => 'messages', :action => 'edit', :board_id => 'lala', :id => '22'},
130 {:method => :post, :path => '/boards/lala/topics/22/edit'}
131 )
132 end
133
134 def test_get_edit
105 def test_get_edit
135 @request.session[:user_id] = 2
106 @request.session[:user_id] = 2
136 get :edit, :board_id => 1, :id => 1
107 get :edit, :board_id => 1, :id => 1
137 assert_response :success
108 assert_response :success
138 assert_template 'edit'
109 assert_template 'edit'
139 end
110 end
140
111
141 def test_post_edit
112 def test_post_edit
142 @request.session[:user_id] = 2
113 @request.session[:user_id] = 2
143 post :edit, :board_id => 1, :id => 1,
114 post :edit, :board_id => 1, :id => 1,
144 :message => { :subject => 'New subject',
115 :message => { :subject => 'New subject',
145 :content => 'New body'}
116 :content => 'New body'}
146 assert_redirected_to 'boards/1/topics/1'
117 assert_redirected_to 'boards/1/topics/1'
147 message = Message.find(1)
118 message = Message.find(1)
148 assert_equal 'New subject', message.subject
119 assert_equal 'New subject', message.subject
149 assert_equal 'New body', message.content
120 assert_equal 'New body', message.content
150 end
121 end
151
122
152 def test_reply_routing
153 assert_recognizes(
154 {:controller => 'messages', :action => 'reply', :board_id => '22', :id => '555'},
155 {:method => :post, :path => '/boards/22/topics/555/replies'}
156 )
157 end
158
159 def test_reply
123 def test_reply
160 @request.session[:user_id] = 2
124 @request.session[:user_id] = 2
161 post :reply, :board_id => 1, :id => 1, :reply => { :content => 'This is a test reply', :subject => 'Test reply' }
125 post :reply, :board_id => 1, :id => 1, :reply => { :content => 'This is a test reply', :subject => 'Test reply' }
162 reply = Message.find(:first, :order => 'id DESC')
126 reply = Message.find(:first, :order => 'id DESC')
163 assert_redirected_to "boards/1/topics/1?r=#{reply.id}"
127 assert_redirected_to "boards/1/topics/1?r=#{reply.id}"
164 assert Message.find_by_subject('Test reply')
128 assert Message.find_by_subject('Test reply')
165 end
129 end
166
130
167 def test_destroy_routing
168 assert_recognizes(#TODO: use DELETE to topic_path, adjust form accordingly
169 {:controller => 'messages', :action => 'destroy', :board_id => '22', :id => '555'},
170 {:method => :post, :path => '/boards/22/topics/555/destroy'}
171 )
172 end
173
174 def test_destroy_topic
131 def test_destroy_topic
175 @request.session[:user_id] = 2
132 @request.session[:user_id] = 2
176 post :destroy, :board_id => 1, :id => 1
133 post :destroy, :board_id => 1, :id => 1
177 assert_redirected_to 'projects/ecookbook/boards/1'
134 assert_redirected_to 'projects/ecookbook/boards/1'
178 assert_nil Message.find_by_id(1)
135 assert_nil Message.find_by_id(1)
179 end
136 end
180
137
181 def test_quote
138 def test_quote
182 @request.session[:user_id] = 2
139 @request.session[:user_id] = 2
183 xhr :get, :quote, :board_id => 1, :id => 3
140 xhr :get, :quote, :board_id => 1, :id => 3
184 assert_response :success
141 assert_response :success
185 assert_select_rjs :show, 'reply'
142 assert_select_rjs :show, 'reply'
186 end
143 end
187 end
144 end
@@ -1,224 +1,160
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 'news_controller'
19 require 'news_controller'
20
20
21 # Re-raise errors caught by the controller.
21 # Re-raise errors caught by the controller.
22 class NewsController; def rescue_action(e) raise e end; end
22 class NewsController; def rescue_action(e) raise e end; end
23
23
24 class NewsControllerTest < ActionController::TestCase
24 class NewsControllerTest < ActionController::TestCase
25 fixtures :projects, :users, :roles, :members, :member_roles, :enabled_modules, :news, :comments
25 fixtures :projects, :users, :roles, :members, :member_roles, :enabled_modules, :news, :comments
26
26
27 def setup
27 def setup
28 @controller = NewsController.new
28 @controller = NewsController.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_index_routing
35 assert_routing(
36 {:method => :get, :path => '/news'},
37 :controller => 'news', :action => 'index'
38 )
39 end
40
41 def test_index_routing_formatted
42 assert_routing(
43 {:method => :get, :path => '/news.atom'},
44 :controller => 'news', :action => 'index', :format => 'atom'
45 )
46 end
47
48 def test_index
34 def test_index
49 get :index
35 get :index
50 assert_response :success
36 assert_response :success
51 assert_template 'index'
37 assert_template 'index'
52 assert_not_nil assigns(:newss)
38 assert_not_nil assigns(:newss)
53 assert_nil assigns(:project)
39 assert_nil assigns(:project)
54 end
40 end
55
41
56 def test_index_with_project_routing
57 assert_routing(
58 {:method => :get, :path => '/projects/567/news'},
59 :controller => 'news', :action => 'index', :project_id => '567'
60 )
61 end
62
63 def test_index_with_project_routing_formatted
64 assert_routing(
65 {:method => :get, :path => '/projects/567/news.atom'},
66 :controller => 'news', :action => 'index', :project_id => '567', :format => 'atom'
67 )
68 end
69
70 def test_index_with_project
42 def test_index_with_project
71 get :index, :project_id => 1
43 get :index, :project_id => 1
72 assert_response :success
44 assert_response :success
73 assert_template 'index'
45 assert_template 'index'
74 assert_not_nil assigns(:newss)
46 assert_not_nil assigns(:newss)
75 end
47 end
76
48
77 def test_show_routing
78 assert_routing(
79 {:method => :get, :path => '/news/2'},
80 :controller => 'news', :action => 'show', :id => '2'
81 )
82 end
83
84 def test_show
49 def test_show
85 get :show, :id => 1
50 get :show, :id => 1
86 assert_response :success
51 assert_response :success
87 assert_template 'show'
52 assert_template 'show'
88 assert_tag :tag => 'h2', :content => /eCookbook first release/
53 assert_tag :tag => 'h2', :content => /eCookbook first release/
89 end
54 end
90
55
91 def test_show_not_found
56 def test_show_not_found
92 get :show, :id => 999
57 get :show, :id => 999
93 assert_response 404
58 assert_response 404
94 end
59 end
95
60
96 def test_new_routing
97 assert_routing(
98 {:method => :get, :path => '/projects/567/news/new'},
99 :controller => 'news', :action => 'new', :project_id => '567'
100 )
101 assert_recognizes(
102 {:controller => 'news', :action => 'new', :project_id => '567'},
103 {:method => :post, :path => '/projects/567/news'}
104 )
105 end
106
107 def test_get_new
61 def test_get_new
108 @request.session[:user_id] = 2
62 @request.session[:user_id] = 2
109 get :new, :project_id => 1
63 get :new, :project_id => 1
110 assert_response :success
64 assert_response :success
111 assert_template 'new'
65 assert_template 'new'
112 end
66 end
113
67
114 def test_post_new
68 def test_post_new
115 ActionMailer::Base.deliveries.clear
69 ActionMailer::Base.deliveries.clear
116 Setting.notified_events << 'news_added'
70 Setting.notified_events << 'news_added'
117
71
118 @request.session[:user_id] = 2
72 @request.session[:user_id] = 2
119 post :new, :project_id => 1, :news => { :title => 'NewsControllerTest',
73 post :new, :project_id => 1, :news => { :title => 'NewsControllerTest',
120 :description => 'This is the description',
74 :description => 'This is the description',
121 :summary => '' }
75 :summary => '' }
122 assert_redirected_to 'projects/ecookbook/news'
76 assert_redirected_to 'projects/ecookbook/news'
123
77
124 news = News.find_by_title('NewsControllerTest')
78 news = News.find_by_title('NewsControllerTest')
125 assert_not_nil news
79 assert_not_nil news
126 assert_equal 'This is the description', news.description
80 assert_equal 'This is the description', news.description
127 assert_equal User.find(2), news.author
81 assert_equal User.find(2), news.author
128 assert_equal Project.find(1), news.project
82 assert_equal Project.find(1), news.project
129 assert_equal 1, ActionMailer::Base.deliveries.size
83 assert_equal 1, ActionMailer::Base.deliveries.size
130 end
84 end
131
85
132 def test_edit_routing
133 assert_routing(
134 {:method => :get, :path => '/news/234'},
135 :controller => 'news', :action => 'show', :id => '234'
136 )
137 assert_recognizes(#TODO: PUT to news URI instead, need to modify form
138 {:controller => 'news', :action => 'edit', :id => '567'},
139 {:method => :post, :path => '/news/567/edit'}
140 )
141 end
142
143 def test_get_edit
86 def test_get_edit
144 @request.session[:user_id] = 2
87 @request.session[:user_id] = 2
145 get :edit, :id => 1
88 get :edit, :id => 1
146 assert_response :success
89 assert_response :success
147 assert_template 'edit'
90 assert_template 'edit'
148 end
91 end
149
92
150 def test_post_edit
93 def test_post_edit
151 @request.session[:user_id] = 2
94 @request.session[:user_id] = 2
152 post :edit, :id => 1, :news => { :description => 'Description changed by test_post_edit' }
95 post :edit, :id => 1, :news => { :description => 'Description changed by test_post_edit' }
153 assert_redirected_to 'news/1'
96 assert_redirected_to 'news/1'
154 news = News.find(1)
97 news = News.find(1)
155 assert_equal 'Description changed by test_post_edit', news.description
98 assert_equal 'Description changed by test_post_edit', news.description
156 end
99 end
157
100
158 def test_post_new_with_validation_failure
101 def test_post_new_with_validation_failure
159 @request.session[:user_id] = 2
102 @request.session[:user_id] = 2
160 post :new, :project_id => 1, :news => { :title => '',
103 post :new, :project_id => 1, :news => { :title => '',
161 :description => 'This is the description',
104 :description => 'This is the description',
162 :summary => '' }
105 :summary => '' }
163 assert_response :success
106 assert_response :success
164 assert_template 'new'
107 assert_template 'new'
165 assert_not_nil assigns(:news)
108 assert_not_nil assigns(:news)
166 assert assigns(:news).new_record?
109 assert assigns(:news).new_record?
167 assert_tag :tag => 'div', :attributes => { :id => 'errorExplanation' },
110 assert_tag :tag => 'div', :attributes => { :id => 'errorExplanation' },
168 :content => /1 error/
111 :content => /1 error/
169 end
112 end
170
113
171 def test_add_comment
114 def test_add_comment
172 @request.session[:user_id] = 2
115 @request.session[:user_id] = 2
173 post :add_comment, :id => 1, :comment => { :comments => 'This is a NewsControllerTest comment' }
116 post :add_comment, :id => 1, :comment => { :comments => 'This is a NewsControllerTest comment' }
174 assert_redirected_to 'news/1'
117 assert_redirected_to 'news/1'
175
118
176 comment = News.find(1).comments.find(:first, :order => 'created_on DESC')
119 comment = News.find(1).comments.find(:first, :order => 'created_on DESC')
177 assert_not_nil comment
120 assert_not_nil comment
178 assert_equal 'This is a NewsControllerTest comment', comment.comments
121 assert_equal 'This is a NewsControllerTest comment', comment.comments
179 assert_equal User.find(2), comment.author
122 assert_equal User.find(2), comment.author
180 end
123 end
181
124
182 def test_empty_comment_should_not_be_added
125 def test_empty_comment_should_not_be_added
183 @request.session[:user_id] = 2
126 @request.session[:user_id] = 2
184 assert_no_difference 'Comment.count' do
127 assert_no_difference 'Comment.count' do
185 post :add_comment, :id => 1, :comment => { :comments => '' }
128 post :add_comment, :id => 1, :comment => { :comments => '' }
186 assert_response :success
129 assert_response :success
187 assert_template 'show'
130 assert_template 'show'
188 end
131 end
189 end
132 end
190
133
191 def test_destroy_comment
134 def test_destroy_comment
192 comments_count = News.find(1).comments.size
135 comments_count = News.find(1).comments.size
193 @request.session[:user_id] = 2
136 @request.session[:user_id] = 2
194 post :destroy_comment, :id => 1, :comment_id => 2
137 post :destroy_comment, :id => 1, :comment_id => 2
195 assert_redirected_to 'news/1'
138 assert_redirected_to 'news/1'
196 assert_nil Comment.find_by_id(2)
139 assert_nil Comment.find_by_id(2)
197 assert_equal comments_count - 1, News.find(1).comments.size
140 assert_equal comments_count - 1, News.find(1).comments.size
198 end
141 end
199
142
200 def test_destroy_routing
201 assert_recognizes(#TODO: should use DELETE to news URI, need to change form
202 {:controller => 'news', :action => 'destroy', :id => '567'},
203 {:method => :post, :path => '/news/567/destroy'}
204 )
205 end
206
207 def test_destroy
143 def test_destroy
208 @request.session[:user_id] = 2
144 @request.session[:user_id] = 2
209 post :destroy, :id => 1
145 post :destroy, :id => 1
210 assert_redirected_to 'projects/ecookbook/news'
146 assert_redirected_to 'projects/ecookbook/news'
211 assert_nil News.find_by_id(1)
147 assert_nil News.find_by_id(1)
212 end
148 end
213
149
214 def test_preview
150 def test_preview
215 get :preview, :project_id => 1,
151 get :preview, :project_id => 1,
216 :news => {:title => '',
152 :news => {:title => '',
217 :description => 'News description',
153 :description => 'News description',
218 :summary => ''}
154 :summary => ''}
219 assert_response :success
155 assert_response :success
220 assert_template 'common/_preview'
156 assert_template 'common/_preview'
221 assert_tag :tag => 'fieldset', :attributes => { :class => 'preview' },
157 assert_tag :tag => 'fieldset', :attributes => { :class => 'preview' },
222 :content => /News description/
158 :content => /News description/
223 end
159 end
224 end
160 end
@@ -1,852 +1,712
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 'projects_controller'
19 require 'projects_controller'
20
20
21 # Re-raise errors caught by the controller.
21 # Re-raise errors caught by the controller.
22 class ProjectsController; def rescue_action(e) raise e end; end
22 class ProjectsController; def rescue_action(e) raise e end; end
23
23
24 class ProjectsControllerTest < ActionController::TestCase
24 class ProjectsControllerTest < ActionController::TestCase
25 fixtures :projects, :versions, :users, :roles, :members, :member_roles, :issues, :journals, :journal_details,
25 fixtures :projects, :versions, :users, :roles, :members, :member_roles, :issues, :journals, :journal_details,
26 :trackers, :projects_trackers, :issue_statuses, :enabled_modules, :enumerations, :boards, :messages,
26 :trackers, :projects_trackers, :issue_statuses, :enabled_modules, :enumerations, :boards, :messages,
27 :attachments, :custom_fields, :custom_values, :time_entries
27 :attachments, :custom_fields, :custom_values, :time_entries
28
28
29 def setup
29 def setup
30 @controller = ProjectsController.new
30 @controller = ProjectsController.new
31 @request = ActionController::TestRequest.new
31 @request = ActionController::TestRequest.new
32 @response = ActionController::TestResponse.new
32 @response = ActionController::TestResponse.new
33 @request.session[:user_id] = nil
33 @request.session[:user_id] = nil
34 Setting.default_language = 'en'
34 Setting.default_language = 'en'
35 end
35 end
36
36
37 def test_index_routing
38 assert_routing(
39 {:method => :get, :path => '/projects'},
40 :controller => 'projects', :action => 'index'
41 )
42 end
43
44 def test_index
37 def test_index
45 get :index
38 get :index
46 assert_response :success
39 assert_response :success
47 assert_template 'index'
40 assert_template 'index'
48 assert_not_nil assigns(:projects)
41 assert_not_nil assigns(:projects)
49
42
50 assert_tag :ul, :child => {:tag => 'li',
43 assert_tag :ul, :child => {:tag => 'li',
51 :descendant => {:tag => 'a', :content => 'eCookbook'},
44 :descendant => {:tag => 'a', :content => 'eCookbook'},
52 :child => { :tag => 'ul',
45 :child => { :tag => 'ul',
53 :descendant => { :tag => 'a',
46 :descendant => { :tag => 'a',
54 :content => 'Child of private child'
47 :content => 'Child of private child'
55 }
48 }
56 }
49 }
57 }
50 }
58
51
59 assert_no_tag :a, :content => /Private child of eCookbook/
52 assert_no_tag :a, :content => /Private child of eCookbook/
60 end
53 end
61
54
62 def test_index_atom_routing
63 assert_routing(
64 {:method => :get, :path => '/projects.atom'},
65 :controller => 'projects', :action => 'index', :format => 'atom'
66 )
67 end
68
69 def test_index_atom
55 def test_index_atom
70 get :index, :format => 'atom'
56 get :index, :format => 'atom'
71 assert_response :success
57 assert_response :success
72 assert_template 'common/feed.atom.rxml'
58 assert_template 'common/feed.atom.rxml'
73 assert_select 'feed>title', :text => 'Redmine: Latest projects'
59 assert_select 'feed>title', :text => 'Redmine: Latest projects'
74 assert_select 'feed>entry', :count => Project.count(:conditions => Project.visible_by(User.current))
60 assert_select 'feed>entry', :count => Project.count(:conditions => Project.visible_by(User.current))
75 end
61 end
76
62
77 def test_add_routing
78 assert_routing(
79 {:method => :get, :path => '/projects/new'},
80 :controller => 'projects', :action => 'add'
81 )
82 assert_recognizes(
83 {:controller => 'projects', :action => 'add'},
84 {:method => :post, :path => '/projects/new'}
85 )
86 assert_recognizes(
87 {:controller => 'projects', :action => 'add'},
88 {:method => :post, :path => '/projects'}
89 )
90 end
91
92 context "#add" do
63 context "#add" do
93 context "by admin user" do
64 context "by admin user" do
94 setup do
65 setup do
95 @request.session[:user_id] = 1
66 @request.session[:user_id] = 1
96 end
67 end
97
68
98 should "accept get" do
69 should "accept get" do
99 get :add
70 get :add
100 assert_response :success
71 assert_response :success
101 assert_template 'add'
72 assert_template 'add'
102 end
73 end
103
74
104 should "accept post" do
75 should "accept post" do
105 post :add, :project => { :name => "blog",
76 post :add, :project => { :name => "blog",
106 :description => "weblog",
77 :description => "weblog",
107 :identifier => "blog",
78 :identifier => "blog",
108 :is_public => 1,
79 :is_public => 1,
109 :custom_field_values => { '3' => 'Beta' }
80 :custom_field_values => { '3' => 'Beta' }
110 }
81 }
111 assert_redirected_to '/projects/blog/settings'
82 assert_redirected_to '/projects/blog/settings'
112
83
113 project = Project.find_by_name('blog')
84 project = Project.find_by_name('blog')
114 assert_kind_of Project, project
85 assert_kind_of Project, project
115 assert_equal 'weblog', project.description
86 assert_equal 'weblog', project.description
116 assert_equal true, project.is_public?
87 assert_equal true, project.is_public?
117 assert_nil project.parent
88 assert_nil project.parent
118 end
89 end
119
90
120 should "accept post with parent" do
91 should "accept post with parent" do
121 post :add, :project => { :name => "blog",
92 post :add, :project => { :name => "blog",
122 :description => "weblog",
93 :description => "weblog",
123 :identifier => "blog",
94 :identifier => "blog",
124 :is_public => 1,
95 :is_public => 1,
125 :custom_field_values => { '3' => 'Beta' },
96 :custom_field_values => { '3' => 'Beta' },
126 :parent_id => 1
97 :parent_id => 1
127 }
98 }
128 assert_redirected_to '/projects/blog/settings'
99 assert_redirected_to '/projects/blog/settings'
129
100
130 project = Project.find_by_name('blog')
101 project = Project.find_by_name('blog')
131 assert_kind_of Project, project
102 assert_kind_of Project, project
132 assert_equal Project.find(1), project.parent
103 assert_equal Project.find(1), project.parent
133 end
104 end
134 end
105 end
135
106
136 context "by non-admin user with add_project permission" do
107 context "by non-admin user with add_project permission" do
137 setup do
108 setup do
138 Role.non_member.add_permission! :add_project
109 Role.non_member.add_permission! :add_project
139 @request.session[:user_id] = 9
110 @request.session[:user_id] = 9
140 end
111 end
141
112
142 should "accept get" do
113 should "accept get" do
143 get :add
114 get :add
144 assert_response :success
115 assert_response :success
145 assert_template 'add'
116 assert_template 'add'
146 assert_no_tag :select, :attributes => {:name => 'project[parent_id]'}
117 assert_no_tag :select, :attributes => {:name => 'project[parent_id]'}
147 end
118 end
148
119
149 should "accept post" do
120 should "accept post" do
150 post :add, :project => { :name => "blog",
121 post :add, :project => { :name => "blog",
151 :description => "weblog",
122 :description => "weblog",
152 :identifier => "blog",
123 :identifier => "blog",
153 :is_public => 1,
124 :is_public => 1,
154 :custom_field_values => { '3' => 'Beta' }
125 :custom_field_values => { '3' => 'Beta' }
155 }
126 }
156
127
157 assert_redirected_to '/projects/blog/settings'
128 assert_redirected_to '/projects/blog/settings'
158
129
159 project = Project.find_by_name('blog')
130 project = Project.find_by_name('blog')
160 assert_kind_of Project, project
131 assert_kind_of Project, project
161 assert_equal 'weblog', project.description
132 assert_equal 'weblog', project.description
162 assert_equal true, project.is_public?
133 assert_equal true, project.is_public?
163
134
164 # User should be added as a project member
135 # User should be added as a project member
165 assert User.find(9).member_of?(project)
136 assert User.find(9).member_of?(project)
166 assert_equal 1, project.members.size
137 assert_equal 1, project.members.size
167 end
138 end
168
139
169 should "fail with parent_id" do
140 should "fail with parent_id" do
170 assert_no_difference 'Project.count' do
141 assert_no_difference 'Project.count' do
171 post :add, :project => { :name => "blog",
142 post :add, :project => { :name => "blog",
172 :description => "weblog",
143 :description => "weblog",
173 :identifier => "blog",
144 :identifier => "blog",
174 :is_public => 1,
145 :is_public => 1,
175 :custom_field_values => { '3' => 'Beta' },
146 :custom_field_values => { '3' => 'Beta' },
176 :parent_id => 1
147 :parent_id => 1
177 }
148 }
178 end
149 end
179 assert_response :success
150 assert_response :success
180 project = assigns(:project)
151 project = assigns(:project)
181 assert_kind_of Project, project
152 assert_kind_of Project, project
182 assert_not_nil project.errors.on(:parent_id)
153 assert_not_nil project.errors.on(:parent_id)
183 end
154 end
184 end
155 end
185
156
186 context "by non-admin user with add_subprojects permission" do
157 context "by non-admin user with add_subprojects permission" do
187 setup do
158 setup do
188 Role.find(1).remove_permission! :add_project
159 Role.find(1).remove_permission! :add_project
189 Role.find(1).add_permission! :add_subprojects
160 Role.find(1).add_permission! :add_subprojects
190 @request.session[:user_id] = 2
161 @request.session[:user_id] = 2
191 end
162 end
192
163
193 should "accept get" do
164 should "accept get" do
194 get :add, :parent_id => 'ecookbook'
165 get :add, :parent_id => 'ecookbook'
195 assert_response :success
166 assert_response :success
196 assert_template 'add'
167 assert_template 'add'
197 # parent project selected
168 # parent project selected
198 assert_tag :select, :attributes => {:name => 'project[parent_id]'},
169 assert_tag :select, :attributes => {:name => 'project[parent_id]'},
199 :child => {:tag => 'option', :attributes => {:value => '1', :selected => 'selected'}}
170 :child => {:tag => 'option', :attributes => {:value => '1', :selected => 'selected'}}
200 # no empty value
171 # no empty value
201 assert_no_tag :select, :attributes => {:name => 'project[parent_id]'},
172 assert_no_tag :select, :attributes => {:name => 'project[parent_id]'},
202 :child => {:tag => 'option', :attributes => {:value => ''}}
173 :child => {:tag => 'option', :attributes => {:value => ''}}
203 end
174 end
204
175
205 should "accept post with parent_id" do
176 should "accept post with parent_id" do
206 post :add, :project => { :name => "blog",
177 post :add, :project => { :name => "blog",
207 :description => "weblog",
178 :description => "weblog",
208 :identifier => "blog",
179 :identifier => "blog",
209 :is_public => 1,
180 :is_public => 1,
210 :custom_field_values => { '3' => 'Beta' },
181 :custom_field_values => { '3' => 'Beta' },
211 :parent_id => 1
182 :parent_id => 1
212 }
183 }
213 assert_redirected_to '/projects/blog/settings'
184 assert_redirected_to '/projects/blog/settings'
214 project = Project.find_by_name('blog')
185 project = Project.find_by_name('blog')
215 end
186 end
216
187
217 should "fail without parent_id" do
188 should "fail without parent_id" do
218 assert_no_difference 'Project.count' do
189 assert_no_difference 'Project.count' do
219 post :add, :project => { :name => "blog",
190 post :add, :project => { :name => "blog",
220 :description => "weblog",
191 :description => "weblog",
221 :identifier => "blog",
192 :identifier => "blog",
222 :is_public => 1,
193 :is_public => 1,
223 :custom_field_values => { '3' => 'Beta' }
194 :custom_field_values => { '3' => 'Beta' }
224 }
195 }
225 end
196 end
226 assert_response :success
197 assert_response :success
227 project = assigns(:project)
198 project = assigns(:project)
228 assert_kind_of Project, project
199 assert_kind_of Project, project
229 assert_not_nil project.errors.on(:parent_id)
200 assert_not_nil project.errors.on(:parent_id)
230 end
201 end
231
202
232 should "fail with unauthorized parent_id" do
203 should "fail with unauthorized parent_id" do
233 assert !User.find(2).member_of?(Project.find(6))
204 assert !User.find(2).member_of?(Project.find(6))
234 assert_no_difference 'Project.count' do
205 assert_no_difference 'Project.count' do
235 post :add, :project => { :name => "blog",
206 post :add, :project => { :name => "blog",
236 :description => "weblog",
207 :description => "weblog",
237 :identifier => "blog",
208 :identifier => "blog",
238 :is_public => 1,
209 :is_public => 1,
239 :custom_field_values => { '3' => 'Beta' },
210 :custom_field_values => { '3' => 'Beta' },
240 :parent_id => 6
211 :parent_id => 6
241 }
212 }
242 end
213 end
243 assert_response :success
214 assert_response :success
244 project = assigns(:project)
215 project = assigns(:project)
245 assert_kind_of Project, project
216 assert_kind_of Project, project
246 assert_not_nil project.errors.on(:parent_id)
217 assert_not_nil project.errors.on(:parent_id)
247 end
218 end
248 end
219 end
249 end
220 end
250
221
251 def test_show_routing
252 assert_routing(
253 {:method => :get, :path => '/projects/test'},
254 :controller => 'projects', :action => 'show', :id => 'test'
255 )
256 end
257
258 def test_show_by_id
222 def test_show_by_id
259 get :show, :id => 1
223 get :show, :id => 1
260 assert_response :success
224 assert_response :success
261 assert_template 'show'
225 assert_template 'show'
262 assert_not_nil assigns(:project)
226 assert_not_nil assigns(:project)
263 end
227 end
264
228
265 def test_show_by_identifier
229 def test_show_by_identifier
266 get :show, :id => 'ecookbook'
230 get :show, :id => 'ecookbook'
267 assert_response :success
231 assert_response :success
268 assert_template 'show'
232 assert_template 'show'
269 assert_not_nil assigns(:project)
233 assert_not_nil assigns(:project)
270 assert_equal Project.find_by_identifier('ecookbook'), assigns(:project)
234 assert_equal Project.find_by_identifier('ecookbook'), assigns(:project)
271 end
235 end
272
236
273 def test_show_should_not_fail_when_custom_values_are_nil
237 def test_show_should_not_fail_when_custom_values_are_nil
274 project = Project.find_by_identifier('ecookbook')
238 project = Project.find_by_identifier('ecookbook')
275 project.custom_values.first.update_attribute(:value, nil)
239 project.custom_values.first.update_attribute(:value, nil)
276 get :show, :id => 'ecookbook'
240 get :show, :id => 'ecookbook'
277 assert_response :success
241 assert_response :success
278 assert_template 'show'
242 assert_template 'show'
279 assert_not_nil assigns(:project)
243 assert_not_nil assigns(:project)
280 assert_equal Project.find_by_identifier('ecookbook'), assigns(:project)
244 assert_equal Project.find_by_identifier('ecookbook'), assigns(:project)
281 end
245 end
282
246
283 def test_private_subprojects_hidden
247 def test_private_subprojects_hidden
284 get :show, :id => 'ecookbook'
248 get :show, :id => 'ecookbook'
285 assert_response :success
249 assert_response :success
286 assert_template 'show'
250 assert_template 'show'
287 assert_no_tag :tag => 'a', :content => /Private child/
251 assert_no_tag :tag => 'a', :content => /Private child/
288 end
252 end
289
253
290 def test_private_subprojects_visible
254 def test_private_subprojects_visible
291 @request.session[:user_id] = 2 # manager who is a member of the private subproject
255 @request.session[:user_id] = 2 # manager who is a member of the private subproject
292 get :show, :id => 'ecookbook'
256 get :show, :id => 'ecookbook'
293 assert_response :success
257 assert_response :success
294 assert_template 'show'
258 assert_template 'show'
295 assert_tag :tag => 'a', :content => /Private child/
259 assert_tag :tag => 'a', :content => /Private child/
296 end
260 end
297
261
298 def test_settings_routing
299 assert_routing(
300 {:method => :get, :path => '/projects/4223/settings'},
301 :controller => 'projects', :action => 'settings', :id => '4223'
302 )
303 assert_routing(
304 {:method => :get, :path => '/projects/4223/settings/members'},
305 :controller => 'projects', :action => 'settings', :id => '4223', :tab => 'members'
306 )
307 end
308
309 def test_settings
262 def test_settings
310 @request.session[:user_id] = 2 # manager
263 @request.session[:user_id] = 2 # manager
311 get :settings, :id => 1
264 get :settings, :id => 1
312 assert_response :success
265 assert_response :success
313 assert_template 'settings'
266 assert_template 'settings'
314 end
267 end
315
268
316 def test_edit_routing
317 assert_routing(
318 {:method => :post, :path => '/projects/4223/edit'},
319 :controller => 'projects', :action => 'edit', :id => '4223'
320 )
321 end
322
323 def test_edit
269 def test_edit
324 @request.session[:user_id] = 2 # manager
270 @request.session[:user_id] = 2 # manager
325 post :edit, :id => 1, :project => {:name => 'Test changed name',
271 post :edit, :id => 1, :project => {:name => 'Test changed name',
326 :issue_custom_field_ids => ['']}
272 :issue_custom_field_ids => ['']}
327 assert_redirected_to 'projects/ecookbook/settings'
273 assert_redirected_to 'projects/ecookbook/settings'
328 project = Project.find(1)
274 project = Project.find(1)
329 assert_equal 'Test changed name', project.name
275 assert_equal 'Test changed name', project.name
330 end
276 end
331
277
332 def test_destroy_routing
333 assert_routing(
334 {:method => :get, :path => '/projects/567/destroy'},
335 :controller => 'projects', :action => 'destroy', :id => '567'
336 )
337 assert_routing(
338 #TODO: use DELETE and update form
339 {:method => :post, :path => 'projects/64/destroy'},
340 :controller => 'projects', :action => 'destroy', :id => '64'
341 )
342 end
343
344 def test_get_destroy
278 def test_get_destroy
345 @request.session[:user_id] = 1 # admin
279 @request.session[:user_id] = 1 # admin
346 get :destroy, :id => 1
280 get :destroy, :id => 1
347 assert_response :success
281 assert_response :success
348 assert_template 'destroy'
282 assert_template 'destroy'
349 assert_not_nil Project.find_by_id(1)
283 assert_not_nil Project.find_by_id(1)
350 end
284 end
351
285
352 def test_post_destroy
286 def test_post_destroy
353 @request.session[:user_id] = 1 # admin
287 @request.session[:user_id] = 1 # admin
354 post :destroy, :id => 1, :confirm => 1
288 post :destroy, :id => 1, :confirm => 1
355 assert_redirected_to 'admin/projects'
289 assert_redirected_to 'admin/projects'
356 assert_nil Project.find_by_id(1)
290 assert_nil Project.find_by_id(1)
357 end
291 end
358
292
359 def test_add_file
293 def test_add_file
360 set_tmp_attachments_directory
294 set_tmp_attachments_directory
361 @request.session[:user_id] = 2
295 @request.session[:user_id] = 2
362 Setting.notified_events = ['file_added']
296 Setting.notified_events = ['file_added']
363 ActionMailer::Base.deliveries.clear
297 ActionMailer::Base.deliveries.clear
364
298
365 assert_difference 'Attachment.count' do
299 assert_difference 'Attachment.count' do
366 post :add_file, :id => 1, :version_id => '',
300 post :add_file, :id => 1, :version_id => '',
367 :attachments => {'1' => {'file' => uploaded_test_file('testfile.txt', 'text/plain')}}
301 :attachments => {'1' => {'file' => uploaded_test_file('testfile.txt', 'text/plain')}}
368 end
302 end
369 assert_redirected_to 'projects/ecookbook/files'
303 assert_redirected_to 'projects/ecookbook/files'
370 a = Attachment.find(:first, :order => 'created_on DESC')
304 a = Attachment.find(:first, :order => 'created_on DESC')
371 assert_equal 'testfile.txt', a.filename
305 assert_equal 'testfile.txt', a.filename
372 assert_equal Project.find(1), a.container
306 assert_equal Project.find(1), a.container
373
307
374 mail = ActionMailer::Base.deliveries.last
308 mail = ActionMailer::Base.deliveries.last
375 assert_kind_of TMail::Mail, mail
309 assert_kind_of TMail::Mail, mail
376 assert_equal "[eCookbook] New file", mail.subject
310 assert_equal "[eCookbook] New file", mail.subject
377 assert mail.body.include?('testfile.txt')
311 assert mail.body.include?('testfile.txt')
378 end
312 end
379
313
380 def test_add_file_routing
381 assert_routing(
382 {:method => :get, :path => '/projects/33/files/new'},
383 :controller => 'projects', :action => 'add_file', :id => '33'
384 )
385 assert_routing(
386 {:method => :post, :path => '/projects/33/files/new'},
387 :controller => 'projects', :action => 'add_file', :id => '33'
388 )
389 end
390
391 def test_add_version_file
314 def test_add_version_file
392 set_tmp_attachments_directory
315 set_tmp_attachments_directory
393 @request.session[:user_id] = 2
316 @request.session[:user_id] = 2
394 Setting.notified_events = ['file_added']
317 Setting.notified_events = ['file_added']
395
318
396 assert_difference 'Attachment.count' do
319 assert_difference 'Attachment.count' do
397 post :add_file, :id => 1, :version_id => '2',
320 post :add_file, :id => 1, :version_id => '2',
398 :attachments => {'1' => {'file' => uploaded_test_file('testfile.txt', 'text/plain')}}
321 :attachments => {'1' => {'file' => uploaded_test_file('testfile.txt', 'text/plain')}}
399 end
322 end
400 assert_redirected_to 'projects/ecookbook/files'
323 assert_redirected_to 'projects/ecookbook/files'
401 a = Attachment.find(:first, :order => 'created_on DESC')
324 a = Attachment.find(:first, :order => 'created_on DESC')
402 assert_equal 'testfile.txt', a.filename
325 assert_equal 'testfile.txt', a.filename
403 assert_equal Version.find(2), a.container
326 assert_equal Version.find(2), a.container
404 end
327 end
405
328
406 def test_list_files
329 def test_list_files
407 get :list_files, :id => 1
330 get :list_files, :id => 1
408 assert_response :success
331 assert_response :success
409 assert_template 'list_files'
332 assert_template 'list_files'
410 assert_not_nil assigns(:containers)
333 assert_not_nil assigns(:containers)
411
334
412 # file attached to the project
335 # file attached to the project
413 assert_tag :a, :content => 'project_file.zip',
336 assert_tag :a, :content => 'project_file.zip',
414 :attributes => { :href => '/attachments/download/8/project_file.zip' }
337 :attributes => { :href => '/attachments/download/8/project_file.zip' }
415
338
416 # file attached to a project's version
339 # file attached to a project's version
417 assert_tag :a, :content => 'version_file.zip',
340 assert_tag :a, :content => 'version_file.zip',
418 :attributes => { :href => '/attachments/download/9/version_file.zip' }
341 :attributes => { :href => '/attachments/download/9/version_file.zip' }
419 end
342 end
420
343
421 def test_list_files_routing
422 assert_routing(
423 {:method => :get, :path => '/projects/33/files'},
424 :controller => 'projects', :action => 'list_files', :id => '33'
425 )
426 end
427
428 def test_roadmap_routing
429 assert_routing(
430 {:method => :get, :path => 'projects/33/roadmap'},
431 :controller => 'projects', :action => 'roadmap', :id => '33'
432 )
433 end
434
435 def test_roadmap
344 def test_roadmap
436 get :roadmap, :id => 1
345 get :roadmap, :id => 1
437 assert_response :success
346 assert_response :success
438 assert_template 'roadmap'
347 assert_template 'roadmap'
439 assert_not_nil assigns(:versions)
348 assert_not_nil assigns(:versions)
440 # Version with no date set appears
349 # Version with no date set appears
441 assert assigns(:versions).include?(Version.find(3))
350 assert assigns(:versions).include?(Version.find(3))
442 # Completed version doesn't appear
351 # Completed version doesn't appear
443 assert !assigns(:versions).include?(Version.find(1))
352 assert !assigns(:versions).include?(Version.find(1))
444 end
353 end
445
354
446 def test_roadmap_with_completed_versions
355 def test_roadmap_with_completed_versions
447 get :roadmap, :id => 1, :completed => 1
356 get :roadmap, :id => 1, :completed => 1
448 assert_response :success
357 assert_response :success
449 assert_template 'roadmap'
358 assert_template 'roadmap'
450 assert_not_nil assigns(:versions)
359 assert_not_nil assigns(:versions)
451 # Version with no date set appears
360 # Version with no date set appears
452 assert assigns(:versions).include?(Version.find(3))
361 assert assigns(:versions).include?(Version.find(3))
453 # Completed version appears
362 # Completed version appears
454 assert assigns(:versions).include?(Version.find(1))
363 assert assigns(:versions).include?(Version.find(1))
455 end
364 end
456
365
457 def test_roadmap_showing_subprojects_versions
366 def test_roadmap_showing_subprojects_versions
458 get :roadmap, :id => 1, :with_subprojects => 1
367 get :roadmap, :id => 1, :with_subprojects => 1
459 assert_response :success
368 assert_response :success
460 assert_template 'roadmap'
369 assert_template 'roadmap'
461 assert_not_nil assigns(:versions)
370 assert_not_nil assigns(:versions)
462 # Version on subproject appears
371 # Version on subproject appears
463 assert assigns(:versions).include?(Version.find(4))
372 assert assigns(:versions).include?(Version.find(4))
464 end
373 end
465
466 def test_project_activity_routing
467 assert_routing(
468 {:method => :get, :path => '/projects/1/activity'},
469 :controller => 'projects', :action => 'activity', :id => '1'
470 )
471 end
472
473 def test_project_activity_atom_routing
474 assert_routing(
475 {:method => :get, :path => '/projects/1/activity.atom'},
476 :controller => 'projects', :action => 'activity', :id => '1', :format => 'atom'
477 )
478 end
479
480 def test_project_activity
374 def test_project_activity
481 get :activity, :id => 1, :with_subprojects => 0
375 get :activity, :id => 1, :with_subprojects => 0
482 assert_response :success
376 assert_response :success
483 assert_template 'activity'
377 assert_template 'activity'
484 assert_not_nil assigns(:events_by_day)
378 assert_not_nil assigns(:events_by_day)
485
379
486 assert_tag :tag => "h3",
380 assert_tag :tag => "h3",
487 :content => /#{2.days.ago.to_date.day}/,
381 :content => /#{2.days.ago.to_date.day}/,
488 :sibling => { :tag => "dl",
382 :sibling => { :tag => "dl",
489 :child => { :tag => "dt",
383 :child => { :tag => "dt",
490 :attributes => { :class => /issue-edit/ },
384 :attributes => { :class => /issue-edit/ },
491 :child => { :tag => "a",
385 :child => { :tag => "a",
492 :content => /(#{IssueStatus.find(2).name})/,
386 :content => /(#{IssueStatus.find(2).name})/,
493 }
387 }
494 }
388 }
495 }
389 }
496 end
390 end
497
391
498 def test_previous_project_activity
392 def test_previous_project_activity
499 get :activity, :id => 1, :from => 3.days.ago.to_date
393 get :activity, :id => 1, :from => 3.days.ago.to_date
500 assert_response :success
394 assert_response :success
501 assert_template 'activity'
395 assert_template 'activity'
502 assert_not_nil assigns(:events_by_day)
396 assert_not_nil assigns(:events_by_day)
503
397
504 assert_tag :tag => "h3",
398 assert_tag :tag => "h3",
505 :content => /#{3.day.ago.to_date.day}/,
399 :content => /#{3.day.ago.to_date.day}/,
506 :sibling => { :tag => "dl",
400 :sibling => { :tag => "dl",
507 :child => { :tag => "dt",
401 :child => { :tag => "dt",
508 :attributes => { :class => /issue/ },
402 :attributes => { :class => /issue/ },
509 :child => { :tag => "a",
403 :child => { :tag => "a",
510 :content => /#{Issue.find(1).subject}/,
404 :content => /#{Issue.find(1).subject}/,
511 }
405 }
512 }
406 }
513 }
407 }
514 end
408 end
515
409
516 def test_global_activity_routing
517 assert_routing({:method => :get, :path => '/activity'}, :controller => 'projects', :action => 'activity', :id => nil)
518 end
519
520 def test_global_activity
410 def test_global_activity
521 get :activity
411 get :activity
522 assert_response :success
412 assert_response :success
523 assert_template 'activity'
413 assert_template 'activity'
524 assert_not_nil assigns(:events_by_day)
414 assert_not_nil assigns(:events_by_day)
525
415
526 assert_tag :tag => "h3",
416 assert_tag :tag => "h3",
527 :content => /#{5.day.ago.to_date.day}/,
417 :content => /#{5.day.ago.to_date.day}/,
528 :sibling => { :tag => "dl",
418 :sibling => { :tag => "dl",
529 :child => { :tag => "dt",
419 :child => { :tag => "dt",
530 :attributes => { :class => /issue/ },
420 :attributes => { :class => /issue/ },
531 :child => { :tag => "a",
421 :child => { :tag => "a",
532 :content => /#{Issue.find(5).subject}/,
422 :content => /#{Issue.find(5).subject}/,
533 }
423 }
534 }
424 }
535 }
425 }
536 end
426 end
537
427
538 def test_user_activity
428 def test_user_activity
539 get :activity, :user_id => 2
429 get :activity, :user_id => 2
540 assert_response :success
430 assert_response :success
541 assert_template 'activity'
431 assert_template 'activity'
542 assert_not_nil assigns(:events_by_day)
432 assert_not_nil assigns(:events_by_day)
543
433
544 assert_tag :tag => "h3",
434 assert_tag :tag => "h3",
545 :content => /#{3.day.ago.to_date.day}/,
435 :content => /#{3.day.ago.to_date.day}/,
546 :sibling => { :tag => "dl",
436 :sibling => { :tag => "dl",
547 :child => { :tag => "dt",
437 :child => { :tag => "dt",
548 :attributes => { :class => /issue/ },
438 :attributes => { :class => /issue/ },
549 :child => { :tag => "a",
439 :child => { :tag => "a",
550 :content => /#{Issue.find(1).subject}/,
440 :content => /#{Issue.find(1).subject}/,
551 }
441 }
552 }
442 }
553 }
443 }
554 end
444 end
555
445
556 def test_global_activity_atom_routing
557 assert_routing({:method => :get, :path => '/activity.atom'}, :controller => 'projects', :action => 'activity', :id => nil, :format => 'atom')
558 end
559
560 def test_activity_atom_feed
446 def test_activity_atom_feed
561 get :activity, :format => 'atom'
447 get :activity, :format => 'atom'
562 assert_response :success
448 assert_response :success
563 assert_template 'common/feed.atom.rxml'
449 assert_template 'common/feed.atom.rxml'
564 end
450 end
565
451
566 def test_archive_routing
567 assert_routing(
568 #TODO: use PUT to project path and modify form
569 {:method => :post, :path => 'projects/64/archive'},
570 :controller => 'projects', :action => 'archive', :id => '64'
571 )
572 end
573
574 def test_archive
452 def test_archive
575 @request.session[:user_id] = 1 # admin
453 @request.session[:user_id] = 1 # admin
576 post :archive, :id => 1
454 post :archive, :id => 1
577 assert_redirected_to 'admin/projects'
455 assert_redirected_to 'admin/projects'
578 assert !Project.find(1).active?
456 assert !Project.find(1).active?
579 end
457 end
580
458
581 def test_unarchive_routing
582 assert_routing(
583 #TODO: use PUT to project path and modify form
584 {:method => :post, :path => '/projects/567/unarchive'},
585 :controller => 'projects', :action => 'unarchive', :id => '567'
586 )
587 end
588
589 def test_unarchive
459 def test_unarchive
590 @request.session[:user_id] = 1 # admin
460 @request.session[:user_id] = 1 # admin
591 Project.find(1).archive
461 Project.find(1).archive
592 post :unarchive, :id => 1
462 post :unarchive, :id => 1
593 assert_redirected_to 'admin/projects'
463 assert_redirected_to 'admin/projects'
594 assert Project.find(1).active?
464 assert Project.find(1).active?
595 end
465 end
596
466
597 def test_project_breadcrumbs_should_be_limited_to_3_ancestors
467 def test_project_breadcrumbs_should_be_limited_to_3_ancestors
598 CustomField.delete_all
468 CustomField.delete_all
599 parent = nil
469 parent = nil
600 6.times do |i|
470 6.times do |i|
601 p = Project.create!(:name => "Breadcrumbs #{i}", :identifier => "breadcrumbs-#{i}")
471 p = Project.create!(:name => "Breadcrumbs #{i}", :identifier => "breadcrumbs-#{i}")
602 p.set_parent!(parent)
472 p.set_parent!(parent)
603 get :show, :id => p
473 get :show, :id => p
604 assert_tag :h1, :parent => { :attributes => {:id => 'header'}},
474 assert_tag :h1, :parent => { :attributes => {:id => 'header'}},
605 :children => { :count => [i, 3].min,
475 :children => { :count => [i, 3].min,
606 :only => { :tag => 'a' } }
476 :only => { :tag => 'a' } }
607
477
608 parent = p
478 parent = p
609 end
479 end
610 end
480 end
611
481
612 def test_copy_with_project
482 def test_copy_with_project
613 @request.session[:user_id] = 1 # admin
483 @request.session[:user_id] = 1 # admin
614 get :copy, :id => 1
484 get :copy, :id => 1
615 assert_response :success
485 assert_response :success
616 assert_template 'copy'
486 assert_template 'copy'
617 assert assigns(:project)
487 assert assigns(:project)
618 assert_equal Project.find(1).description, assigns(:project).description
488 assert_equal Project.find(1).description, assigns(:project).description
619 assert_nil assigns(:project).id
489 assert_nil assigns(:project).id
620 end
490 end
621
491
622 def test_copy_without_project
492 def test_copy_without_project
623 @request.session[:user_id] = 1 # admin
493 @request.session[:user_id] = 1 # admin
624 get :copy
494 get :copy
625 assert_response :redirect
495 assert_response :redirect
626 assert_redirected_to :controller => 'admin', :action => 'projects'
496 assert_redirected_to :controller => 'admin', :action => 'projects'
627 end
497 end
628
498
629 def test_jump_should_redirect_to_active_tab
499 def test_jump_should_redirect_to_active_tab
630 get :show, :id => 1, :jump => 'issues'
500 get :show, :id => 1, :jump => 'issues'
631 assert_redirected_to 'projects/ecookbook/issues'
501 assert_redirected_to 'projects/ecookbook/issues'
632 end
502 end
633
503
634 def test_jump_should_not_redirect_to_inactive_tab
504 def test_jump_should_not_redirect_to_inactive_tab
635 get :show, :id => 3, :jump => 'documents'
505 get :show, :id => 3, :jump => 'documents'
636 assert_response :success
506 assert_response :success
637 assert_template 'show'
507 assert_template 'show'
638 end
508 end
639
509
640 def test_jump_should_not_redirect_to_unknown_tab
510 def test_jump_should_not_redirect_to_unknown_tab
641 get :show, :id => 3, :jump => 'foobar'
511 get :show, :id => 3, :jump => 'foobar'
642 assert_response :success
512 assert_response :success
643 assert_template 'show'
513 assert_template 'show'
644 end
514 end
645
515
646 def test_reset_activities_routing
647 assert_routing({:method => :delete, :path => 'projects/64/reset_activities'},
648 :controller => 'projects', :action => 'reset_activities', :id => '64')
649 end
650
651 def test_reset_activities
516 def test_reset_activities
652 @request.session[:user_id] = 2 # manager
517 @request.session[:user_id] = 2 # manager
653 project_activity = TimeEntryActivity.new({
518 project_activity = TimeEntryActivity.new({
654 :name => 'Project Specific',
519 :name => 'Project Specific',
655 :parent => TimeEntryActivity.find(:first),
520 :parent => TimeEntryActivity.find(:first),
656 :project => Project.find(1),
521 :project => Project.find(1),
657 :active => true
522 :active => true
658 })
523 })
659 assert project_activity.save
524 assert project_activity.save
660 project_activity_two = TimeEntryActivity.new({
525 project_activity_two = TimeEntryActivity.new({
661 :name => 'Project Specific Two',
526 :name => 'Project Specific Two',
662 :parent => TimeEntryActivity.find(:last),
527 :parent => TimeEntryActivity.find(:last),
663 :project => Project.find(1),
528 :project => Project.find(1),
664 :active => true
529 :active => true
665 })
530 })
666 assert project_activity_two.save
531 assert project_activity_two.save
667
532
668 delete :reset_activities, :id => 1
533 delete :reset_activities, :id => 1
669 assert_response :redirect
534 assert_response :redirect
670 assert_redirected_to 'projects/ecookbook/settings/activities'
535 assert_redirected_to 'projects/ecookbook/settings/activities'
671
536
672 assert_nil TimeEntryActivity.find_by_id(project_activity.id)
537 assert_nil TimeEntryActivity.find_by_id(project_activity.id)
673 assert_nil TimeEntryActivity.find_by_id(project_activity_two.id)
538 assert_nil TimeEntryActivity.find_by_id(project_activity_two.id)
674 end
539 end
675
540
676 def test_reset_activities_should_reassign_time_entries_back_to_the_system_activity
541 def test_reset_activities_should_reassign_time_entries_back_to_the_system_activity
677 @request.session[:user_id] = 2 # manager
542 @request.session[:user_id] = 2 # manager
678 project_activity = TimeEntryActivity.new({
543 project_activity = TimeEntryActivity.new({
679 :name => 'Project Specific Design',
544 :name => 'Project Specific Design',
680 :parent => TimeEntryActivity.find(9),
545 :parent => TimeEntryActivity.find(9),
681 :project => Project.find(1),
546 :project => Project.find(1),
682 :active => true
547 :active => true
683 })
548 })
684 assert project_activity.save
549 assert project_activity.save
685 assert TimeEntry.update_all("activity_id = '#{project_activity.id}'", ["project_id = ? AND activity_id = ?", 1, 9])
550 assert TimeEntry.update_all("activity_id = '#{project_activity.id}'", ["project_id = ? AND activity_id = ?", 1, 9])
686 assert 3, TimeEntry.find_all_by_activity_id_and_project_id(project_activity.id, 1).size
551 assert 3, TimeEntry.find_all_by_activity_id_and_project_id(project_activity.id, 1).size
687
552
688 delete :reset_activities, :id => 1
553 delete :reset_activities, :id => 1
689 assert_response :redirect
554 assert_response :redirect
690 assert_redirected_to 'projects/ecookbook/settings/activities'
555 assert_redirected_to 'projects/ecookbook/settings/activities'
691
556
692 assert_nil TimeEntryActivity.find_by_id(project_activity.id)
557 assert_nil TimeEntryActivity.find_by_id(project_activity.id)
693 assert_equal 0, TimeEntry.find_all_by_activity_id_and_project_id(project_activity.id, 1).size, "TimeEntries still assigned to project specific activity"
558 assert_equal 0, TimeEntry.find_all_by_activity_id_and_project_id(project_activity.id, 1).size, "TimeEntries still assigned to project specific activity"
694 assert_equal 3, TimeEntry.find_all_by_activity_id_and_project_id(9, 1).size, "TimeEntries still assigned to project specific activity"
559 assert_equal 3, TimeEntry.find_all_by_activity_id_and_project_id(9, 1).size, "TimeEntries still assigned to project specific activity"
695 end
560 end
696
561
697 def test_save_activities_routing
698 assert_routing({:method => :post, :path => 'projects/64/activities/save'},
699 :controller => 'projects', :action => 'save_activities', :id => '64')
700 end
701
702 def test_save_activities_to_override_system_activities
562 def test_save_activities_to_override_system_activities
703 @request.session[:user_id] = 2 # manager
563 @request.session[:user_id] = 2 # manager
704 billable_field = TimeEntryActivityCustomField.find_by_name("Billable")
564 billable_field = TimeEntryActivityCustomField.find_by_name("Billable")
705
565
706 post :save_activities, :id => 1, :enumerations => {
566 post :save_activities, :id => 1, :enumerations => {
707 "9"=> {"parent_id"=>"9", "custom_field_values"=>{"7" => "1"}, "active"=>"0"}, # Design, De-activate
567 "9"=> {"parent_id"=>"9", "custom_field_values"=>{"7" => "1"}, "active"=>"0"}, # Design, De-activate
708 "10"=> {"parent_id"=>"10", "custom_field_values"=>{"7"=>"0"}, "active"=>"1"}, # Development, Change custom value
568 "10"=> {"parent_id"=>"10", "custom_field_values"=>{"7"=>"0"}, "active"=>"1"}, # Development, Change custom value
709 "14"=>{"parent_id"=>"14", "custom_field_values"=>{"7"=>"1"}, "active"=>"1"}, # Inactive Activity, Activate with custom value
569 "14"=>{"parent_id"=>"14", "custom_field_values"=>{"7"=>"1"}, "active"=>"1"}, # Inactive Activity, Activate with custom value
710 "11"=>{"parent_id"=>"11", "custom_field_values"=>{"7"=>"1"}, "active"=>"1"} # QA, no changes
570 "11"=>{"parent_id"=>"11", "custom_field_values"=>{"7"=>"1"}, "active"=>"1"} # QA, no changes
711 }
571 }
712
572
713 assert_response :redirect
573 assert_response :redirect
714 assert_redirected_to 'projects/ecookbook/settings/activities'
574 assert_redirected_to 'projects/ecookbook/settings/activities'
715
575
716 # Created project specific activities...
576 # Created project specific activities...
717 project = Project.find('ecookbook')
577 project = Project.find('ecookbook')
718
578
719 # ... Design
579 # ... Design
720 design = project.time_entry_activities.find_by_name("Design")
580 design = project.time_entry_activities.find_by_name("Design")
721 assert design, "Project activity not found"
581 assert design, "Project activity not found"
722
582
723 assert_equal 9, design.parent_id # Relate to the system activity
583 assert_equal 9, design.parent_id # Relate to the system activity
724 assert_not_equal design.parent.id, design.id # Different records
584 assert_not_equal design.parent.id, design.id # Different records
725 assert_equal design.parent.name, design.name # Same name
585 assert_equal design.parent.name, design.name # Same name
726 assert !design.active?
586 assert !design.active?
727
587
728 # ... Development
588 # ... Development
729 development = project.time_entry_activities.find_by_name("Development")
589 development = project.time_entry_activities.find_by_name("Development")
730 assert development, "Project activity not found"
590 assert development, "Project activity not found"
731
591
732 assert_equal 10, development.parent_id # Relate to the system activity
592 assert_equal 10, development.parent_id # Relate to the system activity
733 assert_not_equal development.parent.id, development.id # Different records
593 assert_not_equal development.parent.id, development.id # Different records
734 assert_equal development.parent.name, development.name # Same name
594 assert_equal development.parent.name, development.name # Same name
735 assert development.active?
595 assert development.active?
736 assert_equal "0", development.custom_value_for(billable_field).value
596 assert_equal "0", development.custom_value_for(billable_field).value
737
597
738 # ... Inactive Activity
598 # ... Inactive Activity
739 previously_inactive = project.time_entry_activities.find_by_name("Inactive Activity")
599 previously_inactive = project.time_entry_activities.find_by_name("Inactive Activity")
740 assert previously_inactive, "Project activity not found"
600 assert previously_inactive, "Project activity not found"
741
601
742 assert_equal 14, previously_inactive.parent_id # Relate to the system activity
602 assert_equal 14, previously_inactive.parent_id # Relate to the system activity
743 assert_not_equal previously_inactive.parent.id, previously_inactive.id # Different records
603 assert_not_equal previously_inactive.parent.id, previously_inactive.id # Different records
744 assert_equal previously_inactive.parent.name, previously_inactive.name # Same name
604 assert_equal previously_inactive.parent.name, previously_inactive.name # Same name
745 assert previously_inactive.active?
605 assert previously_inactive.active?
746 assert_equal "1", previously_inactive.custom_value_for(billable_field).value
606 assert_equal "1", previously_inactive.custom_value_for(billable_field).value
747
607
748 # ... QA
608 # ... QA
749 assert_equal nil, project.time_entry_activities.find_by_name("QA"), "Custom QA activity created when it wasn't modified"
609 assert_equal nil, project.time_entry_activities.find_by_name("QA"), "Custom QA activity created when it wasn't modified"
750 end
610 end
751
611
752 def test_save_activities_will_update_project_specific_activities
612 def test_save_activities_will_update_project_specific_activities
753 @request.session[:user_id] = 2 # manager
613 @request.session[:user_id] = 2 # manager
754
614
755 project_activity = TimeEntryActivity.new({
615 project_activity = TimeEntryActivity.new({
756 :name => 'Project Specific',
616 :name => 'Project Specific',
757 :parent => TimeEntryActivity.find(:first),
617 :parent => TimeEntryActivity.find(:first),
758 :project => Project.find(1),
618 :project => Project.find(1),
759 :active => true
619 :active => true
760 })
620 })
761 assert project_activity.save
621 assert project_activity.save
762 project_activity_two = TimeEntryActivity.new({
622 project_activity_two = TimeEntryActivity.new({
763 :name => 'Project Specific Two',
623 :name => 'Project Specific Two',
764 :parent => TimeEntryActivity.find(:last),
624 :parent => TimeEntryActivity.find(:last),
765 :project => Project.find(1),
625 :project => Project.find(1),
766 :active => true
626 :active => true
767 })
627 })
768 assert project_activity_two.save
628 assert project_activity_two.save
769
629
770
630
771 post :save_activities, :id => 1, :enumerations => {
631 post :save_activities, :id => 1, :enumerations => {
772 project_activity.id => {"custom_field_values"=>{"7" => "1"}, "active"=>"0"}, # De-activate
632 project_activity.id => {"custom_field_values"=>{"7" => "1"}, "active"=>"0"}, # De-activate
773 project_activity_two.id => {"custom_field_values"=>{"7" => "1"}, "active"=>"0"} # De-activate
633 project_activity_two.id => {"custom_field_values"=>{"7" => "1"}, "active"=>"0"} # De-activate
774 }
634 }
775
635
776 assert_response :redirect
636 assert_response :redirect
777 assert_redirected_to 'projects/ecookbook/settings/activities'
637 assert_redirected_to 'projects/ecookbook/settings/activities'
778
638
779 # Created project specific activities...
639 # Created project specific activities...
780 project = Project.find('ecookbook')
640 project = Project.find('ecookbook')
781 assert_equal 2, project.time_entry_activities.count
641 assert_equal 2, project.time_entry_activities.count
782
642
783 activity_one = project.time_entry_activities.find_by_name(project_activity.name)
643 activity_one = project.time_entry_activities.find_by_name(project_activity.name)
784 assert activity_one, "Project activity not found"
644 assert activity_one, "Project activity not found"
785 assert_equal project_activity.id, activity_one.id
645 assert_equal project_activity.id, activity_one.id
786 assert !activity_one.active?
646 assert !activity_one.active?
787
647
788 activity_two = project.time_entry_activities.find_by_name(project_activity_two.name)
648 activity_two = project.time_entry_activities.find_by_name(project_activity_two.name)
789 assert activity_two, "Project activity not found"
649 assert activity_two, "Project activity not found"
790 assert_equal project_activity_two.id, activity_two.id
650 assert_equal project_activity_two.id, activity_two.id
791 assert !activity_two.active?
651 assert !activity_two.active?
792 end
652 end
793
653
794 def test_save_activities_when_creating_new_activities_will_convert_existing_data
654 def test_save_activities_when_creating_new_activities_will_convert_existing_data
795 assert_equal 3, TimeEntry.find_all_by_activity_id_and_project_id(9, 1).size
655 assert_equal 3, TimeEntry.find_all_by_activity_id_and_project_id(9, 1).size
796
656
797 @request.session[:user_id] = 2 # manager
657 @request.session[:user_id] = 2 # manager
798 post :save_activities, :id => 1, :enumerations => {
658 post :save_activities, :id => 1, :enumerations => {
799 "9"=> {"parent_id"=>"9", "custom_field_values"=>{"7" => "1"}, "active"=>"0"} # Design, De-activate
659 "9"=> {"parent_id"=>"9", "custom_field_values"=>{"7" => "1"}, "active"=>"0"} # Design, De-activate
800 }
660 }
801 assert_response :redirect
661 assert_response :redirect
802
662
803 # No more TimeEntries using the system activity
663 # No more TimeEntries using the system activity
804 assert_equal 0, TimeEntry.find_all_by_activity_id_and_project_id(9, 1).size, "Time Entries still assigned to system activities"
664 assert_equal 0, TimeEntry.find_all_by_activity_id_and_project_id(9, 1).size, "Time Entries still assigned to system activities"
805 # All TimeEntries using project activity
665 # All TimeEntries using project activity
806 project_specific_activity = TimeEntryActivity.find_by_parent_id_and_project_id(9, 1)
666 project_specific_activity = TimeEntryActivity.find_by_parent_id_and_project_id(9, 1)
807 assert_equal 3, TimeEntry.find_all_by_activity_id_and_project_id(project_specific_activity.id, 1).size, "No Time Entries assigned to the project activity"
667 assert_equal 3, TimeEntry.find_all_by_activity_id_and_project_id(project_specific_activity.id, 1).size, "No Time Entries assigned to the project activity"
808 end
668 end
809
669
810 def test_save_activities_when_creating_new_activities_will_not_convert_existing_data_if_an_exception_is_raised
670 def test_save_activities_when_creating_new_activities_will_not_convert_existing_data_if_an_exception_is_raised
811 # TODO: Need to cause an exception on create but these tests
671 # TODO: Need to cause an exception on create but these tests
812 # aren't setup for mocking. Just create a record now so the
672 # aren't setup for mocking. Just create a record now so the
813 # second one is a dupicate
673 # second one is a dupicate
814 parent = TimeEntryActivity.find(9)
674 parent = TimeEntryActivity.find(9)
815 TimeEntryActivity.create!({:name => parent.name, :project_id => 1, :position => parent.position, :active => true})
675 TimeEntryActivity.create!({:name => parent.name, :project_id => 1, :position => parent.position, :active => true})
816 TimeEntry.create!({:project_id => 1, :hours => 1.0, :user => User.find(1), :issue_id => 3, :activity_id => 10, :spent_on => '2009-01-01'})
676 TimeEntry.create!({:project_id => 1, :hours => 1.0, :user => User.find(1), :issue_id => 3, :activity_id => 10, :spent_on => '2009-01-01'})
817
677
818 assert_equal 3, TimeEntry.find_all_by_activity_id_and_project_id(9, 1).size
678 assert_equal 3, TimeEntry.find_all_by_activity_id_and_project_id(9, 1).size
819 assert_equal 1, TimeEntry.find_all_by_activity_id_and_project_id(10, 1).size
679 assert_equal 1, TimeEntry.find_all_by_activity_id_and_project_id(10, 1).size
820
680
821 @request.session[:user_id] = 2 # manager
681 @request.session[:user_id] = 2 # manager
822 post :save_activities, :id => 1, :enumerations => {
682 post :save_activities, :id => 1, :enumerations => {
823 "9"=> {"parent_id"=>"9", "custom_field_values"=>{"7" => "1"}, "active"=>"0"}, # Design
683 "9"=> {"parent_id"=>"9", "custom_field_values"=>{"7" => "1"}, "active"=>"0"}, # Design
824 "10"=> {"parent_id"=>"10", "custom_field_values"=>{"7"=>"0"}, "active"=>"1"} # Development, Change custom value
684 "10"=> {"parent_id"=>"10", "custom_field_values"=>{"7"=>"0"}, "active"=>"1"} # Development, Change custom value
825 }
685 }
826 assert_response :redirect
686 assert_response :redirect
827
687
828 # TimeEntries shouldn't have been reassigned on the failed record
688 # TimeEntries shouldn't have been reassigned on the failed record
829 assert_equal 3, TimeEntry.find_all_by_activity_id_and_project_id(9, 1).size, "Time Entries are not assigned to system activities"
689 assert_equal 3, TimeEntry.find_all_by_activity_id_and_project_id(9, 1).size, "Time Entries are not assigned to system activities"
830 # TimeEntries shouldn't have been reassigned on the saved record either
690 # TimeEntries shouldn't have been reassigned on the saved record either
831 assert_equal 1, TimeEntry.find_all_by_activity_id_and_project_id(10, 1).size, "Time Entries are not assigned to system activities"
691 assert_equal 1, TimeEntry.find_all_by_activity_id_and_project_id(10, 1).size, "Time Entries are not assigned to system activities"
832 end
692 end
833
693
834 # A hook that is manually registered later
694 # A hook that is manually registered later
835 class ProjectBasedTemplate < Redmine::Hook::ViewListener
695 class ProjectBasedTemplate < Redmine::Hook::ViewListener
836 def view_layouts_base_html_head(context)
696 def view_layouts_base_html_head(context)
837 # Adds a project stylesheet
697 # Adds a project stylesheet
838 stylesheet_link_tag(context[:project].identifier) if context[:project]
698 stylesheet_link_tag(context[:project].identifier) if context[:project]
839 end
699 end
840 end
700 end
841 # Don't use this hook now
701 # Don't use this hook now
842 Redmine::Hook.clear_listeners
702 Redmine::Hook.clear_listeners
843
703
844 def test_hook_response
704 def test_hook_response
845 Redmine::Hook.add_listener(ProjectBasedTemplate)
705 Redmine::Hook.add_listener(ProjectBasedTemplate)
846 get :show, :id => 1
706 get :show, :id => 1
847 assert_tag :tag => 'link', :attributes => {:href => '/stylesheets/ecookbook.css'},
707 assert_tag :tag => 'link', :attributes => {:href => '/stylesheets/ecookbook.css'},
848 :parent => {:tag => 'head'}
708 :parent => {:tag => 'head'}
849
709
850 Redmine::Hook.clear_listeners
710 Redmine::Hook.clear_listeners
851 end
711 end
852 end
712 end
@@ -1,228 +1,105
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 'repositories_controller'
19 require 'repositories_controller'
20
20
21 # Re-raise errors caught by the controller.
21 # Re-raise errors caught by the controller.
22 class RepositoriesController; def rescue_action(e) raise e end; end
22 class RepositoriesController; def rescue_action(e) raise e end; end
23
23
24 class RepositoriesControllerTest < ActionController::TestCase
24 class RepositoriesControllerTest < ActionController::TestCase
25 fixtures :projects, :users, :roles, :members, :member_roles, :repositories, :issues, :issue_statuses, :changesets, :changes, :issue_categories, :enumerations, :custom_fields, :custom_values, :trackers
25 fixtures :projects, :users, :roles, :members, :member_roles, :repositories, :issues, :issue_statuses, :changesets, :changes, :issue_categories, :enumerations, :custom_fields, :custom_values, :trackers
26
26
27 def setup
27 def setup
28 @controller = RepositoriesController.new
28 @controller = RepositoriesController.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_routing
35 assert_routing(
36 {:method => :get, :path => '/projects/redmine/repository'},
37 :controller => 'repositories', :action => 'show', :id => 'redmine'
38 )
39 end
40
41 def test_edit_routing
42 assert_routing(
43 {:method => :get, :path => '/projects/world_domination/repository/edit'},
44 :controller => 'repositories', :action => 'edit', :id => 'world_domination'
45 )
46 assert_routing(
47 {:method => :post, :path => '/projects/world_domination/repository/edit'},
48 :controller => 'repositories', :action => 'edit', :id => 'world_domination'
49 )
50 end
51
52 def test_revisions_routing
53 assert_routing(
54 {:method => :get, :path => '/projects/redmine/repository/revisions'},
55 :controller => 'repositories', :action => 'revisions', :id => 'redmine'
56 )
57 end
58
59 def test_revisions_atom_routing
60 assert_routing(
61 {:method => :get, :path => '/projects/redmine/repository/revisions.atom'},
62 :controller => 'repositories', :action => 'revisions', :id => 'redmine', :format => 'atom'
63 )
64 end
65
66 def test_revisions
34 def test_revisions
67 get :revisions, :id => 1
35 get :revisions, :id => 1
68 assert_response :success
36 assert_response :success
69 assert_template 'revisions'
37 assert_template 'revisions'
70 assert_not_nil assigns(:changesets)
38 assert_not_nil assigns(:changesets)
71 end
39 end
72
40
73 def test_revision_routing
74 assert_routing(
75 {:method => :get, :path => '/projects/restmine/repository/revisions/2457'},
76 :controller => 'repositories', :action => 'revision', :id => 'restmine', :rev => '2457'
77 )
78 end
79
80 def test_revision
41 def test_revision
81 get :revision, :id => 1, :rev => 1
42 get :revision, :id => 1, :rev => 1
82 assert_response :success
43 assert_response :success
83 assert_not_nil assigns(:changeset)
44 assert_not_nil assigns(:changeset)
84 assert_equal "1", assigns(:changeset).revision
45 assert_equal "1", assigns(:changeset).revision
85 end
46 end
86
47
87 def test_revision_with_before_nil_and_afer_normal
48 def test_revision_with_before_nil_and_afer_normal
88 get :revision, {:id => 1, :rev => 1}
49 get :revision, {:id => 1, :rev => 1}
89 assert_response :success
50 assert_response :success
90 assert_template 'revision'
51 assert_template 'revision'
91 assert_no_tag :tag => "div", :attributes => { :class => "contextual" },
52 assert_no_tag :tag => "div", :attributes => { :class => "contextual" },
92 :child => { :tag => "a", :attributes => { :href => '/projects/ecookbook/repository/revisions/0'}
53 :child => { :tag => "a", :attributes => { :href => '/projects/ecookbook/repository/revisions/0'}
93 }
54 }
94 assert_tag :tag => "div", :attributes => { :class => "contextual" },
55 assert_tag :tag => "div", :attributes => { :class => "contextual" },
95 :child => { :tag => "a", :attributes => { :href => '/projects/ecookbook/repository/revisions/2'}
56 :child => { :tag => "a", :attributes => { :href => '/projects/ecookbook/repository/revisions/2'}
96 }
57 }
97 end
58 end
98
59
99 def test_diff_routing
100 assert_routing(
101 {:method => :get, :path => '/projects/restmine/repository/revisions/2457/diff'},
102 :controller => 'repositories', :action => 'diff', :id => 'restmine', :rev => '2457'
103 )
104 end
105
106 def test_unified_diff_routing
107 assert_routing(
108 {:method => :get, :path => '/projects/restmine/repository/revisions/2457/diff.diff'},
109 :controller => 'repositories', :action => 'diff', :id => 'restmine', :rev => '2457', :format => 'diff'
110 )
111 end
112
113 def test_diff_path_routing
114 assert_routing(
115 {:method => :get, :path => '/projects/restmine/repository/diff/path/to/file.c'},
116 :controller => 'repositories', :action => 'diff', :id => 'restmine', :path => %w[path to file.c]
117 )
118 end
119
120 def test_diff_path_routing_with_revision
121 assert_routing(
122 {:method => :get, :path => '/projects/restmine/repository/revisions/2/diff/path/to/file.c'},
123 :controller => 'repositories', :action => 'diff', :id => 'restmine', :path => %w[path to file.c], :rev => '2'
124 )
125 end
126
127 def test_browse_routing
128 assert_routing(
129 {:method => :get, :path => '/projects/restmine/repository/browse/path/to/dir'},
130 :controller => 'repositories', :action => 'browse', :id => 'restmine', :path => %w[path to dir]
131 )
132 end
133
134 def test_entry_routing
135 assert_routing(
136 {:method => :get, :path => '/projects/restmine/repository/entry/path/to/file.c'},
137 :controller => 'repositories', :action => 'entry', :id => 'restmine', :path => %w[path to file.c]
138 )
139 end
140
141 def test_entry_routing_with_revision
142 assert_routing(
143 {:method => :get, :path => '/projects/restmine/repository/revisions/2/entry/path/to/file.c'},
144 :controller => 'repositories', :action => 'entry', :id => 'restmine', :path => %w[path to file.c], :rev => '2'
145 )
146 end
147
148 def test_raw_routing
149 assert_routing(
150 {:method => :get, :path => '/projects/restmine/repository/raw/path/to/file.c'},
151 :controller => 'repositories', :action => 'entry', :id => 'restmine', :path => %w[path to file.c], :format => 'raw'
152 )
153 end
154
155 def test_raw_routing_with_revision
156 assert_routing(
157 {:method => :get, :path => '/projects/restmine/repository/revisions/2/raw/path/to/file.c'},
158 :controller => 'repositories', :action => 'entry', :id => 'restmine', :path => %w[path to file.c], :format => 'raw', :rev => '2'
159 )
160 end
161
162 def test_annotate_routing
163 assert_routing(
164 {:method => :get, :path => '/projects/restmine/repository/annotate/path/to/file.c'},
165 :controller => 'repositories', :action => 'annotate', :id => 'restmine', :path => %w[path to file.c]
166 )
167 end
168
169 def test_changesrouting
170 assert_routing(
171 {:method => :get, :path => '/projects/restmine/repository/changes/path/to/file.c'},
172 :controller => 'repositories', :action => 'changes', :id => 'restmine', :path => %w[path to file.c]
173 )
174 end
175
176 def test_statistics_routing
177 assert_routing(
178 {:method => :get, :path => '/projects/restmine/repository/statistics'},
179 :controller => 'repositories', :action => 'stats', :id => 'restmine'
180 )
181 end
182
183 def test_graph_commits_per_month
60 def test_graph_commits_per_month
184 get :graph, :id => 1, :graph => 'commits_per_month'
61 get :graph, :id => 1, :graph => 'commits_per_month'
185 assert_response :success
62 assert_response :success
186 assert_equal 'image/svg+xml', @response.content_type
63 assert_equal 'image/svg+xml', @response.content_type
187 end
64 end
188
65
189 def test_graph_commits_per_author
66 def test_graph_commits_per_author
190 get :graph, :id => 1, :graph => 'commits_per_author'
67 get :graph, :id => 1, :graph => 'commits_per_author'
191 assert_response :success
68 assert_response :success
192 assert_equal 'image/svg+xml', @response.content_type
69 assert_equal 'image/svg+xml', @response.content_type
193 end
70 end
194
71
195 def test_committers
72 def test_committers
196 @request.session[:user_id] = 2
73 @request.session[:user_id] = 2
197 # add a commit with an unknown user
74 # add a commit with an unknown user
198 Changeset.create!(:repository => Project.find(1).repository, :committer => 'foo', :committed_on => Time.now, :revision => 100, :comments => 'Committed by foo.')
75 Changeset.create!(:repository => Project.find(1).repository, :committer => 'foo', :committed_on => Time.now, :revision => 100, :comments => 'Committed by foo.')
199
76
200 get :committers, :id => 1
77 get :committers, :id => 1
201 assert_response :success
78 assert_response :success
202 assert_template 'committers'
79 assert_template 'committers'
203
80
204 assert_tag :td, :content => 'dlopper',
81 assert_tag :td, :content => 'dlopper',
205 :sibling => { :tag => 'td',
82 :sibling => { :tag => 'td',
206 :child => { :tag => 'select', :attributes => { :name => %r{^committers\[\d+\]\[\]$} },
83 :child => { :tag => 'select', :attributes => { :name => %r{^committers\[\d+\]\[\]$} },
207 :child => { :tag => 'option', :content => 'Dave Lopper',
84 :child => { :tag => 'option', :content => 'Dave Lopper',
208 :attributes => { :value => '3', :selected => 'selected' }}}}
85 :attributes => { :value => '3', :selected => 'selected' }}}}
209 assert_tag :td, :content => 'foo',
86 assert_tag :td, :content => 'foo',
210 :sibling => { :tag => 'td',
87 :sibling => { :tag => 'td',
211 :child => { :tag => 'select', :attributes => { :name => %r{^committers\[\d+\]\[\]$} }}}
88 :child => { :tag => 'select', :attributes => { :name => %r{^committers\[\d+\]\[\]$} }}}
212 assert_no_tag :td, :content => 'foo',
89 assert_no_tag :td, :content => 'foo',
213 :sibling => { :tag => 'td',
90 :sibling => { :tag => 'td',
214 :descendant => { :tag => 'option', :attributes => { :selected => 'selected' }}}
91 :descendant => { :tag => 'option', :attributes => { :selected => 'selected' }}}
215 end
92 end
216
93
217 def test_map_committers
94 def test_map_committers
218 @request.session[:user_id] = 2
95 @request.session[:user_id] = 2
219 # add a commit with an unknown user
96 # add a commit with an unknown user
220 c = Changeset.create!(:repository => Project.find(1).repository, :committer => 'foo', :committed_on => Time.now, :revision => 100, :comments => 'Committed by foo.')
97 c = Changeset.create!(:repository => Project.find(1).repository, :committer => 'foo', :committed_on => Time.now, :revision => 100, :comments => 'Committed by foo.')
221
98
222 assert_no_difference "Changeset.count(:conditions => 'user_id = 3')" do
99 assert_no_difference "Changeset.count(:conditions => 'user_id = 3')" do
223 post :committers, :id => 1, :committers => { '0' => ['foo', '2'], '1' => ['dlopper', '3']}
100 post :committers, :id => 1, :committers => { '0' => ['foo', '2'], '1' => ['dlopper', '3']}
224 assert_redirected_to 'projects/ecookbook/repository/committers'
101 assert_redirected_to 'projects/ecookbook/repository/committers'
225 assert_equal User.find(2), c.reload.user
102 assert_equal User.find(2), c.reload.user
226 end
103 end
227 end
104 end
228 end
105 end
@@ -1,445 +1,340
1 # -*- coding: utf-8 -*-
1 # -*- coding: utf-8 -*-
2 # redMine - project management software
2 # redMine - project management software
3 # Copyright (C) 2006-2007 Jean-Philippe Lang
3 # Copyright (C) 2006-2007 Jean-Philippe Lang
4 #
4 #
5 # This program is free software; you can redistribute it and/or
5 # This program is free software; you can redistribute it and/or
6 # modify it under the terms of the GNU General Public License
6 # modify it under the terms of the GNU General Public License
7 # as published by the Free Software Foundation; either version 2
7 # as published by the Free Software Foundation; either version 2
8 # of the License, or (at your option) any later version.
8 # of the License, or (at your option) any later version.
9 #
9 #
10 # This program is distributed in the hope that it will be useful,
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
13 # GNU General Public License for more details.
14 #
14 #
15 # You should have received a copy of the GNU General Public License
15 # You should have received a copy of the GNU General Public License
16 # along with this program; if not, write to the Free Software
16 # along with this program; if not, write to the Free Software
17 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18
18
19 require File.dirname(__FILE__) + '/../test_helper'
19 require File.dirname(__FILE__) + '/../test_helper'
20 require 'timelog_controller'
20 require 'timelog_controller'
21
21
22 # Re-raise errors caught by the controller.
22 # Re-raise errors caught by the controller.
23 class TimelogController; def rescue_action(e) raise e end; end
23 class TimelogController; def rescue_action(e) raise e end; end
24
24
25 class TimelogControllerTest < ActionController::TestCase
25 class TimelogControllerTest < ActionController::TestCase
26 fixtures :projects, :enabled_modules, :roles, :members, :member_roles, :issues, :time_entries, :users, :trackers, :enumerations, :issue_statuses, :custom_fields, :custom_values
26 fixtures :projects, :enabled_modules, :roles, :members, :member_roles, :issues, :time_entries, :users, :trackers, :enumerations, :issue_statuses, :custom_fields, :custom_values
27
27
28 def setup
28 def setup
29 @controller = TimelogController.new
29 @controller = TimelogController.new
30 @request = ActionController::TestRequest.new
30 @request = ActionController::TestRequest.new
31 @response = ActionController::TestResponse.new
31 @response = ActionController::TestResponse.new
32 end
32 end
33
33
34 def test_edit_routing
35 assert_routing(
36 {:method => :get, :path => '/issues/567/time_entries/new'},
37 :controller => 'timelog', :action => 'edit', :issue_id => '567'
38 )
39 assert_routing(
40 {:method => :get, :path => '/projects/ecookbook/time_entries/new'},
41 :controller => 'timelog', :action => 'edit', :project_id => 'ecookbook'
42 )
43 assert_routing(
44 {:method => :get, :path => '/projects/ecookbook/issues/567/time_entries/new'},
45 :controller => 'timelog', :action => 'edit', :project_id => 'ecookbook', :issue_id => '567'
46 )
47
48 #TODO: change new form to POST to issue_time_entries_path instead of to edit action
49 #TODO: change edit form to PUT to time_entry_path
50 assert_routing(
51 {:method => :get, :path => '/time_entries/22/edit'},
52 :controller => 'timelog', :action => 'edit', :id => '22'
53 )
54 end
55
56 def test_get_edit
34 def test_get_edit
57 @request.session[:user_id] = 3
35 @request.session[:user_id] = 3
58 get :edit, :project_id => 1
36 get :edit, :project_id => 1
59 assert_response :success
37 assert_response :success
60 assert_template 'edit'
38 assert_template 'edit'
61 # Default activity selected
39 # Default activity selected
62 assert_tag :tag => 'option', :attributes => { :selected => 'selected' },
40 assert_tag :tag => 'option', :attributes => { :selected => 'selected' },
63 :content => 'Development'
41 :content => 'Development'
64 end
42 end
65
43
66 def test_get_edit_existing_time
44 def test_get_edit_existing_time
67 @request.session[:user_id] = 2
45 @request.session[:user_id] = 2
68 get :edit, :id => 2, :project_id => nil
46 get :edit, :id => 2, :project_id => nil
69 assert_response :success
47 assert_response :success
70 assert_template 'edit'
48 assert_template 'edit'
71 # Default activity selected
49 # Default activity selected
72 assert_tag :tag => 'form', :attributes => { :action => '/projects/ecookbook/timelog/edit/2' }
50 assert_tag :tag => 'form', :attributes => { :action => '/projects/ecookbook/timelog/edit/2' }
73 end
51 end
74
52
75 def test_get_edit_should_only_show_active_time_entry_activities
53 def test_get_edit_should_only_show_active_time_entry_activities
76 @request.session[:user_id] = 3
54 @request.session[:user_id] = 3
77 get :edit, :project_id => 1
55 get :edit, :project_id => 1
78 assert_response :success
56 assert_response :success
79 assert_template 'edit'
57 assert_template 'edit'
80 assert_no_tag :tag => 'option', :content => 'Inactive Activity'
58 assert_no_tag :tag => 'option', :content => 'Inactive Activity'
81
59
82 end
60 end
83
61
84 def test_get_edit_with_an_existing_time_entry_with_inactive_activity
62 def test_get_edit_with_an_existing_time_entry_with_inactive_activity
85 te = TimeEntry.find(1)
63 te = TimeEntry.find(1)
86 te.activity = TimeEntryActivity.find_by_name("Inactive Activity")
64 te.activity = TimeEntryActivity.find_by_name("Inactive Activity")
87 te.save!
65 te.save!
88
66
89 @request.session[:user_id] = 1
67 @request.session[:user_id] = 1
90 get :edit, :project_id => 1, :id => 1
68 get :edit, :project_id => 1, :id => 1
91 assert_response :success
69 assert_response :success
92 assert_template 'edit'
70 assert_template 'edit'
93 # Blank option since nothing is pre-selected
71 # Blank option since nothing is pre-selected
94 assert_tag :tag => 'option', :content => '--- Please select ---'
72 assert_tag :tag => 'option', :content => '--- Please select ---'
95 end
73 end
96
74
97 def test_post_edit
75 def test_post_edit
98 # TODO: should POST to issues’ time log instead of project. change form
76 # TODO: should POST to issues’ time log instead of project. change form
99 # and routing
77 # and routing
100 @request.session[:user_id] = 3
78 @request.session[:user_id] = 3
101 post :edit, :project_id => 1,
79 post :edit, :project_id => 1,
102 :time_entry => {:comments => 'Some work on TimelogControllerTest',
80 :time_entry => {:comments => 'Some work on TimelogControllerTest',
103 # Not the default activity
81 # Not the default activity
104 :activity_id => '11',
82 :activity_id => '11',
105 :spent_on => '2008-03-14',
83 :spent_on => '2008-03-14',
106 :issue_id => '1',
84 :issue_id => '1',
107 :hours => '7.3'}
85 :hours => '7.3'}
108 assert_redirected_to :action => 'details', :project_id => 'ecookbook'
86 assert_redirected_to :action => 'details', :project_id => 'ecookbook'
109
87
110 i = Issue.find(1)
88 i = Issue.find(1)
111 t = TimeEntry.find_by_comments('Some work on TimelogControllerTest')
89 t = TimeEntry.find_by_comments('Some work on TimelogControllerTest')
112 assert_not_nil t
90 assert_not_nil t
113 assert_equal 11, t.activity_id
91 assert_equal 11, t.activity_id
114 assert_equal 7.3, t.hours
92 assert_equal 7.3, t.hours
115 assert_equal 3, t.user_id
93 assert_equal 3, t.user_id
116 assert_equal i, t.issue
94 assert_equal i, t.issue
117 assert_equal i.project, t.project
95 assert_equal i.project, t.project
118 end
96 end
119
97
120 def test_update
98 def test_update
121 entry = TimeEntry.find(1)
99 entry = TimeEntry.find(1)
122 assert_equal 1, entry.issue_id
100 assert_equal 1, entry.issue_id
123 assert_equal 2, entry.user_id
101 assert_equal 2, entry.user_id
124
102
125 @request.session[:user_id] = 1
103 @request.session[:user_id] = 1
126 post :edit, :id => 1,
104 post :edit, :id => 1,
127 :time_entry => {:issue_id => '2',
105 :time_entry => {:issue_id => '2',
128 :hours => '8'}
106 :hours => '8'}
129 assert_redirected_to :action => 'details', :project_id => 'ecookbook'
107 assert_redirected_to :action => 'details', :project_id => 'ecookbook'
130 entry.reload
108 entry.reload
131
109
132 assert_equal 8, entry.hours
110 assert_equal 8, entry.hours
133 assert_equal 2, entry.issue_id
111 assert_equal 2, entry.issue_id
134 assert_equal 2, entry.user_id
112 assert_equal 2, entry.user_id
135 end
113 end
136
114
137 def test_destroy_routing
138 #TODO: use DELETE to time_entry_path
139 assert_routing(
140 {:method => :post, :path => '/time_entries/55/destroy'},
141 :controller => 'timelog', :action => 'destroy', :id => '55'
142 )
143 end
144
145 def test_destroy
115 def test_destroy
146 @request.session[:user_id] = 2
116 @request.session[:user_id] = 2
147 post :destroy, :id => 1
117 post :destroy, :id => 1
148 assert_redirected_to :action => 'details', :project_id => 'ecookbook'
118 assert_redirected_to :action => 'details', :project_id => 'ecookbook'
149 assert_nil TimeEntry.find_by_id(1)
119 assert_nil TimeEntry.find_by_id(1)
150 end
120 end
151
121
152 def test_report_routing
153 assert_routing(
154 {:method => :get, :path => '/projects/567/time_entries/report'},
155 :controller => 'timelog', :action => 'report', :project_id => '567'
156 )
157 assert_routing(
158 {:method => :get, :path => '/projects/567/time_entries/report.csv'},
159 :controller => 'timelog', :action => 'report', :project_id => '567', :format => 'csv'
160 )
161 end
162
163 def test_report_no_criteria
122 def test_report_no_criteria
164 get :report, :project_id => 1
123 get :report, :project_id => 1
165 assert_response :success
124 assert_response :success
166 assert_template 'report'
125 assert_template 'report'
167 end
126 end
168
127
169 def test_report_routing_for_all_projects
170 assert_routing(
171 {:method => :get, :path => '/time_entries/report'},
172 :controller => 'timelog', :action => 'report'
173 )
174 end
175
176 def test_report_all_projects
128 def test_report_all_projects
177 get :report
129 get :report
178 assert_response :success
130 assert_response :success
179 assert_template 'report'
131 assert_template 'report'
180 end
132 end
181
133
182 def test_report_all_projects_denied
134 def test_report_all_projects_denied
183 r = Role.anonymous
135 r = Role.anonymous
184 r.permissions.delete(:view_time_entries)
136 r.permissions.delete(:view_time_entries)
185 r.permissions_will_change!
137 r.permissions_will_change!
186 r.save
138 r.save
187 get :report
139 get :report
188 assert_redirected_to '/login?back_url=http%3A%2F%2Ftest.host%2Ftime_entries%2Freport'
140 assert_redirected_to '/login?back_url=http%3A%2F%2Ftest.host%2Ftime_entries%2Freport'
189 end
141 end
190
142
191 def test_report_all_projects_one_criteria
143 def test_report_all_projects_one_criteria
192 get :report, :columns => 'week', :from => "2007-04-01", :to => "2007-04-30", :criterias => ['project']
144 get :report, :columns => 'week', :from => "2007-04-01", :to => "2007-04-30", :criterias => ['project']
193 assert_response :success
145 assert_response :success
194 assert_template 'report'
146 assert_template 'report'
195 assert_not_nil assigns(:total_hours)
147 assert_not_nil assigns(:total_hours)
196 assert_equal "8.65", "%.2f" % assigns(:total_hours)
148 assert_equal "8.65", "%.2f" % assigns(:total_hours)
197 end
149 end
198
150
199 def test_report_all_time
151 def test_report_all_time
200 get :report, :project_id => 1, :criterias => ['project', 'issue']
152 get :report, :project_id => 1, :criterias => ['project', 'issue']
201 assert_response :success
153 assert_response :success
202 assert_template 'report'
154 assert_template 'report'
203 assert_not_nil assigns(:total_hours)
155 assert_not_nil assigns(:total_hours)
204 assert_equal "162.90", "%.2f" % assigns(:total_hours)
156 assert_equal "162.90", "%.2f" % assigns(:total_hours)
205 end
157 end
206
158
207 def test_report_all_time_by_day
159 def test_report_all_time_by_day
208 get :report, :project_id => 1, :criterias => ['project', 'issue'], :columns => 'day'
160 get :report, :project_id => 1, :criterias => ['project', 'issue'], :columns => 'day'
209 assert_response :success
161 assert_response :success
210 assert_template 'report'
162 assert_template 'report'
211 assert_not_nil assigns(:total_hours)
163 assert_not_nil assigns(:total_hours)
212 assert_equal "162.90", "%.2f" % assigns(:total_hours)
164 assert_equal "162.90", "%.2f" % assigns(:total_hours)
213 assert_tag :tag => 'th', :content => '2007-03-12'
165 assert_tag :tag => 'th', :content => '2007-03-12'
214 end
166 end
215
167
216 def test_report_one_criteria
168 def test_report_one_criteria
217 get :report, :project_id => 1, :columns => 'week', :from => "2007-04-01", :to => "2007-04-30", :criterias => ['project']
169 get :report, :project_id => 1, :columns => 'week', :from => "2007-04-01", :to => "2007-04-30", :criterias => ['project']
218 assert_response :success
170 assert_response :success
219 assert_template 'report'
171 assert_template 'report'
220 assert_not_nil assigns(:total_hours)
172 assert_not_nil assigns(:total_hours)
221 assert_equal "8.65", "%.2f" % assigns(:total_hours)
173 assert_equal "8.65", "%.2f" % assigns(:total_hours)
222 end
174 end
223
175
224 def test_report_two_criterias
176 def test_report_two_criterias
225 get :report, :project_id => 1, :columns => 'month', :from => "2007-01-01", :to => "2007-12-31", :criterias => ["member", "activity"]
177 get :report, :project_id => 1, :columns => 'month', :from => "2007-01-01", :to => "2007-12-31", :criterias => ["member", "activity"]
226 assert_response :success
178 assert_response :success
227 assert_template 'report'
179 assert_template 'report'
228 assert_not_nil assigns(:total_hours)
180 assert_not_nil assigns(:total_hours)
229 assert_equal "162.90", "%.2f" % assigns(:total_hours)
181 assert_equal "162.90", "%.2f" % assigns(:total_hours)
230 end
182 end
231
183
232 def test_report_one_day
184 def test_report_one_day
233 get :report, :project_id => 1, :columns => 'day', :from => "2007-03-23", :to => "2007-03-23", :criterias => ["member", "activity"]
185 get :report, :project_id => 1, :columns => 'day', :from => "2007-03-23", :to => "2007-03-23", :criterias => ["member", "activity"]
234 assert_response :success
186 assert_response :success
235 assert_template 'report'
187 assert_template 'report'
236 assert_not_nil assigns(:total_hours)
188 assert_not_nil assigns(:total_hours)
237 assert_equal "4.25", "%.2f" % assigns(:total_hours)
189 assert_equal "4.25", "%.2f" % assigns(:total_hours)
238 end
190 end
239
191
240 def test_report_at_issue_level
192 def test_report_at_issue_level
241 get :report, :project_id => 1, :issue_id => 1, :columns => 'month', :from => "2007-01-01", :to => "2007-12-31", :criterias => ["member", "activity"]
193 get :report, :project_id => 1, :issue_id => 1, :columns => 'month', :from => "2007-01-01", :to => "2007-12-31", :criterias => ["member", "activity"]
242 assert_response :success
194 assert_response :success
243 assert_template 'report'
195 assert_template 'report'
244 assert_not_nil assigns(:total_hours)
196 assert_not_nil assigns(:total_hours)
245 assert_equal "154.25", "%.2f" % assigns(:total_hours)
197 assert_equal "154.25", "%.2f" % assigns(:total_hours)
246 end
198 end
247
199
248 def test_report_custom_field_criteria
200 def test_report_custom_field_criteria
249 get :report, :project_id => 1, :criterias => ['project', 'cf_1', 'cf_7']
201 get :report, :project_id => 1, :criterias => ['project', 'cf_1', 'cf_7']
250 assert_response :success
202 assert_response :success
251 assert_template 'report'
203 assert_template 'report'
252 assert_not_nil assigns(:total_hours)
204 assert_not_nil assigns(:total_hours)
253 assert_not_nil assigns(:criterias)
205 assert_not_nil assigns(:criterias)
254 assert_equal 3, assigns(:criterias).size
206 assert_equal 3, assigns(:criterias).size
255 assert_equal "162.90", "%.2f" % assigns(:total_hours)
207 assert_equal "162.90", "%.2f" % assigns(:total_hours)
256 # Custom field column
208 # Custom field column
257 assert_tag :tag => 'th', :content => 'Database'
209 assert_tag :tag => 'th', :content => 'Database'
258 # Custom field row
210 # Custom field row
259 assert_tag :tag => 'td', :content => 'MySQL',
211 assert_tag :tag => 'td', :content => 'MySQL',
260 :sibling => { :tag => 'td', :attributes => { :class => 'hours' },
212 :sibling => { :tag => 'td', :attributes => { :class => 'hours' },
261 :child => { :tag => 'span', :attributes => { :class => 'hours hours-int' },
213 :child => { :tag => 'span', :attributes => { :class => 'hours hours-int' },
262 :content => '1' }}
214 :content => '1' }}
263 # Second custom field column
215 # Second custom field column
264 assert_tag :tag => 'th', :content => 'Billable'
216 assert_tag :tag => 'th', :content => 'Billable'
265 end
217 end
266
218
267 def test_report_one_criteria_no_result
219 def test_report_one_criteria_no_result
268 get :report, :project_id => 1, :columns => 'week', :from => "1998-04-01", :to => "1998-04-30", :criterias => ['project']
220 get :report, :project_id => 1, :columns => 'week', :from => "1998-04-01", :to => "1998-04-30", :criterias => ['project']
269 assert_response :success
221 assert_response :success
270 assert_template 'report'
222 assert_template 'report'
271 assert_not_nil assigns(:total_hours)
223 assert_not_nil assigns(:total_hours)
272 assert_equal "0.00", "%.2f" % assigns(:total_hours)
224 assert_equal "0.00", "%.2f" % assigns(:total_hours)
273 end
225 end
274
226
275 def test_report_all_projects_csv_export
227 def test_report_all_projects_csv_export
276 get :report, :columns => 'month', :from => "2007-01-01", :to => "2007-06-30", :criterias => ["project", "member", "activity"], :format => "csv"
228 get :report, :columns => 'month', :from => "2007-01-01", :to => "2007-06-30", :criterias => ["project", "member", "activity"], :format => "csv"
277 assert_response :success
229 assert_response :success
278 assert_equal 'text/csv', @response.content_type
230 assert_equal 'text/csv', @response.content_type
279 lines = @response.body.chomp.split("\n")
231 lines = @response.body.chomp.split("\n")
280 # Headers
232 # Headers
281 assert_equal 'Project,Member,Activity,2007-1,2007-2,2007-3,2007-4,2007-5,2007-6,Total', lines.first
233 assert_equal 'Project,Member,Activity,2007-1,2007-2,2007-3,2007-4,2007-5,2007-6,Total', lines.first
282 # Total row
234 # Total row
283 assert_equal 'Total,"","","","",154.25,8.65,"","",162.90', lines.last
235 assert_equal 'Total,"","","","",154.25,8.65,"","",162.90', lines.last
284 end
236 end
285
237
286 def test_report_csv_export
238 def test_report_csv_export
287 get :report, :project_id => 1, :columns => 'month', :from => "2007-01-01", :to => "2007-06-30", :criterias => ["project", "member", "activity"], :format => "csv"
239 get :report, :project_id => 1, :columns => 'month', :from => "2007-01-01", :to => "2007-06-30", :criterias => ["project", "member", "activity"], :format => "csv"
288 assert_response :success
240 assert_response :success
289 assert_equal 'text/csv', @response.content_type
241 assert_equal 'text/csv', @response.content_type
290 lines = @response.body.chomp.split("\n")
242 lines = @response.body.chomp.split("\n")
291 # Headers
243 # Headers
292 assert_equal 'Project,Member,Activity,2007-1,2007-2,2007-3,2007-4,2007-5,2007-6,Total', lines.first
244 assert_equal 'Project,Member,Activity,2007-1,2007-2,2007-3,2007-4,2007-5,2007-6,Total', lines.first
293 # Total row
245 # Total row
294 assert_equal 'Total,"","","","",154.25,8.65,"","",162.90', lines.last
246 assert_equal 'Total,"","","","",154.25,8.65,"","",162.90', lines.last
295 end
247 end
296
248
297 def test_details_all_projects
249 def test_details_all_projects
298 get :details
250 get :details
299 assert_response :success
251 assert_response :success
300 assert_template 'details'
252 assert_template 'details'
301 assert_not_nil assigns(:total_hours)
253 assert_not_nil assigns(:total_hours)
302 assert_equal "162.90", "%.2f" % assigns(:total_hours)
254 assert_equal "162.90", "%.2f" % assigns(:total_hours)
303 end
255 end
304
256
305 def test_project_details_routing
306 assert_routing(
307 {:method => :get, :path => '/projects/567/time_entries'},
308 :controller => 'timelog', :action => 'details', :project_id => '567'
309 )
310 end
311
312 def test_details_at_project_level
257 def test_details_at_project_level
313 get :details, :project_id => 1
258 get :details, :project_id => 1
314 assert_response :success
259 assert_response :success
315 assert_template 'details'
260 assert_template 'details'
316 assert_not_nil assigns(:entries)
261 assert_not_nil assigns(:entries)
317 assert_equal 4, assigns(:entries).size
262 assert_equal 4, assigns(:entries).size
318 # project and subproject
263 # project and subproject
319 assert_equal [1, 3], assigns(:entries).collect(&:project_id).uniq.sort
264 assert_equal [1, 3], assigns(:entries).collect(&:project_id).uniq.sort
320 assert_not_nil assigns(:total_hours)
265 assert_not_nil assigns(:total_hours)
321 assert_equal "162.90", "%.2f" % assigns(:total_hours)
266 assert_equal "162.90", "%.2f" % assigns(:total_hours)
322 # display all time by default
267 # display all time by default
323 assert_equal '2007-03-11'.to_date, assigns(:from)
268 assert_equal '2007-03-11'.to_date, assigns(:from)
324 assert_equal '2007-04-22'.to_date, assigns(:to)
269 assert_equal '2007-04-22'.to_date, assigns(:to)
325 end
270 end
326
271
327 def test_details_at_project_level_with_date_range
272 def test_details_at_project_level_with_date_range
328 get :details, :project_id => 1, :from => '2007-03-20', :to => '2007-04-30'
273 get :details, :project_id => 1, :from => '2007-03-20', :to => '2007-04-30'
329 assert_response :success
274 assert_response :success
330 assert_template 'details'
275 assert_template 'details'
331 assert_not_nil assigns(:entries)
276 assert_not_nil assigns(:entries)
332 assert_equal 3, assigns(:entries).size
277 assert_equal 3, assigns(:entries).size
333 assert_not_nil assigns(:total_hours)
278 assert_not_nil assigns(:total_hours)
334 assert_equal "12.90", "%.2f" % assigns(:total_hours)
279 assert_equal "12.90", "%.2f" % assigns(:total_hours)
335 assert_equal '2007-03-20'.to_date, assigns(:from)
280 assert_equal '2007-03-20'.to_date, assigns(:from)
336 assert_equal '2007-04-30'.to_date, assigns(:to)
281 assert_equal '2007-04-30'.to_date, assigns(:to)
337 end
282 end
338
283
339 def test_details_at_project_level_with_period
284 def test_details_at_project_level_with_period
340 get :details, :project_id => 1, :period => '7_days'
285 get :details, :project_id => 1, :period => '7_days'
341 assert_response :success
286 assert_response :success
342 assert_template 'details'
287 assert_template 'details'
343 assert_not_nil assigns(:entries)
288 assert_not_nil assigns(:entries)
344 assert_not_nil assigns(:total_hours)
289 assert_not_nil assigns(:total_hours)
345 assert_equal Date.today - 7, assigns(:from)
290 assert_equal Date.today - 7, assigns(:from)
346 assert_equal Date.today, assigns(:to)
291 assert_equal Date.today, assigns(:to)
347 end
292 end
348
293
349 def test_details_one_day
294 def test_details_one_day
350 get :details, :project_id => 1, :from => "2007-03-23", :to => "2007-03-23"
295 get :details, :project_id => 1, :from => "2007-03-23", :to => "2007-03-23"
351 assert_response :success
296 assert_response :success
352 assert_template 'details'
297 assert_template 'details'
353 assert_not_nil assigns(:total_hours)
298 assert_not_nil assigns(:total_hours)
354 assert_equal "4.25", "%.2f" % assigns(:total_hours)
299 assert_equal "4.25", "%.2f" % assigns(:total_hours)
355 end
300 end
356
301
357 def test_issue_details_routing
358 assert_routing(
359 {:method => :get, :path => 'time_entries'},
360 :controller => 'timelog', :action => 'details'
361 )
362 assert_routing(
363 {:method => :get, :path => '/issues/234/time_entries'},
364 :controller => 'timelog', :action => 'details', :issue_id => '234'
365 )
366 # TODO: issue detail page shouldnt link to project_issue_time_entries_path but to normal issues one
367 # doesnt seem to have effect on resulting page so controller can be left untouched
368 assert_routing(
369 {:method => :get, :path => '/projects/ecookbook/issues/123/time_entries'},
370 :controller => 'timelog', :action => 'details', :project_id => 'ecookbook', :issue_id => '123'
371 )
372 end
373
374 def test_details_at_issue_level
302 def test_details_at_issue_level
375 get :details, :issue_id => 1
303 get :details, :issue_id => 1
376 assert_response :success
304 assert_response :success
377 assert_template 'details'
305 assert_template 'details'
378 assert_not_nil assigns(:entries)
306 assert_not_nil assigns(:entries)
379 assert_equal 2, assigns(:entries).size
307 assert_equal 2, assigns(:entries).size
380 assert_not_nil assigns(:total_hours)
308 assert_not_nil assigns(:total_hours)
381 assert_equal 154.25, assigns(:total_hours)
309 assert_equal 154.25, assigns(:total_hours)
382 # display all time by default
310 # display all time by default
383 assert_equal '2007-03-11'.to_date, assigns(:from)
311 assert_equal '2007-03-11'.to_date, assigns(:from)
384 assert_equal '2007-04-22'.to_date, assigns(:to)
312 assert_equal '2007-04-22'.to_date, assigns(:to)
385 end
313 end
386
314
387 def test_details_formatted_routing
388 assert_routing(
389 {:method => :get, :path => 'time_entries.atom'},
390 :controller => 'timelog', :action => 'details', :format => 'atom'
391 )
392 assert_routing(
393 {:method => :get, :path => 'time_entries.csv'},
394 :controller => 'timelog', :action => 'details', :format => 'csv'
395 )
396 end
397
398 def test_details_for_project_formatted_routing
399 assert_routing(
400 {:method => :get, :path => '/projects/567/time_entries.atom'},
401 :controller => 'timelog', :action => 'details', :format => 'atom', :project_id => '567'
402 )
403 assert_routing(
404 {:method => :get, :path => '/projects/567/time_entries.csv'},
405 :controller => 'timelog', :action => 'details', :format => 'csv', :project_id => '567'
406 )
407 end
408
409 def test_details_for_issue_formatted_routing
410 assert_routing(
411 {:method => :get, :path => '/projects/ecookbook/issues/123/time_entries.atom'},
412 :controller => 'timelog', :action => 'details', :project_id => 'ecookbook', :issue_id => '123', :format => 'atom'
413 )
414 assert_routing(
415 {:method => :get, :path => '/projects/ecookbook/issues/123/time_entries.csv'},
416 :controller => 'timelog', :action => 'details', :project_id => 'ecookbook', :issue_id => '123', :format => 'csv'
417 )
418 end
419
420 def test_details_atom_feed
315 def test_details_atom_feed
421 get :details, :project_id => 1, :format => 'atom'
316 get :details, :project_id => 1, :format => 'atom'
422 assert_response :success
317 assert_response :success
423 assert_equal 'application/atom+xml', @response.content_type
318 assert_equal 'application/atom+xml', @response.content_type
424 assert_not_nil assigns(:items)
319 assert_not_nil assigns(:items)
425 assert assigns(:items).first.is_a?(TimeEntry)
320 assert assigns(:items).first.is_a?(TimeEntry)
426 end
321 end
427
322
428 def test_details_all_projects_csv_export
323 def test_details_all_projects_csv_export
429 Setting.date_format = '%m/%d/%Y'
324 Setting.date_format = '%m/%d/%Y'
430 get :details, :format => 'csv'
325 get :details, :format => 'csv'
431 assert_response :success
326 assert_response :success
432 assert_equal 'text/csv', @response.content_type
327 assert_equal 'text/csv', @response.content_type
433 assert @response.body.include?("Date,User,Activity,Project,Issue,Tracker,Subject,Hours,Comment\n")
328 assert @response.body.include?("Date,User,Activity,Project,Issue,Tracker,Subject,Hours,Comment\n")
434 assert @response.body.include?("\n04/21/2007,redMine Admin,Design,eCookbook,3,Bug,Error 281 when updating a recipe,1.0,\"\"\n")
329 assert @response.body.include?("\n04/21/2007,redMine Admin,Design,eCookbook,3,Bug,Error 281 when updating a recipe,1.0,\"\"\n")
435 end
330 end
436
331
437 def test_details_csv_export
332 def test_details_csv_export
438 Setting.date_format = '%m/%d/%Y'
333 Setting.date_format = '%m/%d/%Y'
439 get :details, :project_id => 1, :format => 'csv'
334 get :details, :project_id => 1, :format => 'csv'
440 assert_response :success
335 assert_response :success
441 assert_equal 'text/csv', @response.content_type
336 assert_equal 'text/csv', @response.content_type
442 assert @response.body.include?("Date,User,Activity,Project,Issue,Tracker,Subject,Hours,Comment\n")
337 assert @response.body.include?("Date,User,Activity,Project,Issue,Tracker,Subject,Hours,Comment\n")
443 assert @response.body.include?("\n04/21/2007,redMine Admin,Design,eCookbook,3,Bug,Error 281 when updating a recipe,1.0,\"\"\n")
338 assert @response.body.include?("\n04/21/2007,redMine Admin,Design,eCookbook,3,Bug,Error 281 when updating a recipe,1.0,\"\"\n")
444 end
339 end
445 end
340 end
@@ -1,75 +1,56
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 'wikis_controller'
19 require 'wikis_controller'
20
20
21 # Re-raise errors caught by the controller.
21 # Re-raise errors caught by the controller.
22 class WikisController; def rescue_action(e) raise e end; end
22 class WikisController; def rescue_action(e) raise e end; end
23
23
24 class WikisControllerTest < ActionController::TestCase
24 class WikisControllerTest < ActionController::TestCase
25 fixtures :projects, :users, :roles, :members, :member_roles, :enabled_modules, :wikis
25 fixtures :projects, :users, :roles, :members, :member_roles, :enabled_modules, :wikis
26
26
27 def setup
27 def setup
28 @controller = WikisController.new
28 @controller = WikisController.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_edit_routing
35 assert_routing(
36 #TODO: use PUT
37 {:method => :post, :path => 'projects/ladida/wiki'},
38 :controller => 'wikis', :action => 'edit', :id => 'ladida'
39 )
40 end
41
42 def test_create
34 def test_create
43 @request.session[:user_id] = 1
35 @request.session[:user_id] = 1
44 assert_nil Project.find(3).wiki
36 assert_nil Project.find(3).wiki
45 post :edit, :id => 3, :wiki => { :start_page => 'Start page' }
37 post :edit, :id => 3, :wiki => { :start_page => 'Start page' }
46 assert_response :success
38 assert_response :success
47 wiki = Project.find(3).wiki
39 wiki = Project.find(3).wiki
48 assert_not_nil wiki
40 assert_not_nil wiki
49 assert_equal 'Start page', wiki.start_page
41 assert_equal 'Start page', wiki.start_page
50 end
42 end
51
43
52 def test_destroy_routing
53 assert_routing(
54 {:method => :get, :path => 'projects/ladida/wiki/destroy'},
55 :controller => 'wikis', :action => 'destroy', :id => 'ladida'
56 )
57 assert_recognizes( #TODO: use DELETE and update form
58 {:controller => 'wikis', :action => 'destroy', :id => 'ladida'},
59 {:method => :post, :path => 'projects/ladida/wiki/destroy'}
60 )
61 end
62
63 def test_destroy
44 def test_destroy
64 @request.session[:user_id] = 1
45 @request.session[:user_id] = 1
65 post :destroy, :id => 1, :confirm => 1
46 post :destroy, :id => 1, :confirm => 1
66 assert_redirected_to :controller => 'projects', :action => 'settings', :id => 'ecookbook', :tab => 'wiki'
47 assert_redirected_to :controller => 'projects', :action => 'settings', :id => 'ecookbook', :tab => 'wiki'
67 assert_nil Project.find(1).wiki
48 assert_nil Project.find(1).wiki
68 end
49 end
69
50
70 def test_not_found
51 def test_not_found
71 @request.session[:user_id] = 1
52 @request.session[:user_id] = 1
72 post :destroy, :id => 999, :confirm => 1
53 post :destroy, :id => 999, :confirm => 1
73 assert_response 404
54 assert_response 404
74 end
55 end
75 end
56 end
@@ -1,167 +1,132
1 # Redmine - project management software
1 # Redmine - project management software
2 # Copyright (C) 2006-2010 Jean-Philippe Lang
2 # Copyright (C) 2006-2010 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
19
20 class IssuesApiTest < ActionController::IntegrationTest
20 class IssuesApiTest < ActionController::IntegrationTest
21 fixtures :projects,
21 fixtures :projects,
22 :users,
22 :users,
23 :roles,
23 :roles,
24 :members,
24 :members,
25 :member_roles,
25 :member_roles,
26 :issues,
26 :issues,
27 :issue_statuses,
27 :issue_statuses,
28 :versions,
28 :versions,
29 :trackers,
29 :trackers,
30 :projects_trackers,
30 :projects_trackers,
31 :issue_categories,
31 :issue_categories,
32 :enabled_modules,
32 :enabled_modules,
33 :enumerations,
33 :enumerations,
34 :attachments,
34 :attachments,
35 :workflows,
35 :workflows,
36 :custom_fields,
36 :custom_fields,
37 :custom_values,
37 :custom_values,
38 :custom_fields_projects,
38 :custom_fields_projects,
39 :custom_fields_trackers,
39 :custom_fields_trackers,
40 :time_entries,
40 :time_entries,
41 :journals,
41 :journals,
42 :journal_details,
42 :journal_details,
43 :queries
43 :queries
44
44
45 def setup
45 def setup
46 Setting.rest_api_enabled = '1'
46 Setting.rest_api_enabled = '1'
47 end
47 end
48
48
49 def test_index_routing
50 assert_routing(
51 {:method => :get, :path => '/issues.xml'},
52 :controller => 'issues', :action => 'index', :format => 'xml'
53 )
54 end
55
56 def test_index
49 def test_index
57 get '/issues.xml'
50 get '/issues.xml'
58 assert_response :success
51 assert_response :success
59 assert_equal 'application/xml', @response.content_type
52 assert_equal 'application/xml', @response.content_type
60 end
53 end
61
54
62 def test_index_with_filter
55 def test_index_with_filter
63 get '/issues.xml?status_id=5'
56 get '/issues.xml?status_id=5'
64 assert_response :success
57 assert_response :success
65 assert_equal 'application/xml', @response.content_type
58 assert_equal 'application/xml', @response.content_type
66 assert_tag :tag => 'issues',
59 assert_tag :tag => 'issues',
67 :children => { :count => Issue.visible.count(:conditions => {:status_id => 5}),
60 :children => { :count => Issue.visible.count(:conditions => {:status_id => 5}),
68 :only => { :tag => 'issue' } }
61 :only => { :tag => 'issue' } }
69 end
62 end
70
63
71 def test_show_routing
72 assert_routing(
73 {:method => :get, :path => '/issues/1.xml'},
74 :controller => 'issues', :action => 'show', :id => '1', :format => 'xml'
75 )
76 end
77
78 def test_show
64 def test_show
79 get '/issues/1.xml'
65 get '/issues/1.xml'
80 assert_response :success
66 assert_response :success
81 assert_equal 'application/xml', @response.content_type
67 assert_equal 'application/xml', @response.content_type
82 end
68 end
83
69
84 def test_create_routing
85 assert_routing(
86 {:method => :post, :path => '/issues.xml'},
87 :controller => 'issues', :action => 'new', :format => 'xml'
88 )
89 end
90
91 def test_create
70 def test_create
92 attributes = {:project_id => 1, :subject => 'API test', :tracker_id => 2, :status_id => 3}
71 attributes = {:project_id => 1, :subject => 'API test', :tracker_id => 2, :status_id => 3}
93 assert_difference 'Issue.count' do
72 assert_difference 'Issue.count' do
94 post '/issues.xml', {:issue => attributes}, :authorization => credentials('jsmith')
73 post '/issues.xml', {:issue => attributes}, :authorization => credentials('jsmith')
95 end
74 end
96 assert_response :created
75 assert_response :created
97 assert_equal 'application/xml', @response.content_type
76 assert_equal 'application/xml', @response.content_type
98 issue = Issue.first(:order => 'id DESC')
77 issue = Issue.first(:order => 'id DESC')
99 attributes.each do |attribute, value|
78 attributes.each do |attribute, value|
100 assert_equal value, issue.send(attribute)
79 assert_equal value, issue.send(attribute)
101 end
80 end
102 end
81 end
103
82
104 def test_create_failure
83 def test_create_failure
105 attributes = {:project_id => 1}
84 attributes = {:project_id => 1}
106 assert_no_difference 'Issue.count' do
85 assert_no_difference 'Issue.count' do
107 post '/issues.xml', {:issue => attributes}, :authorization => credentials('jsmith')
86 post '/issues.xml', {:issue => attributes}, :authorization => credentials('jsmith')
108 end
87 end
109 assert_response :unprocessable_entity
88 assert_response :unprocessable_entity
110 assert_equal 'application/xml', @response.content_type
89 assert_equal 'application/xml', @response.content_type
111 assert_tag :errors, :child => {:tag => 'error', :content => "Subject can't be blank"}
90 assert_tag :errors, :child => {:tag => 'error', :content => "Subject can't be blank"}
112 end
91 end
113
92
114 def test_update_routing
115 assert_routing(
116 {:method => :put, :path => '/issues/1.xml'},
117 :controller => 'issues', :action => 'update', :id => '1', :format => 'xml'
118 )
119 end
120
121 def test_update
93 def test_update
122 attributes = {:subject => 'API update'}
94 attributes = {:subject => 'API update'}
123 assert_no_difference 'Issue.count' do
95 assert_no_difference 'Issue.count' do
124 assert_difference 'Journal.count' do
96 assert_difference 'Journal.count' do
125 put '/issues/1.xml', {:issue => attributes}, :authorization => credentials('jsmith')
97 put '/issues/1.xml', {:issue => attributes}, :authorization => credentials('jsmith')
126 end
98 end
127 end
99 end
128 assert_response :ok
100 assert_response :ok
129 assert_equal 'application/xml', @response.content_type
101 assert_equal 'application/xml', @response.content_type
130 issue = Issue.find(1)
102 issue = Issue.find(1)
131 attributes.each do |attribute, value|
103 attributes.each do |attribute, value|
132 assert_equal value, issue.send(attribute)
104 assert_equal value, issue.send(attribute)
133 end
105 end
134 end
106 end
135
107
136 def test_update_failure
108 def test_update_failure
137 attributes = {:subject => ''}
109 attributes = {:subject => ''}
138 assert_no_difference 'Issue.count' do
110 assert_no_difference 'Issue.count' do
139 assert_no_difference 'Journal.count' do
111 assert_no_difference 'Journal.count' do
140 put '/issues/1.xml', {:issue => attributes}, :authorization => credentials('jsmith')
112 put '/issues/1.xml', {:issue => attributes}, :authorization => credentials('jsmith')
141 end
113 end
142 end
114 end
143 assert_response :unprocessable_entity
115 assert_response :unprocessable_entity
144 assert_equal 'application/xml', @response.content_type
116 assert_equal 'application/xml', @response.content_type
145 assert_tag :errors, :child => {:tag => 'error', :content => "Subject can't be blank"}
117 assert_tag :errors, :child => {:tag => 'error', :content => "Subject can't be blank"}
146 end
118 end
147
119
148 def test_destroy_routing
149 assert_routing(
150 {:method => :delete, :path => '/issues/1.xml'},
151 :controller => 'issues', :action => 'destroy', :id => '1', :format => 'xml'
152 )
153 end
154
155 def test_destroy
120 def test_destroy
156 assert_difference 'Issue.count', -1 do
121 assert_difference 'Issue.count', -1 do
157 delete '/issues/1.xml', {}, :authorization => credentials('jsmith')
122 delete '/issues/1.xml', {}, :authorization => credentials('jsmith')
158 end
123 end
159 assert_response :ok
124 assert_response :ok
160 assert_equal 'application/xml', @response.content_type
125 assert_equal 'application/xml', @response.content_type
161 assert_nil Issue.find_by_id(1)
126 assert_nil Issue.find_by_id(1)
162 end
127 end
163
128
164 def credentials(user, password=nil)
129 def credentials(user, password=nil)
165 ActionController::HttpAuthentication::Basic.encode_credentials(user, password || user)
130 ActionController::HttpAuthentication::Basic.encode_credentials(user, password || user)
166 end
131 end
167 end
132 end
@@ -1,134 +1,99
1 # Redmine - project management software
1 # Redmine - project management software
2 # Copyright (C) 2006-2010 Jean-Philippe Lang
2 # Copyright (C) 2006-2010 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
19
20 class ProjectsApiTest < ActionController::IntegrationTest
20 class ProjectsApiTest < ActionController::IntegrationTest
21 fixtures :projects, :versions, :users, :roles, :members, :member_roles, :issues, :journals, :journal_details,
21 fixtures :projects, :versions, :users, :roles, :members, :member_roles, :issues, :journals, :journal_details,
22 :trackers, :projects_trackers, :issue_statuses, :enabled_modules, :enumerations, :boards, :messages,
22 :trackers, :projects_trackers, :issue_statuses, :enabled_modules, :enumerations, :boards, :messages,
23 :attachments, :custom_fields, :custom_values, :time_entries
23 :attachments, :custom_fields, :custom_values, :time_entries
24
24
25 def setup
25 def setup
26 Setting.rest_api_enabled = '1'
26 Setting.rest_api_enabled = '1'
27 end
27 end
28
28
29 def test_index_routing
30 assert_routing(
31 {:method => :get, :path => '/projects.xml'},
32 :controller => 'projects', :action => 'index', :format => 'xml'
33 )
34 end
35
36 def test_index
29 def test_index
37 get '/projects.xml'
30 get '/projects.xml'
38 assert_response :success
31 assert_response :success
39 assert_equal 'application/xml', @response.content_type
32 assert_equal 'application/xml', @response.content_type
40 end
33 end
41
34
42 def test_show_routing
43 assert_routing(
44 {:method => :get, :path => '/projects/1.xml'},
45 :controller => 'projects', :action => 'show', :id => '1', :format => 'xml'
46 )
47 end
48
49 def test_show
35 def test_show
50 get '/projects/1.xml'
36 get '/projects/1.xml'
51 assert_response :success
37 assert_response :success
52 assert_equal 'application/xml', @response.content_type
38 assert_equal 'application/xml', @response.content_type
53 end
39 end
54
40
55 def test_create_routing
56 assert_routing(
57 {:method => :post, :path => '/projects.xml'},
58 :controller => 'projects', :action => 'add', :format => 'xml'
59 )
60 end
61
62 def test_create
41 def test_create
63 attributes = {:name => 'API test', :identifier => 'api-test'}
42 attributes = {:name => 'API test', :identifier => 'api-test'}
64 assert_difference 'Project.count' do
43 assert_difference 'Project.count' do
65 post '/projects.xml', {:project => attributes}, :authorization => credentials('admin')
44 post '/projects.xml', {:project => attributes}, :authorization => credentials('admin')
66 end
45 end
67 assert_response :created
46 assert_response :created
68 assert_equal 'application/xml', @response.content_type
47 assert_equal 'application/xml', @response.content_type
69 project = Project.first(:order => 'id DESC')
48 project = Project.first(:order => 'id DESC')
70 attributes.each do |attribute, value|
49 attributes.each do |attribute, value|
71 assert_equal value, project.send(attribute)
50 assert_equal value, project.send(attribute)
72 end
51 end
73 end
52 end
74
53
75 def test_create_failure
54 def test_create_failure
76 attributes = {:name => 'API test'}
55 attributes = {:name => 'API test'}
77 assert_no_difference 'Project.count' do
56 assert_no_difference 'Project.count' do
78 post '/projects.xml', {:project => attributes}, :authorization => credentials('admin')
57 post '/projects.xml', {:project => attributes}, :authorization => credentials('admin')
79 end
58 end
80 assert_response :unprocessable_entity
59 assert_response :unprocessable_entity
81 assert_equal 'application/xml', @response.content_type
60 assert_equal 'application/xml', @response.content_type
82 assert_tag :errors, :child => {:tag => 'error', :content => "Identifier can't be blank"}
61 assert_tag :errors, :child => {:tag => 'error', :content => "Identifier can't be blank"}
83 end
62 end
84
63
85 def test_update_routing
86 assert_routing(
87 {:method => :put, :path => '/projects/1.xml'},
88 :controller => 'projects', :action => 'edit', :id => '1', :format => 'xml'
89 )
90 end
91
92 def test_update
64 def test_update
93 attributes = {:name => 'API update'}
65 attributes = {:name => 'API update'}
94 assert_no_difference 'Project.count' do
66 assert_no_difference 'Project.count' do
95 put '/projects/1.xml', {:project => attributes}, :authorization => credentials('jsmith')
67 put '/projects/1.xml', {:project => attributes}, :authorization => credentials('jsmith')
96 end
68 end
97 assert_response :ok
69 assert_response :ok
98 assert_equal 'application/xml', @response.content_type
70 assert_equal 'application/xml', @response.content_type
99 project = Project.find(1)
71 project = Project.find(1)
100 attributes.each do |attribute, value|
72 attributes.each do |attribute, value|
101 assert_equal value, project.send(attribute)
73 assert_equal value, project.send(attribute)
102 end
74 end
103 end
75 end
104
76
105 def test_update_failure
77 def test_update_failure
106 attributes = {:name => ''}
78 attributes = {:name => ''}
107 assert_no_difference 'Project.count' do
79 assert_no_difference 'Project.count' do
108 put '/projects/1.xml', {:project => attributes}, :authorization => credentials('jsmith')
80 put '/projects/1.xml', {:project => attributes}, :authorization => credentials('jsmith')
109 end
81 end
110 assert_response :unprocessable_entity
82 assert_response :unprocessable_entity
111 assert_equal 'application/xml', @response.content_type
83 assert_equal 'application/xml', @response.content_type
112 assert_tag :errors, :child => {:tag => 'error', :content => "Name can't be blank"}
84 assert_tag :errors, :child => {:tag => 'error', :content => "Name can't be blank"}
113 end
85 end
114
86
115 def test_destroy_routing
116 assert_routing(
117 {:method => :delete, :path => '/projects/1.xml'},
118 :controller => 'projects', :action => 'destroy', :id => '1', :format => 'xml'
119 )
120 end
121
122 def test_destroy
87 def test_destroy
123 assert_difference 'Project.count', -1 do
88 assert_difference 'Project.count', -1 do
124 delete '/projects/2.xml', {}, :authorization => credentials('admin')
89 delete '/projects/2.xml', {}, :authorization => credentials('admin')
125 end
90 end
126 assert_response :ok
91 assert_response :ok
127 assert_equal 'application/xml', @response.content_type
92 assert_equal 'application/xml', @response.content_type
128 assert_nil Project.find_by_id(2)
93 assert_nil Project.find_by_id(2)
129 end
94 end
130
95
131 def credentials(user, password=nil)
96 def credentials(user, password=nil)
132 ActionController::HttpAuthentication::Basic.encode_credentials(user, password || user)
97 ActionController::HttpAuthentication::Basic.encode_credentials(user, password || user)
133 end
98 end
134 end
99 end
@@ -1,114 +1,280
1 # redMine - project management software
1 # redMine - project management software
2 # Copyright (C) 2006-2010 Jean-Philippe Lang
2 # Copyright (C) 2006-2010 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
19
20 class RoutingTest < ActionController::IntegrationTest
20 class RoutingTest < ActionController::IntegrationTest
21 context "activities" do
22 should_route :get, "/activity", :controller => 'projects', :action => 'activity', :id => nil
23 should_route :get, "/activity.atom", :controller => 'projects', :action => 'activity', :id => nil, :format => 'atom'
24 end
25
26 context "attachments" do
27 should_route :get, "/attachments/1", :controller => 'attachments', :action => 'show', :id => '1'
28 should_route :get, "/attachments/1/filename.ext", :controller => 'attachments', :action => 'show', :id => '1', :filename => 'filename.ext'
29 should_route :get, "/attachments/download/1", :controller => 'attachments', :action => 'download', :id => '1'
30 should_route :get, "/attachments/download/1/filename.ext", :controller => 'attachments', :action => 'download', :id => '1', :filename => 'filename.ext'
31 end
32
33 context "boards" do
34 should_route :get, "/projects/world_domination/boards", :controller => 'boards', :action => 'index', :project_id => 'world_domination'
35 should_route :get, "/projects/world_domination/boards/new", :controller => 'boards', :action => 'new', :project_id => 'world_domination'
36 should_route :get, "/projects/world_domination/boards/44", :controller => 'boards', :action => 'show', :project_id => 'world_domination', :id => '44'
37 should_route :get, "/projects/world_domination/boards/44.atom", :controller => 'boards', :action => 'show', :project_id => 'world_domination', :id => '44', :format => 'atom'
38 should_route :get, "/projects/world_domination/boards/44/edit", :controller => 'boards', :action => 'edit', :project_id => 'world_domination', :id => '44'
39
40 should_route :post, "/projects/world_domination/boards/new", :controller => 'boards', :action => 'new', :project_id => 'world_domination'
41 should_route :post, "/projects/world_domination/boards/44/edit", :controller => 'boards', :action => 'edit', :project_id => 'world_domination', :id => '44'
42 should_route :post, "/projects/world_domination/boards/44/destroy", :controller => 'boards', :action => 'destroy', :project_id => 'world_domination', :id => '44'
43
44 end
45
46 context "documents" do
47 should_route :get, "/projects/567/documents", :controller => 'documents', :action => 'index', :project_id => '567'
48 should_route :get, "/projects/567/documents/new", :controller => 'documents', :action => 'new', :project_id => '567'
49 should_route :get, "/documents/22", :controller => 'documents', :action => 'show', :id => '22'
50 should_route :get, "/documents/22/edit", :controller => 'documents', :action => 'edit', :id => '22'
51
52 should_route :post, "/projects/567/documents/new", :controller => 'documents', :action => 'new', :project_id => '567'
53 should_route :post, "/documents/567/edit", :controller => 'documents', :action => 'edit', :id => '567'
54 should_route :post, "/documents/567/destroy", :controller => 'documents', :action => 'destroy', :id => '567'
55 end
56
21 context "issues" do
57 context "issues" do
22 # REST actions
58 # REST actions
23 should_route :get, "/issues", :controller => 'issues', :action => 'index'
59 should_route :get, "/issues", :controller => 'issues', :action => 'index'
24 should_route :get, "/issues.pdf", :controller => 'issues', :action => 'index', :format => 'pdf'
60 should_route :get, "/issues.pdf", :controller => 'issues', :action => 'index', :format => 'pdf'
25 should_route :get, "/issues.atom", :controller => 'issues', :action => 'index', :format => 'atom'
61 should_route :get, "/issues.atom", :controller => 'issues', :action => 'index', :format => 'atom'
26 should_route :get, "/issues.xml", :controller => 'issues', :action => 'index', :format => 'xml'
62 should_route :get, "/issues.xml", :controller => 'issues', :action => 'index', :format => 'xml'
27 should_route :get, "/projects/23/issues", :controller => 'issues', :action => 'index', :project_id => '23'
63 should_route :get, "/projects/23/issues", :controller => 'issues', :action => 'index', :project_id => '23'
28 should_route :get, "/projects/23/issues.pdf", :controller => 'issues', :action => 'index', :project_id => '23', :format => 'pdf'
64 should_route :get, "/projects/23/issues.pdf", :controller => 'issues', :action => 'index', :project_id => '23', :format => 'pdf'
29 should_route :get, "/projects/23/issues.atom", :controller => 'issues', :action => 'index', :project_id => '23', :format => 'atom'
65 should_route :get, "/projects/23/issues.atom", :controller => 'issues', :action => 'index', :project_id => '23', :format => 'atom'
30 should_route :get, "/projects/23/issues.xml", :controller => 'issues', :action => 'index', :project_id => '23', :format => 'xml'
66 should_route :get, "/projects/23/issues.xml", :controller => 'issues', :action => 'index', :project_id => '23', :format => 'xml'
31 should_route :get, "/issues/64", :controller => 'issues', :action => 'show', :id => '64'
67 should_route :get, "/issues/64", :controller => 'issues', :action => 'show', :id => '64'
32 should_route :get, "/issues/64.pdf", :controller => 'issues', :action => 'show', :id => '64', :format => 'pdf'
68 should_route :get, "/issues/64.pdf", :controller => 'issues', :action => 'show', :id => '64', :format => 'pdf'
33 should_route :get, "/issues/64.atom", :controller => 'issues', :action => 'show', :id => '64', :format => 'atom'
69 should_route :get, "/issues/64.atom", :controller => 'issues', :action => 'show', :id => '64', :format => 'atom'
34 should_route :get, "/issues/64.xml", :controller => 'issues', :action => 'show', :id => '64', :format => 'xml'
70 should_route :get, "/issues/64.xml", :controller => 'issues', :action => 'show', :id => '64', :format => 'xml'
35
71
36 should_route :get, "/projects/23/issues/new", :controller => 'issues', :action => 'new', :project_id => '23'
72 should_route :get, "/projects/23/issues/new", :controller => 'issues', :action => 'new', :project_id => '23'
73 should_route :post, "/issues.xml", :controller => 'issues', :action => 'new', :format => 'xml'
37
74
38 should_route :get, "/issues/64/edit", :controller => 'issues', :action => 'edit', :id => '64'
75 should_route :get, "/issues/64/edit", :controller => 'issues', :action => 'edit', :id => '64'
39 # TODO: Should use PUT
76 # TODO: Should use PUT
40 should_route :post, "/issues/64/edit", :controller => 'issues', :action => 'edit', :id => '64'
77 should_route :post, "/issues/64/edit", :controller => 'issues', :action => 'edit', :id => '64'
78 should_route :put, "/issues/1.xml", :controller => 'issues', :action => 'update', :id => '1', :format => 'xml'
41
79
42 # TODO: Should use DELETE
80 # TODO: Should use DELETE
43 should_route :post, "/issues/64/destroy", :controller => 'issues', :action => 'destroy', :id => '64'
81 should_route :post, "/issues/64/destroy", :controller => 'issues', :action => 'destroy', :id => '64'
82 should_route :delete, "/issues/1.xml", :controller => 'issues', :action => 'destroy', :id => '1', :format => 'xml'
44
83
45 # Extra actions
84 # Extra actions
46 should_route :get, "/projects/23/issues/64/copy", :controller => 'issues', :action => 'new', :project_id => '23', :copy_from => '64'
85 should_route :get, "/projects/23/issues/64/copy", :controller => 'issues', :action => 'new', :project_id => '23', :copy_from => '64'
47
86
48 should_route :get, "/issues/1/move", :controller => 'issues', :action => 'move', :id => '1'
87 should_route :get, "/issues/1/move", :controller => 'issues', :action => 'move', :id => '1'
49 should_route :post, "/issues/1/move", :controller => 'issues', :action => 'move', :id => '1'
88 should_route :post, "/issues/1/move", :controller => 'issues', :action => 'move', :id => '1'
50
89
51 should_route :post, "/issues/1/quoted", :controller => 'issues', :action => 'reply', :id => '1'
90 should_route :post, "/issues/1/quoted", :controller => 'issues', :action => 'reply', :id => '1'
52
91
53 should_route :get, "/issues/calendar", :controller => 'issues', :action => 'calendar'
92 should_route :get, "/issues/calendar", :controller => 'issues', :action => 'calendar'
54 should_route :post, "/issues/calendar", :controller => 'issues', :action => 'calendar'
93 should_route :post, "/issues/calendar", :controller => 'issues', :action => 'calendar'
55 should_route :get, "/projects/project-name/issues/calendar", :controller => 'issues', :action => 'calendar', :project_id => 'project-name'
94 should_route :get, "/projects/project-name/issues/calendar", :controller => 'issues', :action => 'calendar', :project_id => 'project-name'
56 should_route :post, "/projects/project-name/issues/calendar", :controller => 'issues', :action => 'calendar', :project_id => 'project-name'
95 should_route :post, "/projects/project-name/issues/calendar", :controller => 'issues', :action => 'calendar', :project_id => 'project-name'
57
96
58 should_route :get, "/issues/gantt", :controller => 'issues', :action => 'gantt'
97 should_route :get, "/issues/gantt", :controller => 'issues', :action => 'gantt'
59 should_route :post, "/issues/gantt", :controller => 'issues', :action => 'gantt'
98 should_route :post, "/issues/gantt", :controller => 'issues', :action => 'gantt'
60 should_route :get, "/projects/project-name/issues/gantt", :controller => 'issues', :action => 'gantt', :project_id => 'project-name'
99 should_route :get, "/projects/project-name/issues/gantt", :controller => 'issues', :action => 'gantt', :project_id => 'project-name'
61 should_route :post, "/projects/project-name/issues/gantt", :controller => 'issues', :action => 'gantt', :project_id => 'project-name'
100 should_route :post, "/projects/project-name/issues/gantt", :controller => 'issues', :action => 'gantt', :project_id => 'project-name'
62
101
63 should_route :get, "/issues/auto_complete", :controller => 'issues', :action => 'auto_complete'
102 should_route :get, "/issues/auto_complete", :controller => 'issues', :action => 'auto_complete'
64 end
103 end
104
105 context "issue categories" do
106 should_route :get, "/projects/test/issue_categories/new", :controller => 'issue_categories', :action => 'new', :project_id => 'test'
107
108 should_route :post, "/projects/test/issue_categories/new", :controller => 'issue_categories', :action => 'new', :project_id => 'test'
109 end
110
111 context "issue relations" do
112 should_route :post, "/issues/1/relations", :controller => 'issue_relations', :action => 'new', :issue_id => '1'
113 should_route :post, "/issues/1/relations/23/destroy", :controller => 'issue_relations', :action => 'destroy', :issue_id => '1', :id => '23'
114 end
65
115
66 context "issue reports" do
116 context "issue reports" do
67 should_route :get, "/projects/567/issues/report", :controller => 'reports', :action => 'issue_report', :id => '567'
117 should_route :get, "/projects/567/issues/report", :controller => 'reports', :action => 'issue_report', :id => '567'
68 should_route :get, "/projects/567/issues/report/assigned_to", :controller => 'reports', :action => 'issue_report_details', :id => '567', :detail => 'assigned_to'
118 should_route :get, "/projects/567/issues/report/assigned_to", :controller => 'reports', :action => 'issue_report_details', :id => '567', :detail => 'assigned_to'
69 end
119 end
70
120
121 context "members" do
122 should_route :post, "/projects/5234/members/new", :controller => 'members', :action => 'new', :id => '5234'
123 end
124
125 context "messages" do
126 should_route :get, "/boards/22/topics/2", :controller => 'messages', :action => 'show', :id => '2', :board_id => '22'
127 should_route :get, "/boards/lala/topics/new", :controller => 'messages', :action => 'new', :board_id => 'lala'
128 should_route :get, "/boards/lala/topics/22/edit", :controller => 'messages', :action => 'edit', :id => '22', :board_id => 'lala'
129
130 should_route :post, "/boards/lala/topics/new", :controller => 'messages', :action => 'new', :board_id => 'lala'
131 should_route :post, "/boards/lala/topics/22/edit", :controller => 'messages', :action => 'edit', :id => '22', :board_id => 'lala'
132 should_route :post, "/boards/22/topics/555/replies", :controller => 'messages', :action => 'reply', :id => '555', :board_id => '22'
133 should_route :post, "/boards/22/topics/555/destroy", :controller => 'messages', :action => 'destroy', :id => '555', :board_id => '22'
134 end
135
136 context "news" do
137 should_route :get, "/news", :controller => 'news', :action => 'index'
138 should_route :get, "/news.atom", :controller => 'news', :action => 'index', :format => 'atom'
139 should_route :get, "/news.xml", :controller => 'news', :action => 'index', :format => 'xml'
140 should_route :get, "/news.json", :controller => 'news', :action => 'index', :format => 'json'
141 should_route :get, "/projects/567/news", :controller => 'news', :action => 'index', :project_id => '567'
142 should_route :get, "/projects/567/news.atom", :controller => 'news', :action => 'index', :format => 'atom', :project_id => '567'
143 should_route :get, "/projects/567/news.xml", :controller => 'news', :action => 'index', :format => 'xml', :project_id => '567'
144 should_route :get, "/projects/567/news.json", :controller => 'news', :action => 'index', :format => 'json', :project_id => '567'
145 should_route :get, "/news/2", :controller => 'news', :action => 'show', :id => '2'
146 should_route :get, "/projects/567/news/new", :controller => 'news', :action => 'new', :project_id => '567'
147 should_route :get, "/news/234", :controller => 'news', :action => 'show', :id => '234'
148
149 should_route :post, "/projects/567/news/new", :controller => 'news', :action => 'new', :project_id => '567'
150 should_route :post, "/news/567/edit", :controller => 'news', :action => 'edit', :id => '567'
151 should_route :post, "/news/567/destroy", :controller => 'news', :action => 'destroy', :id => '567'
152 end
153
154 context "projects" do
155 should_route :get, "/projects", :controller => 'projects', :action => 'index'
156 should_route :get, "/projects.atom", :controller => 'projects', :action => 'index', :format => 'atom'
157 should_route :get, "/projects.xml", :controller => 'projects', :action => 'index', :format => 'xml'
158 should_route :get, "/projects/new", :controller => 'projects', :action => 'add'
159 should_route :get, "/projects/test", :controller => 'projects', :action => 'show', :id => 'test'
160 should_route :get, "/projects/1.xml", :controller => 'projects', :action => 'show', :id => '1', :format => 'xml'
161 should_route :get, "/projects/4223/settings", :controller => 'projects', :action => 'settings', :id => '4223'
162 should_route :get, "/projects/4223/settings/members", :controller => 'projects', :action => 'settings', :id => '4223', :tab => 'members'
163 should_route :get, "/projects/567/destroy", :controller => 'projects', :action => 'destroy', :id => '567'
164 should_route :get, "/projects/33/files", :controller => 'projects', :action => 'list_files', :id => '33'
165 should_route :get, "/projects/33/files/new", :controller => 'projects', :action => 'add_file', :id => '33'
166 should_route :get, "/projects/33/roadmap", :controller => 'projects', :action => 'roadmap', :id => '33'
167 should_route :get, "/projects/33/activity", :controller => 'projects', :action => 'activity', :id => '33'
168 should_route :get, "/projects/33/activity.atom", :controller => 'projects', :action => 'activity', :id => '33', :format => 'atom'
169
170 should_route :post, "/projects/new", :controller => 'projects', :action => 'add'
171 should_route :post, "/projects.xml", :controller => 'projects', :action => 'add', :format => 'xml'
172 should_route :post, "/projects/4223/edit", :controller => 'projects', :action => 'edit', :id => '4223'
173 should_route :post, "/projects/64/destroy", :controller => 'projects', :action => 'destroy', :id => '64'
174 should_route :post, "/projects/33/files/new", :controller => 'projects', :action => 'add_file', :id => '33'
175 should_route :post, "/projects/64/archive", :controller => 'projects', :action => 'archive', :id => '64'
176 should_route :post, "/projects/64/unarchive", :controller => 'projects', :action => 'unarchive', :id => '64'
177 should_route :post, "/projects/64/activities/save", :controller => 'projects', :action => 'save_activities', :id => '64'
178
179 should_route :put, "/projects/1.xml", :controller => 'projects', :action => 'edit', :id => '1', :format => 'xml'
180
181 should_route :delete, "/projects/1.xml", :controller => 'projects', :action => 'destroy', :id => '1', :format => 'xml'
182 should_route :delete, "/projects/64/reset_activities", :controller => 'projects', :action => 'reset_activities', :id => '64'
183 end
184
185 context "repositories" do
186 should_route :get, "/projects/redmine/repository", :controller => 'repositories', :action => 'show', :id => 'redmine'
187 should_route :get, "/projects/redmine/repository/edit", :controller => 'repositories', :action => 'edit', :id => 'redmine'
188 should_route :get, "/projects/redmine/repository/revisions", :controller => 'repositories', :action => 'revisions', :id => 'redmine'
189 should_route :get, "/projects/redmine/repository/revisions.atom", :controller => 'repositories', :action => 'revisions', :id => 'redmine', :format => 'atom'
190 should_route :get, "/projects/redmine/repository/revisions/2457", :controller => 'repositories', :action => 'revision', :id => 'redmine', :rev => '2457'
191 should_route :get, "/projects/redmine/repository/revisions/2457/diff", :controller => 'repositories', :action => 'diff', :id => 'redmine', :rev => '2457'
192 should_route :get, "/projects/redmine/repository/revisions/2457/diff.diff", :controller => 'repositories', :action => 'diff', :id => 'redmine', :rev => '2457', :format => 'diff'
193 should_route :get, "/projects/redmine/repository/diff/path/to/file.c", :controller => 'repositories', :action => 'diff', :id => 'redmine', :path => %w[path to file.c]
194 should_route :get, "/projects/redmine/repository/revisions/2/diff/path/to/file.c", :controller => 'repositories', :action => 'diff', :id => 'redmine', :path => %w[path to file.c], :rev => '2'
195 should_route :get, "/projects/redmine/repository/browse/path/to/file.c", :controller => 'repositories', :action => 'browse', :id => 'redmine', :path => %w[path to file.c]
196 should_route :get, "/projects/redmine/repository/entry/path/to/file.c", :controller => 'repositories', :action => 'entry', :id => 'redmine', :path => %w[path to file.c]
197 should_route :get, "/projects/redmine/repository/revisions/2/entry/path/to/file.c", :controller => 'repositories', :action => 'entry', :id => 'redmine', :path => %w[path to file.c], :rev => '2'
198 should_route :get, "/projects/redmine/repository/raw/path/to/file.c", :controller => 'repositories', :action => 'entry', :id => 'redmine', :path => %w[path to file.c], :format => 'raw'
199 should_route :get, "/projects/redmine/repository/revisions/2/raw/path/to/file.c", :controller => 'repositories', :action => 'entry', :id => 'redmine', :path => %w[path to file.c], :rev => '2', :format => 'raw'
200 should_route :get, "/projects/redmine/repository/annotate/path/to/file.c", :controller => 'repositories', :action => 'annotate', :id => 'redmine', :path => %w[path to file.c]
201 should_route :get, "/projects/redmine/repository/changes/path/to/file.c", :controller => 'repositories', :action => 'changes', :id => 'redmine', :path => %w[path to file.c]
202 should_route :get, "/projects/redmine/repository/statistics", :controller => 'repositories', :action => 'stats', :id => 'redmine'
203
204
205 should_route :post, "/projects/redmine/repository/edit", :controller => 'repositories', :action => 'edit', :id => 'redmine'
206 end
207
208 context "timelogs" do
209 should_route :get, "/issues/567/time_entries/new", :controller => 'timelog', :action => 'edit', :issue_id => '567'
210 should_route :get, "/projects/ecookbook/time_entries/new", :controller => 'timelog', :action => 'edit', :project_id => 'ecookbook'
211 should_route :get, "/projects/ecookbook/issues/567/time_entries/new", :controller => 'timelog', :action => 'edit', :project_id => 'ecookbook', :issue_id => '567'
212 should_route :get, "/time_entries/22/edit", :controller => 'timelog', :action => 'edit', :id => '22'
213 should_route :get, "/time_entries/report", :controller => 'timelog', :action => 'report'
214 should_route :get, "/projects/567/time_entries/report", :controller => 'timelog', :action => 'report', :project_id => '567'
215 should_route :get, "/projects/567/time_entries/report.csv", :controller => 'timelog', :action => 'report', :project_id => '567', :format => 'csv'
216 should_route :get, "/time_entries", :controller => 'timelog', :action => 'details'
217 should_route :get, "/time_entries.csv", :controller => 'timelog', :action => 'details', :format => 'csv'
218 should_route :get, "/time_entries.atom", :controller => 'timelog', :action => 'details', :format => 'atom'
219 should_route :get, "/projects/567/time_entries", :controller => 'timelog', :action => 'details', :project_id => '567'
220 should_route :get, "/projects/567/time_entries.csv", :controller => 'timelog', :action => 'details', :project_id => '567', :format => 'csv'
221 should_route :get, "/projects/567/time_entries.atom", :controller => 'timelog', :action => 'details', :project_id => '567', :format => 'atom'
222 should_route :get, "/issues/234/time_entries", :controller => 'timelog', :action => 'details', :issue_id => '234'
223 should_route :get, "/issues/234/time_entries.csv", :controller => 'timelog', :action => 'details', :issue_id => '234', :format => 'csv'
224 should_route :get, "/issues/234/time_entries.atom", :controller => 'timelog', :action => 'details', :issue_id => '234', :format => 'atom'
225 should_route :get, "/projects/ecookbook/issues/123/time_entries", :controller => 'timelog', :action => 'details', :project_id => 'ecookbook', :issue_id => '123'
226
227 should_route :post, "/time_entries/55/destroy", :controller => 'timelog', :action => 'destroy', :id => '55'
228 end
229
71 context "users" do
230 context "users" do
72 should_route :get, "/users", :controller => 'users', :action => 'index'
231 should_route :get, "/users", :controller => 'users', :action => 'index'
73 should_route :get, "/users/44", :controller => 'users', :action => 'show', :id => '44'
232 should_route :get, "/users/44", :controller => 'users', :action => 'show', :id => '44'
74 should_route :get, "/users/new", :controller => 'users', :action => 'add'
233 should_route :get, "/users/new", :controller => 'users', :action => 'add'
75 should_route :get, "/users/444/edit", :controller => 'users', :action => 'edit', :id => '444'
234 should_route :get, "/users/444/edit", :controller => 'users', :action => 'edit', :id => '444'
76 should_route :get, "/users/222/edit/membership", :controller => 'users', :action => 'edit', :id => '222', :tab => 'membership'
235 should_route :get, "/users/222/edit/membership", :controller => 'users', :action => 'edit', :id => '222', :tab => 'membership'
77
236
78 should_route :post, "/users/new", :controller => 'users', :action => 'add'
237 should_route :post, "/users/new", :controller => 'users', :action => 'add'
79 should_route :post, "/users/444/edit", :controller => 'users', :action => 'edit', :id => '444'
238 should_route :post, "/users/444/edit", :controller => 'users', :action => 'edit', :id => '444'
80 should_route :post, "/users/123/memberships", :controller => 'users', :action => 'edit_membership', :id => '123'
239 should_route :post, "/users/123/memberships", :controller => 'users', :action => 'edit_membership', :id => '123'
81 should_route :post, "/users/123/memberships/55", :controller => 'users', :action => 'edit_membership', :id => '123', :membership_id => '55'
240 should_route :post, "/users/123/memberships/55", :controller => 'users', :action => 'edit_membership', :id => '123', :membership_id => '55'
82 should_route :post, "/users/567/memberships/12/destroy", :controller => 'users', :action => 'destroy_membership', :id => '567', :membership_id => '12'
241 should_route :post, "/users/567/memberships/12/destroy", :controller => 'users', :action => 'destroy_membership', :id => '567', :membership_id => '12'
83 end
242 end
84
243
85 context "versions" do
244 context "versions" do
86 should_route :get, "/projects/foo/versions/new", :controller => 'versions', :action => 'new', :project_id => 'foo'
245 should_route :get, "/projects/foo/versions/new", :controller => 'versions', :action => 'new', :project_id => 'foo'
87
246
88 should_route :post, "/projects/foo/versions/new", :controller => 'versions', :action => 'new', :project_id => 'foo'
247 should_route :post, "/projects/foo/versions/new", :controller => 'versions', :action => 'new', :project_id => 'foo'
89 end
248 end
90
249
91 context "wikis" do
250 context "wiki (singular, project's pages)" do
92 should_route :get, "/projects/567/wiki", :controller => 'wiki', :action => 'index', :id => '567'
251 should_route :get, "/projects/567/wiki", :controller => 'wiki', :action => 'index', :id => '567'
93 should_route :get, "/projects/567/wiki/lalala", :controller => 'wiki', :action => 'index', :id => '567', :page => 'lalala'
252 should_route :get, "/projects/567/wiki/lalala", :controller => 'wiki', :action => 'index', :id => '567', :page => 'lalala'
94 should_route :get, "/projects/567/wiki/my_page/edit", :controller => 'wiki', :action => 'edit', :id => '567', :page => 'my_page'
253 should_route :get, "/projects/567/wiki/my_page/edit", :controller => 'wiki', :action => 'edit', :id => '567', :page => 'my_page'
95 should_route :get, "/projects/1/wiki/CookBook_documentation/history", :controller => 'wiki', :action => 'history', :id => '1', :page => 'CookBook_documentation'
254 should_route :get, "/projects/1/wiki/CookBook_documentation/history", :controller => 'wiki', :action => 'history', :id => '1', :page => 'CookBook_documentation'
96 should_route :get, "/projects/1/wiki/CookBook_documentation/diff/2/vs/1", :controller => 'wiki', :action => 'diff', :id => '1', :page => 'CookBook_documentation', :version => '2', :version_from => '1'
255 should_route :get, "/projects/1/wiki/CookBook_documentation/diff/2/vs/1", :controller => 'wiki', :action => 'diff', :id => '1', :page => 'CookBook_documentation', :version => '2', :version_from => '1'
97 should_route :get, "/projects/1/wiki/CookBook_documentation/annotate/2", :controller => 'wiki', :action => 'annotate', :id => '1', :page => 'CookBook_documentation', :version => '2'
256 should_route :get, "/projects/1/wiki/CookBook_documentation/annotate/2", :controller => 'wiki', :action => 'annotate', :id => '1', :page => 'CookBook_documentation', :version => '2'
98 should_route :get, "/projects/22/wiki/ladida/rename", :controller => 'wiki', :action => 'rename', :id => '22', :page => 'ladida'
257 should_route :get, "/projects/22/wiki/ladida/rename", :controller => 'wiki', :action => 'rename', :id => '22', :page => 'ladida'
99 should_route :get, "/projects/567/wiki/page_index", :controller => 'wiki', :action => 'special', :id => '567', :page => 'page_index'
258 should_route :get, "/projects/567/wiki/page_index", :controller => 'wiki', :action => 'special', :id => '567', :page => 'page_index'
100 should_route :get, "/projects/567/wiki/Page_Index", :controller => 'wiki', :action => 'special', :id => '567', :page => 'Page_Index'
259 should_route :get, "/projects/567/wiki/Page_Index", :controller => 'wiki', :action => 'special', :id => '567', :page => 'Page_Index'
101 should_route :get, "/projects/567/wiki/date_index", :controller => 'wiki', :action => 'special', :id => '567', :page => 'date_index'
260 should_route :get, "/projects/567/wiki/date_index", :controller => 'wiki', :action => 'special', :id => '567', :page => 'date_index'
102 should_route :get, "/projects/567/wiki/export", :controller => 'wiki', :action => 'special', :id => '567', :page => 'export'
261 should_route :get, "/projects/567/wiki/export", :controller => 'wiki', :action => 'special', :id => '567', :page => 'export'
103
262
104 should_route :post, "/projects/567/wiki/my_page/edit", :controller => 'wiki', :action => 'edit', :id => '567', :page => 'my_page'
263 should_route :post, "/projects/567/wiki/my_page/edit", :controller => 'wiki', :action => 'edit', :id => '567', :page => 'my_page'
105 should_route :post, "/projects/567/wiki/CookBook_documentation/preview", :controller => 'wiki', :action => 'preview', :id => '567', :page => 'CookBook_documentation'
264 should_route :post, "/projects/567/wiki/CookBook_documentation/preview", :controller => 'wiki', :action => 'preview', :id => '567', :page => 'CookBook_documentation'
106 should_route :post, "/projects/22/wiki/ladida/rename", :controller => 'wiki', :action => 'rename', :id => '22', :page => 'ladida'
265 should_route :post, "/projects/22/wiki/ladida/rename", :controller => 'wiki', :action => 'rename', :id => '22', :page => 'ladida'
107 should_route :post, "/projects/22/wiki/ladida/destroy", :controller => 'wiki', :action => 'destroy', :id => '22', :page => 'ladida'
266 should_route :post, "/projects/22/wiki/ladida/destroy", :controller => 'wiki', :action => 'destroy', :id => '22', :page => 'ladida'
108 should_route :post, "/projects/22/wiki/ladida/protect", :controller => 'wiki', :action => 'protect', :id => '22', :page => 'ladida'
267 should_route :post, "/projects/22/wiki/ladida/protect", :controller => 'wiki', :action => 'protect', :id => '22', :page => 'ladida'
109 end
268 end
110
269
270 context "wikis (plural, admin setup)" do
271 should_route :get, "/projects/ladida/wiki/destroy", :controller => 'wikis', :action => 'destroy', :id => 'ladida'
272
273 should_route :post, "/projects/ladida/wiki", :controller => 'wikis', :action => 'edit', :id => 'ladida'
274 should_route :post, "/projects/ladida/wiki/destroy", :controller => 'wikis', :action => 'destroy', :id => 'ladida'
275 end
276
111 context "administration panel" do
277 context "administration panel" do
112 should_route :get, "/admin/projects", :controller => 'admin', :action => 'projects'
278 should_route :get, "/admin/projects", :controller => 'admin', :action => 'projects'
113 end
279 end
114 end
280 end
General Comments 0
You need to be logged in to leave comments. Login now