##// END OF EJS Templates
Adds a few functional tests....
Jean-Philippe Lang -
r13336:c084ef509f11
parent child
Show More
@@ -1,152 +1,160
1 # Redmine - project management software
1 # Redmine - project management software
2 # Copyright (C) 2006-2014 Jean-Philippe Lang
2 # Copyright (C) 2006-2014 Jean-Philippe Lang
3 #
3 #
4 # This program is free software; you can redistribute it and/or
4 # This program is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU General Public License
5 # modify it under the terms of the GNU General Public License
6 # as published by the Free Software Foundation; either version 2
6 # as published by the Free Software Foundation; either version 2
7 # of the License, or (at your option) any later version.
7 # of the License, or (at your option) any later version.
8 #
8 #
9 # This program is distributed in the hope that it will be useful,
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
12 # GNU General Public License for more details.
13 #
13 #
14 # You should have received a copy of the GNU General Public License
14 # You should have received a copy of the GNU General Public License
15 # along with this program; if not, write to the Free Software
15 # along with this program; if not, write to the Free Software
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17
17
18 require File.expand_path('../../test_helper', __FILE__)
18 require File.expand_path('../../test_helper', __FILE__)
19
19
20 class ActivitiesControllerTest < ActionController::TestCase
20 class ActivitiesControllerTest < ActionController::TestCase
21 fixtures :projects, :trackers, :issue_statuses, :issues,
21 fixtures :projects, :trackers, :issue_statuses, :issues,
22 :enumerations, :users, :issue_categories,
22 :enumerations, :users, :issue_categories,
23 :projects_trackers,
23 :projects_trackers,
24 :roles,
24 :roles,
25 :member_roles,
25 :member_roles,
26 :members,
26 :members,
27 :groups_users,
27 :groups_users,
28 :enabled_modules,
28 :enabled_modules,
29 :journals, :journal_details
29 :journals, :journal_details
30
30
31
31
32 def test_project_index
32 def test_project_index
33 get :index, :id => 1, :with_subprojects => 0
33 get :index, :id => 1, :with_subprojects => 0
34 assert_response :success
34 assert_response :success
35 assert_template 'index'
35 assert_template 'index'
36 assert_not_nil assigns(:events_by_day)
36 assert_not_nil assigns(:events_by_day)
37
37
38 assert_select 'h3', :text => /#{2.days.ago.to_date.day}/
38 assert_select 'h3', :text => /#{2.days.ago.to_date.day}/
39 assert_select 'dl dt.issue-edit a', :text => /(#{IssueStatus.find(2).name})/
39 assert_select 'dl dt.issue-edit a', :text => /(#{IssueStatus.find(2).name})/
40 end
40 end
41
41
42 def test_project_index_with_invalid_project_id_should_respond_404
42 def test_project_index_with_invalid_project_id_should_respond_404
43 get :index, :id => 299
43 get :index, :id => 299
44 assert_response 404
44 assert_response 404
45 end
45 end
46
46
47 def test_previous_project_index
47 def test_previous_project_index
48 get :index, :id => 1, :from => 2.days.ago.to_date
48 get :index, :id => 1, :from => 2.days.ago.to_date
49 assert_response :success
49 assert_response :success
50 assert_template 'index'
50 assert_template 'index'
51 assert_not_nil assigns(:events_by_day)
51 assert_not_nil assigns(:events_by_day)
52
52
53 assert_select 'h3', :text => /#{3.days.ago.to_date.day}/
53 assert_select 'h3', :text => /#{3.days.ago.to_date.day}/
54 assert_select 'dl dt.issue a', :text => /#{ESCAPED_UCANT} print recipes/
54 assert_select 'dl dt.issue a', :text => /#{ESCAPED_UCANT} print recipes/
55 end
55 end
56
56
57 def test_global_index
57 def test_global_index
58 @request.session[:user_id] = 1
58 @request.session[:user_id] = 1
59 get :index
59 get :index
60 assert_response :success
60 assert_response :success
61 assert_template 'index'
61 assert_template 'index'
62 assert_not_nil assigns(:events_by_day)
62 assert_not_nil assigns(:events_by_day)
63
63
64 i5 = Issue.find(5)
64 i5 = Issue.find(5)
65 d5 = User.find(1).time_to_date(i5.created_on)
65 d5 = User.find(1).time_to_date(i5.created_on)
66
66
67 assert_select 'h3', :text => /#{d5.day}/
67 assert_select 'h3', :text => /#{d5.day}/
68 assert_select 'dl dt.issue a', :text => /Subproject issue/
68 assert_select 'dl dt.issue a', :text => /Subproject issue/
69 end
69 end
70
70
71 def test_user_index
71 def test_user_index
72 @request.session[:user_id] = 1
72 @request.session[:user_id] = 1
73 get :index, :user_id => 2
73 get :index, :user_id => 2
74 assert_response :success
74 assert_response :success
75 assert_template 'index'
75 assert_template 'index'
76 assert_not_nil assigns(:events_by_day)
76 assert_not_nil assigns(:events_by_day)
77
77
78 assert_select 'h2 a[href="/users/2"]', :text => 'John Smith'
78 assert_select 'h2 a[href="/users/2"]', :text => 'John Smith'
79
79
80 i1 = Issue.find(1)
80 i1 = Issue.find(1)
81 d1 = User.find(1).time_to_date(i1.created_on)
81 d1 = User.find(1).time_to_date(i1.created_on)
82
82
83 assert_select 'h3', :text => /#{d1.day}/
83 assert_select 'h3', :text => /#{d1.day}/
84 assert_select 'dl dt.issue a', :text => /#{ESCAPED_UCANT} print recipes/
84 assert_select 'dl dt.issue a', :text => /#{ESCAPED_UCANT} print recipes/
85 end
85 end
86
86
87 def test_user_index_with_invalid_user_id_should_respond_404
87 def test_user_index_with_invalid_user_id_should_respond_404
88 get :index, :user_id => 299
88 get :index, :user_id => 299
89 assert_response 404
89 assert_response 404
90 end
90 end
91
91
92 def test_index_atom_feed
92 def test_index_atom_feed
93 get :index, :format => 'atom', :with_subprojects => 0
93 get :index, :format => 'atom', :with_subprojects => 0
94 assert_response :success
94 assert_response :success
95 assert_template 'common/feed'
95 assert_template 'common/feed'
96
96
97 assert_select 'feed' do
97 assert_select 'feed' do
98 assert_select 'link[rel=self][href=?]', 'http://test.host/activity.atom?with_subprojects=0'
98 assert_select 'link[rel=self][href=?]', 'http://test.host/activity.atom?with_subprojects=0'
99 assert_select 'link[rel=alternate][href=?]', 'http://test.host/activity?with_subprojects=0'
99 assert_select 'link[rel=alternate][href=?]', 'http://test.host/activity?with_subprojects=0'
100 assert_select 'entry' do
100 assert_select 'entry' do
101 assert_select 'link[href=?]', 'http://test.host/issues/11'
101 assert_select 'link[href=?]', 'http://test.host/issues/11'
102 end
102 end
103 end
103 end
104 end
104 end
105
105
106 def test_index_atom_feed_with_explicit_selection
106 def test_index_atom_feed_with_explicit_selection
107 get :index, :format => 'atom', :with_subprojects => 0,
107 get :index, :format => 'atom', :with_subprojects => 0,
108 :show_changesets => 1,
108 :show_changesets => 1,
109 :show_documents => 1,
109 :show_documents => 1,
110 :show_files => 1,
110 :show_files => 1,
111 :show_issues => 1,
111 :show_issues => 1,
112 :show_messages => 1,
112 :show_messages => 1,
113 :show_news => 1,
113 :show_news => 1,
114 :show_time_entries => 1,
114 :show_time_entries => 1,
115 :show_wiki_edits => 1
115 :show_wiki_edits => 1
116
116
117 assert_response :success
117 assert_response :success
118 assert_template 'common/feed'
118 assert_template 'common/feed'
119
119
120 assert_select 'feed' do
120 assert_select 'feed' do
121 assert_select 'link[rel=self][href=?]', 'http://test.host/activity.atom?show_changesets=1&amp;show_documents=1&amp;show_files=1&amp;show_issues=1&amp;show_messages=1&amp;show_news=1&amp;show_time_entries=1&amp;show_wiki_edits=1&amp;with_subprojects=0'
121 assert_select 'link[rel=self][href=?]', 'http://test.host/activity.atom?show_changesets=1&amp;show_documents=1&amp;show_files=1&amp;show_issues=1&amp;show_messages=1&amp;show_news=1&amp;show_time_entries=1&amp;show_wiki_edits=1&amp;with_subprojects=0'
122 assert_select 'link[rel=alternate][href=?]', 'http://test.host/activity?show_changesets=1&amp;show_documents=1&amp;show_files=1&amp;show_issues=1&amp;show_messages=1&amp;show_news=1&amp;show_time_entries=1&amp;show_wiki_edits=1&amp;with_subprojects=0'
122 assert_select 'link[rel=alternate][href=?]', 'http://test.host/activity?show_changesets=1&amp;show_documents=1&amp;show_files=1&amp;show_issues=1&amp;show_messages=1&amp;show_news=1&amp;show_time_entries=1&amp;show_wiki_edits=1&amp;with_subprojects=0'
123 assert_select 'entry' do
123 assert_select 'entry' do
124 assert_select 'link[href=?]', 'http://test.host/issues/11'
124 assert_select 'link[href=?]', 'http://test.host/issues/11'
125 end
125 end
126 end
126 end
127 end
127 end
128
128
129 def test_index_atom_feed_with_one_item_type
129 def test_index_atom_feed_with_one_item_type
130 with_settings :default_language => 'en' do
130 with_settings :default_language => 'en' do
131 get :index, :format => 'atom', :show_issues => '1'
131 get :index, :format => 'atom', :show_issues => '1'
132 assert_response :success
132 assert_response :success
133 assert_template 'common/feed'
133 assert_template 'common/feed'
134
134
135 assert_select 'title', :text => /Issues/
135 assert_select 'title', :text => /Issues/
136 end
136 end
137 end
137 end
138
138
139 def test_index_atom_feed_with_user
140 get :index, :user_id => 2, :format => 'atom'
141
142 assert_response :success
143 assert_template 'common/feed'
144 assert_select 'title', :text => "Redmine: #{User.find(2).name}"
145 end
146
139 def test_index_should_show_private_notes_with_permission_only
147 def test_index_should_show_private_notes_with_permission_only
140 journal = Journal.create!(:journalized => Issue.find(2), :notes => 'Private notes with searchkeyword', :private_notes => true)
148 journal = Journal.create!(:journalized => Issue.find(2), :notes => 'Private notes with searchkeyword', :private_notes => true)
141 @request.session[:user_id] = 2
149 @request.session[:user_id] = 2
142
150
143 get :index
151 get :index
144 assert_response :success
152 assert_response :success
145 assert_include journal, assigns(:events_by_day).values.flatten
153 assert_include journal, assigns(:events_by_day).values.flatten
146
154
147 Role.find(1).remove_permission! :view_private_notes
155 Role.find(1).remove_permission! :view_private_notes
148 get :index
156 get :index
149 assert_response :success
157 assert_response :success
150 assert_not_include journal, assigns(:events_by_day).values.flatten
158 assert_not_include journal, assigns(:events_by_day).values.flatten
151 end
159 end
152 end
160 end
@@ -1,453 +1,458
1 # encoding: utf-8
1 # encoding: utf-8
2 #
2 #
3 # Redmine - project management software
3 # Redmine - project management software
4 # Copyright (C) 2006-2014 Jean-Philippe Lang
4 # Copyright (C) 2006-2014 Jean-Philippe Lang
5 #
5 #
6 # This program is free software; you can redistribute it and/or
6 # This program is free software; you can redistribute it and/or
7 # modify it under the terms of the GNU General Public License
7 # modify it under the terms of the GNU General Public License
8 # as published by the Free Software Foundation; either version 2
8 # as published by the Free Software Foundation; either version 2
9 # of the License, or (at your option) any later version.
9 # of the License, or (at your option) any later version.
10 #
10 #
11 # This program is distributed in the hope that it will be useful,
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
14 # GNU General Public License for more details.
15 #
15 #
16 # You should have received a copy of the GNU General Public License
16 # You should have received a copy of the GNU General Public License
17 # along with this program; if not, write to the Free Software
17 # along with this program; if not, write to the Free Software
18 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19
19
20 require File.expand_path('../../test_helper', __FILE__)
20 require File.expand_path('../../test_helper', __FILE__)
21
21
22 class AttachmentsControllerTest < ActionController::TestCase
22 class AttachmentsControllerTest < ActionController::TestCase
23 fixtures :users, :projects, :roles, :members, :member_roles,
23 fixtures :users, :projects, :roles, :members, :member_roles,
24 :enabled_modules, :issues, :trackers, :attachments,
24 :enabled_modules, :issues, :trackers, :attachments,
25 :versions, :wiki_pages, :wikis, :documents
25 :versions, :wiki_pages, :wikis, :documents
26
26
27 def setup
27 def setup
28 User.current = nil
28 User.current = nil
29 set_fixtures_attachments_directory
29 set_fixtures_attachments_directory
30 end
30 end
31
31
32 def teardown
32 def teardown
33 set_tmp_attachments_directory
33 set_tmp_attachments_directory
34 end
34 end
35
35
36 def test_show_diff
36 def test_show_diff
37 ['inline', 'sbs'].each do |dt|
37 ['inline', 'sbs'].each do |dt|
38 # 060719210727_changeset_utf8.diff
38 # 060719210727_changeset_utf8.diff
39 get :show, :id => 14, :type => dt
39 get :show, :id => 14, :type => dt
40 assert_response :success
40 assert_response :success
41 assert_template 'diff'
41 assert_template 'diff'
42 assert_equal 'text/html', @response.content_type
42 assert_equal 'text/html', @response.content_type
43 assert_select 'th.filename', :text => /issues_controller.rb\t\(rΓ©vision 1484\)/
43 assert_select 'th.filename', :text => /issues_controller.rb\t\(rΓ©vision 1484\)/
44 assert_select 'td.line-code', :text => /Demande créée avec succès/
44 assert_select 'td.line-code', :text => /Demande créée avec succès/
45 end
45 end
46 set_tmp_attachments_directory
46 set_tmp_attachments_directory
47 end
47 end
48
48
49 def test_show_diff_replace_cannot_convert_content
49 def test_show_diff_replace_cannot_convert_content
50 with_settings :repositories_encodings => 'UTF-8' do
50 with_settings :repositories_encodings => 'UTF-8' do
51 ['inline', 'sbs'].each do |dt|
51 ['inline', 'sbs'].each do |dt|
52 # 060719210727_changeset_iso8859-1.diff
52 # 060719210727_changeset_iso8859-1.diff
53 get :show, :id => 5, :type => dt
53 get :show, :id => 5, :type => dt
54 assert_response :success
54 assert_response :success
55 assert_template 'diff'
55 assert_template 'diff'
56 assert_equal 'text/html', @response.content_type
56 assert_equal 'text/html', @response.content_type
57 assert_select 'th.filename', :text => /issues_controller.rb\t\(r\?vision 1484\)/
57 assert_select 'th.filename', :text => /issues_controller.rb\t\(r\?vision 1484\)/
58 assert_select 'td.line-code', :text => /Demande cr\?\?e avec succ\?s/
58 assert_select 'td.line-code', :text => /Demande cr\?\?e avec succ\?s/
59 end
59 end
60 end
60 end
61 set_tmp_attachments_directory
61 set_tmp_attachments_directory
62 end
62 end
63
63
64 def test_show_diff_latin_1
64 def test_show_diff_latin_1
65 with_settings :repositories_encodings => 'UTF-8,ISO-8859-1' do
65 with_settings :repositories_encodings => 'UTF-8,ISO-8859-1' do
66 ['inline', 'sbs'].each do |dt|
66 ['inline', 'sbs'].each do |dt|
67 # 060719210727_changeset_iso8859-1.diff
67 # 060719210727_changeset_iso8859-1.diff
68 get :show, :id => 5, :type => dt
68 get :show, :id => 5, :type => dt
69 assert_response :success
69 assert_response :success
70 assert_template 'diff'
70 assert_template 'diff'
71 assert_equal 'text/html', @response.content_type
71 assert_equal 'text/html', @response.content_type
72 assert_select 'th.filename', :text => /issues_controller.rb\t\(rΓ©vision 1484\)/
72 assert_select 'th.filename', :text => /issues_controller.rb\t\(rΓ©vision 1484\)/
73 assert_select 'td.line-code', :text => /Demande créée avec succès/
73 assert_select 'td.line-code', :text => /Demande créée avec succès/
74 end
74 end
75 end
75 end
76 set_tmp_attachments_directory
76 set_tmp_attachments_directory
77 end
77 end
78
78
79 def test_save_diff_type
79 def test_save_diff_type
80 user1 = User.find(1)
80 user1 = User.find(1)
81 user1.pref[:diff_type] = nil
81 user1.pref[:diff_type] = nil
82 user1.preference.save
82 user1.preference.save
83 user = User.find(1)
83 user = User.find(1)
84 assert_nil user.pref[:diff_type]
84 assert_nil user.pref[:diff_type]
85
85
86 @request.session[:user_id] = 1 # admin
86 @request.session[:user_id] = 1 # admin
87 get :show, :id => 5
87 get :show, :id => 5
88 assert_response :success
88 assert_response :success
89 assert_template 'diff'
89 assert_template 'diff'
90 user.reload
90 user.reload
91 assert_equal "inline", user.pref[:diff_type]
91 assert_equal "inline", user.pref[:diff_type]
92 get :show, :id => 5, :type => 'sbs'
92 get :show, :id => 5, :type => 'sbs'
93 assert_response :success
93 assert_response :success
94 assert_template 'diff'
94 assert_template 'diff'
95 user.reload
95 user.reload
96 assert_equal "sbs", user.pref[:diff_type]
96 assert_equal "sbs", user.pref[:diff_type]
97 end
97 end
98
98
99 def test_diff_show_filename_in_mercurial_export
99 def test_diff_show_filename_in_mercurial_export
100 set_tmp_attachments_directory
100 set_tmp_attachments_directory
101 a = Attachment.new(:container => Issue.find(1),
101 a = Attachment.new(:container => Issue.find(1),
102 :file => uploaded_test_file("hg-export.diff", "text/plain"),
102 :file => uploaded_test_file("hg-export.diff", "text/plain"),
103 :author => User.find(1))
103 :author => User.find(1))
104 assert a.save
104 assert a.save
105 assert_equal 'hg-export.diff', a.filename
105 assert_equal 'hg-export.diff', a.filename
106
106
107 get :show, :id => a.id, :type => 'inline'
107 get :show, :id => a.id, :type => 'inline'
108 assert_response :success
108 assert_response :success
109 assert_template 'diff'
109 assert_template 'diff'
110 assert_equal 'text/html', @response.content_type
110 assert_equal 'text/html', @response.content_type
111 assert_select 'th.filename', :text => 'test1.txt'
111 assert_select 'th.filename', :text => 'test1.txt'
112 end
112 end
113
113
114 def test_show_text_file
114 def test_show_text_file
115 get :show, :id => 4
115 get :show, :id => 4
116 assert_response :success
116 assert_response :success
117 assert_template 'file'
117 assert_template 'file'
118 assert_equal 'text/html', @response.content_type
118 assert_equal 'text/html', @response.content_type
119 set_tmp_attachments_directory
119 set_tmp_attachments_directory
120 end
120 end
121
121
122 def test_show_text_file_utf_8
122 def test_show_text_file_utf_8
123 set_tmp_attachments_directory
123 set_tmp_attachments_directory
124 a = Attachment.new(:container => Issue.find(1),
124 a = Attachment.new(:container => Issue.find(1),
125 :file => uploaded_test_file("japanese-utf-8.txt", "text/plain"),
125 :file => uploaded_test_file("japanese-utf-8.txt", "text/plain"),
126 :author => User.find(1))
126 :author => User.find(1))
127 assert a.save
127 assert a.save
128 assert_equal 'japanese-utf-8.txt', a.filename
128 assert_equal 'japanese-utf-8.txt', a.filename
129
129
130 str_japanese = "\xe6\x97\xa5\xe6\x9c\xac\xe8\xaa\x9e".force_encoding('UTF-8')
130 str_japanese = "\xe6\x97\xa5\xe6\x9c\xac\xe8\xaa\x9e".force_encoding('UTF-8')
131
131
132 get :show, :id => a.id
132 get :show, :id => a.id
133 assert_response :success
133 assert_response :success
134 assert_template 'file'
134 assert_template 'file'
135 assert_equal 'text/html', @response.content_type
135 assert_equal 'text/html', @response.content_type
136 assert_select 'tr#L1' do
136 assert_select 'tr#L1' do
137 assert_select 'th.line-num', :text => '1'
137 assert_select 'th.line-num', :text => '1'
138 assert_select 'td', :text => /#{str_japanese}/
138 assert_select 'td', :text => /#{str_japanese}/
139 end
139 end
140 end
140 end
141
141
142 def test_show_text_file_replace_cannot_convert_content
142 def test_show_text_file_replace_cannot_convert_content
143 set_tmp_attachments_directory
143 set_tmp_attachments_directory
144 with_settings :repositories_encodings => 'UTF-8' do
144 with_settings :repositories_encodings => 'UTF-8' do
145 a = Attachment.new(:container => Issue.find(1),
145 a = Attachment.new(:container => Issue.find(1),
146 :file => uploaded_test_file("iso8859-1.txt", "text/plain"),
146 :file => uploaded_test_file("iso8859-1.txt", "text/plain"),
147 :author => User.find(1))
147 :author => User.find(1))
148 assert a.save
148 assert a.save
149 assert_equal 'iso8859-1.txt', a.filename
149 assert_equal 'iso8859-1.txt', a.filename
150
150
151 get :show, :id => a.id
151 get :show, :id => a.id
152 assert_response :success
152 assert_response :success
153 assert_template 'file'
153 assert_template 'file'
154 assert_equal 'text/html', @response.content_type
154 assert_equal 'text/html', @response.content_type
155 assert_select 'tr#L7' do
155 assert_select 'tr#L7' do
156 assert_select 'th.line-num', :text => '7'
156 assert_select 'th.line-num', :text => '7'
157 assert_select 'td', :text => /Demande cr\?\?e avec succ\?s/
157 assert_select 'td', :text => /Demande cr\?\?e avec succ\?s/
158 end
158 end
159 end
159 end
160 end
160 end
161
161
162 def test_show_text_file_latin_1
162 def test_show_text_file_latin_1
163 set_tmp_attachments_directory
163 set_tmp_attachments_directory
164 with_settings :repositories_encodings => 'UTF-8,ISO-8859-1' do
164 with_settings :repositories_encodings => 'UTF-8,ISO-8859-1' do
165 a = Attachment.new(:container => Issue.find(1),
165 a = Attachment.new(:container => Issue.find(1),
166 :file => uploaded_test_file("iso8859-1.txt", "text/plain"),
166 :file => uploaded_test_file("iso8859-1.txt", "text/plain"),
167 :author => User.find(1))
167 :author => User.find(1))
168 assert a.save
168 assert a.save
169 assert_equal 'iso8859-1.txt', a.filename
169 assert_equal 'iso8859-1.txt', a.filename
170
170
171 get :show, :id => a.id
171 get :show, :id => a.id
172 assert_response :success
172 assert_response :success
173 assert_template 'file'
173 assert_template 'file'
174 assert_equal 'text/html', @response.content_type
174 assert_equal 'text/html', @response.content_type
175 assert_select 'tr#L7' do
175 assert_select 'tr#L7' do
176 assert_select 'th.line-num', :text => '7'
176 assert_select 'th.line-num', :text => '7'
177 assert_select 'td', :text => /Demande créée avec succès/
177 assert_select 'td', :text => /Demande créée avec succès/
178 end
178 end
179 end
179 end
180 end
180 end
181
181
182 def test_show_text_file_should_send_if_too_big
182 def test_show_text_file_should_send_if_too_big
183 with_settings :file_max_size_displayed => 512 do
183 with_settings :file_max_size_displayed => 512 do
184 Attachment.find(4).update_attribute :filesize, 754.kilobyte
184 Attachment.find(4).update_attribute :filesize, 754.kilobyte
185 get :show, :id => 4
185 get :show, :id => 4
186 assert_response :success
186 assert_response :success
187 assert_equal 'application/x-ruby', @response.content_type
187 assert_equal 'application/x-ruby', @response.content_type
188 end
188 end
189 set_tmp_attachments_directory
189 set_tmp_attachments_directory
190 end
190 end
191
191
192 def test_show_other
192 def test_show_other
193 get :show, :id => 6
193 get :show, :id => 6
194 assert_response :success
194 assert_response :success
195 assert_equal 'application/octet-stream', @response.content_type
195 assert_equal 'application/octet-stream', @response.content_type
196 set_tmp_attachments_directory
196 set_tmp_attachments_directory
197 end
197 end
198
198
199 def test_show_file_from_private_issue_without_permission
199 def test_show_file_from_private_issue_without_permission
200 get :show, :id => 15
200 get :show, :id => 15
201 assert_redirected_to '/login?back_url=http%3A%2F%2Ftest.host%2Fattachments%2F15'
201 assert_redirected_to '/login?back_url=http%3A%2F%2Ftest.host%2Fattachments%2F15'
202 set_tmp_attachments_directory
202 set_tmp_attachments_directory
203 end
203 end
204
204
205 def test_show_file_from_private_issue_with_permission
205 def test_show_file_from_private_issue_with_permission
206 @request.session[:user_id] = 2
206 @request.session[:user_id] = 2
207 get :show, :id => 15
207 get :show, :id => 15
208 assert_response :success
208 assert_response :success
209 assert_select 'h2', :text => /private.diff/
209 assert_select 'h2', :text => /private.diff/
210 set_tmp_attachments_directory
210 set_tmp_attachments_directory
211 end
211 end
212
212
213 def test_show_file_without_container_should_be_allowed_to_author
213 def test_show_file_without_container_should_be_allowed_to_author
214 set_tmp_attachments_directory
214 set_tmp_attachments_directory
215 attachment = Attachment.create!(:file => uploaded_test_file("testfile.txt", "text/plain"), :author_id => 2)
215 attachment = Attachment.create!(:file => uploaded_test_file("testfile.txt", "text/plain"), :author_id => 2)
216
216
217 @request.session[:user_id] = 2
217 @request.session[:user_id] = 2
218 get :show, :id => attachment.id
218 get :show, :id => attachment.id
219 assert_response 200
219 assert_response 200
220 end
220 end
221
221
222 def test_show_file_without_container_should_be_denied_to_other_users
222 def test_show_file_without_container_should_be_denied_to_other_users
223 set_tmp_attachments_directory
223 set_tmp_attachments_directory
224 attachment = Attachment.create!(:file => uploaded_test_file("testfile.txt", "text/plain"), :author_id => 2)
224 attachment = Attachment.create!(:file => uploaded_test_file("testfile.txt", "text/plain"), :author_id => 2)
225
225
226 @request.session[:user_id] = 3
226 @request.session[:user_id] = 3
227 get :show, :id => attachment.id
227 get :show, :id => attachment.id
228 assert_response 403
228 assert_response 403
229 end
229 end
230
230
231 def test_show_invalid_should_respond_with_404
231 def test_show_invalid_should_respond_with_404
232 get :show, :id => 999
232 get :show, :id => 999
233 assert_response 404
233 assert_response 404
234 end
234 end
235
235
236 def test_download_text_file
236 def test_download_text_file
237 get :download, :id => 4
237 get :download, :id => 4
238 assert_response :success
238 assert_response :success
239 assert_equal 'application/x-ruby', @response.content_type
239 assert_equal 'application/x-ruby', @response.content_type
240 etag = @response.etag
240 etag = @response.etag
241 assert_not_nil etag
241 assert_not_nil etag
242
242
243 @request.env["HTTP_IF_NONE_MATCH"] = etag
243 @request.env["HTTP_IF_NONE_MATCH"] = etag
244 get :download, :id => 4
244 get :download, :id => 4
245 assert_response 304
245 assert_response 304
246
246
247 set_tmp_attachments_directory
247 set_tmp_attachments_directory
248 end
248 end
249
249
250 def test_download_version_file_with_issue_tracking_disabled
250 def test_download_version_file_with_issue_tracking_disabled
251 Project.find(1).disable_module! :issue_tracking
251 Project.find(1).disable_module! :issue_tracking
252 get :download, :id => 9
252 get :download, :id => 9
253 assert_response :success
253 assert_response :success
254 end
254 end
255
255
256 def test_download_should_assign_content_type_if_blank
256 def test_download_should_assign_content_type_if_blank
257 Attachment.find(4).update_attribute(:content_type, '')
257 Attachment.find(4).update_attribute(:content_type, '')
258
258
259 get :download, :id => 4
259 get :download, :id => 4
260 assert_response :success
260 assert_response :success
261 assert_equal 'text/x-ruby', @response.content_type
261 assert_equal 'text/x-ruby', @response.content_type
262 set_tmp_attachments_directory
262 set_tmp_attachments_directory
263 end
263 end
264
264
265 def test_download_missing_file
265 def test_download_missing_file
266 get :download, :id => 2
266 get :download, :id => 2
267 assert_response 404
267 assert_response 404
268 set_tmp_attachments_directory
268 set_tmp_attachments_directory
269 end
269 end
270
270
271 def test_download_should_be_denied_without_permission
271 def test_download_should_be_denied_without_permission
272 get :download, :id => 7
272 get :download, :id => 7
273 assert_redirected_to '/login?back_url=http%3A%2F%2Ftest.host%2Fattachments%2Fdownload%2F7'
273 assert_redirected_to '/login?back_url=http%3A%2F%2Ftest.host%2Fattachments%2Fdownload%2F7'
274 set_tmp_attachments_directory
274 set_tmp_attachments_directory
275 end
275 end
276
276
277 if convert_installed?
277 if convert_installed?
278 def test_thumbnail
278 def test_thumbnail
279 Attachment.clear_thumbnails
279 Attachment.clear_thumbnails
280 @request.session[:user_id] = 2
280 @request.session[:user_id] = 2
281 get :thumbnail, :id => 16
281 get :thumbnail, :id => 16
282 assert_response :success
282 assert_response :success
283 assert_equal 'image/png', response.content_type
283 assert_equal 'image/png', response.content_type
284
284
285 etag = @response.etag
285 etag = @response.etag
286 assert_not_nil etag
286 assert_not_nil etag
287
287
288 @request.env["HTTP_IF_NONE_MATCH"] = etag
288 @request.env["HTTP_IF_NONE_MATCH"] = etag
289 get :thumbnail, :id => 16
289 get :thumbnail, :id => 16
290 assert_response 304
290 assert_response 304
291 end
291 end
292
292
293 def test_thumbnail_should_not_exceed_maximum_size
293 def test_thumbnail_should_not_exceed_maximum_size
294 Redmine::Thumbnail.expects(:generate).with {|source, target, size| size == 800}
294 Redmine::Thumbnail.expects(:generate).with {|source, target, size| size == 800}
295
295
296 @request.session[:user_id] = 2
296 @request.session[:user_id] = 2
297 get :thumbnail, :id => 16, :size => 2000
297 get :thumbnail, :id => 16, :size => 2000
298 end
298 end
299
299
300 def test_thumbnail_should_round_size
300 def test_thumbnail_should_round_size
301 Redmine::Thumbnail.expects(:generate).with {|source, target, size| size == 250}
301 Redmine::Thumbnail.expects(:generate).with {|source, target, size| size == 250}
302
302
303 @request.session[:user_id] = 2
303 @request.session[:user_id] = 2
304 get :thumbnail, :id => 16, :size => 260
304 get :thumbnail, :id => 16, :size => 260
305 end
305 end
306
306
307 def test_thumbnail_should_return_404_for_non_image_attachment
307 def test_thumbnail_should_return_404_for_non_image_attachment
308 @request.session[:user_id] = 2
308 @request.session[:user_id] = 2
309
309
310 get :thumbnail, :id => 15
310 get :thumbnail, :id => 15
311 assert_response 404
311 assert_response 404
312 end
312 end
313
313
314 def test_thumbnail_should_return_404_if_thumbnail_generation_failed
314 def test_thumbnail_should_return_404_if_thumbnail_generation_failed
315 Attachment.any_instance.stubs(:thumbnail).returns(nil)
315 Attachment.any_instance.stubs(:thumbnail).returns(nil)
316 @request.session[:user_id] = 2
316 @request.session[:user_id] = 2
317
317
318 get :thumbnail, :id => 16
318 get :thumbnail, :id => 16
319 assert_response 404
319 assert_response 404
320 end
320 end
321
321
322 def test_thumbnail_should_be_denied_without_permission
322 def test_thumbnail_should_be_denied_without_permission
323 get :thumbnail, :id => 16
323 get :thumbnail, :id => 16
324 assert_redirected_to '/login?back_url=http%3A%2F%2Ftest.host%2Fattachments%2Fthumbnail%2F16'
324 assert_redirected_to '/login?back_url=http%3A%2F%2Ftest.host%2Fattachments%2Fthumbnail%2F16'
325 end
325 end
326 else
326 else
327 puts '(ImageMagick convert not available)'
327 puts '(ImageMagick convert not available)'
328 end
328 end
329
329
330 def test_edit
330 def test_edit
331 @request.session[:user_id] = 2
331 @request.session[:user_id] = 2
332 get :edit, :object_type => 'issues', :object_id => '3'
332 get :edit, :object_type => 'issues', :object_id => '3'
333 assert_response :success
333 assert_response :success
334 assert_template 'edit'
334 assert_template 'edit'
335
335
336 container = Issue.find(3)
336 container = Issue.find(3)
337 assert_equal container, assigns(:container)
337 assert_equal container, assigns(:container)
338 assert_equal container.attachments.size, assigns(:attachments).size
338 assert_equal container.attachments.size, assigns(:attachments).size
339
339
340 assert_select 'form[action=?]', '/attachments/issues/3' do
340 assert_select 'form[action=?]', '/attachments/issues/3' do
341 assert_select 'tr#attachment-4' do
341 assert_select 'tr#attachment-4' do
342 assert_select 'input[name=?][value=?]', 'attachments[4][filename]', 'source.rb'
342 assert_select 'input[name=?][value=?]', 'attachments[4][filename]', 'source.rb'
343 assert_select 'input[name=?][value=?]', 'attachments[4][description]', 'This is a Ruby source file'
343 assert_select 'input[name=?][value=?]', 'attachments[4][description]', 'This is a Ruby source file'
344 end
344 end
345 end
345 end
346 end
346 end
347
347
348 def test_edit_invalid_container_class_should_return_404
348 def test_edit_invalid_container_class_should_return_404
349 get :edit, :object_type => 'nuggets', :object_id => '3'
349 get :edit, :object_type => 'nuggets', :object_id => '3'
350 assert_response 404
350 assert_response 404
351 end
351 end
352
352
353 def test_edit_invalid_object_should_return_404
354 get :edit, :object_type => 'issues', :object_id => '999'
355 assert_response 404
356 end
357
353 def test_edit_for_object_that_is_not_visible_should_return_403
358 def test_edit_for_object_that_is_not_visible_should_return_403
354 get :edit, :object_type => 'issues', :object_id => '4'
359 get :edit, :object_type => 'issues', :object_id => '4'
355 assert_response 403
360 assert_response 403
356 end
361 end
357
362
358 def test_update
363 def test_update
359 @request.session[:user_id] = 2
364 @request.session[:user_id] = 2
360 patch :update, :object_type => 'issues', :object_id => '3', :attachments => {
365 patch :update, :object_type => 'issues', :object_id => '3', :attachments => {
361 '1' => {:filename => 'newname.text', :description => ''},
366 '1' => {:filename => 'newname.text', :description => ''},
362 '4' => {:filename => 'newname.rb', :description => 'Renamed'},
367 '4' => {:filename => 'newname.rb', :description => 'Renamed'},
363 }
368 }
364
369
365 assert_response 302
370 assert_response 302
366 attachment = Attachment.find(4)
371 attachment = Attachment.find(4)
367 assert_equal 'newname.rb', attachment.filename
372 assert_equal 'newname.rb', attachment.filename
368 assert_equal 'Renamed', attachment.description
373 assert_equal 'Renamed', attachment.description
369 end
374 end
370
375
371 def test_update_with_failure
376 def test_update_with_failure
372 @request.session[:user_id] = 2
377 @request.session[:user_id] = 2
373 patch :update, :object_type => 'issues', :object_id => '3', :attachments => {
378 patch :update, :object_type => 'issues', :object_id => '3', :attachments => {
374 '1' => {:filename => '', :description => ''},
379 '1' => {:filename => '', :description => ''},
375 '4' => {:filename => 'newname.rb', :description => 'Renamed'},
380 '4' => {:filename => 'newname.rb', :description => 'Renamed'},
376 }
381 }
377
382
378 assert_response :success
383 assert_response :success
379 assert_template 'edit'
384 assert_template 'edit'
380 assert_select_error /file #{ESCAPED_CANT} be blank/i
385 assert_select_error /file #{ESCAPED_CANT} be blank/i
381
386
382 # The other attachment should not be updated
387 # The other attachment should not be updated
383 attachment = Attachment.find(4)
388 attachment = Attachment.find(4)
384 assert_equal 'source.rb', attachment.filename
389 assert_equal 'source.rb', attachment.filename
385 assert_equal 'This is a Ruby source file', attachment.description
390 assert_equal 'This is a Ruby source file', attachment.description
386 end
391 end
387
392
388 def test_destroy_issue_attachment
393 def test_destroy_issue_attachment
389 set_tmp_attachments_directory
394 set_tmp_attachments_directory
390 issue = Issue.find(3)
395 issue = Issue.find(3)
391 @request.session[:user_id] = 2
396 @request.session[:user_id] = 2
392
397
393 assert_difference 'issue.attachments.count', -1 do
398 assert_difference 'issue.attachments.count', -1 do
394 assert_difference 'Journal.count' do
399 assert_difference 'Journal.count' do
395 delete :destroy, :id => 1
400 delete :destroy, :id => 1
396 assert_redirected_to '/projects/ecookbook'
401 assert_redirected_to '/projects/ecookbook'
397 end
402 end
398 end
403 end
399 assert_nil Attachment.find_by_id(1)
404 assert_nil Attachment.find_by_id(1)
400 j = Journal.order('id DESC').first
405 j = Journal.order('id DESC').first
401 assert_equal issue, j.journalized
406 assert_equal issue, j.journalized
402 assert_equal 'attachment', j.details.first.property
407 assert_equal 'attachment', j.details.first.property
403 assert_equal '1', j.details.first.prop_key
408 assert_equal '1', j.details.first.prop_key
404 assert_equal 'error281.txt', j.details.first.old_value
409 assert_equal 'error281.txt', j.details.first.old_value
405 assert_equal User.find(2), j.user
410 assert_equal User.find(2), j.user
406 end
411 end
407
412
408 def test_destroy_wiki_page_attachment
413 def test_destroy_wiki_page_attachment
409 set_tmp_attachments_directory
414 set_tmp_attachments_directory
410 @request.session[:user_id] = 2
415 @request.session[:user_id] = 2
411 assert_difference 'Attachment.count', -1 do
416 assert_difference 'Attachment.count', -1 do
412 delete :destroy, :id => 3
417 delete :destroy, :id => 3
413 assert_response 302
418 assert_response 302
414 end
419 end
415 end
420 end
416
421
417 def test_destroy_project_attachment
422 def test_destroy_project_attachment
418 set_tmp_attachments_directory
423 set_tmp_attachments_directory
419 @request.session[:user_id] = 2
424 @request.session[:user_id] = 2
420 assert_difference 'Attachment.count', -1 do
425 assert_difference 'Attachment.count', -1 do
421 delete :destroy, :id => 8
426 delete :destroy, :id => 8
422 assert_response 302
427 assert_response 302
423 end
428 end
424 end
429 end
425
430
426 def test_destroy_version_attachment
431 def test_destroy_version_attachment
427 set_tmp_attachments_directory
432 set_tmp_attachments_directory
428 @request.session[:user_id] = 2
433 @request.session[:user_id] = 2
429 assert_difference 'Attachment.count', -1 do
434 assert_difference 'Attachment.count', -1 do
430 delete :destroy, :id => 9
435 delete :destroy, :id => 9
431 assert_response 302
436 assert_response 302
432 end
437 end
433 end
438 end
434
439
435 def test_destroy_version_attachment_with_issue_tracking_disabled
440 def test_destroy_version_attachment_with_issue_tracking_disabled
436 Project.find(1).disable_module! :issue_tracking
441 Project.find(1).disable_module! :issue_tracking
437 set_tmp_attachments_directory
442 set_tmp_attachments_directory
438 @request.session[:user_id] = 2
443 @request.session[:user_id] = 2
439 assert_difference 'Attachment.count', -1 do
444 assert_difference 'Attachment.count', -1 do
440 delete :destroy, :id => 9
445 delete :destroy, :id => 9
441 assert_response 302
446 assert_response 302
442 end
447 end
443 end
448 end
444
449
445 def test_destroy_without_permission
450 def test_destroy_without_permission
446 set_tmp_attachments_directory
451 set_tmp_attachments_directory
447 assert_no_difference 'Attachment.count' do
452 assert_no_difference 'Attachment.count' do
448 delete :destroy, :id => 3
453 delete :destroy, :id => 3
449 end
454 end
450 assert_response 302
455 assert_response 302
451 assert Attachment.find_by_id(3)
456 assert Attachment.find_by_id(3)
452 end
457 end
453 end
458 end
@@ -1,279 +1,288
1 # Redmine - project management software
1 # Redmine - project management software
2 # Copyright (C) 2006-2014 Jean-Philippe Lang
2 # Copyright (C) 2006-2014 Jean-Philippe Lang
3 #
3 #
4 # This program is free software; you can redistribute it and/or
4 # This program is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU General Public License
5 # modify it under the terms of the GNU General Public License
6 # as published by the Free Software Foundation; either version 2
6 # as published by the Free Software Foundation; either version 2
7 # of the License, or (at your option) any later version.
7 # of the License, or (at your option) any later version.
8 #
8 #
9 # This program is distributed in the hope that it will be useful,
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
12 # GNU General Public License for more details.
13 #
13 #
14 # You should have received a copy of the GNU General Public License
14 # You should have received a copy of the GNU General Public License
15 # along with this program; if not, write to the Free Software
15 # along with this program; if not, write to the Free Software
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17
17
18 require File.expand_path('../../test_helper', __FILE__)
18 require File.expand_path('../../test_helper', __FILE__)
19
19
20 class ContextMenusControllerTest < ActionController::TestCase
20 class ContextMenusControllerTest < ActionController::TestCase
21 fixtures :projects,
21 fixtures :projects,
22 :trackers,
22 :trackers,
23 :projects_trackers,
23 :projects_trackers,
24 :roles,
24 :roles,
25 :member_roles,
25 :member_roles,
26 :members,
26 :members,
27 :enabled_modules,
27 :enabled_modules,
28 :workflows,
28 :workflows,
29 :journals, :journal_details,
29 :journals, :journal_details,
30 :versions,
30 :versions,
31 :issues, :issue_statuses, :issue_categories,
31 :issues, :issue_statuses, :issue_categories,
32 :users,
32 :users,
33 :enumerations,
33 :enumerations,
34 :time_entries
34 :time_entries
35
35
36 def test_context_menu_one_issue
36 def test_context_menu_one_issue
37 @request.session[:user_id] = 2
37 @request.session[:user_id] = 2
38 get :issues, :ids => [1]
38 get :issues, :ids => [1]
39 assert_response :success
39 assert_response :success
40 assert_template 'context_menus/issues'
40 assert_template 'context_menus/issues'
41
41
42 assert_select 'a.icon-edit[href=?]', '/issues/1/edit', :text => 'Edit'
42 assert_select 'a.icon-edit[href=?]', '/issues/1/edit', :text => 'Edit'
43 assert_select 'a.icon-copy[href=?]', '/projects/ecookbook/issues/1/copy', :text => 'Copy'
43 assert_select 'a.icon-copy[href=?]', '/projects/ecookbook/issues/1/copy', :text => 'Copy'
44 assert_select 'a.icon-del[href=?]', '/issues?ids%5B%5D=1', :text => 'Delete'
44 assert_select 'a.icon-del[href=?]', '/issues?ids%5B%5D=1', :text => 'Delete'
45
45
46 # Statuses
46 # Statuses
47 assert_select 'a[href=?]', '/issues/bulk_update?ids%5B%5D=1&amp;issue%5Bstatus_id%5D=5', :text => 'Closed'
47 assert_select 'a[href=?]', '/issues/bulk_update?ids%5B%5D=1&amp;issue%5Bstatus_id%5D=5', :text => 'Closed'
48 assert_select 'a[href=?]', '/issues/bulk_update?ids%5B%5D=1&amp;issue%5Bpriority_id%5D=8', :text => 'Immediate'
48 assert_select 'a[href=?]', '/issues/bulk_update?ids%5B%5D=1&amp;issue%5Bpriority_id%5D=8', :text => 'Immediate'
49 # No inactive priorities
49 # No inactive priorities
50 assert_select 'a', :text => /Inactive Priority/, :count => 0
50 assert_select 'a', :text => /Inactive Priority/, :count => 0
51 # Versions
51 # Versions
52 assert_select 'a[href=?]', '/issues/bulk_update?ids%5B%5D=1&amp;issue%5Bfixed_version_id%5D=3', :text => '2.0'
52 assert_select 'a[href=?]', '/issues/bulk_update?ids%5B%5D=1&amp;issue%5Bfixed_version_id%5D=3', :text => '2.0'
53 assert_select 'a[href=?]', '/issues/bulk_update?ids%5B%5D=1&amp;issue%5Bfixed_version_id%5D=4', :text => 'eCookbook Subproject 1 - 2.0'
53 assert_select 'a[href=?]', '/issues/bulk_update?ids%5B%5D=1&amp;issue%5Bfixed_version_id%5D=4', :text => 'eCookbook Subproject 1 - 2.0'
54 # Assignees
54 # Assignees
55 assert_select 'a[href=?]', '/issues/bulk_update?ids%5B%5D=1&amp;issue%5Bassigned_to_id%5D=3', :text => 'Dave Lopper'
55 assert_select 'a[href=?]', '/issues/bulk_update?ids%5B%5D=1&amp;issue%5Bassigned_to_id%5D=3', :text => 'Dave Lopper'
56 end
56 end
57
57
58 def test_context_menu_one_issue_by_anonymous
58 def test_context_menu_one_issue_by_anonymous
59 with_settings :default_language => 'en' do
59 with_settings :default_language => 'en' do
60 get :issues, :ids => [1]
60 get :issues, :ids => [1]
61 assert_response :success
61 assert_response :success
62 assert_template 'context_menus/issues'
62 assert_template 'context_menus/issues'
63 assert_select 'a.icon-del.disabled[href="#"]', :text => 'Delete'
63 assert_select 'a.icon-del.disabled[href="#"]', :text => 'Delete'
64 end
64 end
65 end
65 end
66
66
67 def test_context_menu_multiple_issues_of_same_project
67 def test_context_menu_multiple_issues_of_same_project
68 @request.session[:user_id] = 2
68 @request.session[:user_id] = 2
69 get :issues, :ids => [1, 2]
69 get :issues, :ids => [1, 2]
70 assert_response :success
70 assert_response :success
71 assert_template 'context_menus/issues'
71 assert_template 'context_menus/issues'
72 assert_not_nil assigns(:issues)
72 assert_not_nil assigns(:issues)
73 assert_equal [1, 2], assigns(:issues).map(&:id).sort
73 assert_equal [1, 2], assigns(:issues).map(&:id).sort
74
74
75 ids = assigns(:issues).map(&:id).sort.map {|i| "ids%5B%5D=#{i}"}.join('&amp;')
75 ids = assigns(:issues).map(&:id).sort.map {|i| "ids%5B%5D=#{i}"}.join('&amp;')
76
76
77 assert_select 'a.icon-edit[href=?]', "/issues/bulk_edit?#{ids}", :text => 'Edit'
77 assert_select 'a.icon-edit[href=?]', "/issues/bulk_edit?#{ids}", :text => 'Edit'
78 assert_select 'a.icon-copy[href=?]', "/issues/bulk_edit?copy=1&amp;#{ids}", :text => 'Copy'
78 assert_select 'a.icon-copy[href=?]', "/issues/bulk_edit?copy=1&amp;#{ids}", :text => 'Copy'
79 assert_select 'a.icon-del[href=?]', "/issues?#{ids}", :text => 'Delete'
79 assert_select 'a.icon-del[href=?]', "/issues?#{ids}", :text => 'Delete'
80
80
81 assert_select 'a[href=?]', "/issues/bulk_update?#{ids}&amp;issue%5Bstatus_id%5D=5", :text => 'Closed'
81 assert_select 'a[href=?]', "/issues/bulk_update?#{ids}&amp;issue%5Bstatus_id%5D=5", :text => 'Closed'
82 assert_select 'a[href=?]', "/issues/bulk_update?#{ids}&amp;issue%5Bpriority_id%5D=8", :text => 'Immediate'
82 assert_select 'a[href=?]', "/issues/bulk_update?#{ids}&amp;issue%5Bpriority_id%5D=8", :text => 'Immediate'
83 assert_select 'a[href=?]', "/issues/bulk_update?#{ids}&amp;issue%5Bassigned_to_id%5D=3", :text => 'Dave Lopper'
83 assert_select 'a[href=?]', "/issues/bulk_update?#{ids}&amp;issue%5Bassigned_to_id%5D=3", :text => 'Dave Lopper'
84 end
84 end
85
85
86 def test_context_menu_multiple_issues_of_different_projects
86 def test_context_menu_multiple_issues_of_different_projects
87 @request.session[:user_id] = 2
87 @request.session[:user_id] = 2
88 get :issues, :ids => [1, 2, 6]
88 get :issues, :ids => [1, 2, 6]
89 assert_response :success
89 assert_response :success
90 assert_template 'context_menus/issues'
90 assert_template 'context_menus/issues'
91 assert_not_nil assigns(:issues)
91 assert_not_nil assigns(:issues)
92 assert_equal [1, 2, 6], assigns(:issues).map(&:id).sort
92 assert_equal [1, 2, 6], assigns(:issues).map(&:id).sort
93
93
94 ids = assigns(:issues).map(&:id).sort.map {|i| "ids%5B%5D=#{i}"}.join('&amp;')
94 ids = assigns(:issues).map(&:id).sort.map {|i| "ids%5B%5D=#{i}"}.join('&amp;')
95
95
96 assert_select 'a.icon-edit[href=?]', "/issues/bulk_edit?#{ids}", :text => 'Edit'
96 assert_select 'a.icon-edit[href=?]', "/issues/bulk_edit?#{ids}", :text => 'Edit'
97 assert_select 'a.icon-del[href=?]', "/issues?#{ids}", :text => 'Delete'
97 assert_select 'a.icon-del[href=?]', "/issues?#{ids}", :text => 'Delete'
98
98
99 assert_select 'a[href=?]', "/issues/bulk_update?#{ids}&amp;issue%5Bstatus_id%5D=5", :text => 'Closed'
99 assert_select 'a[href=?]', "/issues/bulk_update?#{ids}&amp;issue%5Bstatus_id%5D=5", :text => 'Closed'
100 assert_select 'a[href=?]', "/issues/bulk_update?#{ids}&amp;issue%5Bpriority_id%5D=8", :text => 'Immediate'
100 assert_select 'a[href=?]', "/issues/bulk_update?#{ids}&amp;issue%5Bpriority_id%5D=8", :text => 'Immediate'
101 assert_select 'a[href=?]', "/issues/bulk_update?#{ids}&amp;issue%5Bassigned_to_id%5D=2", :text => 'John Smith'
101 assert_select 'a[href=?]', "/issues/bulk_update?#{ids}&amp;issue%5Bassigned_to_id%5D=2", :text => 'John Smith'
102 end
102 end
103
103
104 def test_context_menu_should_include_list_custom_fields
104 def test_context_menu_should_include_list_custom_fields
105 field = IssueCustomField.create!(:name => 'List', :field_format => 'list',
105 field = IssueCustomField.create!(:name => 'List', :field_format => 'list',
106 :possible_values => ['Foo', 'Bar'], :is_for_all => true, :tracker_ids => [1, 2, 3])
106 :possible_values => ['Foo', 'Bar'], :is_for_all => true, :tracker_ids => [1, 2, 3])
107 @request.session[:user_id] = 2
107 @request.session[:user_id] = 2
108 get :issues, :ids => [1]
108 get :issues, :ids => [1]
109
109
110 assert_select "li.cf_#{field.id}" do
110 assert_select "li.cf_#{field.id}" do
111 assert_select 'a[href=#]', :text => 'List'
111 assert_select 'a[href=#]', :text => 'List'
112 assert_select 'ul' do
112 assert_select 'ul' do
113 assert_select 'a', 3
113 assert_select 'a', 3
114 assert_select 'a[href=?]', "/issues/bulk_update?ids%5B%5D=1&amp;issue%5Bcustom_field_values%5D%5B#{field.id}%5D=Foo", :text => 'Foo'
114 assert_select 'a[href=?]', "/issues/bulk_update?ids%5B%5D=1&amp;issue%5Bcustom_field_values%5D%5B#{field.id}%5D=Foo", :text => 'Foo'
115 assert_select 'a[href=?]', "/issues/bulk_update?ids%5B%5D=1&amp;issue%5Bcustom_field_values%5D%5B#{field.id}%5D=__none__", :text => 'none'
115 assert_select 'a[href=?]', "/issues/bulk_update?ids%5B%5D=1&amp;issue%5Bcustom_field_values%5D%5B#{field.id}%5D=__none__", :text => 'none'
116 end
116 end
117 end
117 end
118 end
118 end
119
119
120 def test_context_menu_should_not_include_null_value_for_required_custom_fields
120 def test_context_menu_should_not_include_null_value_for_required_custom_fields
121 field = IssueCustomField.create!(:name => 'List', :is_required => true, :field_format => 'list',
121 field = IssueCustomField.create!(:name => 'List', :is_required => true, :field_format => 'list',
122 :possible_values => ['Foo', 'Bar'], :is_for_all => true, :tracker_ids => [1, 2, 3])
122 :possible_values => ['Foo', 'Bar'], :is_for_all => true, :tracker_ids => [1, 2, 3])
123 @request.session[:user_id] = 2
123 @request.session[:user_id] = 2
124 get :issues, :ids => [1, 2]
124 get :issues, :ids => [1, 2]
125
125
126 assert_select "li.cf_#{field.id}" do
126 assert_select "li.cf_#{field.id}" do
127 assert_select 'a[href=#]', :text => 'List'
127 assert_select 'a[href=#]', :text => 'List'
128 assert_select 'ul' do
128 assert_select 'ul' do
129 assert_select 'a', 2
129 assert_select 'a', 2
130 assert_select 'a', :text => 'none', :count => 0
130 assert_select 'a', :text => 'none', :count => 0
131 end
131 end
132 end
132 end
133 end
133 end
134
134
135 def test_context_menu_on_single_issue_should_select_current_custom_field_value
135 def test_context_menu_on_single_issue_should_select_current_custom_field_value
136 field = IssueCustomField.create!(:name => 'List', :field_format => 'list',
136 field = IssueCustomField.create!(:name => 'List', :field_format => 'list',
137 :possible_values => ['Foo', 'Bar'], :is_for_all => true, :tracker_ids => [1, 2, 3])
137 :possible_values => ['Foo', 'Bar'], :is_for_all => true, :tracker_ids => [1, 2, 3])
138 issue = Issue.find(1)
138 issue = Issue.find(1)
139 issue.custom_field_values = {field.id => 'Bar'}
139 issue.custom_field_values = {field.id => 'Bar'}
140 issue.save!
140 issue.save!
141 @request.session[:user_id] = 2
141 @request.session[:user_id] = 2
142 get :issues, :ids => [1]
142 get :issues, :ids => [1]
143
143
144 assert_select "li.cf_#{field.id}" do
144 assert_select "li.cf_#{field.id}" do
145 assert_select 'a[href=#]', :text => 'List'
145 assert_select 'a[href=#]', :text => 'List'
146 assert_select 'ul' do
146 assert_select 'ul' do
147 assert_select 'a', 3
147 assert_select 'a', 3
148 assert_select 'a.icon-checked', :text => 'Bar'
148 assert_select 'a.icon-checked', :text => 'Bar'
149 end
149 end
150 end
150 end
151 end
151 end
152
152
153 def test_context_menu_should_include_bool_custom_fields
153 def test_context_menu_should_include_bool_custom_fields
154 field = IssueCustomField.create!(:name => 'Bool', :field_format => 'bool',
154 field = IssueCustomField.create!(:name => 'Bool', :field_format => 'bool',
155 :is_for_all => true, :tracker_ids => [1, 2, 3])
155 :is_for_all => true, :tracker_ids => [1, 2, 3])
156 @request.session[:user_id] = 2
156 @request.session[:user_id] = 2
157 get :issues, :ids => [1]
157 get :issues, :ids => [1]
158
158
159 assert_select "li.cf_#{field.id}" do
159 assert_select "li.cf_#{field.id}" do
160 assert_select 'a[href=#]', :text => 'Bool'
160 assert_select 'a[href=#]', :text => 'Bool'
161 assert_select 'ul' do
161 assert_select 'ul' do
162 assert_select 'a', 3
162 assert_select 'a', 3
163 assert_select 'a[href=?]', "/issues/bulk_update?ids%5B%5D=1&amp;issue%5Bcustom_field_values%5D%5B#{field.id}%5D=0", :text => 'No'
163 assert_select 'a[href=?]', "/issues/bulk_update?ids%5B%5D=1&amp;issue%5Bcustom_field_values%5D%5B#{field.id}%5D=0", :text => 'No'
164 assert_select 'a[href=?]', "/issues/bulk_update?ids%5B%5D=1&amp;issue%5Bcustom_field_values%5D%5B#{field.id}%5D=1", :text => 'Yes'
164 assert_select 'a[href=?]', "/issues/bulk_update?ids%5B%5D=1&amp;issue%5Bcustom_field_values%5D%5B#{field.id}%5D=1", :text => 'Yes'
165 assert_select 'a[href=?]', "/issues/bulk_update?ids%5B%5D=1&amp;issue%5Bcustom_field_values%5D%5B#{field.id}%5D=__none__", :text => 'none'
165 assert_select 'a[href=?]', "/issues/bulk_update?ids%5B%5D=1&amp;issue%5Bcustom_field_values%5D%5B#{field.id}%5D=__none__", :text => 'none'
166 end
166 end
167 end
167 end
168 end
168 end
169
169
170 def test_context_menu_should_include_user_custom_fields
170 def test_context_menu_should_include_user_custom_fields
171 field = IssueCustomField.create!(:name => 'User', :field_format => 'user',
171 field = IssueCustomField.create!(:name => 'User', :field_format => 'user',
172 :is_for_all => true, :tracker_ids => [1, 2, 3])
172 :is_for_all => true, :tracker_ids => [1, 2, 3])
173 @request.session[:user_id] = 2
173 @request.session[:user_id] = 2
174 get :issues, :ids => [1]
174 get :issues, :ids => [1]
175
175
176 assert_select "li.cf_#{field.id}" do
176 assert_select "li.cf_#{field.id}" do
177 assert_select 'a[href=#]', :text => 'User'
177 assert_select 'a[href=#]', :text => 'User'
178 assert_select 'ul' do
178 assert_select 'ul' do
179 assert_select 'a', Project.find(1).members.count + 1
179 assert_select 'a', Project.find(1).members.count + 1
180 assert_select 'a[href=?]', "/issues/bulk_update?ids%5B%5D=1&amp;issue%5Bcustom_field_values%5D%5B#{field.id}%5D=2", :text => 'John Smith'
180 assert_select 'a[href=?]', "/issues/bulk_update?ids%5B%5D=1&amp;issue%5Bcustom_field_values%5D%5B#{field.id}%5D=2", :text => 'John Smith'
181 assert_select 'a[href=?]', "/issues/bulk_update?ids%5B%5D=1&amp;issue%5Bcustom_field_values%5D%5B#{field.id}%5D=__none__", :text => 'none'
181 assert_select 'a[href=?]', "/issues/bulk_update?ids%5B%5D=1&amp;issue%5Bcustom_field_values%5D%5B#{field.id}%5D=__none__", :text => 'none'
182 end
182 end
183 end
183 end
184 end
184 end
185
185
186 def test_context_menu_should_include_version_custom_fields
186 def test_context_menu_should_include_version_custom_fields
187 field = IssueCustomField.create!(:name => 'Version', :field_format => 'version', :is_for_all => true, :tracker_ids => [1, 2, 3])
187 field = IssueCustomField.create!(:name => 'Version', :field_format => 'version', :is_for_all => true, :tracker_ids => [1, 2, 3])
188 @request.session[:user_id] = 2
188 @request.session[:user_id] = 2
189 get :issues, :ids => [1]
189 get :issues, :ids => [1]
190
190
191 assert_select "li.cf_#{field.id}" do
191 assert_select "li.cf_#{field.id}" do
192 assert_select 'a[href=#]', :text => 'Version'
192 assert_select 'a[href=#]', :text => 'Version'
193 assert_select 'ul' do
193 assert_select 'ul' do
194 assert_select 'a', Project.find(1).shared_versions.count + 1
194 assert_select 'a', Project.find(1).shared_versions.count + 1
195 assert_select 'a[href=?]', "/issues/bulk_update?ids%5B%5D=1&amp;issue%5Bcustom_field_values%5D%5B#{field.id}%5D=3", :text => '2.0'
195 assert_select 'a[href=?]', "/issues/bulk_update?ids%5B%5D=1&amp;issue%5Bcustom_field_values%5D%5B#{field.id}%5D=3", :text => '2.0'
196 assert_select 'a[href=?]', "/issues/bulk_update?ids%5B%5D=1&amp;issue%5Bcustom_field_values%5D%5B#{field.id}%5D=__none__", :text => 'none'
196 assert_select 'a[href=?]', "/issues/bulk_update?ids%5B%5D=1&amp;issue%5Bcustom_field_values%5D%5B#{field.id}%5D=__none__", :text => 'none'
197 end
197 end
198 end
198 end
199 end
199 end
200
200
201 def test_context_menu_should_show_enabled_custom_fields_for_the_role_only
201 def test_context_menu_should_show_enabled_custom_fields_for_the_role_only
202 enabled_cf = IssueCustomField.generate!(:field_format => 'bool', :is_for_all => true, :tracker_ids => [1], :visible => false, :role_ids => [1,2])
202 enabled_cf = IssueCustomField.generate!(:field_format => 'bool', :is_for_all => true, :tracker_ids => [1], :visible => false, :role_ids => [1,2])
203 disabled_cf = IssueCustomField.generate!(:field_format => 'bool', :is_for_all => true, :tracker_ids => [1], :visible => false, :role_ids => [2])
203 disabled_cf = IssueCustomField.generate!(:field_format => 'bool', :is_for_all => true, :tracker_ids => [1], :visible => false, :role_ids => [2])
204 issue = Issue.generate!(:project_id => 1, :tracker_id => 1)
204 issue = Issue.generate!(:project_id => 1, :tracker_id => 1)
205
205
206 @request.session[:user_id] = 2
206 @request.session[:user_id] = 2
207 get :issues, :ids => [issue.id]
207 get :issues, :ids => [issue.id]
208
208
209 assert_select "li.cf_#{enabled_cf.id}"
209 assert_select "li.cf_#{enabled_cf.id}"
210 assert_select "li.cf_#{disabled_cf.id}", 0
210 assert_select "li.cf_#{disabled_cf.id}", 0
211 end
211 end
212
212
213 def test_context_menu_by_assignable_user_should_include_assigned_to_me_link
213 def test_context_menu_by_assignable_user_should_include_assigned_to_me_link
214 @request.session[:user_id] = 2
214 @request.session[:user_id] = 2
215 get :issues, :ids => [1]
215 get :issues, :ids => [1]
216 assert_response :success
216 assert_response :success
217 assert_template 'context_menus/issues'
217 assert_template 'context_menus/issues'
218
218
219 assert_select 'a[href=?]', '/issues/bulk_update?ids%5B%5D=1&amp;issue%5Bassigned_to_id%5D=2', :text => / me /
219 assert_select 'a[href=?]', '/issues/bulk_update?ids%5B%5D=1&amp;issue%5Bassigned_to_id%5D=2', :text => / me /
220 end
220 end
221
221
222 def test_context_menu_should_propose_shared_versions_for_issues_from_different_projects
222 def test_context_menu_should_propose_shared_versions_for_issues_from_different_projects
223 @request.session[:user_id] = 2
223 @request.session[:user_id] = 2
224 version = Version.create!(:name => 'Shared', :sharing => 'system', :project_id => 1)
224 version = Version.create!(:name => 'Shared', :sharing => 'system', :project_id => 1)
225
225
226 get :issues, :ids => [1, 4]
226 get :issues, :ids => [1, 4]
227 assert_response :success
227 assert_response :success
228 assert_template 'context_menus/issues'
228 assert_template 'context_menus/issues'
229
229
230 assert_include version, assigns(:versions)
230 assert_include version, assigns(:versions)
231 assert_select 'a', :text => 'eCookbook - Shared'
231 assert_select 'a', :text => 'eCookbook - Shared'
232 end
232 end
233
233
234 def test_context_menu_with_issue_that_is_not_visible_should_fail
234 def test_context_menu_with_issue_that_is_not_visible_should_fail
235 get :issues, :ids => [1, 4] # issue 4 is not visible
235 get :issues, :ids => [1, 4] # issue 4 is not visible
236 assert_response 302
236 assert_response 302
237 end
237 end
238
238
239 def test_should_respond_with_404_without_ids
239 def test_should_respond_with_404_without_ids
240 get :issues
240 get :issues
241 assert_response 404
241 assert_response 404
242 end
242 end
243
243
244 def test_time_entries_context_menu
244 def test_time_entries_context_menu
245 @request.session[:user_id] = 2
245 @request.session[:user_id] = 2
246 get :time_entries, :ids => [1, 2]
246 get :time_entries, :ids => [1, 2]
247 assert_response :success
247 assert_response :success
248 assert_template 'context_menus/time_entries'
248 assert_template 'context_menus/time_entries'
249
249
250 assert_select 'a:not(.disabled)', :text => 'Edit'
250 assert_select 'a:not(.disabled)', :text => 'Edit'
251 end
251 end
252
252
253 def test_context_menu_for_one_time_entry
254 @request.session[:user_id] = 2
255 get :time_entries, :ids => [1]
256 assert_response :success
257 assert_template 'context_menus/time_entries'
258
259 assert_select 'a:not(.disabled)', :text => 'Edit'
260 end
261
253 def test_time_entries_context_menu_should_include_custom_fields
262 def test_time_entries_context_menu_should_include_custom_fields
254 field = TimeEntryCustomField.generate!(:name => "Field", :field_format => "list", :possible_values => ["foo", "bar"])
263 field = TimeEntryCustomField.generate!(:name => "Field", :field_format => "list", :possible_values => ["foo", "bar"])
255
264
256 @request.session[:user_id] = 2
265 @request.session[:user_id] = 2
257 get :time_entries, :ids => [1, 2]
266 get :time_entries, :ids => [1, 2]
258 assert_response :success
267 assert_response :success
259 assert_select "li.cf_#{field.id}" do
268 assert_select "li.cf_#{field.id}" do
260 assert_select 'a[href=#]', :text => "Field"
269 assert_select 'a[href=#]', :text => "Field"
261 assert_select 'ul' do
270 assert_select 'ul' do
262 assert_select 'a', 3
271 assert_select 'a', 3
263 assert_select 'a[href=?]', "/time_entries/bulk_update?ids%5B%5D=1&amp;ids%5B%5D=2&amp;time_entry%5Bcustom_field_values%5D%5B#{field.id}%5D=foo", :text => 'foo'
272 assert_select 'a[href=?]', "/time_entries/bulk_update?ids%5B%5D=1&amp;ids%5B%5D=2&amp;time_entry%5Bcustom_field_values%5D%5B#{field.id}%5D=foo", :text => 'foo'
264 assert_select 'a[href=?]', "/time_entries/bulk_update?ids%5B%5D=1&amp;ids%5B%5D=2&amp;time_entry%5Bcustom_field_values%5D%5B#{field.id}%5D=bar", :text => 'bar'
273 assert_select 'a[href=?]', "/time_entries/bulk_update?ids%5B%5D=1&amp;ids%5B%5D=2&amp;time_entry%5Bcustom_field_values%5D%5B#{field.id}%5D=bar", :text => 'bar'
265 assert_select 'a[href=?]', "/time_entries/bulk_update?ids%5B%5D=1&amp;ids%5B%5D=2&amp;time_entry%5Bcustom_field_values%5D%5B#{field.id}%5D=__none__", :text => 'none'
274 assert_select 'a[href=?]', "/time_entries/bulk_update?ids%5B%5D=1&amp;ids%5B%5D=2&amp;time_entry%5Bcustom_field_values%5D%5B#{field.id}%5D=__none__", :text => 'none'
266 end
275 end
267 end
276 end
268 end
277 end
269
278
270 def test_time_entries_context_menu_without_edit_permission
279 def test_time_entries_context_menu_without_edit_permission
271 @request.session[:user_id] = 2
280 @request.session[:user_id] = 2
272 Role.find_by_name('Manager').remove_permission! :edit_time_entries
281 Role.find_by_name('Manager').remove_permission! :edit_time_entries
273
282
274 get :time_entries, :ids => [1, 2]
283 get :time_entries, :ids => [1, 2]
275 assert_response :success
284 assert_response :success
276 assert_template 'context_menus/time_entries'
285 assert_template 'context_menus/time_entries'
277 assert_select 'a.disabled', :text => 'Edit'
286 assert_select 'a.disabled', :text => 'Edit'
278 end
287 end
279 end
288 end
General Comments 0
You need to be logged in to leave comments. Login now