@@ -1,287 +1,287 | |||||
1 | ActionController::Routing::Routes.draw do |map| |
|
1 | ActionController::Routing::Routes.draw do |map| | |
2 | # Add your own custom routes here. |
|
2 | # Add your own custom routes here. | |
3 | # The priority is based upon order of creation: first created -> highest priority. |
|
3 | # The priority is based upon order of creation: first created -> highest priority. | |
4 |
|
4 | |||
5 | # Here's a sample route: |
|
5 | # Here's a sample route: | |
6 | # map.connect 'products/:id', :controller => 'catalog', :action => 'view' |
|
6 | # map.connect 'products/:id', :controller => 'catalog', :action => 'view' | |
7 | # Keep in mind you can assign values other than :controller and :action |
|
7 | # Keep in mind you can assign values other than :controller and :action | |
8 |
|
8 | |||
9 | map.home '', :controller => 'welcome' |
|
9 | map.home '', :controller => 'welcome' | |
10 |
|
10 | |||
11 | map.signin 'login', :controller => 'account', :action => 'login' |
|
11 | map.signin 'login', :controller => 'account', :action => 'login' | |
12 | map.signout 'logout', :controller => 'account', :action => 'logout' |
|
12 | map.signout 'logout', :controller => 'account', :action => 'logout' | |
13 |
|
13 | |||
14 | map.connect 'roles/workflow/:id/:role_id/:tracker_id', :controller => 'roles', :action => 'workflow' |
|
14 | map.connect 'roles/workflow/:id/:role_id/:tracker_id', :controller => 'roles', :action => 'workflow' | |
15 | map.connect 'help/:ctrl/:page', :controller => 'help' |
|
15 | map.connect 'help/:ctrl/:page', :controller => 'help' | |
16 |
|
16 | |||
17 | map.connect 'time_entries/:id/edit', :action => 'edit', :controller => 'timelog' |
|
17 | map.connect 'time_entries/:id/edit', :action => 'edit', :controller => 'timelog' | |
18 | map.connect 'projects/:project_id/time_entries/new', :action => 'edit', :controller => 'timelog' |
|
18 | map.connect 'projects/:project_id/time_entries/new', :action => 'edit', :controller => 'timelog' | |
19 | map.connect 'projects/:project_id/issues/:issue_id/time_entries/new', :action => 'edit', :controller => 'timelog' |
|
19 | map.connect 'projects/:project_id/issues/:issue_id/time_entries/new', :action => 'edit', :controller => 'timelog' | |
20 |
|
20 | |||
21 | map.with_options :controller => 'timelog' do |timelog| |
|
21 | map.with_options :controller => 'timelog' do |timelog| | |
22 | timelog.connect 'projects/:project_id/time_entries', :action => 'details' |
|
22 | timelog.connect 'projects/:project_id/time_entries', :action => 'details' | |
23 |
|
23 | |||
24 | timelog.with_options :action => 'details', :conditions => {:method => :get} do |time_details| |
|
24 | timelog.with_options :action => 'details', :conditions => {:method => :get} do |time_details| | |
25 | time_details.connect 'time_entries' |
|
25 | time_details.connect 'time_entries' | |
26 | time_details.connect 'time_entries.:format' |
|
26 | time_details.connect 'time_entries.:format' | |
27 | time_details.connect 'issues/:issue_id/time_entries' |
|
27 | time_details.connect 'issues/:issue_id/time_entries' | |
28 | time_details.connect 'issues/:issue_id/time_entries.:format' |
|
28 | time_details.connect 'issues/:issue_id/time_entries.:format' | |
29 | time_details.connect 'projects/:project_id/time_entries.:format' |
|
29 | time_details.connect 'projects/:project_id/time_entries.:format' | |
30 | time_details.connect 'projects/:project_id/issues/:issue_id/time_entries' |
|
30 | time_details.connect 'projects/:project_id/issues/:issue_id/time_entries' | |
31 | time_details.connect 'projects/:project_id/issues/:issue_id/time_entries.:format' |
|
31 | time_details.connect 'projects/:project_id/issues/:issue_id/time_entries.:format' | |
32 | end |
|
32 | end | |
33 | timelog.connect 'projects/:project_id/time_entries/report', :action => 'report' |
|
33 | timelog.connect 'projects/:project_id/time_entries/report', :action => 'report' | |
34 | timelog.with_options :action => 'report',:conditions => {:method => :get} do |time_report| |
|
34 | timelog.with_options :action => 'report',:conditions => {:method => :get} do |time_report| | |
35 | time_report.connect 'time_entries/report' |
|
35 | time_report.connect 'time_entries/report' | |
36 | time_report.connect 'time_entries/report.:format' |
|
36 | time_report.connect 'time_entries/report.:format' | |
37 | time_report.connect 'projects/:project_id/time_entries/report.:format' |
|
37 | time_report.connect 'projects/:project_id/time_entries/report.:format' | |
38 | end |
|
38 | end | |
39 |
|
39 | |||
40 | timelog.with_options :action => 'edit', :conditions => {:method => :get} do |time_edit| |
|
40 | timelog.with_options :action => 'edit', :conditions => {:method => :get} do |time_edit| | |
41 | time_edit.connect 'issues/:issue_id/time_entries/new' |
|
41 | time_edit.connect 'issues/:issue_id/time_entries/new' | |
42 | end |
|
42 | end | |
43 |
|
43 | |||
44 | timelog.connect 'time_entries/:id/destroy', :action => 'destroy', :conditions => {:method => :post} |
|
44 | timelog.connect 'time_entries/:id/destroy', :action => 'destroy', :conditions => {:method => :post} | |
45 | end |
|
45 | end | |
46 |
|
46 | |||
47 | map.connect 'projects/:id/wiki', :controller => 'wikis', :action => 'edit', :conditions => {:method => :post} |
|
47 | map.connect 'projects/:id/wiki', :controller => 'wikis', :action => 'edit', :conditions => {:method => :post} | |
48 | map.connect 'projects/:id/wiki/destroy', :controller => 'wikis', :action => 'destroy', :conditions => {:method => :get} |
|
48 | map.connect 'projects/:id/wiki/destroy', :controller => 'wikis', :action => 'destroy', :conditions => {:method => :get} | |
49 | map.connect 'projects/:id/wiki/destroy', :controller => 'wikis', :action => 'destroy', :conditions => {:method => :post} |
|
49 | map.connect 'projects/:id/wiki/destroy', :controller => 'wikis', :action => 'destroy', :conditions => {:method => :post} | |
50 | map.with_options :controller => 'wiki' do |wiki_routes| |
|
50 | map.with_options :controller => 'wiki' do |wiki_routes| | |
51 | wiki_routes.with_options :conditions => {:method => :get} do |wiki_views| |
|
51 | wiki_routes.with_options :conditions => {:method => :get} do |wiki_views| | |
52 | wiki_views.connect 'projects/:id/wiki/:page', :action => 'special', :page => /page_index|date_index|export/i |
|
52 | wiki_views.connect 'projects/:id/wiki/:page', :action => 'special', :page => /page_index|date_index|export/i | |
53 | wiki_views.connect 'projects/:id/wiki/:page', :action => 'index', :page => nil |
|
53 | wiki_views.connect 'projects/:id/wiki/:page', :action => 'index', :page => nil | |
54 | wiki_views.connect 'projects/:id/wiki/:page/edit', :action => 'edit' |
|
54 | wiki_views.connect 'projects/:id/wiki/:page/edit', :action => 'edit' | |
55 | wiki_views.connect 'projects/:id/wiki/:page/rename', :action => 'rename' |
|
55 | wiki_views.connect 'projects/:id/wiki/:page/rename', :action => 'rename' | |
56 | wiki_views.connect 'projects/:id/wiki/:page/history', :action => 'history' |
|
56 | wiki_views.connect 'projects/:id/wiki/:page/history', :action => 'history' | |
57 | wiki_views.connect 'projects/:id/wiki/:page/diff/:version/vs/:version_from', :action => 'diff' |
|
57 | wiki_views.connect 'projects/:id/wiki/:page/diff/:version/vs/:version_from', :action => 'diff' | |
58 | wiki_views.connect 'projects/:id/wiki/:page/annotate/:version', :action => 'annotate' |
|
58 | wiki_views.connect 'projects/:id/wiki/:page/annotate/:version', :action => 'annotate' | |
59 | end |
|
59 | end | |
60 |
|
60 | |||
61 | wiki_routes.connect 'projects/:id/wiki/:page/:action', |
|
61 | wiki_routes.connect 'projects/:id/wiki/:page/:action', | |
62 | :action => /edit|rename|destroy|preview|protect/, |
|
62 | :action => /edit|rename|destroy|preview|protect/, | |
63 | :conditions => {:method => :post} |
|
63 | :conditions => {:method => :post} | |
64 | end |
|
64 | end | |
65 |
|
65 | |||
66 | map.with_options :controller => 'messages' do |messages_routes| |
|
66 | map.with_options :controller => 'messages' do |messages_routes| | |
67 | messages_routes.with_options :conditions => {:method => :get} do |messages_views| |
|
67 | messages_routes.with_options :conditions => {:method => :get} do |messages_views| | |
68 | messages_views.connect 'boards/:board_id/topics/new', :action => 'new' |
|
68 | messages_views.connect 'boards/:board_id/topics/new', :action => 'new' | |
69 | messages_views.connect 'boards/:board_id/topics/:id', :action => 'show' |
|
69 | messages_views.connect 'boards/:board_id/topics/:id', :action => 'show' | |
70 | messages_views.connect 'boards/:board_id/topics/:id/edit', :action => 'edit' |
|
70 | messages_views.connect 'boards/:board_id/topics/:id/edit', :action => 'edit' | |
71 | end |
|
71 | end | |
72 | messages_routes.with_options :conditions => {:method => :post} do |messages_actions| |
|
72 | messages_routes.with_options :conditions => {:method => :post} do |messages_actions| | |
73 | messages_actions.connect 'boards/:board_id/topics/new', :action => 'new' |
|
73 | messages_actions.connect 'boards/:board_id/topics/new', :action => 'new' | |
74 | messages_actions.connect 'boards/:board_id/topics/:id/replies', :action => 'reply' |
|
74 | messages_actions.connect 'boards/:board_id/topics/:id/replies', :action => 'reply' | |
75 | messages_actions.connect 'boards/:board_id/topics/:id/:action', :action => /edit|destroy/ |
|
75 | messages_actions.connect 'boards/:board_id/topics/:id/:action', :action => /edit|destroy/ | |
76 | end |
|
76 | end | |
77 | end |
|
77 | end | |
78 |
|
78 | |||
79 | map.with_options :controller => 'boards' do |board_routes| |
|
79 | map.with_options :controller => 'boards' do |board_routes| | |
80 | board_routes.with_options :conditions => {:method => :get} do |board_views| |
|
80 | board_routes.with_options :conditions => {:method => :get} do |board_views| | |
81 | board_views.connect 'projects/:project_id/boards', :action => 'index' |
|
81 | board_views.connect 'projects/:project_id/boards', :action => 'index' | |
82 | board_views.connect 'projects/:project_id/boards/new', :action => 'new' |
|
82 | board_views.connect 'projects/:project_id/boards/new', :action => 'new' | |
83 | board_views.connect 'projects/:project_id/boards/:id', :action => 'show' |
|
83 | board_views.connect 'projects/:project_id/boards/:id', :action => 'show' | |
84 | board_views.connect 'projects/:project_id/boards/:id.:format', :action => 'show' |
|
84 | board_views.connect 'projects/:project_id/boards/:id.:format', :action => 'show' | |
85 | board_views.connect 'projects/:project_id/boards/:id/edit', :action => 'edit' |
|
85 | board_views.connect 'projects/:project_id/boards/:id/edit', :action => 'edit' | |
86 | end |
|
86 | end | |
87 | board_routes.with_options :conditions => {:method => :post} do |board_actions| |
|
87 | board_routes.with_options :conditions => {:method => :post} do |board_actions| | |
88 | board_actions.connect 'projects/:project_id/boards', :action => 'new' |
|
88 | board_actions.connect 'projects/:project_id/boards', :action => 'new' | |
89 | board_actions.connect 'projects/:project_id/boards/:id/:action', :action => /edit|destroy/ |
|
89 | board_actions.connect 'projects/:project_id/boards/:id/:action', :action => /edit|destroy/ | |
90 | end |
|
90 | end | |
91 | end |
|
91 | end | |
92 |
|
92 | |||
93 | map.with_options :controller => 'documents' do |document_routes| |
|
93 | map.with_options :controller => 'documents' do |document_routes| | |
94 | document_routes.with_options :conditions => {:method => :get} do |document_views| |
|
94 | document_routes.with_options :conditions => {:method => :get} do |document_views| | |
95 | document_views.connect 'projects/:project_id/documents', :action => 'index' |
|
95 | document_views.connect 'projects/:project_id/documents', :action => 'index' | |
96 | document_views.connect 'projects/:project_id/documents/new', :action => 'new' |
|
96 | document_views.connect 'projects/:project_id/documents/new', :action => 'new' | |
97 | document_views.connect 'documents/:id', :action => 'show' |
|
97 | document_views.connect 'documents/:id', :action => 'show' | |
98 | document_views.connect 'documents/:id/edit', :action => 'edit' |
|
98 | document_views.connect 'documents/:id/edit', :action => 'edit' | |
99 | end |
|
99 | end | |
100 | document_routes.with_options :conditions => {:method => :post} do |document_actions| |
|
100 | document_routes.with_options :conditions => {:method => :post} do |document_actions| | |
101 | document_actions.connect 'projects/:project_id/documents', :action => 'new' |
|
101 | document_actions.connect 'projects/:project_id/documents', :action => 'new' | |
102 | document_actions.connect 'documents/:id/:action', :action => /destroy|edit/ |
|
102 | document_actions.connect 'documents/:id/:action', :action => /destroy|edit/ | |
103 | end |
|
103 | end | |
104 | end |
|
104 | end | |
105 |
|
105 | |||
106 | map.with_options :controller => 'issues' do |issues_routes| |
|
106 | map.with_options :controller => 'issues' do |issues_routes| | |
107 | issues_routes.with_options :conditions => {:method => :get} do |issues_views| |
|
107 | issues_routes.with_options :conditions => {:method => :get} do |issues_views| | |
108 | issues_views.connect 'issues', :action => 'index' |
|
108 | issues_views.connect 'issues', :action => 'index' | |
109 | issues_views.connect 'issues.:format', :action => 'index' |
|
109 | issues_views.connect 'issues.:format', :action => 'index' | |
110 | issues_views.connect 'projects/:project_id/issues', :action => 'index' |
|
110 | issues_views.connect 'projects/:project_id/issues', :action => 'index' | |
111 | issues_views.connect 'projects/:project_id/issues.:format', :action => 'index' |
|
111 | issues_views.connect 'projects/:project_id/issues.:format', :action => 'index' | |
112 | issues_views.connect 'projects/:project_id/issues/new', :action => 'new' |
|
112 | issues_views.connect 'projects/:project_id/issues/new', :action => 'new' | |
113 | issues_views.connect 'projects/:project_id/issues/gantt', :action => 'gantt' |
|
113 | issues_views.connect 'projects/:project_id/issues/gantt', :action => 'gantt' | |
114 | issues_views.connect 'projects/:project_id/issues/calendar', :action => 'calendar' |
|
114 | issues_views.connect 'projects/:project_id/issues/calendar', :action => 'calendar' | |
115 | issues_views.connect 'projects/:project_id/issues/:copy_from/copy', :action => 'new' |
|
115 | issues_views.connect 'projects/:project_id/issues/:copy_from/copy', :action => 'new' | |
116 | issues_views.connect 'issues/:id', :action => 'show', :id => /\d+/ |
|
116 | issues_views.connect 'issues/:id', :action => 'show', :id => /\d+/ | |
117 | issues_views.connect 'issues/:id.:format', :action => 'show', :id => /\d+/ |
|
117 | issues_views.connect 'issues/:id.:format', :action => 'show', :id => /\d+/ | |
118 | issues_views.connect 'issues/:id/edit', :action => 'edit', :id => /\d+/ |
|
118 | issues_views.connect 'issues/:id/edit', :action => 'edit', :id => /\d+/ | |
119 | issues_views.connect 'issues/:id/move', :action => 'move', :id => /\d+/ |
|
119 | issues_views.connect 'issues/:id/move', :action => 'move', :id => /\d+/ | |
120 | end |
|
120 | end | |
121 | issues_routes.with_options :conditions => {:method => :post} do |issues_actions| |
|
121 | issues_routes.with_options :conditions => {:method => :post} do |issues_actions| | |
122 | issues_actions.connect 'issues', :action => 'index' |
|
122 | issues_actions.connect 'issues', :action => 'index' | |
123 | issues_actions.connect 'projects/:project_id/issues', :action => 'new' |
|
123 | issues_actions.connect 'projects/:project_id/issues', :action => 'new' | |
124 | issues_actions.connect 'issues/:id/quoted', :action => 'reply', :id => /\d+/ |
|
124 | issues_actions.connect 'issues/:id/quoted', :action => 'reply', :id => /\d+/ | |
125 | issues_actions.connect 'issues/:id/:action', :action => /edit|move|destroy/, :id => /\d+/ |
|
125 | issues_actions.connect 'issues/:id/:action', :action => /edit|move|destroy/, :id => /\d+/ | |
126 | issues_actions.connect 'issues.:format', :action => 'new', :format => /xml/ |
|
126 | issues_actions.connect 'issues.:format', :action => 'new', :format => /xml/ | |
127 | end |
|
127 | end | |
128 | issues_routes.with_options :conditions => {:method => :put} do |issues_actions| |
|
128 | issues_routes.with_options :conditions => {:method => :put} do |issues_actions| | |
129 | issues_actions.connect 'issues/:id.:format', :action => 'edit', :id => /\d+/, :format => /xml/ |
|
129 | issues_actions.connect 'issues/:id.:format', :action => 'edit', :id => /\d+/, :format => /xml/ | |
130 | end |
|
130 | end | |
131 | issues_routes.with_options :conditions => {:method => :delete} do |issues_actions| |
|
131 | issues_routes.with_options :conditions => {:method => :delete} do |issues_actions| | |
132 | issues_actions.connect 'issues/:id.:format', :action => 'destroy', :id => /\d+/, :format => /xml/ |
|
132 | issues_actions.connect 'issues/:id.:format', :action => 'destroy', :id => /\d+/, :format => /xml/ | |
133 | end |
|
133 | end | |
134 | issues_routes.connect 'issues/:action' |
|
134 | issues_routes.connect 'issues/:action' | |
135 | end |
|
135 | end | |
136 |
|
136 | |||
137 | map.with_options :controller => 'issue_relations', :conditions => {:method => :post} do |relations| |
|
137 | map.with_options :controller => 'issue_relations', :conditions => {:method => :post} do |relations| | |
138 | relations.connect 'issues/:issue_id/relations/:id', :action => 'new' |
|
138 | relations.connect 'issues/:issue_id/relations/:id', :action => 'new' | |
139 | relations.connect 'issues/:issue_id/relations/:id/destroy', :action => 'destroy' |
|
139 | relations.connect 'issues/:issue_id/relations/:id/destroy', :action => 'destroy' | |
140 | end |
|
140 | end | |
141 |
|
141 | |||
142 | map.with_options :controller => 'reports', :action => 'issue_report', :conditions => {:method => :get} do |reports| |
|
142 | map.with_options :controller => 'reports', :action => 'issue_report', :conditions => {:method => :get} do |reports| | |
143 | reports.connect 'projects/:id/issues/report' |
|
143 | reports.connect 'projects/:id/issues/report' | |
144 | reports.connect 'projects/:id/issues/report/:detail' |
|
144 | reports.connect 'projects/:id/issues/report/:detail' | |
145 | end |
|
145 | end | |
146 |
|
146 | |||
147 | map.with_options :controller => 'news' do |news_routes| |
|
147 | map.with_options :controller => 'news' do |news_routes| | |
148 | news_routes.with_options :conditions => {:method => :get} do |news_views| |
|
148 | news_routes.with_options :conditions => {:method => :get} do |news_views| | |
149 | news_views.connect 'news', :action => 'index' |
|
149 | news_views.connect 'news', :action => 'index' | |
150 | news_views.connect 'projects/:project_id/news', :action => 'index' |
|
150 | news_views.connect 'projects/:project_id/news', :action => 'index' | |
151 | news_views.connect 'projects/:project_id/news.:format', :action => 'index' |
|
151 | news_views.connect 'projects/:project_id/news.:format', :action => 'index' | |
152 | news_views.connect 'news.:format', :action => 'index' |
|
152 | news_views.connect 'news.:format', :action => 'index' | |
153 | news_views.connect 'projects/:project_id/news/new', :action => 'new' |
|
153 | news_views.connect 'projects/:project_id/news/new', :action => 'new' | |
154 | news_views.connect 'news/:id', :action => 'show' |
|
154 | news_views.connect 'news/:id', :action => 'show' | |
155 | news_views.connect 'news/:id/edit', :action => 'edit' |
|
155 | news_views.connect 'news/:id/edit', :action => 'edit' | |
156 | end |
|
156 | end | |
157 | news_routes.with_options do |news_actions| |
|
157 | news_routes.with_options do |news_actions| | |
158 | news_actions.connect 'projects/:project_id/news', :action => 'new' |
|
158 | news_actions.connect 'projects/:project_id/news', :action => 'new' | |
159 | news_actions.connect 'news/:id/edit', :action => 'edit' |
|
159 | news_actions.connect 'news/:id/edit', :action => 'edit' | |
160 | news_actions.connect 'news/:id/destroy', :action => 'destroy' |
|
160 | news_actions.connect 'news/:id/destroy', :action => 'destroy' | |
161 | end |
|
161 | end | |
162 | end |
|
162 | end | |
163 |
|
163 | |||
164 | map.connect 'projects/:id/members/new', :controller => 'members', :action => 'new' |
|
164 | map.connect 'projects/:id/members/new', :controller => 'members', :action => 'new' | |
165 |
|
165 | |||
166 | map.with_options :controller => 'users' do |users| |
|
166 | map.with_options :controller => 'users' do |users| | |
167 | users.with_options :conditions => {:method => :get} do |user_views| |
|
167 | users.with_options :conditions => {:method => :get} do |user_views| | |
168 | user_views.connect 'users', :action => 'index' |
|
168 | user_views.connect 'users', :action => 'index' | |
169 | user_views.connect 'users/:id', :action => 'show', :id => /\d+/ |
|
169 | user_views.connect 'users/:id', :action => 'show', :id => /\d+/ | |
170 | user_views.connect 'users/new', :action => 'add' |
|
170 | user_views.connect 'users/new', :action => 'add' | |
171 | user_views.connect 'users/:id/edit/:tab', :action => 'edit', :tab => nil |
|
171 | user_views.connect 'users/:id/edit/:tab', :action => 'edit', :tab => nil | |
172 | end |
|
172 | end | |
173 | users.with_options :conditions => {:method => :post} do |user_actions| |
|
173 | users.with_options :conditions => {:method => :post} do |user_actions| | |
174 | user_actions.connect 'users', :action => 'add' |
|
174 | user_actions.connect 'users', :action => 'add' | |
175 | user_actions.connect 'users/new', :action => 'add' |
|
175 | user_actions.connect 'users/new', :action => 'add' | |
176 | user_actions.connect 'users/:id/edit', :action => 'edit' |
|
176 | user_actions.connect 'users/:id/edit', :action => 'edit' | |
177 | user_actions.connect 'users/:id/memberships', :action => 'edit_membership' |
|
177 | user_actions.connect 'users/:id/memberships', :action => 'edit_membership' | |
178 | user_actions.connect 'users/:id/memberships/:membership_id', :action => 'edit_membership' |
|
178 | user_actions.connect 'users/:id/memberships/:membership_id', :action => 'edit_membership' | |
179 | user_actions.connect 'users/:id/memberships/:membership_id/destroy', :action => 'destroy_membership' |
|
179 | user_actions.connect 'users/:id/memberships/:membership_id/destroy', :action => 'destroy_membership' | |
180 | end |
|
180 | end | |
181 | end |
|
181 | end | |
182 |
|
182 | |||
183 | map.with_options :controller => 'projects' do |projects| |
|
183 | map.with_options :controller => 'projects' do |projects| | |
184 | projects.with_options :conditions => {:method => :get} do |project_views| |
|
184 | projects.with_options :conditions => {:method => :get} do |project_views| | |
185 | project_views.connect 'projects', :action => 'index' |
|
185 | project_views.connect 'projects', :action => 'index' | |
186 | project_views.connect 'projects.:format', :action => 'index' |
|
186 | project_views.connect 'projects.:format', :action => 'index' | |
187 | project_views.connect 'projects/new', :action => 'add' |
|
187 | project_views.connect 'projects/new', :action => 'add' | |
188 | project_views.connect 'projects/:id', :action => 'show' |
|
188 | project_views.connect 'projects/:id', :action => 'show' | |
189 | project_views.connect 'projects/:id.:format', :action => 'show' |
|
189 | project_views.connect 'projects/:id.:format', :action => 'show' | |
190 | project_views.connect 'projects/:id/:action', :action => /roadmap|destroy|settings/ |
|
190 | project_views.connect 'projects/:id/:action', :action => /roadmap|destroy|settings/ | |
191 | project_views.connect 'projects/:id/files', :action => 'list_files' |
|
191 | project_views.connect 'projects/:id/files', :action => 'list_files' | |
192 | project_views.connect 'projects/:id/files/new', :action => 'add_file' |
|
192 | project_views.connect 'projects/:id/files/new', :action => 'add_file' | |
193 | project_views.connect 'projects/:id/versions/new', :action => 'add_version' |
|
193 | project_views.connect 'projects/:id/versions/new', :action => 'add_version' | |
194 | project_views.connect 'projects/:id/categories/new', :action => 'add_issue_category' |
|
194 | project_views.connect 'projects/:id/categories/new', :action => 'add_issue_category' | |
195 | project_views.connect 'projects/:id/settings/:tab', :action => 'settings' |
|
195 | project_views.connect 'projects/:id/settings/:tab', :action => 'settings' | |
196 | end |
|
196 | end | |
197 |
|
197 | |||
198 | projects.with_options :action => 'activity', :conditions => {:method => :get} do |activity| |
|
198 | projects.with_options :action => 'activity', :conditions => {:method => :get} do |activity| | |
199 | activity.connect 'projects/:id/activity' |
|
199 | activity.connect 'projects/:id/activity' | |
200 | activity.connect 'projects/:id/activity.:format' |
|
200 | activity.connect 'projects/:id/activity.:format' | |
201 | activity.connect 'activity', :id => nil |
|
201 | activity.connect 'activity', :id => nil | |
202 | activity.connect 'activity.:format', :id => nil |
|
202 | activity.connect 'activity.:format', :id => nil | |
203 | end |
|
203 | end | |
204 |
|
204 | |||
205 | projects.with_options :conditions => {:method => :post} do |project_actions| |
|
205 | projects.with_options :conditions => {:method => :post} do |project_actions| | |
206 | project_actions.connect 'projects/new', :action => 'add' |
|
206 | project_actions.connect 'projects/new', :action => 'add' | |
207 | project_actions.connect 'projects', :action => 'add' |
|
207 | project_actions.connect 'projects', :action => 'add' | |
208 | project_actions.connect 'projects.:format', :action => 'add', :format => /xml/ |
|
208 | project_actions.connect 'projects.:format', :action => 'add', :format => /xml/ | |
209 | project_actions.connect 'projects/:id/:action', :action => /destroy|archive|unarchive/ |
|
209 | project_actions.connect 'projects/:id/:action', :action => /edit|destroy|archive|unarchive/ | |
210 | project_actions.connect 'projects/:id/files/new', :action => 'add_file' |
|
210 | project_actions.connect 'projects/:id/files/new', :action => 'add_file' | |
211 | project_actions.connect 'projects/:id/versions/new', :action => 'add_version' |
|
211 | project_actions.connect 'projects/:id/versions/new', :action => 'add_version' | |
212 | project_actions.connect 'projects/:id/categories/new', :action => 'add_issue_category' |
|
212 | project_actions.connect 'projects/:id/categories/new', :action => 'add_issue_category' | |
213 | project_actions.connect 'projects/:id/activities/save', :action => 'save_activities' |
|
213 | project_actions.connect 'projects/:id/activities/save', :action => 'save_activities' | |
214 | end |
|
214 | end | |
215 |
|
215 | |||
216 | projects.with_options :conditions => {:method => :put} do |project_actions| |
|
216 | projects.with_options :conditions => {:method => :put} do |project_actions| | |
217 | project_actions.conditions 'projects/:id.:format', :action => 'edit', :format => /xml/ |
|
217 | project_actions.conditions 'projects/:id.:format', :action => 'edit', :format => /xml/ | |
218 | end |
|
218 | end | |
219 |
|
219 | |||
220 | projects.with_options :conditions => {:method => :delete} do |project_actions| |
|
220 | projects.with_options :conditions => {:method => :delete} do |project_actions| | |
221 | project_actions.conditions 'projects/:id.:format', :action => 'destroy', :format => /xml/ |
|
221 | project_actions.conditions 'projects/:id.:format', :action => 'destroy', :format => /xml/ | |
222 | project_actions.conditions 'projects/:id/reset_activities', :action => 'reset_activities' |
|
222 | project_actions.conditions 'projects/:id/reset_activities', :action => 'reset_activities' | |
223 | end |
|
223 | end | |
224 | end |
|
224 | end | |
225 |
|
225 | |||
226 | map.with_options :controller => 'versions' do |versions| |
|
226 | map.with_options :controller => 'versions' do |versions| | |
227 | versions.with_options :conditions => {:method => :post} do |version_actions| |
|
227 | versions.with_options :conditions => {:method => :post} do |version_actions| | |
228 | version_actions.connect 'projects/:project_id/versions/close_completed', :action => 'close_completed' |
|
228 | version_actions.connect 'projects/:project_id/versions/close_completed', :action => 'close_completed' | |
229 | end |
|
229 | end | |
230 | end |
|
230 | end | |
231 |
|
231 | |||
232 | map.with_options :controller => 'repositories' do |repositories| |
|
232 | map.with_options :controller => 'repositories' do |repositories| | |
233 | repositories.with_options :conditions => {:method => :get} do |repository_views| |
|
233 | repositories.with_options :conditions => {:method => :get} do |repository_views| | |
234 | repository_views.connect 'projects/:id/repository', :action => 'show' |
|
234 | repository_views.connect 'projects/:id/repository', :action => 'show' | |
235 | repository_views.connect 'projects/:id/repository/edit', :action => 'edit' |
|
235 | repository_views.connect 'projects/:id/repository/edit', :action => 'edit' | |
236 | repository_views.connect 'projects/:id/repository/statistics', :action => 'stats' |
|
236 | repository_views.connect 'projects/:id/repository/statistics', :action => 'stats' | |
237 | repository_views.connect 'projects/:id/repository/revisions', :action => 'revisions' |
|
237 | repository_views.connect 'projects/:id/repository/revisions', :action => 'revisions' | |
238 | repository_views.connect 'projects/:id/repository/revisions.:format', :action => 'revisions' |
|
238 | repository_views.connect 'projects/:id/repository/revisions.:format', :action => 'revisions' | |
239 | repository_views.connect 'projects/:id/repository/revisions/:rev', :action => 'revision' |
|
239 | repository_views.connect 'projects/:id/repository/revisions/:rev', :action => 'revision' | |
240 | repository_views.connect 'projects/:id/repository/revisions/:rev/diff', :action => 'diff' |
|
240 | repository_views.connect 'projects/:id/repository/revisions/:rev/diff', :action => 'diff' | |
241 | repository_views.connect 'projects/:id/repository/revisions/:rev/diff.:format', :action => 'diff' |
|
241 | repository_views.connect 'projects/:id/repository/revisions/:rev/diff.:format', :action => 'diff' | |
242 | repository_views.connect 'projects/:id/repository/revisions/:rev/raw/*path', :action => 'entry', :format => 'raw', :requirements => { :rev => /[a-z0-9\.\-_]+/ } |
|
242 | repository_views.connect 'projects/:id/repository/revisions/:rev/raw/*path', :action => 'entry', :format => 'raw', :requirements => { :rev => /[a-z0-9\.\-_]+/ } | |
243 | repository_views.connect 'projects/:id/repository/revisions/:rev/:action/*path', :requirements => { :rev => /[a-z0-9\.\-_]+/ } |
|
243 | repository_views.connect 'projects/:id/repository/revisions/:rev/:action/*path', :requirements => { :rev => /[a-z0-9\.\-_]+/ } | |
244 | repository_views.connect 'projects/:id/repository/raw/*path', :action => 'entry', :format => 'raw' |
|
244 | repository_views.connect 'projects/:id/repository/raw/*path', :action => 'entry', :format => 'raw' | |
245 | # TODO: why the following route is required? |
|
245 | # TODO: why the following route is required? | |
246 | repository_views.connect 'projects/:id/repository/entry/*path', :action => 'entry' |
|
246 | repository_views.connect 'projects/:id/repository/entry/*path', :action => 'entry' | |
247 | repository_views.connect 'projects/:id/repository/:action/*path' |
|
247 | repository_views.connect 'projects/:id/repository/:action/*path' | |
248 | end |
|
248 | end | |
249 |
|
249 | |||
250 | repositories.connect 'projects/:id/repository/:action', :conditions => {:method => :post} |
|
250 | repositories.connect 'projects/:id/repository/:action', :conditions => {:method => :post} | |
251 | end |
|
251 | end | |
252 |
|
252 | |||
253 | map.connect 'attachments/:id', :controller => 'attachments', :action => 'show', :id => /\d+/ |
|
253 | map.connect 'attachments/:id', :controller => 'attachments', :action => 'show', :id => /\d+/ | |
254 | map.connect 'attachments/:id/:filename', :controller => 'attachments', :action => 'show', :id => /\d+/, :filename => /.*/ |
|
254 | map.connect 'attachments/:id/:filename', :controller => 'attachments', :action => 'show', :id => /\d+/, :filename => /.*/ | |
255 | map.connect 'attachments/download/:id/:filename', :controller => 'attachments', :action => 'download', :id => /\d+/, :filename => /.*/ |
|
255 | map.connect 'attachments/download/:id/:filename', :controller => 'attachments', :action => 'download', :id => /\d+/, :filename => /.*/ | |
256 |
|
256 | |||
257 | map.resources :groups |
|
257 | map.resources :groups | |
258 |
|
258 | |||
259 | #left old routes at the bottom for backwards compat |
|
259 | #left old routes at the bottom for backwards compat | |
260 | map.connect 'projects/:project_id/issues/:action', :controller => 'issues' |
|
260 | map.connect 'projects/:project_id/issues/:action', :controller => 'issues' | |
261 | map.connect 'projects/:project_id/documents/:action', :controller => 'documents' |
|
261 | map.connect 'projects/:project_id/documents/:action', :controller => 'documents' | |
262 | map.connect 'projects/:project_id/boards/:action/:id', :controller => 'boards' |
|
262 | map.connect 'projects/:project_id/boards/:action/:id', :controller => 'boards' | |
263 | map.connect 'boards/:board_id/topics/:action/:id', :controller => 'messages' |
|
263 | map.connect 'boards/:board_id/topics/:action/:id', :controller => 'messages' | |
264 | map.connect 'wiki/:id/:page/:action', :page => nil, :controller => 'wiki' |
|
264 | map.connect 'wiki/:id/:page/:action', :page => nil, :controller => 'wiki' | |
265 | map.connect 'issues/:issue_id/relations/:action/:id', :controller => 'issue_relations' |
|
265 | map.connect 'issues/:issue_id/relations/:action/:id', :controller => 'issue_relations' | |
266 | map.connect 'projects/:project_id/news/:action', :controller => 'news' |
|
266 | map.connect 'projects/:project_id/news/:action', :controller => 'news' | |
267 | map.connect 'projects/:project_id/timelog/:action/:id', :controller => 'timelog', :project_id => /.+/ |
|
267 | map.connect 'projects/:project_id/timelog/:action/:id', :controller => 'timelog', :project_id => /.+/ | |
268 | map.with_options :controller => 'repositories' do |omap| |
|
268 | map.with_options :controller => 'repositories' do |omap| | |
269 | omap.repositories_show 'repositories/browse/:id/*path', :action => 'browse' |
|
269 | omap.repositories_show 'repositories/browse/:id/*path', :action => 'browse' | |
270 | omap.repositories_changes 'repositories/changes/:id/*path', :action => 'changes' |
|
270 | omap.repositories_changes 'repositories/changes/:id/*path', :action => 'changes' | |
271 | omap.repositories_diff 'repositories/diff/:id/*path', :action => 'diff' |
|
271 | omap.repositories_diff 'repositories/diff/:id/*path', :action => 'diff' | |
272 | omap.repositories_entry 'repositories/entry/:id/*path', :action => 'entry' |
|
272 | omap.repositories_entry 'repositories/entry/:id/*path', :action => 'entry' | |
273 | omap.repositories_entry 'repositories/annotate/:id/*path', :action => 'annotate' |
|
273 | omap.repositories_entry 'repositories/annotate/:id/*path', :action => 'annotate' | |
274 | omap.connect 'repositories/revision/:id/:rev', :action => 'revision' |
|
274 | omap.connect 'repositories/revision/:id/:rev', :action => 'revision' | |
275 | end |
|
275 | end | |
276 |
|
276 | |||
277 | map.with_options :controller => 'sys' do |sys| |
|
277 | map.with_options :controller => 'sys' do |sys| | |
278 | sys.connect 'sys/projects.:format', :action => 'projects', :conditions => {:method => :get} |
|
278 | sys.connect 'sys/projects.:format', :action => 'projects', :conditions => {:method => :get} | |
279 | sys.connect 'sys/projects/:id/repository.:format', :action => 'create_project_repository', :conditions => {:method => :post} |
|
279 | sys.connect 'sys/projects/:id/repository.:format', :action => 'create_project_repository', :conditions => {:method => :post} | |
280 | end |
|
280 | end | |
281 |
|
281 | |||
282 | # Install the default route as the lowest priority. |
|
282 | # Install the default route as the lowest priority. | |
283 | map.connect ':controller/:action/:id' |
|
283 | map.connect ':controller/:action/:id' | |
284 | map.connect 'robots.txt', :controller => 'welcome', :action => 'robots' |
|
284 | map.connect 'robots.txt', :controller => 'welcome', :action => 'robots' | |
285 | # Used for OpenID |
|
285 | # Used for OpenID | |
286 | map.root :controller => 'account', :action => 'login' |
|
286 | map.root :controller => 'account', :action => 'login' | |
287 | end |
|
287 | end |
@@ -1,892 +1,899 | |||||
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 |
|
37 | def test_index_routing | |
38 | assert_routing( |
|
38 | assert_routing( | |
39 | {:method => :get, :path => '/projects'}, |
|
39 | {:method => :get, :path => '/projects'}, | |
40 | :controller => 'projects', :action => 'index' |
|
40 | :controller => 'projects', :action => 'index' | |
41 | ) |
|
41 | ) | |
42 | end |
|
42 | end | |
43 |
|
43 | |||
44 | def test_index |
|
44 | def test_index | |
45 | get :index |
|
45 | get :index | |
46 | assert_response :success |
|
46 | assert_response :success | |
47 | assert_template 'index' |
|
47 | assert_template 'index' | |
48 | assert_not_nil assigns(:projects) |
|
48 | assert_not_nil assigns(:projects) | |
49 |
|
49 | |||
50 | assert_tag :ul, :child => {:tag => 'li', |
|
50 | assert_tag :ul, :child => {:tag => 'li', | |
51 | :descendant => {:tag => 'a', :content => 'eCookbook'}, |
|
51 | :descendant => {:tag => 'a', :content => 'eCookbook'}, | |
52 | :child => { :tag => 'ul', |
|
52 | :child => { :tag => 'ul', | |
53 | :descendant => { :tag => 'a', |
|
53 | :descendant => { :tag => 'a', | |
54 | :content => 'Child of private child' |
|
54 | :content => 'Child of private child' | |
55 | } |
|
55 | } | |
56 | } |
|
56 | } | |
57 | } |
|
57 | } | |
58 |
|
58 | |||
59 | assert_no_tag :a, :content => /Private child of eCookbook/ |
|
59 | assert_no_tag :a, :content => /Private child of eCookbook/ | |
60 | end |
|
60 | end | |
61 |
|
61 | |||
62 | def test_index_atom_routing |
|
62 | def test_index_atom_routing | |
63 | assert_routing( |
|
63 | assert_routing( | |
64 | {:method => :get, :path => '/projects.atom'}, |
|
64 | {:method => :get, :path => '/projects.atom'}, | |
65 | :controller => 'projects', :action => 'index', :format => 'atom' |
|
65 | :controller => 'projects', :action => 'index', :format => 'atom' | |
66 | ) |
|
66 | ) | |
67 | end |
|
67 | end | |
68 |
|
68 | |||
69 | def test_index_atom |
|
69 | def test_index_atom | |
70 | get :index, :format => 'atom' |
|
70 | get :index, :format => 'atom' | |
71 | assert_response :success |
|
71 | assert_response :success | |
72 | assert_template 'common/feed.atom.rxml' |
|
72 | assert_template 'common/feed.atom.rxml' | |
73 | assert_select 'feed>title', :text => 'Redmine: Latest projects' |
|
73 | assert_select 'feed>title', :text => 'Redmine: Latest projects' | |
74 | assert_select 'feed>entry', :count => Project.count(:conditions => Project.visible_by(User.current)) |
|
74 | assert_select 'feed>entry', :count => Project.count(:conditions => Project.visible_by(User.current)) | |
75 | end |
|
75 | end | |
76 |
|
76 | |||
77 | def test_add_routing |
|
77 | def test_add_routing | |
78 | assert_routing( |
|
78 | assert_routing( | |
79 | {:method => :get, :path => '/projects/new'}, |
|
79 | {:method => :get, :path => '/projects/new'}, | |
80 | :controller => 'projects', :action => 'add' |
|
80 | :controller => 'projects', :action => 'add' | |
81 | ) |
|
81 | ) | |
82 | assert_recognizes( |
|
82 | assert_recognizes( | |
83 | {:controller => 'projects', :action => 'add'}, |
|
83 | {:controller => 'projects', :action => 'add'}, | |
84 | {:method => :post, :path => '/projects/new'} |
|
84 | {:method => :post, :path => '/projects/new'} | |
85 | ) |
|
85 | ) | |
86 | assert_recognizes( |
|
86 | assert_recognizes( | |
87 | {:controller => 'projects', :action => 'add'}, |
|
87 | {:controller => 'projects', :action => 'add'}, | |
88 | {:method => :post, :path => '/projects'} |
|
88 | {:method => :post, :path => '/projects'} | |
89 | ) |
|
89 | ) | |
90 | end |
|
90 | end | |
91 |
|
91 | |||
92 | context "#add" do |
|
92 | context "#add" do | |
93 | context "by admin user" do |
|
93 | context "by admin user" do | |
94 | setup do |
|
94 | setup do | |
95 | @request.session[:user_id] = 1 |
|
95 | @request.session[:user_id] = 1 | |
96 | end |
|
96 | end | |
97 |
|
97 | |||
98 | should "accept get" do |
|
98 | should "accept get" do | |
99 | get :add |
|
99 | get :add | |
100 | assert_response :success |
|
100 | assert_response :success | |
101 | assert_template 'add' |
|
101 | assert_template 'add' | |
102 | end |
|
102 | end | |
103 |
|
103 | |||
104 | should "accept post" do |
|
104 | should "accept post" do | |
105 | post :add, :project => { :name => "blog", |
|
105 | post :add, :project => { :name => "blog", | |
106 | :description => "weblog", |
|
106 | :description => "weblog", | |
107 | :identifier => "blog", |
|
107 | :identifier => "blog", | |
108 | :is_public => 1, |
|
108 | :is_public => 1, | |
109 | :custom_field_values => { '3' => 'Beta' } |
|
109 | :custom_field_values => { '3' => 'Beta' } | |
110 | } |
|
110 | } | |
111 | assert_redirected_to '/projects/blog/settings' |
|
111 | assert_redirected_to '/projects/blog/settings' | |
112 |
|
112 | |||
113 | project = Project.find_by_name('blog') |
|
113 | project = Project.find_by_name('blog') | |
114 | assert_kind_of Project, project |
|
114 | assert_kind_of Project, project | |
115 | assert_equal 'weblog', project.description |
|
115 | assert_equal 'weblog', project.description | |
116 | assert_equal true, project.is_public? |
|
116 | assert_equal true, project.is_public? | |
117 | assert_nil project.parent |
|
117 | assert_nil project.parent | |
118 | end |
|
118 | end | |
119 |
|
119 | |||
120 | should "accept post with parent" do |
|
120 | should "accept post with parent" do | |
121 | post :add, :project => { :name => "blog", |
|
121 | post :add, :project => { :name => "blog", | |
122 | :description => "weblog", |
|
122 | :description => "weblog", | |
123 | :identifier => "blog", |
|
123 | :identifier => "blog", | |
124 | :is_public => 1, |
|
124 | :is_public => 1, | |
125 | :custom_field_values => { '3' => 'Beta' }, |
|
125 | :custom_field_values => { '3' => 'Beta' }, | |
126 | :parent_id => 1 |
|
126 | :parent_id => 1 | |
127 | } |
|
127 | } | |
128 | assert_redirected_to '/projects/blog/settings' |
|
128 | assert_redirected_to '/projects/blog/settings' | |
129 |
|
129 | |||
130 | project = Project.find_by_name('blog') |
|
130 | project = Project.find_by_name('blog') | |
131 | assert_kind_of Project, project |
|
131 | assert_kind_of Project, project | |
132 | assert_equal Project.find(1), project.parent |
|
132 | assert_equal Project.find(1), project.parent | |
133 | end |
|
133 | end | |
134 | end |
|
134 | end | |
135 |
|
135 | |||
136 | context "by non-admin user with add_project permission" do |
|
136 | context "by non-admin user with add_project permission" do | |
137 | setup do |
|
137 | setup do | |
138 | Role.non_member.add_permission! :add_project |
|
138 | Role.non_member.add_permission! :add_project | |
139 | @request.session[:user_id] = 9 |
|
139 | @request.session[:user_id] = 9 | |
140 | end |
|
140 | end | |
141 |
|
141 | |||
142 | should "accept get" do |
|
142 | should "accept get" do | |
143 | get :add |
|
143 | get :add | |
144 | assert_response :success |
|
144 | assert_response :success | |
145 | assert_template 'add' |
|
145 | assert_template 'add' | |
146 | assert_no_tag :select, :attributes => {:name => 'project[parent_id]'} |
|
146 | assert_no_tag :select, :attributes => {:name => 'project[parent_id]'} | |
147 | end |
|
147 | end | |
148 |
|
148 | |||
149 | should "accept post" do |
|
149 | should "accept post" do | |
150 | post :add, :project => { :name => "blog", |
|
150 | post :add, :project => { :name => "blog", | |
151 | :description => "weblog", |
|
151 | :description => "weblog", | |
152 | :identifier => "blog", |
|
152 | :identifier => "blog", | |
153 | :is_public => 1, |
|
153 | :is_public => 1, | |
154 | :custom_field_values => { '3' => 'Beta' } |
|
154 | :custom_field_values => { '3' => 'Beta' } | |
155 | } |
|
155 | } | |
156 |
|
156 | |||
157 | assert_redirected_to '/projects/blog/settings' |
|
157 | assert_redirected_to '/projects/blog/settings' | |
158 |
|
158 | |||
159 | project = Project.find_by_name('blog') |
|
159 | project = Project.find_by_name('blog') | |
160 | assert_kind_of Project, project |
|
160 | assert_kind_of Project, project | |
161 | assert_equal 'weblog', project.description |
|
161 | assert_equal 'weblog', project.description | |
162 | assert_equal true, project.is_public? |
|
162 | assert_equal true, project.is_public? | |
163 |
|
163 | |||
164 | # User should be added as a project member |
|
164 | # User should be added as a project member | |
165 | assert User.find(9).member_of?(project) |
|
165 | assert User.find(9).member_of?(project) | |
166 | assert_equal 1, project.members.size |
|
166 | assert_equal 1, project.members.size | |
167 | end |
|
167 | end | |
168 |
|
168 | |||
169 | should "fail with parent_id" do |
|
169 | should "fail with parent_id" do | |
170 | assert_no_difference 'Project.count' do |
|
170 | assert_no_difference 'Project.count' do | |
171 | post :add, :project => { :name => "blog", |
|
171 | post :add, :project => { :name => "blog", | |
172 | :description => "weblog", |
|
172 | :description => "weblog", | |
173 | :identifier => "blog", |
|
173 | :identifier => "blog", | |
174 | :is_public => 1, |
|
174 | :is_public => 1, | |
175 | :custom_field_values => { '3' => 'Beta' }, |
|
175 | :custom_field_values => { '3' => 'Beta' }, | |
176 | :parent_id => 1 |
|
176 | :parent_id => 1 | |
177 | } |
|
177 | } | |
178 | end |
|
178 | end | |
179 | assert_response :success |
|
179 | assert_response :success | |
180 | project = assigns(:project) |
|
180 | project = assigns(:project) | |
181 | assert_kind_of Project, project |
|
181 | assert_kind_of Project, project | |
182 | assert_not_nil project.errors.on(:parent_id) |
|
182 | assert_not_nil project.errors.on(:parent_id) | |
183 | end |
|
183 | end | |
184 | end |
|
184 | end | |
185 |
|
185 | |||
186 | context "by non-admin user with add_subprojects permission" do |
|
186 | context "by non-admin user with add_subprojects permission" do | |
187 | setup do |
|
187 | setup do | |
188 | Role.find(1).remove_permission! :add_project |
|
188 | Role.find(1).remove_permission! :add_project | |
189 | Role.find(1).add_permission! :add_subprojects |
|
189 | Role.find(1).add_permission! :add_subprojects | |
190 | @request.session[:user_id] = 2 |
|
190 | @request.session[:user_id] = 2 | |
191 | end |
|
191 | end | |
192 |
|
192 | |||
193 | should "accept get" do |
|
193 | should "accept get" do | |
194 | get :add, :parent_id => 'ecookbook' |
|
194 | get :add, :parent_id => 'ecookbook' | |
195 | assert_response :success |
|
195 | assert_response :success | |
196 | assert_template 'add' |
|
196 | assert_template 'add' | |
197 | # parent project selected |
|
197 | # parent project selected | |
198 | assert_tag :select, :attributes => {:name => 'project[parent_id]'}, |
|
198 | assert_tag :select, :attributes => {:name => 'project[parent_id]'}, | |
199 | :child => {:tag => 'option', :attributes => {:value => '1', :selected => 'selected'}} |
|
199 | :child => {:tag => 'option', :attributes => {:value => '1', :selected => 'selected'}} | |
200 | # no empty value |
|
200 | # no empty value | |
201 | assert_no_tag :select, :attributes => {:name => 'project[parent_id]'}, |
|
201 | assert_no_tag :select, :attributes => {:name => 'project[parent_id]'}, | |
202 | :child => {:tag => 'option', :attributes => {:value => ''}} |
|
202 | :child => {:tag => 'option', :attributes => {:value => ''}} | |
203 | end |
|
203 | end | |
204 |
|
204 | |||
205 | should "accept post with parent_id" do |
|
205 | should "accept post with parent_id" do | |
206 | post :add, :project => { :name => "blog", |
|
206 | post :add, :project => { :name => "blog", | |
207 | :description => "weblog", |
|
207 | :description => "weblog", | |
208 | :identifier => "blog", |
|
208 | :identifier => "blog", | |
209 | :is_public => 1, |
|
209 | :is_public => 1, | |
210 | :custom_field_values => { '3' => 'Beta' }, |
|
210 | :custom_field_values => { '3' => 'Beta' }, | |
211 | :parent_id => 1 |
|
211 | :parent_id => 1 | |
212 | } |
|
212 | } | |
213 | assert_redirected_to '/projects/blog/settings' |
|
213 | assert_redirected_to '/projects/blog/settings' | |
214 | project = Project.find_by_name('blog') |
|
214 | project = Project.find_by_name('blog') | |
215 | end |
|
215 | end | |
216 |
|
216 | |||
217 | should "fail without parent_id" do |
|
217 | should "fail without parent_id" do | |
218 | assert_no_difference 'Project.count' do |
|
218 | assert_no_difference 'Project.count' do | |
219 | post :add, :project => { :name => "blog", |
|
219 | post :add, :project => { :name => "blog", | |
220 | :description => "weblog", |
|
220 | :description => "weblog", | |
221 | :identifier => "blog", |
|
221 | :identifier => "blog", | |
222 | :is_public => 1, |
|
222 | :is_public => 1, | |
223 | :custom_field_values => { '3' => 'Beta' } |
|
223 | :custom_field_values => { '3' => 'Beta' } | |
224 | } |
|
224 | } | |
225 | end |
|
225 | end | |
226 | assert_response :success |
|
226 | assert_response :success | |
227 | project = assigns(:project) |
|
227 | project = assigns(:project) | |
228 | assert_kind_of Project, project |
|
228 | assert_kind_of Project, project | |
229 | assert_not_nil project.errors.on(:parent_id) |
|
229 | assert_not_nil project.errors.on(:parent_id) | |
230 | end |
|
230 | end | |
231 |
|
231 | |||
232 | should "fail with unauthorized parent_id" do |
|
232 | should "fail with unauthorized parent_id" do | |
233 | assert !User.find(2).member_of?(Project.find(6)) |
|
233 | assert !User.find(2).member_of?(Project.find(6)) | |
234 | assert_no_difference 'Project.count' do |
|
234 | assert_no_difference 'Project.count' do | |
235 | post :add, :project => { :name => "blog", |
|
235 | post :add, :project => { :name => "blog", | |
236 | :description => "weblog", |
|
236 | :description => "weblog", | |
237 | :identifier => "blog", |
|
237 | :identifier => "blog", | |
238 | :is_public => 1, |
|
238 | :is_public => 1, | |
239 | :custom_field_values => { '3' => 'Beta' }, |
|
239 | :custom_field_values => { '3' => 'Beta' }, | |
240 | :parent_id => 6 |
|
240 | :parent_id => 6 | |
241 | } |
|
241 | } | |
242 | end |
|
242 | end | |
243 | assert_response :success |
|
243 | assert_response :success | |
244 | project = assigns(:project) |
|
244 | project = assigns(:project) | |
245 | assert_kind_of Project, project |
|
245 | assert_kind_of Project, project | |
246 | assert_not_nil project.errors.on(:parent_id) |
|
246 | assert_not_nil project.errors.on(:parent_id) | |
247 | end |
|
247 | end | |
248 | end |
|
248 | end | |
249 | end |
|
249 | end | |
250 |
|
250 | |||
251 | def test_show_routing |
|
251 | def test_show_routing | |
252 | assert_routing( |
|
252 | assert_routing( | |
253 | {:method => :get, :path => '/projects/test'}, |
|
253 | {:method => :get, :path => '/projects/test'}, | |
254 | :controller => 'projects', :action => 'show', :id => 'test' |
|
254 | :controller => 'projects', :action => 'show', :id => 'test' | |
255 | ) |
|
255 | ) | |
256 | end |
|
256 | end | |
257 |
|
257 | |||
258 | def test_show_by_id |
|
258 | def test_show_by_id | |
259 | get :show, :id => 1 |
|
259 | get :show, :id => 1 | |
260 | assert_response :success |
|
260 | assert_response :success | |
261 | assert_template 'show' |
|
261 | assert_template 'show' | |
262 | assert_not_nil assigns(:project) |
|
262 | assert_not_nil assigns(:project) | |
263 | end |
|
263 | end | |
264 |
|
264 | |||
265 | def test_show_by_identifier |
|
265 | def test_show_by_identifier | |
266 | get :show, :id => 'ecookbook' |
|
266 | get :show, :id => 'ecookbook' | |
267 | assert_response :success |
|
267 | assert_response :success | |
268 | assert_template 'show' |
|
268 | assert_template 'show' | |
269 | assert_not_nil assigns(:project) |
|
269 | assert_not_nil assigns(:project) | |
270 | assert_equal Project.find_by_identifier('ecookbook'), assigns(:project) |
|
270 | assert_equal Project.find_by_identifier('ecookbook'), assigns(:project) | |
271 | end |
|
271 | end | |
272 |
|
272 | |||
273 | def test_show_should_not_fail_when_custom_values_are_nil |
|
273 | def test_show_should_not_fail_when_custom_values_are_nil | |
274 | project = Project.find_by_identifier('ecookbook') |
|
274 | project = Project.find_by_identifier('ecookbook') | |
275 | project.custom_values.first.update_attribute(:value, nil) |
|
275 | project.custom_values.first.update_attribute(:value, nil) | |
276 | get :show, :id => 'ecookbook' |
|
276 | get :show, :id => 'ecookbook' | |
277 | assert_response :success |
|
277 | assert_response :success | |
278 | assert_template 'show' |
|
278 | assert_template 'show' | |
279 | assert_not_nil assigns(:project) |
|
279 | assert_not_nil assigns(:project) | |
280 | assert_equal Project.find_by_identifier('ecookbook'), assigns(:project) |
|
280 | assert_equal Project.find_by_identifier('ecookbook'), assigns(:project) | |
281 | end |
|
281 | end | |
282 |
|
282 | |||
283 | def test_private_subprojects_hidden |
|
283 | def test_private_subprojects_hidden | |
284 | get :show, :id => 'ecookbook' |
|
284 | get :show, :id => 'ecookbook' | |
285 | assert_response :success |
|
285 | assert_response :success | |
286 | assert_template 'show' |
|
286 | assert_template 'show' | |
287 | assert_no_tag :tag => 'a', :content => /Private child/ |
|
287 | assert_no_tag :tag => 'a', :content => /Private child/ | |
288 | end |
|
288 | end | |
289 |
|
289 | |||
290 | def test_private_subprojects_visible |
|
290 | def test_private_subprojects_visible | |
291 | @request.session[:user_id] = 2 # manager who is a member of the private subproject |
|
291 | @request.session[:user_id] = 2 # manager who is a member of the private subproject | |
292 | get :show, :id => 'ecookbook' |
|
292 | get :show, :id => 'ecookbook' | |
293 | assert_response :success |
|
293 | assert_response :success | |
294 | assert_template 'show' |
|
294 | assert_template 'show' | |
295 | assert_tag :tag => 'a', :content => /Private child/ |
|
295 | assert_tag :tag => 'a', :content => /Private child/ | |
296 | end |
|
296 | end | |
297 |
|
297 | |||
298 | def test_settings_routing |
|
298 | def test_settings_routing | |
299 | assert_routing( |
|
299 | assert_routing( | |
300 | {:method => :get, :path => '/projects/4223/settings'}, |
|
300 | {:method => :get, :path => '/projects/4223/settings'}, | |
301 | :controller => 'projects', :action => 'settings', :id => '4223' |
|
301 | :controller => 'projects', :action => 'settings', :id => '4223' | |
302 | ) |
|
302 | ) | |
303 | assert_routing( |
|
303 | assert_routing( | |
304 | {:method => :get, :path => '/projects/4223/settings/members'}, |
|
304 | {:method => :get, :path => '/projects/4223/settings/members'}, | |
305 | :controller => 'projects', :action => 'settings', :id => '4223', :tab => 'members' |
|
305 | :controller => 'projects', :action => 'settings', :id => '4223', :tab => 'members' | |
306 | ) |
|
306 | ) | |
307 | end |
|
307 | end | |
308 |
|
308 | |||
309 | def test_settings |
|
309 | def test_settings | |
310 | @request.session[:user_id] = 2 # manager |
|
310 | @request.session[:user_id] = 2 # manager | |
311 | get :settings, :id => 1 |
|
311 | get :settings, :id => 1 | |
312 | assert_response :success |
|
312 | assert_response :success | |
313 | assert_template 'settings' |
|
313 | assert_template 'settings' | |
314 | end |
|
314 | end | |
315 |
|
315 | |||
|
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 | ||||
316 | def test_edit |
|
323 | def test_edit | |
317 | @request.session[:user_id] = 2 # manager |
|
324 | @request.session[:user_id] = 2 # manager | |
318 | post :edit, :id => 1, :project => {:name => 'Test changed name', |
|
325 | post :edit, :id => 1, :project => {:name => 'Test changed name', | |
319 | :issue_custom_field_ids => ['']} |
|
326 | :issue_custom_field_ids => ['']} | |
320 | assert_redirected_to 'projects/ecookbook/settings' |
|
327 | assert_redirected_to 'projects/ecookbook/settings' | |
321 | project = Project.find(1) |
|
328 | project = Project.find(1) | |
322 | assert_equal 'Test changed name', project.name |
|
329 | assert_equal 'Test changed name', project.name | |
323 | end |
|
330 | end | |
324 |
|
331 | |||
325 | def test_add_version_routing |
|
332 | def test_add_version_routing | |
326 | assert_routing( |
|
333 | assert_routing( | |
327 | {:method => :get, :path => 'projects/64/versions/new'}, |
|
334 | {:method => :get, :path => 'projects/64/versions/new'}, | |
328 | :controller => 'projects', :action => 'add_version', :id => '64' |
|
335 | :controller => 'projects', :action => 'add_version', :id => '64' | |
329 | ) |
|
336 | ) | |
330 | assert_routing( |
|
337 | assert_routing( | |
331 | #TODO: use PUT |
|
338 | #TODO: use PUT | |
332 | {:method => :post, :path => 'projects/64/versions/new'}, |
|
339 | {:method => :post, :path => 'projects/64/versions/new'}, | |
333 | :controller => 'projects', :action => 'add_version', :id => '64' |
|
340 | :controller => 'projects', :action => 'add_version', :id => '64' | |
334 | ) |
|
341 | ) | |
335 | end |
|
342 | end | |
336 |
|
343 | |||
337 | def test_add_version |
|
344 | def test_add_version | |
338 | @request.session[:user_id] = 2 # manager |
|
345 | @request.session[:user_id] = 2 # manager | |
339 | assert_difference 'Version.count' do |
|
346 | assert_difference 'Version.count' do | |
340 | post :add_version, :id => '1', :version => {:name => 'test_add_version'} |
|
347 | post :add_version, :id => '1', :version => {:name => 'test_add_version'} | |
341 | end |
|
348 | end | |
342 | assert_redirected_to '/projects/ecookbook/settings/versions' |
|
349 | assert_redirected_to '/projects/ecookbook/settings/versions' | |
343 | version = Version.find_by_name('test_add_version') |
|
350 | version = Version.find_by_name('test_add_version') | |
344 | assert_not_nil version |
|
351 | assert_not_nil version | |
345 | assert_equal 1, version.project_id |
|
352 | assert_equal 1, version.project_id | |
346 | end |
|
353 | end | |
347 |
|
354 | |||
348 | def test_add_version_from_issue_form |
|
355 | def test_add_version_from_issue_form | |
349 | @request.session[:user_id] = 2 # manager |
|
356 | @request.session[:user_id] = 2 # manager | |
350 | assert_difference 'Version.count' do |
|
357 | assert_difference 'Version.count' do | |
351 | xhr :post, :add_version, :id => '1', :version => {:name => 'test_add_version_from_issue_form'} |
|
358 | xhr :post, :add_version, :id => '1', :version => {:name => 'test_add_version_from_issue_form'} | |
352 | end |
|
359 | end | |
353 | assert_response :success |
|
360 | assert_response :success | |
354 | assert_select_rjs :replace, 'issue_fixed_version_id' |
|
361 | assert_select_rjs :replace, 'issue_fixed_version_id' | |
355 | version = Version.find_by_name('test_add_version_from_issue_form') |
|
362 | version = Version.find_by_name('test_add_version_from_issue_form') | |
356 | assert_not_nil version |
|
363 | assert_not_nil version | |
357 | assert_equal 1, version.project_id |
|
364 | assert_equal 1, version.project_id | |
358 | end |
|
365 | end | |
359 |
|
366 | |||
360 | def test_add_issue_category_routing |
|
367 | def test_add_issue_category_routing | |
361 | assert_routing( |
|
368 | assert_routing( | |
362 | {:method => :get, :path => 'projects/test/categories/new'}, |
|
369 | {:method => :get, :path => 'projects/test/categories/new'}, | |
363 | :controller => 'projects', :action => 'add_issue_category', :id => 'test' |
|
370 | :controller => 'projects', :action => 'add_issue_category', :id => 'test' | |
364 | ) |
|
371 | ) | |
365 | assert_routing( |
|
372 | assert_routing( | |
366 | #TODO: use PUT and update form |
|
373 | #TODO: use PUT and update form | |
367 | {:method => :post, :path => 'projects/64/categories/new'}, |
|
374 | {:method => :post, :path => 'projects/64/categories/new'}, | |
368 | :controller => 'projects', :action => 'add_issue_category', :id => '64' |
|
375 | :controller => 'projects', :action => 'add_issue_category', :id => '64' | |
369 | ) |
|
376 | ) | |
370 | end |
|
377 | end | |
371 |
|
378 | |||
372 | def test_destroy_routing |
|
379 | def test_destroy_routing | |
373 | assert_routing( |
|
380 | assert_routing( | |
374 | {:method => :get, :path => '/projects/567/destroy'}, |
|
381 | {:method => :get, :path => '/projects/567/destroy'}, | |
375 | :controller => 'projects', :action => 'destroy', :id => '567' |
|
382 | :controller => 'projects', :action => 'destroy', :id => '567' | |
376 | ) |
|
383 | ) | |
377 | assert_routing( |
|
384 | assert_routing( | |
378 | #TODO: use DELETE and update form |
|
385 | #TODO: use DELETE and update form | |
379 | {:method => :post, :path => 'projects/64/destroy'}, |
|
386 | {:method => :post, :path => 'projects/64/destroy'}, | |
380 | :controller => 'projects', :action => 'destroy', :id => '64' |
|
387 | :controller => 'projects', :action => 'destroy', :id => '64' | |
381 | ) |
|
388 | ) | |
382 | end |
|
389 | end | |
383 |
|
390 | |||
384 | def test_get_destroy |
|
391 | def test_get_destroy | |
385 | @request.session[:user_id] = 1 # admin |
|
392 | @request.session[:user_id] = 1 # admin | |
386 | get :destroy, :id => 1 |
|
393 | get :destroy, :id => 1 | |
387 | assert_response :success |
|
394 | assert_response :success | |
388 | assert_template 'destroy' |
|
395 | assert_template 'destroy' | |
389 | assert_not_nil Project.find_by_id(1) |
|
396 | assert_not_nil Project.find_by_id(1) | |
390 | end |
|
397 | end | |
391 |
|
398 | |||
392 | def test_post_destroy |
|
399 | def test_post_destroy | |
393 | @request.session[:user_id] = 1 # admin |
|
400 | @request.session[:user_id] = 1 # admin | |
394 | post :destroy, :id => 1, :confirm => 1 |
|
401 | post :destroy, :id => 1, :confirm => 1 | |
395 | assert_redirected_to 'admin/projects' |
|
402 | assert_redirected_to 'admin/projects' | |
396 | assert_nil Project.find_by_id(1) |
|
403 | assert_nil Project.find_by_id(1) | |
397 | end |
|
404 | end | |
398 |
|
405 | |||
399 | def test_add_file |
|
406 | def test_add_file | |
400 | set_tmp_attachments_directory |
|
407 | set_tmp_attachments_directory | |
401 | @request.session[:user_id] = 2 |
|
408 | @request.session[:user_id] = 2 | |
402 | Setting.notified_events = ['file_added'] |
|
409 | Setting.notified_events = ['file_added'] | |
403 | ActionMailer::Base.deliveries.clear |
|
410 | ActionMailer::Base.deliveries.clear | |
404 |
|
411 | |||
405 | assert_difference 'Attachment.count' do |
|
412 | assert_difference 'Attachment.count' do | |
406 | post :add_file, :id => 1, :version_id => '', |
|
413 | post :add_file, :id => 1, :version_id => '', | |
407 | :attachments => {'1' => {'file' => uploaded_test_file('testfile.txt', 'text/plain')}} |
|
414 | :attachments => {'1' => {'file' => uploaded_test_file('testfile.txt', 'text/plain')}} | |
408 | end |
|
415 | end | |
409 | assert_redirected_to 'projects/ecookbook/files' |
|
416 | assert_redirected_to 'projects/ecookbook/files' | |
410 | a = Attachment.find(:first, :order => 'created_on DESC') |
|
417 | a = Attachment.find(:first, :order => 'created_on DESC') | |
411 | assert_equal 'testfile.txt', a.filename |
|
418 | assert_equal 'testfile.txt', a.filename | |
412 | assert_equal Project.find(1), a.container |
|
419 | assert_equal Project.find(1), a.container | |
413 |
|
420 | |||
414 | mail = ActionMailer::Base.deliveries.last |
|
421 | mail = ActionMailer::Base.deliveries.last | |
415 | assert_kind_of TMail::Mail, mail |
|
422 | assert_kind_of TMail::Mail, mail | |
416 | assert_equal "[eCookbook] New file", mail.subject |
|
423 | assert_equal "[eCookbook] New file", mail.subject | |
417 | assert mail.body.include?('testfile.txt') |
|
424 | assert mail.body.include?('testfile.txt') | |
418 | end |
|
425 | end | |
419 |
|
426 | |||
420 | def test_add_file_routing |
|
427 | def test_add_file_routing | |
421 | assert_routing( |
|
428 | assert_routing( | |
422 | {:method => :get, :path => '/projects/33/files/new'}, |
|
429 | {:method => :get, :path => '/projects/33/files/new'}, | |
423 | :controller => 'projects', :action => 'add_file', :id => '33' |
|
430 | :controller => 'projects', :action => 'add_file', :id => '33' | |
424 | ) |
|
431 | ) | |
425 | assert_routing( |
|
432 | assert_routing( | |
426 | {:method => :post, :path => '/projects/33/files/new'}, |
|
433 | {:method => :post, :path => '/projects/33/files/new'}, | |
427 | :controller => 'projects', :action => 'add_file', :id => '33' |
|
434 | :controller => 'projects', :action => 'add_file', :id => '33' | |
428 | ) |
|
435 | ) | |
429 | end |
|
436 | end | |
430 |
|
437 | |||
431 | def test_add_version_file |
|
438 | def test_add_version_file | |
432 | set_tmp_attachments_directory |
|
439 | set_tmp_attachments_directory | |
433 | @request.session[:user_id] = 2 |
|
440 | @request.session[:user_id] = 2 | |
434 | Setting.notified_events = ['file_added'] |
|
441 | Setting.notified_events = ['file_added'] | |
435 |
|
442 | |||
436 | assert_difference 'Attachment.count' do |
|
443 | assert_difference 'Attachment.count' do | |
437 | post :add_file, :id => 1, :version_id => '2', |
|
444 | post :add_file, :id => 1, :version_id => '2', | |
438 | :attachments => {'1' => {'file' => uploaded_test_file('testfile.txt', 'text/plain')}} |
|
445 | :attachments => {'1' => {'file' => uploaded_test_file('testfile.txt', 'text/plain')}} | |
439 | end |
|
446 | end | |
440 | assert_redirected_to 'projects/ecookbook/files' |
|
447 | assert_redirected_to 'projects/ecookbook/files' | |
441 | a = Attachment.find(:first, :order => 'created_on DESC') |
|
448 | a = Attachment.find(:first, :order => 'created_on DESC') | |
442 | assert_equal 'testfile.txt', a.filename |
|
449 | assert_equal 'testfile.txt', a.filename | |
443 | assert_equal Version.find(2), a.container |
|
450 | assert_equal Version.find(2), a.container | |
444 | end |
|
451 | end | |
445 |
|
452 | |||
446 | def test_list_files |
|
453 | def test_list_files | |
447 | get :list_files, :id => 1 |
|
454 | get :list_files, :id => 1 | |
448 | assert_response :success |
|
455 | assert_response :success | |
449 | assert_template 'list_files' |
|
456 | assert_template 'list_files' | |
450 | assert_not_nil assigns(:containers) |
|
457 | assert_not_nil assigns(:containers) | |
451 |
|
458 | |||
452 | # file attached to the project |
|
459 | # file attached to the project | |
453 | assert_tag :a, :content => 'project_file.zip', |
|
460 | assert_tag :a, :content => 'project_file.zip', | |
454 | :attributes => { :href => '/attachments/download/8/project_file.zip' } |
|
461 | :attributes => { :href => '/attachments/download/8/project_file.zip' } | |
455 |
|
462 | |||
456 | # file attached to a project's version |
|
463 | # file attached to a project's version | |
457 | assert_tag :a, :content => 'version_file.zip', |
|
464 | assert_tag :a, :content => 'version_file.zip', | |
458 | :attributes => { :href => '/attachments/download/9/version_file.zip' } |
|
465 | :attributes => { :href => '/attachments/download/9/version_file.zip' } | |
459 | end |
|
466 | end | |
460 |
|
467 | |||
461 | def test_list_files_routing |
|
468 | def test_list_files_routing | |
462 | assert_routing( |
|
469 | assert_routing( | |
463 | {:method => :get, :path => '/projects/33/files'}, |
|
470 | {:method => :get, :path => '/projects/33/files'}, | |
464 | :controller => 'projects', :action => 'list_files', :id => '33' |
|
471 | :controller => 'projects', :action => 'list_files', :id => '33' | |
465 | ) |
|
472 | ) | |
466 | end |
|
473 | end | |
467 |
|
474 | |||
468 | def test_roadmap_routing |
|
475 | def test_roadmap_routing | |
469 | assert_routing( |
|
476 | assert_routing( | |
470 | {:method => :get, :path => 'projects/33/roadmap'}, |
|
477 | {:method => :get, :path => 'projects/33/roadmap'}, | |
471 | :controller => 'projects', :action => 'roadmap', :id => '33' |
|
478 | :controller => 'projects', :action => 'roadmap', :id => '33' | |
472 | ) |
|
479 | ) | |
473 | end |
|
480 | end | |
474 |
|
481 | |||
475 | def test_roadmap |
|
482 | def test_roadmap | |
476 | get :roadmap, :id => 1 |
|
483 | get :roadmap, :id => 1 | |
477 | assert_response :success |
|
484 | assert_response :success | |
478 | assert_template 'roadmap' |
|
485 | assert_template 'roadmap' | |
479 | assert_not_nil assigns(:versions) |
|
486 | assert_not_nil assigns(:versions) | |
480 | # Version with no date set appears |
|
487 | # Version with no date set appears | |
481 | assert assigns(:versions).include?(Version.find(3)) |
|
488 | assert assigns(:versions).include?(Version.find(3)) | |
482 | # Completed version doesn't appear |
|
489 | # Completed version doesn't appear | |
483 | assert !assigns(:versions).include?(Version.find(1)) |
|
490 | assert !assigns(:versions).include?(Version.find(1)) | |
484 | end |
|
491 | end | |
485 |
|
492 | |||
486 | def test_roadmap_with_completed_versions |
|
493 | def test_roadmap_with_completed_versions | |
487 | get :roadmap, :id => 1, :completed => 1 |
|
494 | get :roadmap, :id => 1, :completed => 1 | |
488 | assert_response :success |
|
495 | assert_response :success | |
489 | assert_template 'roadmap' |
|
496 | assert_template 'roadmap' | |
490 | assert_not_nil assigns(:versions) |
|
497 | assert_not_nil assigns(:versions) | |
491 | # Version with no date set appears |
|
498 | # Version with no date set appears | |
492 | assert assigns(:versions).include?(Version.find(3)) |
|
499 | assert assigns(:versions).include?(Version.find(3)) | |
493 | # Completed version appears |
|
500 | # Completed version appears | |
494 | assert assigns(:versions).include?(Version.find(1)) |
|
501 | assert assigns(:versions).include?(Version.find(1)) | |
495 | end |
|
502 | end | |
496 |
|
503 | |||
497 | def test_roadmap_showing_subprojects_versions |
|
504 | def test_roadmap_showing_subprojects_versions | |
498 | get :roadmap, :id => 1, :with_subprojects => 1 |
|
505 | get :roadmap, :id => 1, :with_subprojects => 1 | |
499 | assert_response :success |
|
506 | assert_response :success | |
500 | assert_template 'roadmap' |
|
507 | assert_template 'roadmap' | |
501 | assert_not_nil assigns(:versions) |
|
508 | assert_not_nil assigns(:versions) | |
502 | # Version on subproject appears |
|
509 | # Version on subproject appears | |
503 | assert assigns(:versions).include?(Version.find(4)) |
|
510 | assert assigns(:versions).include?(Version.find(4)) | |
504 | end |
|
511 | end | |
505 |
|
512 | |||
506 | def test_project_activity_routing |
|
513 | def test_project_activity_routing | |
507 | assert_routing( |
|
514 | assert_routing( | |
508 | {:method => :get, :path => '/projects/1/activity'}, |
|
515 | {:method => :get, :path => '/projects/1/activity'}, | |
509 | :controller => 'projects', :action => 'activity', :id => '1' |
|
516 | :controller => 'projects', :action => 'activity', :id => '1' | |
510 | ) |
|
517 | ) | |
511 | end |
|
518 | end | |
512 |
|
519 | |||
513 | def test_project_activity_atom_routing |
|
520 | def test_project_activity_atom_routing | |
514 | assert_routing( |
|
521 | assert_routing( | |
515 | {:method => :get, :path => '/projects/1/activity.atom'}, |
|
522 | {:method => :get, :path => '/projects/1/activity.atom'}, | |
516 | :controller => 'projects', :action => 'activity', :id => '1', :format => 'atom' |
|
523 | :controller => 'projects', :action => 'activity', :id => '1', :format => 'atom' | |
517 | ) |
|
524 | ) | |
518 | end |
|
525 | end | |
519 |
|
526 | |||
520 | def test_project_activity |
|
527 | def test_project_activity | |
521 | get :activity, :id => 1, :with_subprojects => 0 |
|
528 | get :activity, :id => 1, :with_subprojects => 0 | |
522 | assert_response :success |
|
529 | assert_response :success | |
523 | assert_template 'activity' |
|
530 | assert_template 'activity' | |
524 | assert_not_nil assigns(:events_by_day) |
|
531 | assert_not_nil assigns(:events_by_day) | |
525 |
|
532 | |||
526 | assert_tag :tag => "h3", |
|
533 | assert_tag :tag => "h3", | |
527 | :content => /#{2.days.ago.to_date.day}/, |
|
534 | :content => /#{2.days.ago.to_date.day}/, | |
528 | :sibling => { :tag => "dl", |
|
535 | :sibling => { :tag => "dl", | |
529 | :child => { :tag => "dt", |
|
536 | :child => { :tag => "dt", | |
530 | :attributes => { :class => /issue-edit/ }, |
|
537 | :attributes => { :class => /issue-edit/ }, | |
531 | :child => { :tag => "a", |
|
538 | :child => { :tag => "a", | |
532 | :content => /(#{IssueStatus.find(2).name})/, |
|
539 | :content => /(#{IssueStatus.find(2).name})/, | |
533 | } |
|
540 | } | |
534 | } |
|
541 | } | |
535 | } |
|
542 | } | |
536 | end |
|
543 | end | |
537 |
|
544 | |||
538 | def test_previous_project_activity |
|
545 | def test_previous_project_activity | |
539 | get :activity, :id => 1, :from => 3.days.ago.to_date |
|
546 | get :activity, :id => 1, :from => 3.days.ago.to_date | |
540 | assert_response :success |
|
547 | assert_response :success | |
541 | assert_template 'activity' |
|
548 | assert_template 'activity' | |
542 | assert_not_nil assigns(:events_by_day) |
|
549 | assert_not_nil assigns(:events_by_day) | |
543 |
|
550 | |||
544 | assert_tag :tag => "h3", |
|
551 | assert_tag :tag => "h3", | |
545 | :content => /#{3.day.ago.to_date.day}/, |
|
552 | :content => /#{3.day.ago.to_date.day}/, | |
546 | :sibling => { :tag => "dl", |
|
553 | :sibling => { :tag => "dl", | |
547 | :child => { :tag => "dt", |
|
554 | :child => { :tag => "dt", | |
548 | :attributes => { :class => /issue/ }, |
|
555 | :attributes => { :class => /issue/ }, | |
549 | :child => { :tag => "a", |
|
556 | :child => { :tag => "a", | |
550 | :content => /#{Issue.find(1).subject}/, |
|
557 | :content => /#{Issue.find(1).subject}/, | |
551 | } |
|
558 | } | |
552 | } |
|
559 | } | |
553 | } |
|
560 | } | |
554 | end |
|
561 | end | |
555 |
|
562 | |||
556 | def test_global_activity_routing |
|
563 | def test_global_activity_routing | |
557 | assert_routing({:method => :get, :path => '/activity'}, :controller => 'projects', :action => 'activity', :id => nil) |
|
564 | assert_routing({:method => :get, :path => '/activity'}, :controller => 'projects', :action => 'activity', :id => nil) | |
558 | end |
|
565 | end | |
559 |
|
566 | |||
560 | def test_global_activity |
|
567 | def test_global_activity | |
561 | get :activity |
|
568 | get :activity | |
562 | assert_response :success |
|
569 | assert_response :success | |
563 | assert_template 'activity' |
|
570 | assert_template 'activity' | |
564 | assert_not_nil assigns(:events_by_day) |
|
571 | assert_not_nil assigns(:events_by_day) | |
565 |
|
572 | |||
566 | assert_tag :tag => "h3", |
|
573 | assert_tag :tag => "h3", | |
567 | :content => /#{5.day.ago.to_date.day}/, |
|
574 | :content => /#{5.day.ago.to_date.day}/, | |
568 | :sibling => { :tag => "dl", |
|
575 | :sibling => { :tag => "dl", | |
569 | :child => { :tag => "dt", |
|
576 | :child => { :tag => "dt", | |
570 | :attributes => { :class => /issue/ }, |
|
577 | :attributes => { :class => /issue/ }, | |
571 | :child => { :tag => "a", |
|
578 | :child => { :tag => "a", | |
572 | :content => /#{Issue.find(5).subject}/, |
|
579 | :content => /#{Issue.find(5).subject}/, | |
573 | } |
|
580 | } | |
574 | } |
|
581 | } | |
575 | } |
|
582 | } | |
576 | end |
|
583 | end | |
577 |
|
584 | |||
578 | def test_user_activity |
|
585 | def test_user_activity | |
579 | get :activity, :user_id => 2 |
|
586 | get :activity, :user_id => 2 | |
580 | assert_response :success |
|
587 | assert_response :success | |
581 | assert_template 'activity' |
|
588 | assert_template 'activity' | |
582 | assert_not_nil assigns(:events_by_day) |
|
589 | assert_not_nil assigns(:events_by_day) | |
583 |
|
590 | |||
584 | assert_tag :tag => "h3", |
|
591 | assert_tag :tag => "h3", | |
585 | :content => /#{3.day.ago.to_date.day}/, |
|
592 | :content => /#{3.day.ago.to_date.day}/, | |
586 | :sibling => { :tag => "dl", |
|
593 | :sibling => { :tag => "dl", | |
587 | :child => { :tag => "dt", |
|
594 | :child => { :tag => "dt", | |
588 | :attributes => { :class => /issue/ }, |
|
595 | :attributes => { :class => /issue/ }, | |
589 | :child => { :tag => "a", |
|
596 | :child => { :tag => "a", | |
590 | :content => /#{Issue.find(1).subject}/, |
|
597 | :content => /#{Issue.find(1).subject}/, | |
591 | } |
|
598 | } | |
592 | } |
|
599 | } | |
593 | } |
|
600 | } | |
594 | end |
|
601 | end | |
595 |
|
602 | |||
596 | def test_global_activity_atom_routing |
|
603 | def test_global_activity_atom_routing | |
597 | assert_routing({:method => :get, :path => '/activity.atom'}, :controller => 'projects', :action => 'activity', :id => nil, :format => 'atom') |
|
604 | assert_routing({:method => :get, :path => '/activity.atom'}, :controller => 'projects', :action => 'activity', :id => nil, :format => 'atom') | |
598 | end |
|
605 | end | |
599 |
|
606 | |||
600 | def test_activity_atom_feed |
|
607 | def test_activity_atom_feed | |
601 | get :activity, :format => 'atom' |
|
608 | get :activity, :format => 'atom' | |
602 | assert_response :success |
|
609 | assert_response :success | |
603 | assert_template 'common/feed.atom.rxml' |
|
610 | assert_template 'common/feed.atom.rxml' | |
604 | end |
|
611 | end | |
605 |
|
612 | |||
606 | def test_archive_routing |
|
613 | def test_archive_routing | |
607 | assert_routing( |
|
614 | assert_routing( | |
608 | #TODO: use PUT to project path and modify form |
|
615 | #TODO: use PUT to project path and modify form | |
609 | {:method => :post, :path => 'projects/64/archive'}, |
|
616 | {:method => :post, :path => 'projects/64/archive'}, | |
610 | :controller => 'projects', :action => 'archive', :id => '64' |
|
617 | :controller => 'projects', :action => 'archive', :id => '64' | |
611 | ) |
|
618 | ) | |
612 | end |
|
619 | end | |
613 |
|
620 | |||
614 | def test_archive |
|
621 | def test_archive | |
615 | @request.session[:user_id] = 1 # admin |
|
622 | @request.session[:user_id] = 1 # admin | |
616 | post :archive, :id => 1 |
|
623 | post :archive, :id => 1 | |
617 | assert_redirected_to 'admin/projects' |
|
624 | assert_redirected_to 'admin/projects' | |
618 | assert !Project.find(1).active? |
|
625 | assert !Project.find(1).active? | |
619 | end |
|
626 | end | |
620 |
|
627 | |||
621 | def test_unarchive_routing |
|
628 | def test_unarchive_routing | |
622 | assert_routing( |
|
629 | assert_routing( | |
623 | #TODO: use PUT to project path and modify form |
|
630 | #TODO: use PUT to project path and modify form | |
624 | {:method => :post, :path => '/projects/567/unarchive'}, |
|
631 | {:method => :post, :path => '/projects/567/unarchive'}, | |
625 | :controller => 'projects', :action => 'unarchive', :id => '567' |
|
632 | :controller => 'projects', :action => 'unarchive', :id => '567' | |
626 | ) |
|
633 | ) | |
627 | end |
|
634 | end | |
628 |
|
635 | |||
629 | def test_unarchive |
|
636 | def test_unarchive | |
630 | @request.session[:user_id] = 1 # admin |
|
637 | @request.session[:user_id] = 1 # admin | |
631 | Project.find(1).archive |
|
638 | Project.find(1).archive | |
632 | post :unarchive, :id => 1 |
|
639 | post :unarchive, :id => 1 | |
633 | assert_redirected_to 'admin/projects' |
|
640 | assert_redirected_to 'admin/projects' | |
634 | assert Project.find(1).active? |
|
641 | assert Project.find(1).active? | |
635 | end |
|
642 | end | |
636 |
|
643 | |||
637 | def test_project_breadcrumbs_should_be_limited_to_3_ancestors |
|
644 | def test_project_breadcrumbs_should_be_limited_to_3_ancestors | |
638 | CustomField.delete_all |
|
645 | CustomField.delete_all | |
639 | parent = nil |
|
646 | parent = nil | |
640 | 6.times do |i| |
|
647 | 6.times do |i| | |
641 | p = Project.create!(:name => "Breadcrumbs #{i}", :identifier => "breadcrumbs-#{i}") |
|
648 | p = Project.create!(:name => "Breadcrumbs #{i}", :identifier => "breadcrumbs-#{i}") | |
642 | p.set_parent!(parent) |
|
649 | p.set_parent!(parent) | |
643 | get :show, :id => p |
|
650 | get :show, :id => p | |
644 | assert_tag :h1, :parent => { :attributes => {:id => 'header'}}, |
|
651 | assert_tag :h1, :parent => { :attributes => {:id => 'header'}}, | |
645 | :children => { :count => [i, 3].min, |
|
652 | :children => { :count => [i, 3].min, | |
646 | :only => { :tag => 'a' } } |
|
653 | :only => { :tag => 'a' } } | |
647 |
|
654 | |||
648 | parent = p |
|
655 | parent = p | |
649 | end |
|
656 | end | |
650 | end |
|
657 | end | |
651 |
|
658 | |||
652 | def test_copy_with_project |
|
659 | def test_copy_with_project | |
653 | @request.session[:user_id] = 1 # admin |
|
660 | @request.session[:user_id] = 1 # admin | |
654 | get :copy, :id => 1 |
|
661 | get :copy, :id => 1 | |
655 | assert_response :success |
|
662 | assert_response :success | |
656 | assert_template 'copy' |
|
663 | assert_template 'copy' | |
657 | assert assigns(:project) |
|
664 | assert assigns(:project) | |
658 | assert_equal Project.find(1).description, assigns(:project).description |
|
665 | assert_equal Project.find(1).description, assigns(:project).description | |
659 | assert_nil assigns(:project).id |
|
666 | assert_nil assigns(:project).id | |
660 | end |
|
667 | end | |
661 |
|
668 | |||
662 | def test_copy_without_project |
|
669 | def test_copy_without_project | |
663 | @request.session[:user_id] = 1 # admin |
|
670 | @request.session[:user_id] = 1 # admin | |
664 | get :copy |
|
671 | get :copy | |
665 | assert_response :redirect |
|
672 | assert_response :redirect | |
666 | assert_redirected_to :controller => 'admin', :action => 'projects' |
|
673 | assert_redirected_to :controller => 'admin', :action => 'projects' | |
667 | end |
|
674 | end | |
668 |
|
675 | |||
669 | def test_jump_should_redirect_to_active_tab |
|
676 | def test_jump_should_redirect_to_active_tab | |
670 | get :show, :id => 1, :jump => 'issues' |
|
677 | get :show, :id => 1, :jump => 'issues' | |
671 | assert_redirected_to 'projects/ecookbook/issues' |
|
678 | assert_redirected_to 'projects/ecookbook/issues' | |
672 | end |
|
679 | end | |
673 |
|
680 | |||
674 | def test_jump_should_not_redirect_to_inactive_tab |
|
681 | def test_jump_should_not_redirect_to_inactive_tab | |
675 | get :show, :id => 3, :jump => 'documents' |
|
682 | get :show, :id => 3, :jump => 'documents' | |
676 | assert_response :success |
|
683 | assert_response :success | |
677 | assert_template 'show' |
|
684 | assert_template 'show' | |
678 | end |
|
685 | end | |
679 |
|
686 | |||
680 | def test_jump_should_not_redirect_to_unknown_tab |
|
687 | def test_jump_should_not_redirect_to_unknown_tab | |
681 | get :show, :id => 3, :jump => 'foobar' |
|
688 | get :show, :id => 3, :jump => 'foobar' | |
682 | assert_response :success |
|
689 | assert_response :success | |
683 | assert_template 'show' |
|
690 | assert_template 'show' | |
684 | end |
|
691 | end | |
685 |
|
692 | |||
686 | def test_reset_activities_routing |
|
693 | def test_reset_activities_routing | |
687 | assert_routing({:method => :delete, :path => 'projects/64/reset_activities'}, |
|
694 | assert_routing({:method => :delete, :path => 'projects/64/reset_activities'}, | |
688 | :controller => 'projects', :action => 'reset_activities', :id => '64') |
|
695 | :controller => 'projects', :action => 'reset_activities', :id => '64') | |
689 | end |
|
696 | end | |
690 |
|
697 | |||
691 | def test_reset_activities |
|
698 | def test_reset_activities | |
692 | @request.session[:user_id] = 2 # manager |
|
699 | @request.session[:user_id] = 2 # manager | |
693 | project_activity = TimeEntryActivity.new({ |
|
700 | project_activity = TimeEntryActivity.new({ | |
694 | :name => 'Project Specific', |
|
701 | :name => 'Project Specific', | |
695 | :parent => TimeEntryActivity.find(:first), |
|
702 | :parent => TimeEntryActivity.find(:first), | |
696 | :project => Project.find(1), |
|
703 | :project => Project.find(1), | |
697 | :active => true |
|
704 | :active => true | |
698 | }) |
|
705 | }) | |
699 | assert project_activity.save |
|
706 | assert project_activity.save | |
700 | project_activity_two = TimeEntryActivity.new({ |
|
707 | project_activity_two = TimeEntryActivity.new({ | |
701 | :name => 'Project Specific Two', |
|
708 | :name => 'Project Specific Two', | |
702 | :parent => TimeEntryActivity.find(:last), |
|
709 | :parent => TimeEntryActivity.find(:last), | |
703 | :project => Project.find(1), |
|
710 | :project => Project.find(1), | |
704 | :active => true |
|
711 | :active => true | |
705 | }) |
|
712 | }) | |
706 | assert project_activity_two.save |
|
713 | assert project_activity_two.save | |
707 |
|
714 | |||
708 | delete :reset_activities, :id => 1 |
|
715 | delete :reset_activities, :id => 1 | |
709 | assert_response :redirect |
|
716 | assert_response :redirect | |
710 | assert_redirected_to 'projects/ecookbook/settings/activities' |
|
717 | assert_redirected_to 'projects/ecookbook/settings/activities' | |
711 |
|
718 | |||
712 | assert_nil TimeEntryActivity.find_by_id(project_activity.id) |
|
719 | assert_nil TimeEntryActivity.find_by_id(project_activity.id) | |
713 | assert_nil TimeEntryActivity.find_by_id(project_activity_two.id) |
|
720 | assert_nil TimeEntryActivity.find_by_id(project_activity_two.id) | |
714 | end |
|
721 | end | |
715 |
|
722 | |||
716 | def test_reset_activities_should_reassign_time_entries_back_to_the_system_activity |
|
723 | def test_reset_activities_should_reassign_time_entries_back_to_the_system_activity | |
717 | @request.session[:user_id] = 2 # manager |
|
724 | @request.session[:user_id] = 2 # manager | |
718 | project_activity = TimeEntryActivity.new({ |
|
725 | project_activity = TimeEntryActivity.new({ | |
719 | :name => 'Project Specific Design', |
|
726 | :name => 'Project Specific Design', | |
720 | :parent => TimeEntryActivity.find(9), |
|
727 | :parent => TimeEntryActivity.find(9), | |
721 | :project => Project.find(1), |
|
728 | :project => Project.find(1), | |
722 | :active => true |
|
729 | :active => true | |
723 | }) |
|
730 | }) | |
724 | assert project_activity.save |
|
731 | assert project_activity.save | |
725 | assert TimeEntry.update_all("activity_id = '#{project_activity.id}'", ["project_id = ? AND activity_id = ?", 1, 9]) |
|
732 | assert TimeEntry.update_all("activity_id = '#{project_activity.id}'", ["project_id = ? AND activity_id = ?", 1, 9]) | |
726 | assert 3, TimeEntry.find_all_by_activity_id_and_project_id(project_activity.id, 1).size |
|
733 | assert 3, TimeEntry.find_all_by_activity_id_and_project_id(project_activity.id, 1).size | |
727 |
|
734 | |||
728 | delete :reset_activities, :id => 1 |
|
735 | delete :reset_activities, :id => 1 | |
729 | assert_response :redirect |
|
736 | assert_response :redirect | |
730 | assert_redirected_to 'projects/ecookbook/settings/activities' |
|
737 | assert_redirected_to 'projects/ecookbook/settings/activities' | |
731 |
|
738 | |||
732 | assert_nil TimeEntryActivity.find_by_id(project_activity.id) |
|
739 | assert_nil TimeEntryActivity.find_by_id(project_activity.id) | |
733 | assert_equal 0, TimeEntry.find_all_by_activity_id_and_project_id(project_activity.id, 1).size, "TimeEntries still assigned to project specific activity" |
|
740 | assert_equal 0, TimeEntry.find_all_by_activity_id_and_project_id(project_activity.id, 1).size, "TimeEntries still assigned to project specific activity" | |
734 | assert_equal 3, TimeEntry.find_all_by_activity_id_and_project_id(9, 1).size, "TimeEntries still assigned to project specific activity" |
|
741 | assert_equal 3, TimeEntry.find_all_by_activity_id_and_project_id(9, 1).size, "TimeEntries still assigned to project specific activity" | |
735 | end |
|
742 | end | |
736 |
|
743 | |||
737 | def test_save_activities_routing |
|
744 | def test_save_activities_routing | |
738 | assert_routing({:method => :post, :path => 'projects/64/activities/save'}, |
|
745 | assert_routing({:method => :post, :path => 'projects/64/activities/save'}, | |
739 | :controller => 'projects', :action => 'save_activities', :id => '64') |
|
746 | :controller => 'projects', :action => 'save_activities', :id => '64') | |
740 | end |
|
747 | end | |
741 |
|
748 | |||
742 | def test_save_activities_to_override_system_activities |
|
749 | def test_save_activities_to_override_system_activities | |
743 | @request.session[:user_id] = 2 # manager |
|
750 | @request.session[:user_id] = 2 # manager | |
744 | billable_field = TimeEntryActivityCustomField.find_by_name("Billable") |
|
751 | billable_field = TimeEntryActivityCustomField.find_by_name("Billable") | |
745 |
|
752 | |||
746 | post :save_activities, :id => 1, :enumerations => { |
|
753 | post :save_activities, :id => 1, :enumerations => { | |
747 | "9"=> {"parent_id"=>"9", "custom_field_values"=>{"7" => "1"}, "active"=>"0"}, # Design, De-activate |
|
754 | "9"=> {"parent_id"=>"9", "custom_field_values"=>{"7" => "1"}, "active"=>"0"}, # Design, De-activate | |
748 | "10"=> {"parent_id"=>"10", "custom_field_values"=>{"7"=>"0"}, "active"=>"1"}, # Development, Change custom value |
|
755 | "10"=> {"parent_id"=>"10", "custom_field_values"=>{"7"=>"0"}, "active"=>"1"}, # Development, Change custom value | |
749 | "14"=>{"parent_id"=>"14", "custom_field_values"=>{"7"=>"1"}, "active"=>"1"}, # Inactive Activity, Activate with custom value |
|
756 | "14"=>{"parent_id"=>"14", "custom_field_values"=>{"7"=>"1"}, "active"=>"1"}, # Inactive Activity, Activate with custom value | |
750 | "11"=>{"parent_id"=>"11", "custom_field_values"=>{"7"=>"1"}, "active"=>"1"} # QA, no changes |
|
757 | "11"=>{"parent_id"=>"11", "custom_field_values"=>{"7"=>"1"}, "active"=>"1"} # QA, no changes | |
751 | } |
|
758 | } | |
752 |
|
759 | |||
753 | assert_response :redirect |
|
760 | assert_response :redirect | |
754 | assert_redirected_to 'projects/ecookbook/settings/activities' |
|
761 | assert_redirected_to 'projects/ecookbook/settings/activities' | |
755 |
|
762 | |||
756 | # Created project specific activities... |
|
763 | # Created project specific activities... | |
757 | project = Project.find('ecookbook') |
|
764 | project = Project.find('ecookbook') | |
758 |
|
765 | |||
759 | # ... Design |
|
766 | # ... Design | |
760 | design = project.time_entry_activities.find_by_name("Design") |
|
767 | design = project.time_entry_activities.find_by_name("Design") | |
761 | assert design, "Project activity not found" |
|
768 | assert design, "Project activity not found" | |
762 |
|
769 | |||
763 | assert_equal 9, design.parent_id # Relate to the system activity |
|
770 | assert_equal 9, design.parent_id # Relate to the system activity | |
764 | assert_not_equal design.parent.id, design.id # Different records |
|
771 | assert_not_equal design.parent.id, design.id # Different records | |
765 | assert_equal design.parent.name, design.name # Same name |
|
772 | assert_equal design.parent.name, design.name # Same name | |
766 | assert !design.active? |
|
773 | assert !design.active? | |
767 |
|
774 | |||
768 | # ... Development |
|
775 | # ... Development | |
769 | development = project.time_entry_activities.find_by_name("Development") |
|
776 | development = project.time_entry_activities.find_by_name("Development") | |
770 | assert development, "Project activity not found" |
|
777 | assert development, "Project activity not found" | |
771 |
|
778 | |||
772 | assert_equal 10, development.parent_id # Relate to the system activity |
|
779 | assert_equal 10, development.parent_id # Relate to the system activity | |
773 | assert_not_equal development.parent.id, development.id # Different records |
|
780 | assert_not_equal development.parent.id, development.id # Different records | |
774 | assert_equal development.parent.name, development.name # Same name |
|
781 | assert_equal development.parent.name, development.name # Same name | |
775 | assert development.active? |
|
782 | assert development.active? | |
776 | assert_equal "0", development.custom_value_for(billable_field).value |
|
783 | assert_equal "0", development.custom_value_for(billable_field).value | |
777 |
|
784 | |||
778 | # ... Inactive Activity |
|
785 | # ... Inactive Activity | |
779 | previously_inactive = project.time_entry_activities.find_by_name("Inactive Activity") |
|
786 | previously_inactive = project.time_entry_activities.find_by_name("Inactive Activity") | |
780 | assert previously_inactive, "Project activity not found" |
|
787 | assert previously_inactive, "Project activity not found" | |
781 |
|
788 | |||
782 | assert_equal 14, previously_inactive.parent_id # Relate to the system activity |
|
789 | assert_equal 14, previously_inactive.parent_id # Relate to the system activity | |
783 | assert_not_equal previously_inactive.parent.id, previously_inactive.id # Different records |
|
790 | assert_not_equal previously_inactive.parent.id, previously_inactive.id # Different records | |
784 | assert_equal previously_inactive.parent.name, previously_inactive.name # Same name |
|
791 | assert_equal previously_inactive.parent.name, previously_inactive.name # Same name | |
785 | assert previously_inactive.active? |
|
792 | assert previously_inactive.active? | |
786 | assert_equal "1", previously_inactive.custom_value_for(billable_field).value |
|
793 | assert_equal "1", previously_inactive.custom_value_for(billable_field).value | |
787 |
|
794 | |||
788 | # ... QA |
|
795 | # ... QA | |
789 | assert_equal nil, project.time_entry_activities.find_by_name("QA"), "Custom QA activity created when it wasn't modified" |
|
796 | assert_equal nil, project.time_entry_activities.find_by_name("QA"), "Custom QA activity created when it wasn't modified" | |
790 | end |
|
797 | end | |
791 |
|
798 | |||
792 | def test_save_activities_will_update_project_specific_activities |
|
799 | def test_save_activities_will_update_project_specific_activities | |
793 | @request.session[:user_id] = 2 # manager |
|
800 | @request.session[:user_id] = 2 # manager | |
794 |
|
801 | |||
795 | project_activity = TimeEntryActivity.new({ |
|
802 | project_activity = TimeEntryActivity.new({ | |
796 | :name => 'Project Specific', |
|
803 | :name => 'Project Specific', | |
797 | :parent => TimeEntryActivity.find(:first), |
|
804 | :parent => TimeEntryActivity.find(:first), | |
798 | :project => Project.find(1), |
|
805 | :project => Project.find(1), | |
799 | :active => true |
|
806 | :active => true | |
800 | }) |
|
807 | }) | |
801 | assert project_activity.save |
|
808 | assert project_activity.save | |
802 | project_activity_two = TimeEntryActivity.new({ |
|
809 | project_activity_two = TimeEntryActivity.new({ | |
803 | :name => 'Project Specific Two', |
|
810 | :name => 'Project Specific Two', | |
804 | :parent => TimeEntryActivity.find(:last), |
|
811 | :parent => TimeEntryActivity.find(:last), | |
805 | :project => Project.find(1), |
|
812 | :project => Project.find(1), | |
806 | :active => true |
|
813 | :active => true | |
807 | }) |
|
814 | }) | |
808 | assert project_activity_two.save |
|
815 | assert project_activity_two.save | |
809 |
|
816 | |||
810 |
|
817 | |||
811 | post :save_activities, :id => 1, :enumerations => { |
|
818 | post :save_activities, :id => 1, :enumerations => { | |
812 | project_activity.id => {"custom_field_values"=>{"7" => "1"}, "active"=>"0"}, # De-activate |
|
819 | project_activity.id => {"custom_field_values"=>{"7" => "1"}, "active"=>"0"}, # De-activate | |
813 | project_activity_two.id => {"custom_field_values"=>{"7" => "1"}, "active"=>"0"} # De-activate |
|
820 | project_activity_two.id => {"custom_field_values"=>{"7" => "1"}, "active"=>"0"} # De-activate | |
814 | } |
|
821 | } | |
815 |
|
822 | |||
816 | assert_response :redirect |
|
823 | assert_response :redirect | |
817 | assert_redirected_to 'projects/ecookbook/settings/activities' |
|
824 | assert_redirected_to 'projects/ecookbook/settings/activities' | |
818 |
|
825 | |||
819 | # Created project specific activities... |
|
826 | # Created project specific activities... | |
820 | project = Project.find('ecookbook') |
|
827 | project = Project.find('ecookbook') | |
821 | assert_equal 2, project.time_entry_activities.count |
|
828 | assert_equal 2, project.time_entry_activities.count | |
822 |
|
829 | |||
823 | activity_one = project.time_entry_activities.find_by_name(project_activity.name) |
|
830 | activity_one = project.time_entry_activities.find_by_name(project_activity.name) | |
824 | assert activity_one, "Project activity not found" |
|
831 | assert activity_one, "Project activity not found" | |
825 | assert_equal project_activity.id, activity_one.id |
|
832 | assert_equal project_activity.id, activity_one.id | |
826 | assert !activity_one.active? |
|
833 | assert !activity_one.active? | |
827 |
|
834 | |||
828 | activity_two = project.time_entry_activities.find_by_name(project_activity_two.name) |
|
835 | activity_two = project.time_entry_activities.find_by_name(project_activity_two.name) | |
829 | assert activity_two, "Project activity not found" |
|
836 | assert activity_two, "Project activity not found" | |
830 | assert_equal project_activity_two.id, activity_two.id |
|
837 | assert_equal project_activity_two.id, activity_two.id | |
831 | assert !activity_two.active? |
|
838 | assert !activity_two.active? | |
832 | end |
|
839 | end | |
833 |
|
840 | |||
834 | def test_save_activities_when_creating_new_activities_will_convert_existing_data |
|
841 | def test_save_activities_when_creating_new_activities_will_convert_existing_data | |
835 | assert_equal 3, TimeEntry.find_all_by_activity_id_and_project_id(9, 1).size |
|
842 | assert_equal 3, TimeEntry.find_all_by_activity_id_and_project_id(9, 1).size | |
836 |
|
843 | |||
837 | @request.session[:user_id] = 2 # manager |
|
844 | @request.session[:user_id] = 2 # manager | |
838 | post :save_activities, :id => 1, :enumerations => { |
|
845 | post :save_activities, :id => 1, :enumerations => { | |
839 | "9"=> {"parent_id"=>"9", "custom_field_values"=>{"7" => "1"}, "active"=>"0"} # Design, De-activate |
|
846 | "9"=> {"parent_id"=>"9", "custom_field_values"=>{"7" => "1"}, "active"=>"0"} # Design, De-activate | |
840 | } |
|
847 | } | |
841 | assert_response :redirect |
|
848 | assert_response :redirect | |
842 |
|
849 | |||
843 | # No more TimeEntries using the system activity |
|
850 | # No more TimeEntries using the system activity | |
844 | assert_equal 0, TimeEntry.find_all_by_activity_id_and_project_id(9, 1).size, "Time Entries still assigned to system activities" |
|
851 | assert_equal 0, TimeEntry.find_all_by_activity_id_and_project_id(9, 1).size, "Time Entries still assigned to system activities" | |
845 | # All TimeEntries using project activity |
|
852 | # All TimeEntries using project activity | |
846 | project_specific_activity = TimeEntryActivity.find_by_parent_id_and_project_id(9, 1) |
|
853 | project_specific_activity = TimeEntryActivity.find_by_parent_id_and_project_id(9, 1) | |
847 | 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" |
|
854 | 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" | |
848 | end |
|
855 | end | |
849 |
|
856 | |||
850 | def test_save_activities_when_creating_new_activities_will_not_convert_existing_data_if_an_exception_is_raised |
|
857 | def test_save_activities_when_creating_new_activities_will_not_convert_existing_data_if_an_exception_is_raised | |
851 | # TODO: Need to cause an exception on create but these tests |
|
858 | # TODO: Need to cause an exception on create but these tests | |
852 | # aren't setup for mocking. Just create a record now so the |
|
859 | # aren't setup for mocking. Just create a record now so the | |
853 | # second one is a dupicate |
|
860 | # second one is a dupicate | |
854 | parent = TimeEntryActivity.find(9) |
|
861 | parent = TimeEntryActivity.find(9) | |
855 | TimeEntryActivity.create!({:name => parent.name, :project_id => 1, :position => parent.position, :active => true}) |
|
862 | TimeEntryActivity.create!({:name => parent.name, :project_id => 1, :position => parent.position, :active => true}) | |
856 | TimeEntry.create!({:project_id => 1, :hours => 1.0, :user => User.find(1), :issue_id => 3, :activity_id => 10, :spent_on => '2009-01-01'}) |
|
863 | TimeEntry.create!({:project_id => 1, :hours => 1.0, :user => User.find(1), :issue_id => 3, :activity_id => 10, :spent_on => '2009-01-01'}) | |
857 |
|
864 | |||
858 | assert_equal 3, TimeEntry.find_all_by_activity_id_and_project_id(9, 1).size |
|
865 | assert_equal 3, TimeEntry.find_all_by_activity_id_and_project_id(9, 1).size | |
859 | assert_equal 1, TimeEntry.find_all_by_activity_id_and_project_id(10, 1).size |
|
866 | assert_equal 1, TimeEntry.find_all_by_activity_id_and_project_id(10, 1).size | |
860 |
|
867 | |||
861 | @request.session[:user_id] = 2 # manager |
|
868 | @request.session[:user_id] = 2 # manager | |
862 | post :save_activities, :id => 1, :enumerations => { |
|
869 | post :save_activities, :id => 1, :enumerations => { | |
863 | "9"=> {"parent_id"=>"9", "custom_field_values"=>{"7" => "1"}, "active"=>"0"}, # Design |
|
870 | "9"=> {"parent_id"=>"9", "custom_field_values"=>{"7" => "1"}, "active"=>"0"}, # Design | |
864 | "10"=> {"parent_id"=>"10", "custom_field_values"=>{"7"=>"0"}, "active"=>"1"} # Development, Change custom value |
|
871 | "10"=> {"parent_id"=>"10", "custom_field_values"=>{"7"=>"0"}, "active"=>"1"} # Development, Change custom value | |
865 | } |
|
872 | } | |
866 | assert_response :redirect |
|
873 | assert_response :redirect | |
867 |
|
874 | |||
868 | # TimeEntries shouldn't have been reassigned on the failed record |
|
875 | # TimeEntries shouldn't have been reassigned on the failed record | |
869 | assert_equal 3, TimeEntry.find_all_by_activity_id_and_project_id(9, 1).size, "Time Entries are not assigned to system activities" |
|
876 | assert_equal 3, TimeEntry.find_all_by_activity_id_and_project_id(9, 1).size, "Time Entries are not assigned to system activities" | |
870 | # TimeEntries shouldn't have been reassigned on the saved record either |
|
877 | # TimeEntries shouldn't have been reassigned on the saved record either | |
871 | assert_equal 1, TimeEntry.find_all_by_activity_id_and_project_id(10, 1).size, "Time Entries are not assigned to system activities" |
|
878 | assert_equal 1, TimeEntry.find_all_by_activity_id_and_project_id(10, 1).size, "Time Entries are not assigned to system activities" | |
872 | end |
|
879 | end | |
873 |
|
880 | |||
874 | # A hook that is manually registered later |
|
881 | # A hook that is manually registered later | |
875 | class ProjectBasedTemplate < Redmine::Hook::ViewListener |
|
882 | class ProjectBasedTemplate < Redmine::Hook::ViewListener | |
876 | def view_layouts_base_html_head(context) |
|
883 | def view_layouts_base_html_head(context) | |
877 | # Adds a project stylesheet |
|
884 | # Adds a project stylesheet | |
878 | stylesheet_link_tag(context[:project].identifier) if context[:project] |
|
885 | stylesheet_link_tag(context[:project].identifier) if context[:project] | |
879 | end |
|
886 | end | |
880 | end |
|
887 | end | |
881 | # Don't use this hook now |
|
888 | # Don't use this hook now | |
882 | Redmine::Hook.clear_listeners |
|
889 | Redmine::Hook.clear_listeners | |
883 |
|
890 | |||
884 | def test_hook_response |
|
891 | def test_hook_response | |
885 | Redmine::Hook.add_listener(ProjectBasedTemplate) |
|
892 | Redmine::Hook.add_listener(ProjectBasedTemplate) | |
886 | get :show, :id => 1 |
|
893 | get :show, :id => 1 | |
887 | assert_tag :tag => 'link', :attributes => {:href => '/stylesheets/ecookbook.css'}, |
|
894 | assert_tag :tag => 'link', :attributes => {:href => '/stylesheets/ecookbook.css'}, | |
888 | :parent => {:tag => 'head'} |
|
895 | :parent => {:tag => 'head'} | |
889 |
|
896 | |||
890 | Redmine::Hook.clear_listeners |
|
897 | Redmine::Hook.clear_listeners | |
891 | end |
|
898 | end | |
892 | end |
|
899 | end |
General Comments 0
You need to be logged in to leave comments.
Login now