@@ -1,95 +1,89 | |||
|
1 | 1 | # Redmine - project management software |
|
2 | 2 | # Copyright (C) 2006-2016 Jean-Philippe Lang |
|
3 | 3 | # |
|
4 | 4 | # This program is free software; you can redistribute it and/or |
|
5 | 5 | # modify it under the terms of the GNU General Public License |
|
6 | 6 | # as published by the Free Software Foundation; either version 2 |
|
7 | 7 | # of the License, or (at your option) any later version. |
|
8 | 8 | # |
|
9 | 9 | # This program is distributed in the hope that it will be useful, |
|
10 | 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 | 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12 | 12 | # GNU General Public License for more details. |
|
13 | 13 | # |
|
14 | 14 | # You should have received a copy of the GNU General Public License |
|
15 | 15 | # along with this program; if not, write to the Free Software |
|
16 | 16 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
|
17 | 17 | |
|
18 | 18 | class ReportsController < ApplicationController |
|
19 | 19 | menu_item :issues |
|
20 | 20 | before_action :find_project, :authorize, :find_issue_statuses |
|
21 | 21 | |
|
22 | 22 | def issue_report |
|
23 | 23 | @trackers = @project.rolled_up_trackers(false).visible |
|
24 | 24 | @versions = @project.shared_versions.sort |
|
25 | 25 | @priorities = IssuePriority.all.reverse |
|
26 | 26 | @categories = @project.issue_categories |
|
27 | 27 | @assignees = (Setting.issue_group_assignment? ? @project.principals : @project.users).sort |
|
28 | 28 | @authors = @project.users.sort |
|
29 | 29 | @subprojects = @project.descendants.visible |
|
30 | 30 | |
|
31 | 31 | @issues_by_tracker = Issue.by_tracker(@project) |
|
32 | 32 | @issues_by_version = Issue.by_version(@project) |
|
33 | 33 | @issues_by_priority = Issue.by_priority(@project) |
|
34 | 34 | @issues_by_category = Issue.by_category(@project) |
|
35 | 35 | @issues_by_assigned_to = Issue.by_assigned_to(@project) |
|
36 | 36 | @issues_by_author = Issue.by_author(@project) |
|
37 | 37 | @issues_by_subproject = Issue.by_subproject(@project) || [] |
|
38 | 38 | |
|
39 | 39 | render :template => "reports/issue_report" |
|
40 | 40 | end |
|
41 | 41 | |
|
42 | 42 | def issue_report_details |
|
43 | 43 | case params[:detail] |
|
44 | 44 | when "tracker" |
|
45 | 45 | @field = "tracker_id" |
|
46 | 46 | @rows = @project.rolled_up_trackers(false).visible |
|
47 | 47 | @data = Issue.by_tracker(@project) |
|
48 | 48 | @report_title = l(:field_tracker) |
|
49 | 49 | when "version" |
|
50 | 50 | @field = "fixed_version_id" |
|
51 | 51 | @rows = @project.shared_versions.sort |
|
52 | 52 | @data = Issue.by_version(@project) |
|
53 | 53 | @report_title = l(:field_version) |
|
54 | 54 | when "priority" |
|
55 | 55 | @field = "priority_id" |
|
56 | 56 | @rows = IssuePriority.all.reverse |
|
57 | 57 | @data = Issue.by_priority(@project) |
|
58 | 58 | @report_title = l(:field_priority) |
|
59 | 59 | when "category" |
|
60 | 60 | @field = "category_id" |
|
61 | 61 | @rows = @project.issue_categories |
|
62 | 62 | @data = Issue.by_category(@project) |
|
63 | 63 | @report_title = l(:field_category) |
|
64 | 64 | when "assigned_to" |
|
65 | 65 | @field = "assigned_to_id" |
|
66 | 66 | @rows = (Setting.issue_group_assignment? ? @project.principals : @project.users).sort |
|
67 | 67 | @data = Issue.by_assigned_to(@project) |
|
68 | 68 | @report_title = l(:field_assigned_to) |
|
69 | 69 | when "author" |
|
70 | 70 | @field = "author_id" |
|
71 | 71 | @rows = @project.users.sort |
|
72 | 72 | @data = Issue.by_author(@project) |
|
73 | 73 | @report_title = l(:field_author) |
|
74 | 74 | when "subproject" |
|
75 | 75 | @field = "project_id" |
|
76 | 76 | @rows = @project.descendants.visible |
|
77 | 77 | @data = Issue.by_subproject(@project) || [] |
|
78 | 78 | @report_title = l(:field_subproject) |
|
79 |
e |
|
|
80 | ||
|
81 | respond_to do |format| | |
|
82 | if @field | |
|
83 | format.html {} | |
|
84 | else | |
|
85 | format.html { redirect_to :action => 'issue_report', :id => @project } | |
|
86 | end | |
|
79 | else | |
|
80 | render_404 | |
|
87 | 81 | end |
|
88 | 82 | end |
|
89 | 83 | |
|
90 | 84 | private |
|
91 | 85 | |
|
92 | 86 | def find_issue_statuses |
|
93 | 87 | @statuses = IssueStatus.sorted.to_a |
|
94 | 88 | end |
|
95 | 89 | end |
@@ -1,219 +1,219 | |||
|
1 | 1 | # Redmine - project management software |
|
2 | 2 | # Copyright (C) 2006-2016 Jean-Philippe Lang |
|
3 | 3 | # |
|
4 | 4 | # This program is free software; you can redistribute it and/or |
|
5 | 5 | # modify it under the terms of the GNU General Public License |
|
6 | 6 | # as published by the Free Software Foundation; either version 2 |
|
7 | 7 | # of the License, or (at your option) any later version. |
|
8 | 8 | # |
|
9 | 9 | # This program is distributed in the hope that it will be useful, |
|
10 | 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 | 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12 | 12 | # GNU General Public License for more details. |
|
13 | 13 | # |
|
14 | 14 | # You should have received a copy of the GNU General Public License |
|
15 | 15 | # along with this program; if not, write to the Free Software |
|
16 | 16 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
|
17 | 17 | |
|
18 | 18 | require File.expand_path('../../test_helper', __FILE__) |
|
19 | 19 | |
|
20 | 20 | class MessagesControllerTest < Redmine::ControllerTest |
|
21 | 21 | fixtures :projects, :users, :email_addresses, :user_preferences, :members, :member_roles, :roles, :boards, :messages, :enabled_modules |
|
22 | 22 | |
|
23 | 23 | def setup |
|
24 | 24 | User.current = nil |
|
25 | 25 | end |
|
26 | 26 | |
|
27 | 27 | def test_show |
|
28 | 28 | get :show, :board_id => 1, :id => 1 |
|
29 | 29 | assert_response :success |
|
30 | assert_template 'show' | |
|
31 | assert_not_nil assigns(:board) | |
|
32 | assert_not_nil assigns(:project) | |
|
33 | assert_not_nil assigns(:topic) | |
|
30 | ||
|
31 | assert_select 'h2', :text => 'First post' | |
|
34 | 32 | end |
|
35 | 33 | |
|
36 | 34 | def test_show_should_contain_reply_field_tags_for_quoting |
|
37 | 35 | @request.session[:user_id] = 2 |
|
38 | 36 | get :show, :board_id => 1, :id => 1 |
|
39 | 37 | assert_response :success |
|
40 | 38 | |
|
41 | 39 | # tags required by MessagesController#quote |
|
42 | 40 | assert_select 'input#message_subject' |
|
43 | 41 | assert_select 'textarea#message_content' |
|
44 | 42 | assert_select 'div#reply' |
|
45 | 43 | end |
|
46 | 44 | |
|
47 | 45 | def test_show_with_pagination |
|
48 | 46 | message = Message.find(1) |
|
49 | 47 | assert_difference 'Message.count', 30 do |
|
50 | 48 | 30.times do |
|
51 | 49 | message.children << Message.new(:subject => 'Reply', |
|
52 | 50 | :content => 'Reply body', |
|
53 | 51 | :author_id => 2, |
|
54 | 52 | :board_id => 1) |
|
55 | 53 | end |
|
56 | 54 | end |
|
57 | get :show, :board_id => 1, :id => 1, :r => message.children.order('id').last.id | |
|
55 | reply_ids = message.children.map(&:id).sort | |
|
56 | ||
|
57 | get :show, :board_id => 1, :id => 1, :r => reply_ids.last | |
|
58 | 58 | assert_response :success |
|
59 | assert_template 'show' | |
|
60 | replies = assigns(:replies) | |
|
61 | assert_not_nil replies | |
|
62 | assert_not_include message.children.reorder('id').first, replies | |
|
63 | assert_include message.children.reorder('id').last, replies | |
|
59 | ||
|
60 | assert_select 'a[href=?]', "/boards/1/topics/1?r=#{reply_ids.last}#message-#{reply_ids.last}" | |
|
61 | assert_select 'a[href=?]', "/boards/1/topics/1?r=#{reply_ids.first}#message-#{reply_ids.first}", 0 | |
|
64 | 62 | end |
|
65 | 63 | |
|
66 | 64 | def test_show_with_reply_permission |
|
67 | 65 | @request.session[:user_id] = 2 |
|
68 | 66 | get :show, :board_id => 1, :id => 1 |
|
69 | 67 | assert_response :success |
|
70 | assert_template 'show' | |
|
68 | ||
|
71 | 69 | assert_select 'div#reply textarea#message_content' |
|
72 | 70 | end |
|
73 | 71 | |
|
74 | 72 | def test_show_message_not_found |
|
75 | 73 | get :show, :board_id => 1, :id => 99999 |
|
76 | 74 | assert_response 404 |
|
77 | 75 | end |
|
78 | 76 | |
|
79 | 77 | def test_show_message_from_invalid_board_should_respond_with_404 |
|
80 | 78 | get :show, :board_id => 999, :id => 1 |
|
81 | 79 | assert_response 404 |
|
82 | 80 | end |
|
83 | 81 | |
|
84 | 82 | def test_get_new |
|
85 | 83 | @request.session[:user_id] = 2 |
|
86 | 84 | get :new, :board_id => 1 |
|
87 | 85 | assert_response :success |
|
88 | assert_template 'new' | |
|
86 | ||
|
87 | assert_select 'input[name=?]', 'message[subject]' | |
|
89 | 88 | end |
|
90 | 89 | |
|
91 | 90 | def test_get_new_with_invalid_board |
|
92 | 91 | @request.session[:user_id] = 2 |
|
93 | 92 | get :new, :board_id => 99 |
|
94 | 93 | assert_response 404 |
|
95 | 94 | end |
|
96 | 95 | |
|
97 | 96 | def test_post_new |
|
98 | 97 | @request.session[:user_id] = 2 |
|
99 | 98 | ActionMailer::Base.deliveries.clear |
|
100 | 99 | |
|
101 | 100 | with_settings :notified_events => %w(message_posted) do |
|
102 | 101 | post :new, :board_id => 1, |
|
103 | 102 | :message => { :subject => 'Test created message', |
|
104 | 103 | :content => 'Message body'} |
|
105 | 104 | end |
|
106 | 105 | message = Message.find_by_subject('Test created message') |
|
107 | 106 | assert_not_nil message |
|
108 | 107 | assert_redirected_to "/boards/1/topics/#{message.to_param}" |
|
109 | 108 | assert_equal 'Message body', message.content |
|
110 | 109 | assert_equal 2, message.author_id |
|
111 | 110 | assert_equal 1, message.board_id |
|
112 | 111 | |
|
113 | 112 | mail = ActionMailer::Base.deliveries.last |
|
114 | 113 | assert_not_nil mail |
|
115 | 114 | assert_equal "[#{message.board.project.name} - #{message.board.name} - msg#{message.root.id}] Test created message", mail.subject |
|
116 | 115 | assert_mail_body_match 'Message body', mail |
|
117 | 116 | # author |
|
118 | 117 | assert mail.bcc.include?('jsmith@somenet.foo') |
|
119 | 118 | # project member |
|
120 | 119 | assert mail.bcc.include?('dlopper@somenet.foo') |
|
121 | 120 | end |
|
122 | 121 | |
|
123 | 122 | def test_get_edit |
|
124 | 123 | @request.session[:user_id] = 2 |
|
125 | 124 | get :edit, :board_id => 1, :id => 1 |
|
126 | 125 | assert_response :success |
|
127 | assert_template 'edit' | |
|
126 | ||
|
127 | assert_select 'input[name=?][value=?]', 'message[subject]', 'First post' | |
|
128 | 128 | end |
|
129 | 129 | |
|
130 | 130 | def test_post_edit |
|
131 | 131 | @request.session[:user_id] = 2 |
|
132 | 132 | post :edit, :board_id => 1, :id => 1, |
|
133 | 133 | :message => { :subject => 'New subject', |
|
134 | 134 | :content => 'New body'} |
|
135 | 135 | assert_redirected_to '/boards/1/topics/1' |
|
136 | 136 | message = Message.find(1) |
|
137 | 137 | assert_equal 'New subject', message.subject |
|
138 | 138 | assert_equal 'New body', message.content |
|
139 | 139 | end |
|
140 | 140 | |
|
141 | 141 | def test_post_edit_sticky_and_locked |
|
142 | 142 | @request.session[:user_id] = 2 |
|
143 | 143 | post :edit, :board_id => 1, :id => 1, |
|
144 | 144 | :message => { :subject => 'New subject', |
|
145 | 145 | :content => 'New body', |
|
146 | 146 | :locked => '1', |
|
147 | 147 | :sticky => '1'} |
|
148 | 148 | assert_redirected_to '/boards/1/topics/1' |
|
149 | 149 | message = Message.find(1) |
|
150 | 150 | assert_equal true, message.sticky? |
|
151 | 151 | assert_equal true, message.locked? |
|
152 | 152 | end |
|
153 | 153 | |
|
154 | 154 | def test_post_edit_should_allow_to_change_board |
|
155 | 155 | @request.session[:user_id] = 2 |
|
156 | 156 | post :edit, :board_id => 1, :id => 1, |
|
157 | 157 | :message => { :subject => 'New subject', |
|
158 | 158 | :content => 'New body', |
|
159 | 159 | :board_id => 2} |
|
160 | 160 | assert_redirected_to '/boards/2/topics/1' |
|
161 | 161 | message = Message.find(1) |
|
162 | 162 | assert_equal Board.find(2), message.board |
|
163 | 163 | end |
|
164 | 164 | |
|
165 | 165 | def test_reply |
|
166 | 166 | @request.session[:user_id] = 2 |
|
167 | 167 | post :reply, :board_id => 1, :id => 1, :reply => { :content => 'This is a test reply', :subject => 'Test reply' } |
|
168 | 168 | reply = Message.order('id DESC').first |
|
169 | 169 | assert_redirected_to "/boards/1/topics/1?r=#{reply.id}" |
|
170 | 170 | assert Message.find_by_subject('Test reply') |
|
171 | 171 | end |
|
172 | 172 | |
|
173 | 173 | def test_destroy_topic |
|
174 | 174 | @request.session[:user_id] = 2 |
|
175 | 175 | assert_difference 'Message.count', -3 do |
|
176 | 176 | post :destroy, :board_id => 1, :id => 1 |
|
177 | 177 | end |
|
178 | 178 | assert_redirected_to '/projects/ecookbook/boards/1' |
|
179 | 179 | assert_nil Message.find_by_id(1) |
|
180 | 180 | end |
|
181 | 181 | |
|
182 | 182 | def test_destroy_reply |
|
183 | 183 | @request.session[:user_id] = 2 |
|
184 | 184 | assert_difference 'Message.count', -1 do |
|
185 | 185 | post :destroy, :board_id => 1, :id => 2 |
|
186 | 186 | end |
|
187 | 187 | assert_redirected_to '/boards/1/topics/1?r=2' |
|
188 | 188 | assert_nil Message.find_by_id(2) |
|
189 | 189 | end |
|
190 | 190 | |
|
191 | 191 | def test_quote |
|
192 | 192 | @request.session[:user_id] = 2 |
|
193 | 193 | xhr :get, :quote, :board_id => 1, :id => 3 |
|
194 | 194 | assert_response :success |
|
195 | 195 | assert_equal 'text/javascript', response.content_type |
|
196 | assert_template 'quote' | |
|
196 | ||
|
197 | 197 | assert_include 'RE: First post', response.body |
|
198 | 198 | assert_include '> An other reply', response.body |
|
199 | 199 | end |
|
200 | 200 | |
|
201 | 201 | def test_preview_new |
|
202 | 202 | @request.session[:user_id] = 2 |
|
203 | 203 | post :preview, |
|
204 | 204 | :board_id => 1, |
|
205 | 205 | :message => {:subject => "", :content => "Previewed text"} |
|
206 | 206 | assert_response :success |
|
207 | assert_template 'common/_preview' | |
|
207 | assert_include 'Previewed text', response.body | |
|
208 | 208 | end |
|
209 | 209 | |
|
210 | 210 | def test_preview_edit |
|
211 | 211 | @request.session[:user_id] = 2 |
|
212 | 212 | post :preview, |
|
213 | 213 | :id => 4, |
|
214 | 214 | :board_id => 1, |
|
215 | 215 | :message => {:subject => "", :content => "Previewed text"} |
|
216 | 216 | assert_response :success |
|
217 | assert_template 'common/_preview' | |
|
217 | assert_include 'Previewed text', response.body | |
|
218 | 218 | end |
|
219 | 219 | end |
@@ -1,299 +1,295 | |||
|
1 | 1 | # Redmine - project management software |
|
2 | 2 | # Copyright (C) 2006-2016 Jean-Philippe Lang |
|
3 | 3 | # |
|
4 | 4 | # This program is free software; you can redistribute it and/or |
|
5 | 5 | # modify it under the terms of the GNU General Public License |
|
6 | 6 | # as published by the Free Software Foundation; either version 2 |
|
7 | 7 | # of the License, or (at your option) any later version. |
|
8 | 8 | # |
|
9 | 9 | # This program is distributed in the hope that it will be useful, |
|
10 | 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 | 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12 | 12 | # GNU General Public License for more details. |
|
13 | 13 | # |
|
14 | 14 | # You should have received a copy of the GNU General Public License |
|
15 | 15 | # along with this program; if not, write to the Free Software |
|
16 | 16 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
|
17 | 17 | |
|
18 | 18 | require File.expand_path('../../test_helper', __FILE__) |
|
19 | 19 | |
|
20 | 20 | class MyControllerTest < Redmine::ControllerTest |
|
21 | 21 | fixtures :users, :email_addresses, :user_preferences, :roles, :projects, :members, :member_roles, |
|
22 | 22 | :issues, :issue_statuses, :trackers, :enumerations, :custom_fields, :auth_sources |
|
23 | 23 | |
|
24 | 24 | def setup |
|
25 | 25 | @request.session[:user_id] = 2 |
|
26 | 26 | end |
|
27 | 27 | |
|
28 | 28 | def test_index |
|
29 | 29 | get :index |
|
30 | 30 | assert_response :success |
|
31 |
assert_ |
|
|
31 | assert_select 'h2', 'My page' | |
|
32 | 32 | end |
|
33 | 33 | |
|
34 | 34 | def test_page |
|
35 | 35 | get :page |
|
36 | 36 | assert_response :success |
|
37 |
assert_ |
|
|
37 | assert_select 'h2', 'My page' | |
|
38 | 38 | end |
|
39 | 39 | |
|
40 | 40 | def test_page_with_timelog_block |
|
41 | 41 | preferences = User.find(2).pref |
|
42 | 42 | preferences[:my_page_layout] = {'top' => ['timelog']} |
|
43 | 43 | preferences.save! |
|
44 | 44 | TimeEntry.create!(:user => User.find(2), :spent_on => Date.yesterday, :issue_id => 1, :hours => 2.5, :activity_id => 10) |
|
45 | 45 | |
|
46 | 46 | get :page |
|
47 | 47 | assert_response :success |
|
48 | 48 | assert_select 'tr.time-entry' do |
|
49 | 49 | assert_select 'td.subject a[href="/issues/1"]' |
|
50 | 50 | assert_select 'td.hours', :text => '2.50' |
|
51 | 51 | end |
|
52 | 52 | end |
|
53 | 53 | |
|
54 | 54 | def test_page_with_all_blocks |
|
55 | 55 | blocks = MyController::BLOCKS.keys |
|
56 | 56 | preferences = User.find(2).pref |
|
57 | 57 | preferences[:my_page_layout] = {'top' => blocks} |
|
58 | 58 | preferences.save! |
|
59 | 59 | |
|
60 | 60 | get :page |
|
61 | 61 | assert_response :success |
|
62 | 62 | assert_select 'div.mypage-box', blocks.size |
|
63 | 63 | end |
|
64 | 64 | |
|
65 | 65 | def test_my_account_should_show_editable_custom_fields |
|
66 | 66 | get :account |
|
67 | 67 | assert_response :success |
|
68 | assert_template 'account' | |
|
69 | assert_equal User.find(2), assigns(:user) | |
|
70 | ||
|
71 | 68 | assert_select 'input[name=?]', 'user[custom_field_values][4]' |
|
72 | 69 | end |
|
73 | 70 | |
|
74 | 71 | def test_my_account_should_not_show_non_editable_custom_fields |
|
75 | 72 | UserCustomField.find(4).update_attribute :editable, false |
|
76 | 73 | |
|
77 | 74 | get :account |
|
78 | 75 | assert_response :success |
|
79 | assert_template 'account' | |
|
80 | assert_equal User.find(2), assigns(:user) | |
|
81 | ||
|
82 | 76 | assert_select 'input[name=?]', 'user[custom_field_values][4]', 0 |
|
83 | 77 | end |
|
84 | 78 | |
|
85 | 79 | def test_my_account_should_show_language_select |
|
86 | 80 | get :account |
|
87 | 81 | assert_response :success |
|
88 | 82 | assert_select 'select[name=?]', 'user[language]' |
|
89 | 83 | end |
|
90 | 84 | |
|
91 | 85 | def test_my_account_should_not_show_language_select_with_force_default_language_for_loggedin |
|
92 | 86 | with_settings :force_default_language_for_loggedin => '1' do |
|
93 | 87 | get :account |
|
94 | 88 | assert_response :success |
|
95 | 89 | assert_select 'select[name=?]', 'user[language]', 0 |
|
96 | 90 | end |
|
97 | 91 | end |
|
98 | 92 | |
|
99 | 93 | def test_update_account |
|
100 | 94 | post :account, |
|
101 | 95 | :user => { |
|
102 | 96 | :firstname => "Joe", |
|
103 | 97 | :login => "root", |
|
104 | 98 | :admin => 1, |
|
105 | 99 | :group_ids => ['10'], |
|
106 | 100 | :custom_field_values => {"4" => "0100562500"} |
|
107 | 101 | } |
|
108 | 102 | |
|
109 | 103 | assert_redirected_to '/my/account' |
|
110 | 104 | user = User.find(2) |
|
111 | assert_equal user, assigns(:user) | |
|
112 | 105 | assert_equal "Joe", user.firstname |
|
113 | 106 | assert_equal "jsmith", user.login |
|
114 | 107 | assert_equal "0100562500", user.custom_value_for(4).value |
|
115 | 108 | # ignored |
|
116 | 109 | assert !user.admin? |
|
117 | 110 | assert user.groups.empty? |
|
118 | 111 | end |
|
119 | 112 | |
|
120 | 113 | def test_update_account_should_send_security_notification |
|
121 | 114 | ActionMailer::Base.deliveries.clear |
|
122 | 115 | post :account, |
|
123 | 116 | :user => { |
|
124 | 117 | :mail => 'foobar@example.com' |
|
125 | 118 | } |
|
126 | 119 | |
|
127 | 120 | assert_not_nil (mail = ActionMailer::Base.deliveries.last) |
|
128 | 121 | assert_mail_body_match '0.0.0.0', mail |
|
129 | 122 | assert_mail_body_match I18n.t(:mail_body_security_notification_change_to, field: I18n.t(:field_mail), value: 'foobar@example.com'), mail |
|
130 | 123 | assert_select_email do |
|
131 | 124 | assert_select 'a[href^=?]', 'http://localhost:3000/my/account', :text => 'My account' |
|
132 | 125 | end |
|
133 | 126 | # The old email address should be notified about the change for security purposes |
|
134 | 127 | assert [mail.bcc, mail.cc].flatten.include?(User.find(2).mail) |
|
135 | 128 | assert [mail.bcc, mail.cc].flatten.include?('foobar@example.com') |
|
136 | 129 | end |
|
137 | 130 | |
|
138 | 131 | def test_my_account_should_show_destroy_link |
|
139 | 132 | get :account |
|
140 | 133 | assert_select 'a[href="/my/account/destroy"]' |
|
141 | 134 | end |
|
142 | 135 | |
|
143 | 136 | def test_get_destroy_should_display_the_destroy_confirmation |
|
144 | 137 | get :destroy |
|
145 | 138 | assert_response :success |
|
146 | assert_template 'destroy' | |
|
147 | 139 | assert_select 'form[action="/my/account/destroy"]' do |
|
148 | 140 | assert_select 'input[name=confirm]' |
|
149 | 141 | end |
|
150 | 142 | end |
|
151 | 143 | |
|
152 | 144 | def test_post_destroy_without_confirmation_should_not_destroy_account |
|
153 | 145 | assert_no_difference 'User.count' do |
|
154 | 146 | post :destroy |
|
155 | 147 | end |
|
156 | 148 | assert_response :success |
|
157 | assert_template 'destroy' | |
|
158 | 149 | end |
|
159 | 150 | |
|
160 | 151 | def test_post_destroy_without_confirmation_should_destroy_account |
|
161 | 152 | assert_difference 'User.count', -1 do |
|
162 | 153 | post :destroy, :confirm => '1' |
|
163 | 154 | end |
|
164 | 155 | assert_redirected_to '/' |
|
165 | 156 | assert_match /deleted/i, flash[:notice] |
|
166 | 157 | end |
|
167 | 158 | |
|
168 | 159 | def test_post_destroy_with_unsubscribe_not_allowed_should_not_destroy_account |
|
169 | 160 | User.any_instance.stubs(:own_account_deletable?).returns(false) |
|
170 | 161 | |
|
171 | 162 | assert_no_difference 'User.count' do |
|
172 | 163 | post :destroy, :confirm => '1' |
|
173 | 164 | end |
|
174 | 165 | assert_redirected_to '/my/account' |
|
175 | 166 | end |
|
176 | 167 | |
|
177 | 168 | def test_change_password |
|
178 | 169 | get :password |
|
179 | 170 | assert_response :success |
|
180 | assert_template 'password' | |
|
171 | assert_select 'input[type=password][name=password]' | |
|
172 | assert_select 'input[type=password][name=new_password]' | |
|
173 | assert_select 'input[type=password][name=new_password_confirmation]' | |
|
174 | end | |
|
181 | 175 | |
|
182 | # non matching password confirmation | |
|
176 | def test_update_password | |
|
177 | post :password, :password => 'jsmith', | |
|
178 | :new_password => 'secret123', | |
|
179 | :new_password_confirmation => 'secret123' | |
|
180 | assert_redirected_to '/my/account' | |
|
181 | assert User.try_to_login('jsmith', 'secret123') | |
|
182 | end | |
|
183 | ||
|
184 | def test_update_password_with_non_matching_confirmation | |
|
183 | 185 | post :password, :password => 'jsmith', |
|
184 | 186 | :new_password => 'secret123', |
|
185 | 187 | :new_password_confirmation => 'secret1234' |
|
186 | 188 | assert_response :success |
|
187 | assert_template 'password' | |
|
188 | 189 | assert_select_error /Password doesn.*t match confirmation/ |
|
190 | assert User.try_to_login('jsmith', 'jsmith') | |
|
191 | end | |
|
189 | 192 | |
|
193 | def test_update_password_with_wrong_password | |
|
190 | 194 | # wrong password |
|
191 | 195 | post :password, :password => 'wrongpassword', |
|
192 | 196 | :new_password => 'secret123', |
|
193 | 197 | :new_password_confirmation => 'secret123' |
|
194 | 198 | assert_response :success |
|
195 | assert_template 'password' | |
|
196 | 199 | assert_equal 'Wrong password', flash[:error] |
|
197 | ||
|
198 | # good password | |
|
199 | post :password, :password => 'jsmith', | |
|
200 | :new_password => 'secret123', | |
|
201 | :new_password_confirmation => 'secret123' | |
|
202 | assert_redirected_to '/my/account' | |
|
203 | assert User.try_to_login('jsmith', 'secret123') | |
|
200 | assert User.try_to_login('jsmith', 'jsmith') | |
|
204 | 201 | end |
|
205 | 202 | |
|
206 | 203 | def test_change_password_should_redirect_if_user_cannot_change_its_password |
|
207 | 204 | User.find(2).update_attribute(:auth_source_id, 1) |
|
208 | 205 | |
|
209 | 206 | get :password |
|
210 | 207 | assert_not_nil flash[:error] |
|
211 | 208 | assert_redirected_to '/my/account' |
|
212 | 209 | end |
|
213 | 210 | |
|
214 |
def test_ |
|
|
211 | def test_update_password_should_send_security_notification | |
|
215 | 212 | ActionMailer::Base.deliveries.clear |
|
216 | 213 | post :password, :password => 'jsmith', |
|
217 | 214 | :new_password => 'secret123', |
|
218 | 215 | :new_password_confirmation => 'secret123' |
|
219 | 216 | |
|
220 | 217 | assert_not_nil (mail = ActionMailer::Base.deliveries.last) |
|
221 | 218 | assert_mail_body_no_match 'secret123', mail # just to be sure: pw should never be sent! |
|
222 | 219 | assert_select_email do |
|
223 | 220 | assert_select 'a[href^=?]', 'http://localhost:3000/my/password', :text => 'Change password' |
|
224 | 221 | end |
|
225 | 222 | end |
|
226 | 223 | |
|
227 | 224 | def test_page_layout |
|
228 | 225 | get :page_layout |
|
229 | 226 | assert_response :success |
|
230 | assert_template 'page_layout' | |
|
231 | 227 | end |
|
232 | 228 | |
|
233 | 229 | def test_add_block |
|
234 | 230 | post :add_block, :block => 'issuesreportedbyme' |
|
235 | 231 | assert_redirected_to '/my/page_layout' |
|
236 | 232 | assert User.find(2).pref[:my_page_layout]['top'].include?('issuesreportedbyme') |
|
237 | 233 | end |
|
238 | 234 | |
|
239 | 235 | def test_add_invalid_block_should_redirect |
|
240 | 236 | post :add_block, :block => 'invalid' |
|
241 | 237 | assert_redirected_to '/my/page_layout' |
|
242 | 238 | end |
|
243 | 239 | |
|
244 | 240 | def test_remove_block |
|
245 | 241 | post :remove_block, :block => 'issuesassignedtome' |
|
246 | 242 | assert_redirected_to '/my/page_layout' |
|
247 | 243 | assert !User.find(2).pref[:my_page_layout].values.flatten.include?('issuesassignedtome') |
|
248 | 244 | end |
|
249 | 245 | |
|
250 | 246 | def test_order_blocks |
|
251 | 247 | xhr :post, :order_blocks, :group => 'left', 'blocks' => ['documents', 'calendar', 'latestnews'] |
|
252 | 248 | assert_response :success |
|
253 | 249 | assert_equal ['documents', 'calendar', 'latestnews'], User.find(2).pref[:my_page_layout]['left'] |
|
254 | 250 | end |
|
255 | 251 | |
|
256 | 252 | def test_reset_rss_key_with_existing_key |
|
257 | 253 | @previous_token_value = User.find(2).rss_key # Will generate one if it's missing |
|
258 | 254 | post :reset_rss_key |
|
259 | 255 | |
|
260 | 256 | assert_not_equal @previous_token_value, User.find(2).rss_key |
|
261 | 257 | assert User.find(2).rss_token |
|
262 | 258 | assert_match /reset/, flash[:notice] |
|
263 | 259 | assert_redirected_to '/my/account' |
|
264 | 260 | end |
|
265 | 261 | |
|
266 | 262 | def test_reset_rss_key_without_existing_key |
|
267 | 263 | assert_nil User.find(2).rss_token |
|
268 | 264 | post :reset_rss_key |
|
269 | 265 | |
|
270 | 266 | assert User.find(2).rss_token |
|
271 | 267 | assert_match /reset/, flash[:notice] |
|
272 | 268 | assert_redirected_to '/my/account' |
|
273 | 269 | end |
|
274 | 270 | |
|
275 | 271 | def test_show_api_key |
|
276 | 272 | get :show_api_key |
|
277 | 273 | assert_response :success |
|
278 | 274 | assert_select 'pre', User.find(2).api_key |
|
279 | 275 | end |
|
280 | 276 | |
|
281 | 277 | def test_reset_api_key_with_existing_key |
|
282 | 278 | @previous_token_value = User.find(2).api_key # Will generate one if it's missing |
|
283 | 279 | post :reset_api_key |
|
284 | 280 | |
|
285 | 281 | assert_not_equal @previous_token_value, User.find(2).api_key |
|
286 | 282 | assert User.find(2).api_token |
|
287 | 283 | assert_match /reset/, flash[:notice] |
|
288 | 284 | assert_redirected_to '/my/account' |
|
289 | 285 | end |
|
290 | 286 | |
|
291 | 287 | def test_reset_api_key_without_existing_key |
|
292 | 288 | assert_nil User.find(2).api_token |
|
293 | 289 | post :reset_api_key |
|
294 | 290 | |
|
295 | 291 | assert User.find(2).api_token |
|
296 | 292 | assert_match /reset/, flash[:notice] |
|
297 | 293 | assert_redirected_to '/my/account' |
|
298 | 294 | end |
|
299 | 295 | end |
@@ -1,178 +1,172 | |||
|
1 | 1 | # Redmine - project management software |
|
2 | 2 | # Copyright (C) 2006-2016 Jean-Philippe Lang |
|
3 | 3 | # |
|
4 | 4 | # This program is free software; you can redistribute it and/or |
|
5 | 5 | # modify it under the terms of the GNU General Public License |
|
6 | 6 | # as published by the Free Software Foundation; either version 2 |
|
7 | 7 | # of the License, or (at your option) any later version. |
|
8 | 8 | # |
|
9 | 9 | # This program is distributed in the hope that it will be useful, |
|
10 | 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 | 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12 | 12 | # GNU General Public License for more details. |
|
13 | 13 | # |
|
14 | 14 | # You should have received a copy of the GNU General Public License |
|
15 | 15 | # along with this program; if not, write to the Free Software |
|
16 | 16 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
|
17 | 17 | |
|
18 | 18 | require File.expand_path('../../test_helper', __FILE__) |
|
19 | 19 | |
|
20 | 20 | class NewsControllerTest < Redmine::ControllerTest |
|
21 | 21 | fixtures :projects, :users, :email_addresses, :roles, :members, :member_roles, |
|
22 | 22 | :enabled_modules, :news, :comments, |
|
23 | 23 | :attachments |
|
24 | 24 | |
|
25 | 25 | def setup |
|
26 | 26 | User.current = nil |
|
27 | 27 | end |
|
28 | 28 | |
|
29 | 29 | def test_index |
|
30 | 30 | get :index |
|
31 | 31 | assert_response :success |
|
32 | assert_template 'index' | |
|
33 | assert_not_nil assigns(:newss) | |
|
34 | assert_nil assigns(:project) | |
|
32 | assert_select 'h3 a', :text => 'eCookbook first release !' | |
|
35 | 33 | end |
|
36 | 34 | |
|
37 | 35 | def test_index_with_project |
|
38 | 36 | get :index, :project_id => 1 |
|
39 | 37 | assert_response :success |
|
40 | assert_template 'index' | |
|
41 | assert_not_nil assigns(:newss) | |
|
38 | assert_select 'h3 a', :text => 'eCookbook first release !' | |
|
42 | 39 | end |
|
43 | 40 | |
|
44 | 41 | def test_index_with_invalid_project_should_respond_with_404 |
|
45 | 42 | get :index, :project_id => 999 |
|
46 | 43 | assert_response 404 |
|
47 | 44 | end |
|
48 | 45 | |
|
49 | 46 | def test_show |
|
50 | 47 | get :show, :id => 1 |
|
51 | 48 | assert_response :success |
|
52 | assert_template 'show' | |
|
53 | assert_select 'h2', :text => /eCookbook first release/ | |
|
49 | assert_select 'h2', :text => 'eCookbook first release !' | |
|
54 | 50 | end |
|
55 | 51 | |
|
56 | 52 | def test_show_should_show_attachments |
|
57 | 53 | attachment = Attachment.first |
|
58 | 54 | attachment.container = News.find(1) |
|
59 | 55 | attachment.save! |
|
60 | 56 | |
|
61 | 57 | get :show, :id => 1 |
|
62 | 58 | assert_response :success |
|
63 | 59 | assert_select 'a', :text => attachment.filename |
|
64 | 60 | end |
|
65 | 61 | |
|
66 | 62 | def test_show_with_comments_in_reverse_order |
|
67 | 63 | user = User.find(1) |
|
68 | 64 | user.pref[:comments_sorting] = 'desc' |
|
69 | 65 | user.pref.save! |
|
70 | 66 | |
|
71 | 67 | @request.session[:user_id] = 1 |
|
72 | 68 | get :show, :id => 1 |
|
73 | 69 | assert_response :success |
|
74 | assert_equal News.find(1).comments.to_a.sort_by(&:created_on).reverse, assigns(:comments) | |
|
70 | ||
|
71 | comments = css_select('#comments .wiki').map(&:text).map(&:strip) | |
|
72 | assert_equal ["This is an other comment", "my first comment"], comments | |
|
75 | 73 | end |
|
76 | 74 | |
|
77 | 75 | def test_show_not_found |
|
78 | 76 | get :show, :id => 999 |
|
79 | 77 | assert_response 404 |
|
80 | 78 | end |
|
81 | 79 | |
|
82 | 80 | def test_get_new |
|
83 | 81 | @request.session[:user_id] = 2 |
|
84 | 82 | get :new, :project_id => 1 |
|
85 | 83 | assert_response :success |
|
86 | assert_template 'new' | |
|
84 | assert_select 'input[name=?]', 'news[title]' | |
|
87 | 85 | end |
|
88 | 86 | |
|
89 | 87 | def test_post_create |
|
90 | 88 | ActionMailer::Base.deliveries.clear |
|
91 | 89 | @request.session[:user_id] = 2 |
|
92 | 90 | |
|
93 | 91 | with_settings :notified_events => %w(news_added) do |
|
94 | 92 | post :create, :project_id => 1, :news => { :title => 'NewsControllerTest', |
|
95 | 93 | :description => 'This is the description', |
|
96 | 94 | :summary => '' } |
|
97 | 95 | end |
|
98 | 96 | assert_redirected_to '/projects/ecookbook/news' |
|
99 | 97 | |
|
100 | 98 | news = News.find_by_title('NewsControllerTest') |
|
101 | 99 | assert_not_nil news |
|
102 | 100 | assert_equal 'This is the description', news.description |
|
103 | 101 | assert_equal User.find(2), news.author |
|
104 | 102 | assert_equal Project.find(1), news.project |
|
105 | 103 | assert_equal 1, ActionMailer::Base.deliveries.size |
|
106 | 104 | end |
|
107 | 105 | |
|
108 | 106 | def test_post_create_with_attachment |
|
109 | 107 | set_tmp_attachments_directory |
|
110 | 108 | @request.session[:user_id] = 2 |
|
111 | 109 | assert_difference 'News.count' do |
|
112 | 110 | assert_difference 'Attachment.count' do |
|
113 | 111 | post :create, :project_id => 1, |
|
114 | 112 | :news => { :title => 'Test', :description => 'This is the description' }, |
|
115 | 113 | :attachments => {'1' => {'file' => uploaded_test_file('testfile.txt', 'text/plain')}} |
|
116 | 114 | end |
|
117 | 115 | end |
|
118 | 116 | attachment = Attachment.order('id DESC').first |
|
119 | 117 | news = News.order('id DESC').first |
|
120 | 118 | assert_equal news, attachment.container |
|
121 | 119 | end |
|
122 | 120 | |
|
123 | 121 | def test_post_create_with_validation_failure |
|
124 | 122 | @request.session[:user_id] = 2 |
|
125 | 123 | post :create, :project_id => 1, :news => { :title => '', |
|
126 | 124 | :description => 'This is the description', |
|
127 | 125 | :summary => '' } |
|
128 | 126 | assert_response :success |
|
129 | assert_template 'new' | |
|
130 | assert_not_nil assigns(:news) | |
|
131 | assert assigns(:news).new_record? | |
|
132 | 127 | assert_select_error /title cannot be blank/i |
|
133 | 128 | end |
|
134 | 129 | |
|
135 | 130 | def test_get_edit |
|
136 | 131 | @request.session[:user_id] = 2 |
|
137 | 132 | get :edit, :id => 1 |
|
138 | 133 | assert_response :success |
|
139 | assert_template 'edit' | |
|
134 | assert_select 'input[name=?][value=?]', 'news[title]', 'eCookbook first release !' | |
|
140 | 135 | end |
|
141 | 136 | |
|
142 | 137 | def test_put_update |
|
143 | 138 | @request.session[:user_id] = 2 |
|
144 | 139 | put :update, :id => 1, :news => { :description => 'Description changed by test_post_edit' } |
|
145 | 140 | assert_redirected_to '/news/1' |
|
146 | 141 | news = News.find(1) |
|
147 | 142 | assert_equal 'Description changed by test_post_edit', news.description |
|
148 | 143 | end |
|
149 | 144 | |
|
150 | 145 | def test_put_update_with_attachment |
|
151 | 146 | set_tmp_attachments_directory |
|
152 | 147 | @request.session[:user_id] = 2 |
|
153 | 148 | assert_no_difference 'News.count' do |
|
154 | 149 | assert_difference 'Attachment.count' do |
|
155 | 150 | put :update, :id => 1, |
|
156 | 151 | :news => { :description => 'This is the description' }, |
|
157 | 152 | :attachments => {'1' => {'file' => uploaded_test_file('testfile.txt', 'text/plain')}} |
|
158 | 153 | end |
|
159 | 154 | end |
|
160 | 155 | attachment = Attachment.order('id DESC').first |
|
161 | 156 | assert_equal News.find(1), attachment.container |
|
162 | 157 | end |
|
163 | 158 | |
|
164 | 159 | def test_update_with_failure |
|
165 | 160 | @request.session[:user_id] = 2 |
|
166 | 161 | put :update, :id => 1, :news => { :description => '' } |
|
167 | 162 | assert_response :success |
|
168 | assert_template 'edit' | |
|
169 | 163 | assert_select_error /description cannot be blank/i |
|
170 | 164 | end |
|
171 | 165 | |
|
172 | 166 | def test_destroy |
|
173 | 167 | @request.session[:user_id] = 2 |
|
174 | 168 | delete :destroy, :id => 1 |
|
175 | 169 | assert_redirected_to '/projects/ecookbook/news' |
|
176 | 170 | assert_nil News.find_by_id(1) |
|
177 | 171 | end |
|
178 | 172 | end |
@@ -1,95 +1,99 | |||
|
1 | 1 | # Redmine - project management software |
|
2 | 2 | # Copyright (C) 2006-2016 Jean-Philippe Lang |
|
3 | 3 | # |
|
4 | 4 | # This program is free software; you can redistribute it and/or |
|
5 | 5 | # modify it under the terms of the GNU General Public License |
|
6 | 6 | # as published by the Free Software Foundation; either version 2 |
|
7 | 7 | # of the License, or (at your option) any later version. |
|
8 | 8 | # |
|
9 | 9 | # This program is distributed in the hope that it will be useful, |
|
10 | 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 | 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12 | 12 | # GNU General Public License for more details. |
|
13 | 13 | # |
|
14 | 14 | # You should have received a copy of the GNU General Public License |
|
15 | 15 | # along with this program; if not, write to the Free Software |
|
16 | 16 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
|
17 | 17 | |
|
18 | 18 | require File.expand_path('../../test_helper', __FILE__) |
|
19 | 19 | |
|
20 | 20 | class PreviewsControllerTest < Redmine::ControllerTest |
|
21 | 21 | fixtures :projects, :trackers, :issue_statuses, :issues, |
|
22 | 22 | :enumerations, :users, :issue_categories, |
|
23 | 23 | :projects_trackers, |
|
24 | 24 | :roles, |
|
25 | 25 | :member_roles, |
|
26 | 26 | :members, |
|
27 | 27 | :enabled_modules, |
|
28 | 28 | :journals, :journal_details, |
|
29 | 29 | :news |
|
30 | 30 | |
|
31 | 31 | def test_preview_new_issue |
|
32 | 32 | @request.session[:user_id] = 2 |
|
33 | 33 | post :issue, :project_id => '1', :issue => {:description => 'Foo'} |
|
34 | 34 | assert_response :success |
|
35 | assert_template 'previews/issue' | |
|
36 | assert_not_nil assigns(:description) | |
|
35 | assert_select 'fieldset' do | |
|
36 | assert_select 'legend', :text => 'Description' | |
|
37 | assert_select 'p', :text => 'Foo' | |
|
38 | end | |
|
37 | 39 | end |
|
38 | 40 | |
|
39 | def test_preview_issue_notes | |
|
41 | def test_preview_issue_notes_with_no_change_to_description | |
|
40 | 42 | @request.session[:user_id] = 2 |
|
41 | 43 | post :issue, :project_id => '1', :id => 1, |
|
42 | 44 | :issue => {:description => Issue.find(1).description, :notes => 'Foo'} |
|
43 | 45 | assert_response :success |
|
44 | assert_template 'previews/issue' | |
|
45 | assert_not_nil assigns(:notes) | |
|
46 | assert_select 'legend', :text => 'Description', :count => 0 | |
|
47 | assert_select 'legend', :text => 'Notes' | |
|
48 | end | |
|
49 | ||
|
50 | def test_preview_issue_notes_with_no_change_to_description | |
|
51 | @request.session[:user_id] = 2 | |
|
52 | post :issue, :project_id => '1', :id => 1, | |
|
53 | :issue => {:description => 'Changed description', :notes => 'Foo'} | |
|
54 | assert_response :success | |
|
55 | assert_select 'legend', :text => 'Description' | |
|
56 | assert_select 'legend', :text => 'Notes' | |
|
46 | 57 | end |
|
47 | 58 | |
|
48 | 59 | def test_preview_journal_notes_for_update |
|
49 | 60 | @request.session[:user_id] = 2 |
|
50 | 61 | post :issue, :project_id => '1', :id => 1, :notes => 'Foo' |
|
51 | 62 | assert_response :success |
|
52 | assert_template 'previews/issue' | |
|
53 | assert_not_nil assigns(:notes) | |
|
63 | assert_select 'legend', :text => 'Notes' | |
|
54 | 64 | assert_select 'p', :text => 'Foo' |
|
55 | 65 | end |
|
56 | 66 | |
|
57 | 67 | def test_preview_issue_notes_should_support_links_to_existing_attachments |
|
58 | 68 | Attachment.generate!(:container => Issue.find(1), :filename => 'foo.bar') |
|
59 | 69 | @request.session[:user_id] = 2 |
|
60 | 70 | post :issue, :project_id => '1', :id => 1, :notes => 'attachment:foo.bar' |
|
61 | 71 | assert_response :success |
|
62 | 72 | assert_select 'a.attachment', :text => 'foo.bar' |
|
63 | 73 | end |
|
64 | 74 | |
|
65 | 75 | def test_preview_issue_with_project_changed |
|
66 | 76 | @request.session[:user_id] = 2 |
|
67 | 77 | post :issue, :project_id => '1', :id => 1, :issue => {:notes => 'notes', :project_id => 2} |
|
68 | 78 | assert_response :success |
|
69 | assert_not_nil assigns(:issue) | |
|
70 | assert_not_nil assigns(:notes) | |
|
79 | assert_select 'legend', :text => 'Notes' | |
|
71 | 80 | end |
|
72 | 81 | |
|
73 | 82 | def test_preview_new_news |
|
74 | 83 | get :news, :project_id => 1, |
|
75 | 84 | :news => {:title => '', |
|
76 | 85 | :description => 'News description', |
|
77 | 86 | :summary => ''} |
|
78 | 87 | assert_response :success |
|
79 | assert_template 'common/_preview' | |
|
80 | 88 | assert_select 'fieldset.preview', :text => /News description/ |
|
81 | 89 | end |
|
82 | 90 | |
|
83 |
def test_existing |
|
|
91 | def test_preview_existing_news | |
|
84 | 92 | get :news, :project_id => 1, :id => 2, |
|
85 | 93 | :news => {:title => '', |
|
86 | 94 | :description => 'News description', |
|
87 | 95 | :summary => ''} |
|
88 | 96 | assert_response :success |
|
89 | assert_template 'common/_preview' | |
|
90 | assert_equal News.find(2), assigns(:previewed) | |
|
91 | assert_not_nil assigns(:attachments) | |
|
92 | ||
|
93 | 97 | assert_select 'fieldset.preview', :text => /News description/ |
|
94 | 98 | end |
|
95 | 99 | end |
@@ -1,209 +1,201 | |||
|
1 | 1 | # Redmine - project management software |
|
2 | 2 | # Copyright (C) 2006-2016 Jean-Philippe Lang |
|
3 | 3 | # |
|
4 | 4 | # This program is free software; you can redistribute it and/or |
|
5 | 5 | # modify it under the terms of the GNU General Public License |
|
6 | 6 | # as published by the Free Software Foundation; either version 2 |
|
7 | 7 | # of the License, or (at your option) any later version. |
|
8 | 8 | # |
|
9 | 9 | # This program is distributed in the hope that it will be useful, |
|
10 | 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 | 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12 | 12 | # GNU General Public License for more details. |
|
13 | 13 | # |
|
14 | 14 | # You should have received a copy of the GNU General Public License |
|
15 | 15 | # along with this program; if not, write to the Free Software |
|
16 | 16 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
|
17 | 17 | |
|
18 | 18 | require File.expand_path('../../test_helper', __FILE__) |
|
19 | 19 | |
|
20 | 20 | class PrincipalMembershipsControllerTest < Redmine::ControllerTest |
|
21 | 21 | fixtures :projects, :users, :members, :member_roles, :roles, :groups_users |
|
22 | 22 | |
|
23 | 23 | def setup |
|
24 | 24 | @request.session[:user_id] = 1 |
|
25 | 25 | end |
|
26 | 26 | |
|
27 | 27 | def test_new_user_membership |
|
28 | 28 | get :new, :user_id => 7 |
|
29 | 29 | assert_response :success |
|
30 | 30 | assert_select 'label', :text => 'eCookbook' do |
|
31 | 31 | assert_select 'input[name=?][value="1"]:not([disabled])', 'membership[project_ids][]' |
|
32 | 32 | end |
|
33 | 33 | end |
|
34 | 34 | |
|
35 | 35 | def test_new_user_membership_should_disable_user_projects |
|
36 | 36 | Member.create!(:user_id => 7, :project_id => 1, :role_ids => [1]) |
|
37 | 37 | |
|
38 | 38 | get :new, :user_id => 7 |
|
39 | 39 | assert_response :success |
|
40 | 40 | assert_select 'label', :text => 'eCookbook' do |
|
41 | 41 | assert_select 'input[name=?][value="1"][disabled=disabled]', 'membership[project_ids][]' |
|
42 | 42 | end |
|
43 | 43 | end |
|
44 | 44 | |
|
45 | 45 | def test_xhr_new_user_membership |
|
46 | 46 | xhr :get, :new, :user_id => 7 |
|
47 | 47 | assert_response :success |
|
48 | 48 | assert_equal 'text/javascript', response.content_type |
|
49 | 49 | end |
|
50 | 50 | |
|
51 | 51 | def test_create_user_membership |
|
52 | 52 | assert_difference 'Member.count' do |
|
53 | 53 | post :create, :user_id => 7, :membership => {:project_ids => [3], :role_ids => [2]} |
|
54 | 54 | end |
|
55 | 55 | assert_redirected_to '/users/7/edit?tab=memberships' |
|
56 | 56 | member = Member.order('id DESC').first |
|
57 | 57 | assert_equal User.find(7), member.principal |
|
58 | 58 | assert_equal [2], member.role_ids |
|
59 | 59 | assert_equal 3, member.project_id |
|
60 | 60 | end |
|
61 | 61 | |
|
62 | 62 | def test_create_user_membership_with_multiple_roles |
|
63 | 63 | assert_difference 'Member.count' do |
|
64 | 64 | post :create, :user_id => 7, :membership => {:project_ids => [3], :role_ids => [2, 3]} |
|
65 | 65 | end |
|
66 | 66 | member = Member.order('id DESC').first |
|
67 | 67 | assert_equal User.find(7), member.principal |
|
68 | 68 | assert_equal [2, 3], member.role_ids.sort |
|
69 | 69 | assert_equal 3, member.project_id |
|
70 | 70 | end |
|
71 | 71 | |
|
72 | 72 | def test_create_user_membership_with_multiple_projects_and_roles |
|
73 | 73 | assert_difference 'Member.count', 2 do |
|
74 | 74 | post :create, :user_id => 7, :membership => {:project_ids => [1, 3], :role_ids => [2, 3]} |
|
75 | 75 | end |
|
76 | 76 | members = Member.order('id DESC').limit(2).sort_by(&:project_id) |
|
77 | 77 | assert_equal 1, members[0].project_id |
|
78 | 78 | assert_equal 3, members[1].project_id |
|
79 | 79 | members.each do |member| |
|
80 | 80 | assert_equal User.find(7), member.principal |
|
81 | 81 | assert_equal [2, 3], member.role_ids.sort |
|
82 | 82 | end |
|
83 | 83 | end |
|
84 | 84 | |
|
85 | 85 | def test_xhr_create_user_membership |
|
86 | 86 | assert_difference 'Member.count' do |
|
87 | 87 | xhr :post, :create, :user_id => 7, :membership => {:project_ids => [3], :role_ids => [2]}, :format => 'js' |
|
88 | 88 | assert_response :success |
|
89 | assert_template 'create' | |
|
90 | 89 | assert_equal 'text/javascript', response.content_type |
|
91 | 90 | end |
|
92 | 91 | member = Member.order('id DESC').first |
|
93 | 92 | assert_equal User.find(7), member.principal |
|
94 | 93 | assert_equal [2], member.role_ids |
|
95 | 94 | assert_equal 3, member.project_id |
|
96 | 95 | assert_include 'tab-content-memberships', response.body |
|
97 | 96 | end |
|
98 | 97 | |
|
99 | 98 | def test_xhr_create_user_membership_with_failure |
|
100 | 99 | assert_no_difference 'Member.count' do |
|
101 | 100 | xhr :post, :create, :user_id => 7, :membership => {:project_ids => [3]}, :format => 'js' |
|
102 | 101 | assert_response :success |
|
103 | assert_template 'create' | |
|
104 | 102 | assert_equal 'text/javascript', response.content_type |
|
105 | 103 | end |
|
106 | 104 | assert_include 'alert', response.body, "Alert message not sent" |
|
107 | 105 | assert_include 'Role cannot be empty', response.body, "Error message not sent" |
|
108 | 106 | end |
|
109 | 107 | |
|
110 | 108 | def test_update_user_membership |
|
111 | 109 | assert_no_difference 'Member.count' do |
|
112 | 110 | put :update, :user_id => 2, :id => 1, :membership => {:role_ids => [2]} |
|
113 | 111 | assert_redirected_to '/users/2/edit?tab=memberships' |
|
114 | 112 | end |
|
115 | 113 | assert_equal [2], Member.find(1).role_ids |
|
116 | 114 | end |
|
117 | 115 | |
|
118 | 116 | def test_xhr_update_user_membership |
|
119 | 117 | assert_no_difference 'Member.count' do |
|
120 | 118 | xhr :put, :update, :user_id => 2, :id => 1, :membership => {:role_ids => [2]}, :format => 'js' |
|
121 | 119 | assert_response :success |
|
122 | assert_template 'update' | |
|
123 | 120 | assert_equal 'text/javascript', response.content_type |
|
124 | 121 | end |
|
125 | 122 | assert_equal [2], Member.find(1).role_ids |
|
126 | 123 | assert_include 'tab-content-memberships', response.body |
|
127 | 124 | end |
|
128 | 125 | |
|
129 | 126 | def test_destroy_user_membership |
|
130 | 127 | assert_difference 'Member.count', -1 do |
|
131 | 128 | delete :destroy, :user_id => 2, :id => 1 |
|
132 | 129 | end |
|
133 | 130 | assert_redirected_to '/users/2/edit?tab=memberships' |
|
134 | 131 | assert_nil Member.find_by_id(1) |
|
135 | 132 | end |
|
136 | 133 | |
|
137 | 134 | def test_xhr_destroy_user_membership_js_format |
|
138 | 135 | assert_difference 'Member.count', -1 do |
|
139 | 136 | xhr :delete, :destroy, :user_id => 2, :id => 1 |
|
140 | 137 | assert_response :success |
|
141 | assert_template 'destroy' | |
|
142 | 138 | assert_equal 'text/javascript', response.content_type |
|
143 | 139 | end |
|
144 | 140 | assert_nil Member.find_by_id(1) |
|
145 | 141 | assert_include 'tab-content-memberships', response.body |
|
146 | 142 | end |
|
147 | 143 | |
|
148 | 144 | def test_xhr_new_group_membership |
|
149 | 145 | xhr :get, :new, :group_id => 10 |
|
150 | 146 | assert_response :success |
|
151 | 147 | assert_equal 'text/javascript', response.content_type |
|
152 | 148 | end |
|
153 | 149 | |
|
154 | 150 | def test_create_group_membership |
|
155 | 151 | assert_difference 'Group.find(10).members.count' do |
|
156 | 152 | post :create, :group_id => 10, :membership => {:project_ids => [2], :role_ids => ['1', '2']} |
|
157 | 153 | end |
|
158 | 154 | end |
|
159 | 155 | |
|
160 | 156 | def test_xhr_create_group_membership |
|
161 | 157 | assert_difference 'Group.find(10).members.count' do |
|
162 | 158 | xhr :post, :create, :group_id => 10, :membership => {:project_ids => [2], :role_ids => ['1', '2']} |
|
163 | 159 | assert_response :success |
|
164 | assert_template 'create' | |
|
165 | 160 | assert_equal 'text/javascript', response.content_type |
|
166 | 161 | end |
|
167 | 162 | assert_match /OnlineStore/, response.body |
|
168 | 163 | end |
|
169 | 164 | |
|
170 | 165 | def test_xhr_create_group_membership_with_failure |
|
171 | 166 | assert_no_difference 'Group.find(10).members.count' do |
|
172 | 167 | xhr :post, :create, :group_id => 10, :membership => {:project_ids => [999], :role_ids => ['1', '2']} |
|
173 | 168 | assert_response :success |
|
174 | assert_template 'create' | |
|
175 | 169 | assert_equal 'text/javascript', response.content_type |
|
176 | 170 | end |
|
177 | 171 | assert_match /alert/, response.body, "Alert message not sent" |
|
178 | 172 | end |
|
179 | 173 | |
|
180 | 174 | def test_update_group_membership |
|
181 | 175 | assert_no_difference 'Group.find(10).members.count' do |
|
182 | 176 | put :update, :group_id => 10, :id => 6, :membership => {:role_ids => ['1', '3']} |
|
183 | 177 | end |
|
184 | 178 | end |
|
185 | 179 | |
|
186 | 180 | def test_xhr_update_group_membership |
|
187 | 181 | assert_no_difference 'Group.find(10).members.count' do |
|
188 | 182 | xhr :post, :update, :group_id => 10, :id => 6, :membership => {:role_ids => ['1', '3']} |
|
189 | 183 | assert_response :success |
|
190 | assert_template 'update' | |
|
191 | 184 | assert_equal 'text/javascript', response.content_type |
|
192 | 185 | end |
|
193 | 186 | end |
|
194 | 187 | |
|
195 | 188 | def test_destroy_group_membership |
|
196 | 189 | assert_difference 'Group.find(10).members.count', -1 do |
|
197 | 190 | delete :destroy, :group_id => 10, :id => 6 |
|
198 | 191 | end |
|
199 | 192 | end |
|
200 | 193 | |
|
201 | 194 | def test_xhr_destroy_group_membership |
|
202 | 195 | assert_difference 'Group.find(10).members.count', -1 do |
|
203 | 196 | xhr :delete, :destroy, :group_id => 10, :id => 6 |
|
204 | 197 | assert_response :success |
|
205 | assert_template 'destroy' | |
|
206 | 198 | assert_equal 'text/javascript', response.content_type |
|
207 | 199 | end |
|
208 | 200 | end |
|
209 | 201 | end |
@@ -1,694 +1,675 | |||
|
1 | 1 | # Redmine - project management software |
|
2 | 2 | # Copyright (C) 2006-2016 Jean-Philippe Lang |
|
3 | 3 | # |
|
4 | 4 | # This program is free software; you can redistribute it and/or |
|
5 | 5 | # modify it under the terms of the GNU General Public License |
|
6 | 6 | # as published by the Free Software Foundation; either version 2 |
|
7 | 7 | # of the License, or (at your option) any later version. |
|
8 | 8 | # |
|
9 | 9 | # This program is distributed in the hope that it will be useful, |
|
10 | 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 | 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12 | 12 | # GNU General Public License for more details. |
|
13 | 13 | # |
|
14 | 14 | # You should have received a copy of the GNU General Public License |
|
15 | 15 | # along with this program; if not, write to the Free Software |
|
16 | 16 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
|
17 | 17 | |
|
18 | 18 | require File.expand_path('../../test_helper', __FILE__) |
|
19 | 19 | |
|
20 | 20 | class ProjectsControllerTest < Redmine::ControllerTest |
|
21 | 21 | fixtures :projects, :versions, :users, :email_addresses, :roles, :members, |
|
22 | 22 | :member_roles, :issues, :journals, :journal_details, |
|
23 | 23 | :trackers, :projects_trackers, :issue_statuses, |
|
24 | 24 | :enabled_modules, :enumerations, :boards, :messages, |
|
25 | 25 | :attachments, :custom_fields, :custom_values, :time_entries, |
|
26 | 26 | :wikis, :wiki_pages, :wiki_contents, :wiki_content_versions |
|
27 | 27 | |
|
28 | 28 | def setup |
|
29 | 29 | @request.session[:user_id] = nil |
|
30 | 30 | Setting.default_language = 'en' |
|
31 | 31 | end |
|
32 | 32 | |
|
33 | 33 | def test_index_by_anonymous_should_not_show_private_projects |
|
34 | 34 | get :index |
|
35 | 35 | assert_response :success |
|
36 | assert_template 'index' | |
|
37 | projects = assigns(:projects) | |
|
38 | assert_not_nil projects | |
|
39 | assert projects.all?(&:is_public?) | |
|
40 | 36 | |
|
41 | 37 | assert_select 'ul' do |
|
42 | 38 | assert_select 'li' do |
|
43 | 39 | assert_select 'a', :text => 'eCookbook' |
|
44 | 40 | assert_select 'ul' do |
|
45 | 41 | assert_select 'a', :text => 'Child of private child' |
|
46 | 42 | end |
|
47 | 43 | end |
|
48 | 44 | end |
|
49 | 45 | assert_select 'a', :text => /Private child of eCookbook/, :count => 0 |
|
50 | 46 | end |
|
51 | 47 | |
|
52 | 48 | def test_index_atom |
|
53 | 49 | get :index, :format => 'atom' |
|
54 | 50 | assert_response :success |
|
55 | assert_template 'common/feed' | |
|
56 | 51 | assert_select 'feed>title', :text => 'Redmine: Latest projects' |
|
57 | 52 | assert_select 'feed>entry', :count => Project.visible(User.current).count |
|
58 | 53 | end |
|
59 | 54 | |
|
60 | 55 | test "#index by non-admin user with view_time_entries permission should show overall spent time link" do |
|
61 | 56 | @request.session[:user_id] = 3 |
|
62 | 57 | get :index |
|
63 | assert_template 'index' | |
|
64 | 58 | assert_select 'a[href=?]', '/time_entries' |
|
65 | 59 | end |
|
66 | 60 | |
|
67 | 61 | test "#index by non-admin user without view_time_entries permission should not show overall spent time link" do |
|
68 | 62 | Role.find(2).remove_permission! :view_time_entries |
|
69 | 63 | Role.non_member.remove_permission! :view_time_entries |
|
70 | 64 | Role.anonymous.remove_permission! :view_time_entries |
|
71 | 65 | @request.session[:user_id] = 3 |
|
72 | 66 | |
|
73 | 67 | get :index |
|
74 | assert_template 'index' | |
|
75 | 68 | assert_select 'a[href=?]', '/time_entries', 0 |
|
76 | 69 | end |
|
77 | 70 | |
|
78 | 71 | test "#index by non-admin user with permission should show add project link" do |
|
79 | 72 | Role.find(1).add_permission! :add_project |
|
80 | 73 | @request.session[:user_id] = 2 |
|
74 | ||
|
81 | 75 | get :index |
|
82 | assert_template 'index' | |
|
83 | 76 | assert_select 'a[href=?]', '/projects/new' |
|
84 | 77 | end |
|
85 | 78 | |
|
86 | 79 | test "#new by admin user should accept get" do |
|
87 | 80 | @request.session[:user_id] = 1 |
|
88 | 81 | |
|
89 | 82 | get :new |
|
90 | 83 | assert_response :success |
|
91 | assert_template 'new' | |
|
84 | assert_select 'input[name=?]', 'project[name]' | |
|
85 | assert_select 'select[name=?]', 'project[parent_id]' | |
|
92 | 86 | end |
|
93 | 87 | |
|
94 | 88 | test "#new by non-admin user with add_project permission should accept get" do |
|
95 | 89 | Role.non_member.add_permission! :add_project |
|
96 | 90 | @request.session[:user_id] = 9 |
|
97 | 91 | |
|
98 | 92 | get :new |
|
99 | 93 | assert_response :success |
|
100 | assert_template 'new' | |
|
94 | assert_select 'input[name=?]', 'project[name]' | |
|
101 | 95 | assert_select 'select[name=?]', 'project[parent_id]', 0 |
|
102 | 96 | end |
|
103 | 97 | |
|
104 | 98 | test "#new by non-admin user with add_subprojects permission should accept get" do |
|
105 | 99 | Role.find(1).remove_permission! :add_project |
|
106 | 100 | Role.find(1).add_permission! :add_subprojects |
|
107 | 101 | @request.session[:user_id] = 2 |
|
108 | 102 | |
|
109 | 103 | get :new, :parent_id => 'ecookbook' |
|
110 | 104 | assert_response :success |
|
111 | assert_template 'new' | |
|
112 | 105 | |
|
113 | 106 | assert_select 'select[name=?]', 'project[parent_id]' do |
|
114 | 107 | # parent project selected |
|
115 | 108 | assert_select 'option[value="1"][selected=selected]' |
|
116 | 109 | # no empty value |
|
117 | 110 | assert_select 'option[value=""]', 0 |
|
118 | 111 | end |
|
119 | 112 | end |
|
120 | 113 | |
|
121 | 114 | def test_new_should_not_display_invalid_search_link |
|
122 | 115 | @request.session[:user_id] = 1 |
|
123 | 116 | |
|
124 | 117 | get :new |
|
125 | 118 | assert_response :success |
|
126 | 119 | assert_select '#quick-search form[action=?]', '/search' |
|
127 | 120 | assert_select '#quick-search a[href=?]', '/search' |
|
128 | 121 | end |
|
129 | 122 | |
|
130 | 123 | test "#create by admin user should create a new project" do |
|
131 | 124 | @request.session[:user_id] = 1 |
|
132 | 125 | |
|
133 | 126 | post :create, |
|
134 | 127 | :project => { |
|
135 | 128 | :name => "blog", |
|
136 | 129 | :description => "weblog", |
|
137 | 130 | :homepage => 'http://weblog', |
|
138 | 131 | :identifier => "blog", |
|
139 | 132 | :is_public => 1, |
|
140 | 133 | :custom_field_values => { '3' => 'Beta' }, |
|
141 | 134 | :tracker_ids => ['1', '3'], |
|
142 | 135 | # an issue custom field that is not for all project |
|
143 | 136 | :issue_custom_field_ids => ['9'], |
|
144 | 137 | :enabled_module_names => ['issue_tracking', 'news', 'repository'] |
|
145 | 138 | } |
|
146 | 139 | assert_redirected_to '/projects/blog/settings' |
|
147 | 140 | |
|
148 | 141 | project = Project.find_by_name('blog') |
|
149 | 142 | assert_kind_of Project, project |
|
150 | 143 | assert project.active? |
|
151 | 144 | assert_equal 'weblog', project.description |
|
152 | 145 | assert_equal 'http://weblog', project.homepage |
|
153 | 146 | assert_equal true, project.is_public? |
|
154 | 147 | assert_nil project.parent |
|
155 | 148 | assert_equal 'Beta', project.custom_value_for(3).value |
|
156 | 149 | assert_equal [1, 3], project.trackers.map(&:id).sort |
|
157 | 150 | assert_equal ['issue_tracking', 'news', 'repository'], project.enabled_module_names.sort |
|
158 | 151 | assert project.issue_custom_fields.include?(IssueCustomField.find(9)) |
|
159 | 152 | end |
|
160 | 153 | |
|
161 | 154 | test "#create by admin user should create a new subproject" do |
|
162 | 155 | @request.session[:user_id] = 1 |
|
163 | 156 | |
|
164 | 157 | assert_difference 'Project.count' do |
|
165 | 158 | post :create, :project => { :name => "blog", |
|
166 | 159 | :description => "weblog", |
|
167 | 160 | :identifier => "blog", |
|
168 | 161 | :is_public => 1, |
|
169 | 162 | :custom_field_values => { '3' => 'Beta' }, |
|
170 | 163 | :parent_id => 1 |
|
171 | 164 | } |
|
172 | 165 | assert_redirected_to '/projects/blog/settings' |
|
173 | 166 | end |
|
174 | 167 | |
|
175 | 168 | project = Project.find_by_name('blog') |
|
176 | 169 | assert_kind_of Project, project |
|
177 | 170 | assert_equal Project.find(1), project.parent |
|
178 | 171 | end |
|
179 | 172 | |
|
180 | 173 | test "#create by admin user should continue" do |
|
181 | 174 | @request.session[:user_id] = 1 |
|
182 | 175 | |
|
183 | 176 | assert_difference 'Project.count' do |
|
184 | 177 | post :create, :project => {:name => "blog", :identifier => "blog"}, :continue => 'Create and continue' |
|
185 | 178 | end |
|
186 | 179 | assert_redirected_to '/projects/new' |
|
187 | 180 | end |
|
188 | 181 | |
|
189 | 182 | test "#create by non-admin user with add_project permission should create a new project" do |
|
190 | 183 | Role.non_member.add_permission! :add_project |
|
191 | 184 | @request.session[:user_id] = 9 |
|
192 | 185 | |
|
193 | 186 | post :create, :project => { :name => "blog", |
|
194 | 187 | :description => "weblog", |
|
195 | 188 | :identifier => "blog", |
|
196 | 189 | :is_public => 1, |
|
197 | 190 | :custom_field_values => { '3' => 'Beta' }, |
|
198 | 191 | :tracker_ids => ['1', '3'], |
|
199 | 192 | :enabled_module_names => ['issue_tracking', 'news', 'repository'] |
|
200 | 193 | } |
|
201 | 194 | |
|
202 | 195 | assert_redirected_to '/projects/blog/settings' |
|
203 | 196 | |
|
204 | 197 | project = Project.find_by_name('blog') |
|
205 | 198 | assert_kind_of Project, project |
|
206 | 199 | assert_equal 'weblog', project.description |
|
207 | 200 | assert_equal true, project.is_public? |
|
208 | 201 | assert_equal [1, 3], project.trackers.map(&:id).sort |
|
209 | 202 | assert_equal ['issue_tracking', 'news', 'repository'], project.enabled_module_names.sort |
|
210 | 203 | |
|
211 | 204 | # User should be added as a project member |
|
212 | 205 | assert User.find(9).member_of?(project) |
|
213 | 206 | assert_equal 1, project.members.size |
|
214 | 207 | end |
|
215 | 208 | |
|
216 | 209 | test "#create by non-admin user with add_project permission should fail with parent_id" do |
|
217 | 210 | Role.non_member.add_permission! :add_project |
|
211 | User.find(9).update! :language => 'en' | |
|
218 | 212 | @request.session[:user_id] = 9 |
|
219 | 213 | |
|
220 | 214 | assert_no_difference 'Project.count' do |
|
221 | 215 | post :create, :project => { :name => "blog", |
|
222 | 216 | :description => "weblog", |
|
223 | 217 | :identifier => "blog", |
|
224 | 218 | :is_public => 1, |
|
225 | 219 | :custom_field_values => { '3' => 'Beta' }, |
|
226 | 220 | :parent_id => 1 |
|
227 | 221 | } |
|
228 | 222 | end |
|
229 | 223 | assert_response :success |
|
230 | project = assigns(:project) | |
|
231 | assert_kind_of Project, project | |
|
232 | assert_not_equal [], project.errors[:parent_id] | |
|
224 | assert_select_error /Subproject of is invalid/ | |
|
233 | 225 | end |
|
234 | 226 | |
|
235 | 227 | test "#create by non-admin user with add_subprojects permission should create a project with a parent_id" do |
|
236 | 228 | Role.find(1).remove_permission! :add_project |
|
237 | 229 | Role.find(1).add_permission! :add_subprojects |
|
238 | 230 | @request.session[:user_id] = 2 |
|
239 | 231 | |
|
240 | 232 | post :create, :project => { :name => "blog", |
|
241 | 233 | :description => "weblog", |
|
242 | 234 | :identifier => "blog", |
|
243 | 235 | :is_public => 1, |
|
244 | 236 | :custom_field_values => { '3' => 'Beta' }, |
|
245 | 237 | :parent_id => 1 |
|
246 | 238 | } |
|
247 | 239 | assert_redirected_to '/projects/blog/settings' |
|
248 | 240 | project = Project.find_by_name('blog') |
|
241 | assert_equal 1, project.parent_id | |
|
249 | 242 | end |
|
250 | 243 | |
|
251 | 244 | test "#create by non-admin user with add_subprojects permission should fail without parent_id" do |
|
252 | 245 | Role.find(1).remove_permission! :add_project |
|
253 | 246 | Role.find(1).add_permission! :add_subprojects |
|
254 | 247 | @request.session[:user_id] = 2 |
|
255 | 248 | |
|
256 | 249 | assert_no_difference 'Project.count' do |
|
257 | 250 | post :create, :project => { :name => "blog", |
|
258 | 251 | :description => "weblog", |
|
259 | 252 | :identifier => "blog", |
|
260 | 253 | :is_public => 1, |
|
261 | 254 | :custom_field_values => { '3' => 'Beta' } |
|
262 | 255 | } |
|
263 | 256 | end |
|
264 | 257 | assert_response :success |
|
265 | project = assigns(:project) | |
|
266 | assert_kind_of Project, project | |
|
267 | assert_not_equal [], project.errors[:parent_id] | |
|
258 | assert_select_error /Subproject of is invalid/ | |
|
268 | 259 | end |
|
269 | 260 | |
|
270 | 261 | test "#create by non-admin user with add_subprojects permission should fail with unauthorized parent_id" do |
|
271 | 262 | Role.find(1).remove_permission! :add_project |
|
272 | 263 | Role.find(1).add_permission! :add_subprojects |
|
273 | 264 | @request.session[:user_id] = 2 |
|
274 | 265 | |
|
275 | 266 | assert !User.find(2).member_of?(Project.find(6)) |
|
276 | 267 | assert_no_difference 'Project.count' do |
|
277 | 268 | post :create, :project => { :name => "blog", |
|
278 | 269 | :description => "weblog", |
|
279 | 270 | :identifier => "blog", |
|
280 | 271 | :is_public => 1, |
|
281 | 272 | :custom_field_values => { '3' => 'Beta' }, |
|
282 | 273 | :parent_id => 6 |
|
283 | 274 | } |
|
284 | 275 | end |
|
285 | 276 | assert_response :success |
|
286 | project = assigns(:project) | |
|
287 | assert_kind_of Project, project | |
|
288 | assert_not_equal [], project.errors[:parent_id] | |
|
277 | assert_select_error /Subproject of is invalid/ | |
|
289 | 278 | end |
|
290 | 279 | |
|
291 | 280 | def test_create_subproject_with_inherit_members_should_inherit_members |
|
292 | 281 | Role.find_by_name('Manager').add_permission! :add_subprojects |
|
293 | 282 | parent = Project.find(1) |
|
294 | 283 | @request.session[:user_id] = 2 |
|
295 | 284 | |
|
296 | 285 | assert_difference 'Project.count' do |
|
297 | 286 | post :create, :project => { |
|
298 | 287 | :name => 'inherited', :identifier => 'inherited', :parent_id => parent.id, :inherit_members => '1' |
|
299 | 288 | } |
|
300 | 289 | assert_response 302 |
|
301 | 290 | end |
|
302 | 291 | |
|
303 | 292 | project = Project.order('id desc').first |
|
304 | 293 | assert_equal 'inherited', project.name |
|
305 | 294 | assert_equal parent, project.parent |
|
306 | 295 | assert project.memberships.count > 0 |
|
307 | 296 | assert_equal parent.memberships.count, project.memberships.count |
|
308 | 297 | end |
|
309 | 298 | |
|
310 | 299 | def test_create_should_preserve_modules_on_validation_failure |
|
311 | 300 | with_settings :default_projects_modules => ['issue_tracking', 'repository'] do |
|
312 | 301 | @request.session[:user_id] = 1 |
|
313 | 302 | assert_no_difference 'Project.count' do |
|
314 | 303 | post :create, :project => { |
|
315 | 304 | :name => "blog", |
|
316 | 305 | :identifier => "", |
|
317 | 306 | :enabled_module_names => %w(issue_tracking news) |
|
318 | 307 | } |
|
319 | 308 | end |
|
320 | 309 | assert_response :success |
|
321 | project = assigns(:project) | |
|
322 | assert_equal %w(issue_tracking news), project.enabled_module_names.sort | |
|
310 | %w(issue_tracking news).each do |mod| | |
|
311 | assert_select 'input[name=?][value=?][checked=checked]', 'project[enabled_module_names][]', mod | |
|
312 | end | |
|
313 | assert_select 'input[name=?][checked=checked]', 'project[enabled_module_names][]', :count => 2 | |
|
323 | 314 | end |
|
324 | 315 | end |
|
325 | 316 | |
|
326 | 317 | def test_show_by_id |
|
327 | 318 | get :show, :id => 1 |
|
328 | 319 | assert_response :success |
|
329 | assert_template 'show' | |
|
330 | assert_not_nil assigns(:project) | |
|
320 | assert_select '#header h1', :text => "eCookbook" | |
|
331 | 321 | end |
|
332 | 322 | |
|
333 | 323 | def test_show_by_identifier |
|
334 | 324 | get :show, :id => 'ecookbook' |
|
335 | 325 | assert_response :success |
|
336 | assert_template 'show' | |
|
337 | assert_not_nil assigns(:project) | |
|
338 | assert_equal Project.find_by_identifier('ecookbook'), assigns(:project) | |
|
339 | ||
|
340 | assert_select 'li', :text => /Development status/ | |
|
326 | assert_select '#header h1', :text => "eCookbook" | |
|
341 | 327 | end |
|
342 | 328 | |
|
343 | 329 | def test_show_should_not_display_empty_sidebar |
|
344 | 330 | p = Project.find(1) |
|
345 | 331 | p.enabled_module_names = [] |
|
346 | 332 | p.save! |
|
347 | 333 | |
|
348 | 334 | get :show, :id => 'ecookbook' |
|
349 | 335 | assert_response :success |
|
350 | 336 | assert_select '#main.nosidebar' |
|
351 | 337 | end |
|
352 | 338 | |
|
339 | def test_show_should_display_visible_custom_fields | |
|
340 | ProjectCustomField.find_by_name('Development status').update_attribute :visible, true | |
|
341 | get :show, :id => 'ecookbook' | |
|
342 | assert_response :success | |
|
343 | ||
|
344 | assert_select 'li', :text => /Development status/ | |
|
345 | end | |
|
346 | ||
|
353 | 347 | def test_show_should_not_display_hidden_custom_fields |
|
354 | 348 | ProjectCustomField.find_by_name('Development status').update_attribute :visible, false |
|
355 | 349 | get :show, :id => 'ecookbook' |
|
356 | 350 | assert_response :success |
|
357 | assert_template 'show' | |
|
358 | assert_not_nil assigns(:project) | |
|
359 | 351 | |
|
360 | 352 | assert_select 'li', :text => /Development status/, :count => 0 |
|
361 | 353 | end |
|
362 | 354 | |
|
363 | 355 | def test_show_should_not_display_blank_custom_fields_with_multiple_values |
|
364 | 356 | f1 = ProjectCustomField.generate! :field_format => 'list', :possible_values => %w(Foo Bar), :multiple => true |
|
365 | 357 | f2 = ProjectCustomField.generate! :field_format => 'list', :possible_values => %w(Baz Qux), :multiple => true |
|
366 | 358 | project = Project.generate!(:custom_field_values => {f2.id.to_s => %w(Qux)}) |
|
367 | 359 | |
|
368 | 360 | get :show, :id => project.id |
|
369 | 361 | assert_response :success |
|
370 | 362 | |
|
371 | 363 | assert_select 'li', :text => /#{f1.name}/, :count => 0 |
|
372 | 364 | assert_select 'li', :text => /#{f2.name}/ |
|
373 | 365 | end |
|
374 | 366 | |
|
375 | 367 | def test_show_should_not_display_blank_text_custom_fields |
|
376 | 368 | f1 = ProjectCustomField.generate! :field_format => 'text' |
|
377 | 369 | |
|
378 | 370 | get :show, :id => 1 |
|
379 | 371 | assert_response :success |
|
380 | 372 | |
|
381 | 373 | assert_select 'li', :text => /#{f1.name}/, :count => 0 |
|
382 | 374 | end |
|
383 | 375 | |
|
384 | 376 | def test_show_should_not_fail_when_custom_values_are_nil |
|
385 | 377 | project = Project.find_by_identifier('ecookbook') |
|
386 | 378 | project.custom_values.first.update_attribute(:value, nil) |
|
387 | 379 | get :show, :id => 'ecookbook' |
|
388 | 380 | assert_response :success |
|
389 | assert_template 'show' | |
|
390 | assert_not_nil assigns(:project) | |
|
391 | assert_equal Project.find_by_identifier('ecookbook'), assigns(:project) | |
|
392 | 381 | end |
|
393 | 382 | |
|
394 | 383 | def show_archived_project_should_be_denied |
|
395 | 384 | project = Project.find_by_identifier('ecookbook') |
|
396 | 385 | project.archive! |
|
397 | 386 | |
|
398 | 387 | get :show, :id => 'ecookbook' |
|
399 | 388 | assert_response 403 |
|
400 | assert_nil assigns(:project) | |
|
401 | 389 | assert_select 'p', :text => /archived/ |
|
390 | assert_not_include project.name, response.body | |
|
402 | 391 | end |
|
403 | 392 | |
|
404 | 393 | def test_show_should_not_show_private_subprojects_that_are_not_visible |
|
405 | 394 | get :show, :id => 'ecookbook' |
|
406 | 395 | assert_response :success |
|
407 | assert_template 'show' | |
|
408 | 396 | assert_select 'a', :text => /Private child/, :count => 0 |
|
409 | 397 | end |
|
410 | 398 | |
|
411 | 399 | def test_show_should_show_private_subprojects_that_are_visible |
|
412 | 400 | @request.session[:user_id] = 2 # manager who is a member of the private subproject |
|
413 | 401 | get :show, :id => 'ecookbook' |
|
414 | 402 | assert_response :success |
|
415 | assert_template 'show' | |
|
416 | 403 | assert_select 'a', :text => /Private child/ |
|
417 | 404 | end |
|
418 | 405 | |
|
419 | 406 | def test_settings |
|
420 | 407 | @request.session[:user_id] = 2 # manager |
|
421 | 408 | get :settings, :id => 1 |
|
422 | 409 | assert_response :success |
|
423 | assert_template 'settings' | |
|
410 | ||
|
411 | assert_select 'input[name=?]', 'project[name]' | |
|
424 | 412 | end |
|
425 | 413 | |
|
426 | 414 | def test_settings_of_subproject |
|
427 | 415 | @request.session[:user_id] = 2 |
|
428 | 416 | get :settings, :id => 'private-child' |
|
429 | 417 | assert_response :success |
|
430 | assert_template 'settings' | |
|
431 | 418 | |
|
432 | 419 | assert_select 'input[type=checkbox][name=?]', 'project[inherit_members]' |
|
433 | 420 | end |
|
434 | 421 | |
|
435 | 422 | def test_settings_should_be_denied_for_member_on_closed_project |
|
436 | 423 | Project.find(1).close |
|
437 | 424 | @request.session[:user_id] = 2 # manager |
|
438 | 425 | |
|
439 | 426 | get :settings, :id => 1 |
|
440 | 427 | assert_response 403 |
|
441 | 428 | end |
|
442 | 429 | |
|
443 | 430 | def test_settings_should_be_denied_for_anonymous_on_closed_project |
|
444 | 431 | Project.find(1).close |
|
445 | 432 | |
|
446 | 433 | get :settings, :id => 1 |
|
447 | 434 | assert_response 302 |
|
448 | 435 | end |
|
449 | 436 | |
|
450 | 437 | def test_setting_with_wiki_module_and_no_wiki |
|
451 | 438 | Project.find(1).wiki.destroy |
|
452 | 439 | Role.find(1).add_permission! :manage_wiki |
|
453 | 440 | @request.session[:user_id] = 2 |
|
454 | 441 | |
|
455 | 442 | get :settings, :id => 1 |
|
456 | 443 | assert_response :success |
|
457 | assert_template 'settings' | |
|
458 | 444 | |
|
459 | 445 | assert_select 'form[action=?]', '/projects/ecookbook/wiki' do |
|
460 | 446 | assert_select 'input[name=?]', 'wiki[start_page]' |
|
461 | 447 | end |
|
462 | 448 | end |
|
463 | 449 | |
|
464 | 450 | def test_update |
|
465 | 451 | @request.session[:user_id] = 2 # manager |
|
466 | 452 | post :update, :id => 1, :project => {:name => 'Test changed name', |
|
467 | 453 | :issue_custom_field_ids => ['']} |
|
468 | 454 | assert_redirected_to '/projects/ecookbook/settings' |
|
469 | 455 | project = Project.find(1) |
|
470 | 456 | assert_equal 'Test changed name', project.name |
|
471 | 457 | end |
|
472 | 458 | |
|
473 | 459 | def test_update_with_failure |
|
474 | 460 | @request.session[:user_id] = 2 # manager |
|
475 | 461 | post :update, :id => 1, :project => {:name => ''} |
|
476 | 462 | assert_response :success |
|
477 | assert_template 'settings' | |
|
478 | 463 | assert_select_error /name cannot be blank/i |
|
479 | 464 | end |
|
480 | 465 | |
|
481 | 466 | def test_update_should_be_denied_for_member_on_closed_project |
|
482 | 467 | Project.find(1).close |
|
483 | 468 | @request.session[:user_id] = 2 # manager |
|
484 | 469 | |
|
485 | 470 | post :update, :id => 1, :project => {:name => 'Closed'} |
|
486 | 471 | assert_response 403 |
|
487 | 472 | assert_equal 'eCookbook', Project.find(1).name |
|
488 | 473 | end |
|
489 | 474 | |
|
490 | 475 | def test_update_should_be_denied_for_anonymous_on_closed_project |
|
491 | 476 | Project.find(1).close |
|
492 | 477 | |
|
493 | 478 | post :update, :id => 1, :project => {:name => 'Closed'} |
|
494 | 479 | assert_response 302 |
|
495 | 480 | assert_equal 'eCookbook', Project.find(1).name |
|
496 | 481 | end |
|
497 | 482 | |
|
498 | 483 | def test_update_child_project_without_parent_permission_should_not_show_validation_error |
|
499 | 484 | child = Project.generate_with_parent! |
|
500 | 485 | user = User.generate! |
|
501 | 486 | User.add_to_project(user, child, Role.generate!(:permissions => [:edit_project])) |
|
502 | 487 | @request.session[:user_id] = user.id |
|
503 | 488 | |
|
504 | 489 | post :update, :id => child.id, :project => {:name => 'Updated'} |
|
505 | 490 | assert_response 302 |
|
506 | 491 | assert_match /Successful update/, flash[:notice] |
|
507 | 492 | end |
|
508 | 493 | |
|
509 | 494 | def test_modules |
|
510 | 495 | @request.session[:user_id] = 2 |
|
511 | 496 | Project.find(1).enabled_module_names = ['issue_tracking', 'news'] |
|
512 | 497 | |
|
513 | 498 | post :modules, :id => 1, :enabled_module_names => ['issue_tracking', 'repository', 'documents'] |
|
514 | 499 | assert_redirected_to '/projects/ecookbook/settings/modules' |
|
515 | 500 | assert_equal ['documents', 'issue_tracking', 'repository'], Project.find(1).enabled_module_names.sort |
|
516 | 501 | end |
|
517 | 502 | |
|
518 | 503 | def test_destroy_leaf_project_without_confirmation_should_show_confirmation |
|
519 | 504 | @request.session[:user_id] = 1 # admin |
|
520 | 505 | |
|
521 | 506 | assert_no_difference 'Project.count' do |
|
522 | 507 | delete :destroy, :id => 2 |
|
523 | 508 | assert_response :success |
|
524 | assert_template 'destroy' | |
|
525 | 509 | end |
|
510 | assert_select '.warning', :text => /Are you sure you want to delete this project/ | |
|
526 | 511 | end |
|
527 | 512 | |
|
528 | 513 | def test_destroy_without_confirmation_should_show_confirmation_with_subprojects |
|
529 | 514 | @request.session[:user_id] = 1 # admin |
|
530 | 515 | |
|
531 | 516 | assert_no_difference 'Project.count' do |
|
532 | 517 | delete :destroy, :id => 1 |
|
533 | 518 | assert_response :success |
|
534 | assert_template 'destroy' | |
|
535 | 519 | end |
|
536 | 520 | assert_select 'strong', |
|
537 | 521 | :text => ['Private child of eCookbook', |
|
538 | 522 | 'Child of private child, eCookbook Subproject 1', |
|
539 | 523 | 'eCookbook Subproject 2'].join(', ') |
|
540 | 524 | end |
|
541 | 525 | |
|
542 | 526 | def test_destroy_with_confirmation_should_destroy_the_project_and_subprojects |
|
543 | 527 | @request.session[:user_id] = 1 # admin |
|
544 | 528 | |
|
545 | 529 | assert_difference 'Project.count', -5 do |
|
546 | 530 | delete :destroy, :id => 1, :confirm => 1 |
|
547 | 531 | assert_redirected_to '/admin/projects' |
|
548 | 532 | end |
|
549 | 533 | assert_nil Project.find_by_id(1) |
|
550 | 534 | end |
|
551 | 535 | |
|
552 | 536 | def test_archive |
|
553 | 537 | @request.session[:user_id] = 1 # admin |
|
554 | 538 | post :archive, :id => 1 |
|
555 | 539 | assert_redirected_to '/admin/projects' |
|
556 | 540 | assert !Project.find(1).active? |
|
557 | 541 | end |
|
558 | 542 | |
|
559 | 543 | def test_archive_with_failure |
|
560 | 544 | @request.session[:user_id] = 1 |
|
561 | 545 | Project.any_instance.stubs(:archive).returns(false) |
|
562 | 546 | post :archive, :id => 1 |
|
563 | 547 | assert_redirected_to '/admin/projects' |
|
564 | 548 | assert_match /project cannot be archived/i, flash[:error] |
|
565 | 549 | end |
|
566 | 550 | |
|
567 | 551 | def test_unarchive |
|
568 | 552 | @request.session[:user_id] = 1 # admin |
|
569 | 553 | Project.find(1).archive |
|
570 | 554 | post :unarchive, :id => 1 |
|
571 | 555 | assert_redirected_to '/admin/projects' |
|
572 | 556 | assert Project.find(1).active? |
|
573 | 557 | end |
|
574 | 558 | |
|
575 | 559 | def test_close |
|
576 | 560 | @request.session[:user_id] = 2 |
|
577 | 561 | post :close, :id => 1 |
|
578 | 562 | assert_redirected_to '/projects/ecookbook' |
|
579 | 563 | assert_equal Project::STATUS_CLOSED, Project.find(1).status |
|
580 | 564 | end |
|
581 | 565 | |
|
582 | 566 | def test_reopen |
|
583 | 567 | Project.find(1).close |
|
584 | 568 | @request.session[:user_id] = 2 |
|
585 | 569 | post :reopen, :id => 1 |
|
586 | 570 | assert_redirected_to '/projects/ecookbook' |
|
587 | 571 | assert Project.find(1).active? |
|
588 | 572 | end |
|
589 | 573 | |
|
590 | 574 | def test_project_breadcrumbs_should_be_limited_to_3_ancestors |
|
591 | 575 | CustomField.delete_all |
|
592 | 576 | parent = nil |
|
593 | 577 | 6.times do |i| |
|
594 | 578 | p = Project.generate_with_parent!(parent) |
|
595 | 579 | get :show, :id => p |
|
596 | 580 | assert_select '#header h1' do |
|
597 | 581 | assert_select 'a', :count => [i, 3].min |
|
598 | 582 | end |
|
599 | 583 | |
|
600 | 584 | parent = p |
|
601 | 585 | end |
|
602 | 586 | end |
|
603 | 587 | |
|
604 | 588 | def test_get_copy |
|
605 | 589 | @request.session[:user_id] = 1 # admin |
|
606 | get :copy, :id => 1 | |
|
590 | orig = Project.find(1) | |
|
591 | ||
|
592 | get :copy, :id => orig.id | |
|
607 | 593 | assert_response :success |
|
608 | assert_template 'copy' | |
|
609 | assert assigns(:project) | |
|
610 | assert_equal Project.find(1).description, assigns(:project).description | |
|
611 | assert_nil assigns(:project).id | |
|
612 | 594 | |
|
595 | assert_select 'textarea[name=?]', 'project[description]', :text => orig.description | |
|
613 | 596 | assert_select 'input[name=?][value=?]', 'project[enabled_module_names][]', 'issue_tracking', 1 |
|
614 | 597 | end |
|
615 | 598 | |
|
616 | 599 | def test_get_copy_with_invalid_source_should_respond_with_404 |
|
617 | 600 | @request.session[:user_id] = 1 |
|
618 | 601 | get :copy, :id => 99 |
|
619 | 602 | assert_response 404 |
|
620 | 603 | end |
|
621 | 604 | |
|
622 | 605 | def test_get_copy_should_preselect_custom_fields |
|
623 | 606 | field1 = IssueCustomField.generate!(:is_for_all => false) |
|
624 | 607 | field2 = IssueCustomField.generate!(:is_for_all => false) |
|
625 | 608 | source = Project.generate!(:issue_custom_fields => [field1]) |
|
626 | 609 | @request.session[:user_id] = 1 |
|
627 | 610 | |
|
628 | 611 | get :copy, :id => source.id |
|
629 | 612 | assert_response :success |
|
630 | 613 | assert_select 'fieldset#project_issue_custom_fields' do |
|
631 | 614 | assert_select 'input[type=checkbox][value=?][checked=checked]', field1.id.to_s |
|
632 | 615 | assert_select 'input[type=checkbox][value=?]:not([checked])', field2.id.to_s |
|
633 | 616 | end |
|
634 | 617 | end |
|
635 | 618 | |
|
636 | 619 | def test_post_copy_should_copy_requested_items |
|
637 | 620 | @request.session[:user_id] = 1 # admin |
|
638 | 621 | CustomField.delete_all |
|
639 | 622 | |
|
640 | 623 | assert_difference 'Project.count' do |
|
641 | 624 | post :copy, :id => 1, |
|
642 | 625 | :project => { |
|
643 | 626 | :name => 'Copy', |
|
644 | 627 | :identifier => 'unique-copy', |
|
645 | 628 | :tracker_ids => ['1', '2', '3', ''], |
|
646 | 629 | :enabled_module_names => %w(issue_tracking time_tracking) |
|
647 | 630 | }, |
|
648 | 631 | :only => %w(issues versions) |
|
649 | 632 | end |
|
650 | 633 | project = Project.find('unique-copy') |
|
651 | 634 | source = Project.find(1) |
|
652 | 635 | assert_equal %w(issue_tracking time_tracking), project.enabled_module_names.sort |
|
653 | 636 | |
|
654 | 637 | assert_equal source.versions.count, project.versions.count, "All versions were not copied" |
|
655 | 638 | assert_equal source.issues.count, project.issues.count, "All issues were not copied" |
|
656 | 639 | assert_equal 0, project.members.count |
|
657 | 640 | end |
|
658 | 641 | |
|
659 | 642 | def test_post_copy_should_redirect_to_settings_when_successful |
|
660 | 643 | @request.session[:user_id] = 1 # admin |
|
661 | 644 | post :copy, :id => 1, :project => {:name => 'Copy', :identifier => 'unique-copy'} |
|
662 | 645 | assert_response :redirect |
|
663 | 646 | assert_redirected_to :controller => 'projects', :action => 'settings', :id => 'unique-copy' |
|
664 | 647 | end |
|
665 | 648 | |
|
666 | 649 | def test_post_copy_with_failure |
|
667 | 650 | @request.session[:user_id] = 1 |
|
668 | 651 | post :copy, :id => 1, :project => {:name => 'Copy', :identifier => ''} |
|
669 | 652 | assert_response :success |
|
670 | assert_template 'copy' | |
|
653 | assert_select_error /Identifier cannot be blank/ | |
|
671 | 654 | end |
|
672 | 655 | |
|
673 | 656 | def test_jump_should_redirect_to_active_tab |
|
674 | 657 | get :show, :id => 1, :jump => 'issues' |
|
675 | 658 | assert_redirected_to '/projects/ecookbook/issues' |
|
676 | 659 | end |
|
677 | 660 | |
|
678 | 661 | def test_jump_should_not_redirect_to_inactive_tab |
|
679 | 662 | get :show, :id => 3, :jump => 'documents' |
|
680 | 663 | assert_response :success |
|
681 | assert_template 'show' | |
|
682 | 664 | end |
|
683 | 665 | |
|
684 | 666 | def test_jump_should_not_redirect_to_unknown_tab |
|
685 | 667 | get :show, :id => 3, :jump => 'foobar' |
|
686 | 668 | assert_response :success |
|
687 | assert_template 'show' | |
|
688 | 669 | end |
|
689 | 670 | |
|
690 | 671 | def test_body_should_have_project_css_class |
|
691 | 672 | get :show, :id => 1 |
|
692 | 673 | assert_select 'body.project-ecookbook' |
|
693 | 674 | end |
|
694 | 675 | end |
@@ -1,401 +1,400 | |||
|
1 | 1 | # Redmine - project management software |
|
2 | 2 | # Copyright (C) 2006-2016 Jean-Philippe Lang |
|
3 | 3 | # |
|
4 | 4 | # This program is free software; you can redistribute it and/or |
|
5 | 5 | # modify it under the terms of the GNU General Public License |
|
6 | 6 | # as published by the Free Software Foundation; either version 2 |
|
7 | 7 | # of the License, or (at your option) any later version. |
|
8 | 8 | # |
|
9 | 9 | # This program is distributed in the hope that it will be useful, |
|
10 | 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 | 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12 | 12 | # GNU General Public License for more details. |
|
13 | 13 | # |
|
14 | 14 | # You should have received a copy of the GNU General Public License |
|
15 | 15 | # along with this program; if not, write to the Free Software |
|
16 | 16 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
|
17 | 17 | |
|
18 | 18 | require File.expand_path('../../test_helper', __FILE__) |
|
19 | 19 | |
|
20 | 20 | class QueriesControllerTest < Redmine::ControllerTest |
|
21 | 21 | fixtures :projects, :users, :members, :member_roles, :roles, :trackers, :issue_statuses, :issue_categories, :enumerations, :issues, :custom_fields, :custom_values, :queries, :enabled_modules |
|
22 | 22 | |
|
23 | 23 | def setup |
|
24 | 24 | User.current = nil |
|
25 | 25 | end |
|
26 | 26 | |
|
27 | 27 | def test_index |
|
28 | 28 | get :index |
|
29 | 29 | # HTML response not implemented |
|
30 | 30 | assert_response 406 |
|
31 | 31 | end |
|
32 | 32 | |
|
33 | 33 | def test_new_project_query |
|
34 | 34 | @request.session[:user_id] = 2 |
|
35 | 35 | get :new, :project_id => 1 |
|
36 | 36 | assert_response :success |
|
37 | assert_template 'new' | |
|
37 | ||
|
38 | 38 | assert_select 'input[name=?][value="0"][checked=checked]', 'query[visibility]' |
|
39 | 39 | assert_select 'input[name=query_is_for_all][type=checkbox]:not([checked]):not([disabled])' |
|
40 | 40 | assert_select 'select[name=?]', 'c[]' do |
|
41 | 41 | assert_select 'option[value=tracker]' |
|
42 | 42 | assert_select 'option[value=subject]' |
|
43 | 43 | end |
|
44 | 44 | end |
|
45 | 45 | |
|
46 | 46 | def test_new_global_query |
|
47 | 47 | @request.session[:user_id] = 2 |
|
48 | 48 | get :new |
|
49 | 49 | assert_response :success |
|
50 | assert_template 'new' | |
|
50 | ||
|
51 | 51 | assert_select 'input[name=?]', 'query[visibility]', 0 |
|
52 | 52 | assert_select 'input[name=query_is_for_all][type=checkbox][checked]:not([disabled])' |
|
53 | 53 | end |
|
54 | 54 | |
|
55 | 55 | def test_new_on_invalid_project |
|
56 | 56 | @request.session[:user_id] = 2 |
|
57 | 57 | get :new, :project_id => 'invalid' |
|
58 | 58 | assert_response 404 |
|
59 | 59 | end |
|
60 | 60 | |
|
61 | 61 | def test_new_time_entry_query |
|
62 | 62 | @request.session[:user_id] = 2 |
|
63 | 63 | get :new, :project_id => 1, :type => 'TimeEntryQuery' |
|
64 | 64 | assert_response :success |
|
65 | 65 | assert_select 'input[name=type][value=?]', 'TimeEntryQuery' |
|
66 | 66 | end |
|
67 | 67 | |
|
68 | 68 | def test_create_project_public_query |
|
69 | 69 | @request.session[:user_id] = 2 |
|
70 | 70 | post :create, |
|
71 | 71 | :project_id => 'ecookbook', |
|
72 | 72 | :default_columns => '1', |
|
73 | 73 | :f => ["status_id", "assigned_to_id"], |
|
74 | 74 | :op => {"assigned_to_id" => "=", "status_id" => "o"}, |
|
75 | 75 | :v => { "assigned_to_id" => ["1"], "status_id" => ["1"]}, |
|
76 | 76 | :query => {"name" => "test_new_project_public_query", "visibility" => "2"} |
|
77 | 77 | |
|
78 | 78 | q = Query.find_by_name('test_new_project_public_query') |
|
79 | 79 | assert_redirected_to :controller => 'issues', :action => 'index', :project_id => 'ecookbook', :query_id => q |
|
80 | 80 | assert q.is_public? |
|
81 | 81 | assert q.has_default_columns? |
|
82 | 82 | assert q.valid? |
|
83 | 83 | end |
|
84 | 84 | |
|
85 | 85 | def test_create_project_private_query |
|
86 | 86 | @request.session[:user_id] = 3 |
|
87 | 87 | post :create, |
|
88 | 88 | :project_id => 'ecookbook', |
|
89 | 89 | :default_columns => '1', |
|
90 | 90 | :fields => ["status_id", "assigned_to_id"], |
|
91 | 91 | :operators => {"assigned_to_id" => "=", "status_id" => "o"}, |
|
92 | 92 | :values => { "assigned_to_id" => ["1"], "status_id" => ["1"]}, |
|
93 | 93 | :query => {"name" => "test_new_project_private_query", "visibility" => "0"} |
|
94 | 94 | |
|
95 | 95 | q = Query.find_by_name('test_new_project_private_query') |
|
96 | 96 | assert_redirected_to :controller => 'issues', :action => 'index', :project_id => 'ecookbook', :query_id => q |
|
97 | 97 | assert !q.is_public? |
|
98 | 98 | assert q.has_default_columns? |
|
99 | 99 | assert q.valid? |
|
100 | 100 | end |
|
101 | 101 | |
|
102 | 102 | def test_create_project_roles_query |
|
103 | 103 | @request.session[:user_id] = 2 |
|
104 | 104 | post :create, |
|
105 | 105 | :project_id => 'ecookbook', |
|
106 | 106 | :default_columns => '1', |
|
107 | 107 | :fields => ["status_id", "assigned_to_id"], |
|
108 | 108 | :operators => {"assigned_to_id" => "=", "status_id" => "o"}, |
|
109 | 109 | :values => { "assigned_to_id" => ["1"], "status_id" => ["1"]}, |
|
110 | 110 | :query => {"name" => "test_create_project_roles_query", "visibility" => "1", "role_ids" => ["1", "2", ""]} |
|
111 | 111 | |
|
112 | 112 | q = Query.find_by_name('test_create_project_roles_query') |
|
113 | 113 | assert_redirected_to :controller => 'issues', :action => 'index', :project_id => 'ecookbook', :query_id => q |
|
114 | 114 | assert_equal Query::VISIBILITY_ROLES, q.visibility |
|
115 | 115 | assert_equal [1, 2], q.roles.ids.sort |
|
116 | 116 | end |
|
117 | 117 | |
|
118 | 118 | def test_create_global_private_query_with_custom_columns |
|
119 | 119 | @request.session[:user_id] = 3 |
|
120 | 120 | post :create, |
|
121 | 121 | :fields => ["status_id", "assigned_to_id"], |
|
122 | 122 | :operators => {"assigned_to_id" => "=", "status_id" => "o"}, |
|
123 | 123 | :values => { "assigned_to_id" => ["me"], "status_id" => ["1"]}, |
|
124 | 124 | :query => {"name" => "test_new_global_private_query", "visibility" => "0"}, |
|
125 | 125 | :c => ["", "tracker", "subject", "priority", "category"] |
|
126 | 126 | |
|
127 | 127 | q = Query.find_by_name('test_new_global_private_query') |
|
128 | 128 | assert_redirected_to :controller => 'issues', :action => 'index', :project_id => nil, :query_id => q |
|
129 | 129 | assert !q.is_public? |
|
130 | 130 | assert !q.has_default_columns? |
|
131 | 131 | assert_equal [:id, :tracker, :subject, :priority, :category], q.columns.collect {|c| c.name} |
|
132 | 132 | assert q.valid? |
|
133 | 133 | end |
|
134 | 134 | |
|
135 | 135 | def test_create_global_query_with_custom_filters |
|
136 | 136 | @request.session[:user_id] = 3 |
|
137 | 137 | post :create, |
|
138 | 138 | :fields => ["assigned_to_id"], |
|
139 | 139 | :operators => {"assigned_to_id" => "="}, |
|
140 | 140 | :values => { "assigned_to_id" => ["me"]}, |
|
141 | 141 | :query => {"name" => "test_new_global_query"} |
|
142 | 142 | |
|
143 | 143 | q = Query.find_by_name('test_new_global_query') |
|
144 | 144 | assert_redirected_to :controller => 'issues', :action => 'index', :project_id => nil, :query_id => q |
|
145 | 145 | assert !q.is_public? |
|
146 | 146 | assert !q.has_filter?(:status_id) |
|
147 | 147 | assert_equal ['assigned_to_id'], q.filters.keys |
|
148 | 148 | assert q.valid? |
|
149 | 149 | end |
|
150 | 150 | |
|
151 | 151 | def test_create_with_sort |
|
152 | 152 | @request.session[:user_id] = 1 |
|
153 | 153 | post :create, |
|
154 | 154 | :default_columns => '1', |
|
155 | 155 | :operators => {"status_id" => "o"}, |
|
156 | 156 | :values => {"status_id" => ["1"]}, |
|
157 | 157 | :query => {:name => "test_new_with_sort", |
|
158 | 158 | :visibility => "2", |
|
159 | 159 | :sort_criteria => {"0" => ["due_date", "desc"], "1" => ["tracker", ""]}} |
|
160 | 160 | |
|
161 | 161 | query = Query.find_by_name("test_new_with_sort") |
|
162 | 162 | assert_not_nil query |
|
163 | 163 | assert_equal [['due_date', 'desc'], ['tracker', 'asc']], query.sort_criteria |
|
164 | 164 | end |
|
165 | 165 | |
|
166 | 166 | def test_create_with_failure |
|
167 | 167 | @request.session[:user_id] = 2 |
|
168 | 168 | assert_no_difference '::Query.count' do |
|
169 | 169 | post :create, :project_id => 'ecookbook', :query => {:name => ''} |
|
170 | 170 | end |
|
171 | 171 | assert_response :success |
|
172 | assert_template 'new' | |
|
172 | ||
|
173 | 173 | assert_select 'input[name=?]', 'query[name]' |
|
174 | 174 | end |
|
175 | 175 | |
|
176 | 176 | def test_create_global_query_from_gantt |
|
177 | 177 | @request.session[:user_id] = 1 |
|
178 | 178 | assert_difference 'IssueQuery.count' do |
|
179 | 179 | post :create, |
|
180 | 180 | :gantt => 1, |
|
181 | 181 | :operators => {"status_id" => "o"}, |
|
182 | 182 | :values => {"status_id" => ["1"]}, |
|
183 | 183 | :query => {:name => "test_create_from_gantt", |
|
184 | 184 | :draw_relations => '1', |
|
185 | 185 | :draw_progress_line => '1'} |
|
186 | 186 | assert_response 302 |
|
187 | 187 | end |
|
188 | 188 | query = IssueQuery.order('id DESC').first |
|
189 | 189 | assert_redirected_to "/issues/gantt?query_id=#{query.id}" |
|
190 | 190 | assert_equal true, query.draw_relations |
|
191 | 191 | assert_equal true, query.draw_progress_line |
|
192 | 192 | end |
|
193 | 193 | |
|
194 | 194 | def test_create_project_query_from_gantt |
|
195 | 195 | @request.session[:user_id] = 1 |
|
196 | 196 | assert_difference 'IssueQuery.count' do |
|
197 | 197 | post :create, |
|
198 | 198 | :project_id => 'ecookbook', |
|
199 | 199 | :gantt => 1, |
|
200 | 200 | :operators => {"status_id" => "o"}, |
|
201 | 201 | :values => {"status_id" => ["1"]}, |
|
202 | 202 | :query => {:name => "test_create_from_gantt", |
|
203 | 203 | :draw_relations => '0', |
|
204 | 204 | :draw_progress_line => '0'} |
|
205 | 205 | assert_response 302 |
|
206 | 206 | end |
|
207 | 207 | query = IssueQuery.order('id DESC').first |
|
208 | 208 | assert_redirected_to "/projects/ecookbook/issues/gantt?query_id=#{query.id}" |
|
209 | 209 | assert_equal false, query.draw_relations |
|
210 | 210 | assert_equal false, query.draw_progress_line |
|
211 | 211 | end |
|
212 | 212 | |
|
213 | 213 | def test_create_project_public_query_should_force_private_without_manage_public_queries_permission |
|
214 | 214 | @request.session[:user_id] = 3 |
|
215 | 215 | query = new_record(Query) do |
|
216 | 216 | post :create, |
|
217 | 217 | :project_id => 'ecookbook', |
|
218 | 218 | :query => {"name" => "name", "visibility" => "2"} |
|
219 | 219 | assert_response 302 |
|
220 | 220 | end |
|
221 | 221 | assert_not_nil query.project |
|
222 | 222 | assert_equal Query::VISIBILITY_PRIVATE, query.visibility |
|
223 | 223 | end |
|
224 | 224 | |
|
225 | 225 | def test_create_global_public_query_should_force_private_without_manage_public_queries_permission |
|
226 | 226 | @request.session[:user_id] = 3 |
|
227 | 227 | query = new_record(Query) do |
|
228 | 228 | post :create, |
|
229 | 229 | :project_id => 'ecookbook', :query_is_for_all => '1', |
|
230 | 230 | :query => {"name" => "name", "visibility" => "2"} |
|
231 | 231 | assert_response 302 |
|
232 | 232 | end |
|
233 | 233 | assert_nil query.project |
|
234 | 234 | assert_equal Query::VISIBILITY_PRIVATE, query.visibility |
|
235 | 235 | end |
|
236 | 236 | |
|
237 | 237 | def test_create_project_public_query_with_manage_public_queries_permission |
|
238 | 238 | @request.session[:user_id] = 2 |
|
239 | 239 | query = new_record(Query) do |
|
240 | 240 | post :create, |
|
241 | 241 | :project_id => 'ecookbook', |
|
242 | 242 | :query => {"name" => "name", "visibility" => "2"} |
|
243 | 243 | assert_response 302 |
|
244 | 244 | end |
|
245 | 245 | assert_not_nil query.project |
|
246 | 246 | assert_equal Query::VISIBILITY_PUBLIC, query.visibility |
|
247 | 247 | end |
|
248 | 248 | |
|
249 | 249 | def test_create_global_public_query_should_force_private_with_manage_public_queries_permission |
|
250 | 250 | @request.session[:user_id] = 2 |
|
251 | 251 | query = new_record(Query) do |
|
252 | 252 | post :create, |
|
253 | 253 | :project_id => 'ecookbook', :query_is_for_all => '1', |
|
254 | 254 | :query => {"name" => "name", "visibility" => "2"} |
|
255 | 255 | assert_response 302 |
|
256 | 256 | end |
|
257 | 257 | assert_nil query.project |
|
258 | 258 | assert_equal Query::VISIBILITY_PRIVATE, query.visibility |
|
259 | 259 | end |
|
260 | 260 | |
|
261 | 261 | def test_create_global_public_query_by_admin |
|
262 | 262 | @request.session[:user_id] = 1 |
|
263 | 263 | query = new_record(Query) do |
|
264 | 264 | post :create, |
|
265 | 265 | :project_id => 'ecookbook', :query_is_for_all => '1', |
|
266 | 266 | :query => {"name" => "name", "visibility" => "2"} |
|
267 | 267 | assert_response 302 |
|
268 | 268 | end |
|
269 | 269 | assert_nil query.project |
|
270 | 270 | assert_equal Query::VISIBILITY_PUBLIC, query.visibility |
|
271 | 271 | end |
|
272 | 272 | |
|
273 | 273 | def test_create_project_public_time_entry_query |
|
274 | 274 | @request.session[:user_id] = 2 |
|
275 | 275 | |
|
276 | 276 | q = new_record(TimeEntryQuery) do |
|
277 | 277 | post :create, |
|
278 | 278 | :project_id => 'ecookbook', |
|
279 | 279 | :type => 'TimeEntryQuery', |
|
280 | 280 | :default_columns => '1', |
|
281 | 281 | :f => ["spent_on"], |
|
282 | 282 | :op => {"spent_on" => "="}, |
|
283 | 283 | :v => { "spent_on" => ["2016-07-14"]}, |
|
284 | 284 | :query => {"name" => "test_new_project_public_query", "visibility" => "2"} |
|
285 | 285 | end |
|
286 | 286 | |
|
287 | 287 | assert_redirected_to :controller => 'timelog', :action => 'index', :project_id => 'ecookbook', :query_id => q.id |
|
288 | 288 | assert q.is_public? |
|
289 | 289 | assert q.has_default_columns? |
|
290 | 290 | assert q.valid? |
|
291 | 291 | end |
|
292 | 292 | |
|
293 | 293 | def test_edit_global_public_query |
|
294 | 294 | @request.session[:user_id] = 1 |
|
295 | 295 | get :edit, :id => 4 |
|
296 | 296 | assert_response :success |
|
297 | assert_template 'edit' | |
|
297 | ||
|
298 | 298 | assert_select 'input[name=?][value="2"][checked=checked]', 'query[visibility]' |
|
299 | 299 | assert_select 'input[name=query_is_for_all][type=checkbox][checked=checked]' |
|
300 | 300 | end |
|
301 | 301 | |
|
302 | 302 | def test_edit_global_private_query |
|
303 | 303 | @request.session[:user_id] = 3 |
|
304 | 304 | get :edit, :id => 3 |
|
305 | 305 | assert_response :success |
|
306 | assert_template 'edit' | |
|
306 | ||
|
307 | 307 | assert_select 'input[name=?]', 'query[visibility]', 0 |
|
308 | 308 | assert_select 'input[name=query_is_for_all][type=checkbox][checked=checked]' |
|
309 | 309 | end |
|
310 | 310 | |
|
311 | 311 | def test_edit_project_private_query |
|
312 | 312 | @request.session[:user_id] = 3 |
|
313 | 313 | get :edit, :id => 2 |
|
314 | 314 | assert_response :success |
|
315 | assert_template 'edit' | |
|
315 | ||
|
316 | 316 | assert_select 'input[name=?]', 'query[visibility]', 0 |
|
317 | 317 | assert_select 'input[name=query_is_for_all][type=checkbox]:not([checked])' |
|
318 | 318 | end |
|
319 | 319 | |
|
320 | 320 | def test_edit_project_public_query |
|
321 | 321 | @request.session[:user_id] = 2 |
|
322 | 322 | get :edit, :id => 1 |
|
323 | 323 | assert_response :success |
|
324 | assert_template 'edit' | |
|
324 | ||
|
325 | 325 | assert_select 'input[name=?][value="2"][checked=checked]', 'query[visibility]' |
|
326 | 326 | assert_select 'input[name=query_is_for_all][type=checkbox]:not([checked])' |
|
327 | 327 | end |
|
328 | 328 | |
|
329 | 329 | def test_edit_sort_criteria |
|
330 | 330 | @request.session[:user_id] = 1 |
|
331 | 331 | get :edit, :id => 5 |
|
332 | 332 | assert_response :success |
|
333 | assert_template 'edit' | |
|
333 | ||
|
334 | 334 | assert_select 'select[name=?]', 'query[sort_criteria][0][]' do |
|
335 | 335 | assert_select 'option[value=priority][selected=selected]' |
|
336 | 336 | assert_select 'option[value=desc][selected=selected]' |
|
337 | 337 | end |
|
338 | 338 | end |
|
339 | 339 | |
|
340 | 340 | def test_edit_invalid_query |
|
341 | 341 | @request.session[:user_id] = 2 |
|
342 | 342 | get :edit, :id => 99 |
|
343 | 343 | assert_response 404 |
|
344 | 344 | end |
|
345 | 345 | |
|
346 | 346 | def test_udpate_global_private_query |
|
347 | 347 | @request.session[:user_id] = 3 |
|
348 | 348 | put :update, |
|
349 | 349 | :id => 3, |
|
350 | 350 | :default_columns => '1', |
|
351 | 351 | :fields => ["status_id", "assigned_to_id"], |
|
352 | 352 | :operators => {"assigned_to_id" => "=", "status_id" => "o"}, |
|
353 | 353 | :values => { "assigned_to_id" => ["me"], "status_id" => ["1"]}, |
|
354 | 354 | :query => {"name" => "test_edit_global_private_query", "visibility" => "2"} |
|
355 | 355 | |
|
356 | 356 | assert_redirected_to :controller => 'issues', :action => 'index', :query_id => 3 |
|
357 | 357 | q = Query.find_by_name('test_edit_global_private_query') |
|
358 | 358 | assert !q.is_public? |
|
359 | 359 | assert q.has_default_columns? |
|
360 | 360 | assert q.valid? |
|
361 | 361 | end |
|
362 | 362 | |
|
363 | 363 | def test_update_global_public_query |
|
364 | 364 | @request.session[:user_id] = 1 |
|
365 | 365 | put :update, |
|
366 | 366 | :id => 4, |
|
367 | 367 | :default_columns => '1', |
|
368 | 368 | :fields => ["status_id", "assigned_to_id"], |
|
369 | 369 | :operators => {"assigned_to_id" => "=", "status_id" => "o"}, |
|
370 | 370 | :values => { "assigned_to_id" => ["1"], "status_id" => ["1"]}, |
|
371 | 371 | :query => {"name" => "test_edit_global_public_query", "visibility" => "2"} |
|
372 | 372 | |
|
373 | 373 | assert_redirected_to :controller => 'issues', :action => 'index', :query_id => 4 |
|
374 | 374 | q = Query.find_by_name('test_edit_global_public_query') |
|
375 | 375 | assert q.is_public? |
|
376 | 376 | assert q.has_default_columns? |
|
377 | 377 | assert q.valid? |
|
378 | 378 | end |
|
379 | 379 | |
|
380 | 380 | def test_update_with_failure |
|
381 | 381 | @request.session[:user_id] = 1 |
|
382 | 382 | put :update, :id => 4, :query => {:name => ''} |
|
383 | 383 | assert_response :success |
|
384 | assert_template 'edit' | |
|
384 | assert_select_error /Name cannot be blank/ | |
|
385 | 385 | end |
|
386 | 386 | |
|
387 | 387 | def test_destroy |
|
388 | 388 | @request.session[:user_id] = 2 |
|
389 | 389 | delete :destroy, :id => 1 |
|
390 | 390 | assert_redirected_to :controller => 'issues', :action => 'index', :project_id => 'ecookbook', :set_filter => 1, :query_id => nil |
|
391 | 391 | assert_nil Query.find_by_id(1) |
|
392 | 392 | end |
|
393 | 393 | |
|
394 | 394 | def test_backslash_should_be_escaped_in_filters |
|
395 | 395 | @request.session[:user_id] = 2 |
|
396 | 396 | get :new, :subject => 'foo/bar' |
|
397 | 397 | assert_response :success |
|
398 | assert_template 'new' | |
|
399 | 398 | assert_include 'addFilter("subject", "=", ["foo\/bar"]);', response.body |
|
400 | 399 | end |
|
401 | 400 | end |
@@ -1,85 +1,64 | |||
|
1 | 1 | # Redmine - project management software |
|
2 | 2 | # Copyright (C) 2006-2016 Jean-Philippe Lang |
|
3 | 3 | # |
|
4 | 4 | # This program is free software; you can redistribute it and/or |
|
5 | 5 | # modify it under the terms of the GNU General Public License |
|
6 | 6 | # as published by the Free Software Foundation; either version 2 |
|
7 | 7 | # of the License, or (at your option) any later version. |
|
8 | 8 | # |
|
9 | 9 | # This program is distributed in the hope that it will be useful, |
|
10 | 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 | 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12 | 12 | # GNU General Public License for more details. |
|
13 | 13 | # |
|
14 | 14 | # You should have received a copy of the GNU General Public License |
|
15 | 15 | # along with this program; if not, write to the Free Software |
|
16 | 16 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
|
17 | 17 | |
|
18 | 18 | require File.expand_path('../../test_helper', __FILE__) |
|
19 | 19 | |
|
20 | 20 | class ReportsControllerTest < Redmine::ControllerTest |
|
21 | 21 | fixtures :projects, :trackers, :issue_statuses, :issues, |
|
22 | 22 | :enumerations, :users, :issue_categories, |
|
23 | 23 | :projects_trackers, |
|
24 | 24 | :roles, |
|
25 | 25 | :member_roles, |
|
26 | 26 | :members, |
|
27 | 27 | :enabled_modules, |
|
28 | 28 | :versions |
|
29 | 29 | |
|
30 | 30 | def test_get_issue_report |
|
31 | 31 | get :issue_report, :id => 1 |
|
32 | ||
|
33 | 32 | assert_response :success |
|
34 | assert_template 'issue_report' | |
|
35 | ||
|
36 | [:issues_by_tracker, :issues_by_version, :issues_by_category, :issues_by_assigned_to, | |
|
37 | :issues_by_author, :issues_by_subproject, :issues_by_priority].each do |ivar| | |
|
38 | assert_not_nil assigns(ivar) | |
|
39 | end | |
|
40 | ||
|
41 | assert_equal IssuePriority.all.reverse, assigns(:priorities) | |
|
42 | 33 | end |
|
43 | 34 | |
|
44 | 35 | def test_get_issue_report_details |
|
45 | 36 | %w(tracker version priority category assigned_to author subproject).each do |detail| |
|
46 | 37 | get :issue_report_details, :id => 1, :detail => detail |
|
47 | ||
|
48 | 38 | assert_response :success |
|
49 | assert_template 'issue_report_details' | |
|
50 | assert_not_nil assigns(:field) | |
|
51 | assert_not_nil assigns(:rows) | |
|
52 | assert_not_nil assigns(:data) | |
|
53 | assert_not_nil assigns(:report_title) | |
|
54 | 39 | end |
|
55 | 40 | end |
|
56 | 41 | |
|
57 | 42 | def test_get_issue_report_details_by_tracker_should_show_issue_count |
|
58 | 43 | Issue.delete_all |
|
59 | 44 | Issue.generate!(:tracker_id => 1) |
|
60 | 45 | Issue.generate!(:tracker_id => 1) |
|
61 | 46 | Issue.generate!(:tracker_id => 1, :status_id => 5) |
|
62 | 47 | Issue.generate!(:tracker_id => 2) |
|
63 | 48 | |
|
64 | 49 | get :issue_report_details, :id => 1, :detail => 'tracker' |
|
65 | 50 | assert_select 'table.list tbody :nth-child(1)' do |
|
66 | 51 | assert_select 'td', :text => 'Bug' |
|
67 | 52 | assert_select ':nth-child(2)', :text => '2' # status:1 |
|
68 | 53 | assert_select ':nth-child(3)', :text => '-' # status:2 |
|
69 | 54 | assert_select ':nth-child(8)', :text => '2' # open |
|
70 | 55 | assert_select ':nth-child(9)', :text => '1' # closed |
|
71 | 56 | assert_select ':nth-child(10)', :text => '3' # total |
|
72 | 57 | end |
|
73 | 58 | end |
|
74 | 59 | |
|
75 | def test_get_issue_report_details_by_priority | |
|
76 | get :issue_report_details, :id => 1, :detail => 'priority' | |
|
77 | assert_equal IssuePriority.all.reverse, assigns(:rows) | |
|
78 | end | |
|
79 | ||
|
80 | 60 | def test_get_issue_report_details_with_an_invalid_detail |
|
81 | 61 | get :issue_report_details, :id => 1, :detail => 'invalid' |
|
82 | ||
|
83 | assert_redirected_to '/projects/ecookbook/issues/report' | |
|
62 | assert_response 404 | |
|
84 | 63 | end |
|
85 | 64 | end |
General Comments 0
You need to be logged in to leave comments.
Login now