@@ -1,31 +1,31 | |||
|
1 | 1 | xml.instruct! |
|
2 | 2 | xml.feed "xmlns" => "http://www.w3.org/2005/Atom" do |
|
3 | 3 | xml.title @title |
|
4 | 4 | xml.link "rel" => "self", "href" => url_for(:format => 'atom', :key => User.current.rss_key, :only_path => false) |
|
5 | 5 | xml.link "rel" => "alternate", "href" => home_url |
|
6 | 6 | xml.id home_url |
|
7 | 7 | xml.icon favicon_url |
|
8 | 8 | xml.updated((@journals.first ? @journals.first.event_datetime : Time.now).xmlschema) |
|
9 | 9 | xml.author { xml.name "#{Setting.app_title}" } |
|
10 | 10 | @journals.each do |change| |
|
11 | 11 | issue = change.issue |
|
12 | 12 | xml.entry do |
|
13 | 13 | xml.title "#{issue.project.name} - #{issue.tracker.name} ##{issue.id}: #{issue.subject}" |
|
14 | 14 | xml.link "rel" => "alternate", "href" => issue_url(issue) |
|
15 | 15 | xml.id issue_url(issue, :journal_id => change) |
|
16 | 16 | xml.updated change.created_on.xmlschema |
|
17 | 17 | xml.author do |
|
18 | 18 | xml.name change.user.name |
|
19 | 19 | xml.email(change.user.mail) if change.user.is_a?(User) && !change.user.mail.blank? && !change.user.pref.hide_mail |
|
20 | 20 | end |
|
21 | 21 | xml.content "type" => "html" do |
|
22 | 22 | xml.text! '<ul>' |
|
23 | details_to_strings(change.details, false).each do |string| | |
|
23 | details_to_strings(change.visible_details, false).each do |string| | |
|
24 | 24 | xml.text! '<li>' + string + '</li>' |
|
25 | 25 | end |
|
26 | 26 | xml.text! '</ul>' |
|
27 | 27 | xml.text! textilizable(change, :notes, :only_path => false) unless change.notes.blank? |
|
28 | 28 | end |
|
29 | 29 | end |
|
30 | 30 | end |
|
31 | 31 | end |
@@ -1,181 +1,221 | |||
|
1 | 1 | # Redmine - project management software |
|
2 | 2 | # Copyright (C) 2006-2015 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 JournalsControllerTest < ActionController::TestCase |
|
21 | 21 | fixtures :projects, :users, :members, :member_roles, :roles, :issues, :journals, :journal_details, :enabled_modules, |
|
22 | :trackers, :issue_statuses, :enumerations, :custom_fields, :custom_values, :custom_fields_projects | |
|
22 | :trackers, :issue_statuses, :enumerations, :custom_fields, :custom_values, :custom_fields_projects, :projects_trackers | |
|
23 | 23 | |
|
24 | 24 | def setup |
|
25 | 25 | User.current = nil |
|
26 | 26 | end |
|
27 | 27 | |
|
28 | 28 | def test_index |
|
29 | 29 | get :index, :project_id => 1 |
|
30 | 30 | assert_response :success |
|
31 | 31 | assert_not_nil assigns(:journals) |
|
32 | 32 | assert_equal 'application/atom+xml', @response.content_type |
|
33 | 33 | end |
|
34 | 34 | |
|
35 | 35 | def test_index_with_invalid_query_id |
|
36 | 36 | get :index, :project_id => 1, :query_id => 999 |
|
37 | 37 | assert_response 404 |
|
38 | 38 | end |
|
39 | 39 | |
|
40 | 40 | def test_index_should_return_privates_notes_with_permission_only |
|
41 | 41 | journal = Journal.create!(:journalized => Issue.find(2), :notes => 'Privates notes', :private_notes => true, :user_id => 1) |
|
42 | 42 | @request.session[:user_id] = 2 |
|
43 | 43 | |
|
44 | 44 | get :index, :project_id => 1 |
|
45 | 45 | assert_response :success |
|
46 | 46 | assert_include journal, assigns(:journals) |
|
47 | 47 | |
|
48 | 48 | Role.find(1).remove_permission! :view_private_notes |
|
49 | 49 | get :index, :project_id => 1 |
|
50 | 50 | assert_response :success |
|
51 | 51 | assert_not_include journal, assigns(:journals) |
|
52 | 52 | end |
|
53 | 53 | |
|
54 | def test_index_should_show_visible_custom_fields_only | |
|
55 | Issue.destroy_all | |
|
56 | field_attributes = {:field_format => 'string', :is_for_all => true, :is_filter => true, :trackers => Tracker.all} | |
|
57 | @fields = [] | |
|
58 | @fields << (@field1 = IssueCustomField.create!(field_attributes.merge(:name => 'Field 1', :visible => true))) | |
|
59 | @fields << (@field2 = IssueCustomField.create!(field_attributes.merge(:name => 'Field 2', :visible => false, :role_ids => [1, 2]))) | |
|
60 | @fields << (@field3 = IssueCustomField.create!(field_attributes.merge(:name => 'Field 3', :visible => false, :role_ids => [1, 3]))) | |
|
61 | @issue = Issue.generate!( | |
|
62 | :author_id => 1, | |
|
63 | :project_id => 1, | |
|
64 | :tracker_id => 1, | |
|
65 | :custom_field_values => {@field1.id => 'Value0', @field2.id => 'Value1', @field3.id => 'Value2'} | |
|
66 | ) | |
|
67 | @issue.init_journal(User.find(1)) | |
|
68 | @issue.update_attribute :custom_field_values, {@field1.id => 'NewValue0', @field2.id => 'NewValue1', @field3.id => 'NewValue2'} | |
|
69 | ||
|
70 | ||
|
71 | user_with_role_on_other_project = User.generate! | |
|
72 | User.add_to_project(user_with_role_on_other_project, Project.find(2), Role.find(3)) | |
|
73 | users_to_test = { | |
|
74 | User.find(1) => [@field1, @field2, @field3], | |
|
75 | User.find(3) => [@field1, @field2], | |
|
76 | user_with_role_on_other_project => [@field1], # should see field1 only on Project 1 | |
|
77 | User.generate! => [@field1], | |
|
78 | User.anonymous => [@field1] | |
|
79 | } | |
|
80 | ||
|
81 | users_to_test.each do |user, visible_fields| | |
|
82 | get :index, :format => 'atom', :key => user.rss_key | |
|
83 | @fields.each_with_index do |field, i| | |
|
84 | if visible_fields.include?(field) | |
|
85 | assert_select "content[type=html]", { :text => /NewValue#{i}/, :count => 1 }, "User #{user.id} was not able to view #{field.name} in API" | |
|
86 | else | |
|
87 | assert_select "content[type=html]", { :text => /NewValue#{i}/, :count => 0 }, "User #{user.id} was able to view #{field.name} in API" | |
|
88 | end | |
|
89 | end | |
|
90 | end | |
|
91 | ||
|
92 | end | |
|
93 | ||
|
54 | 94 | def test_diff_for_description_change |
|
55 | 95 | get :diff, :id => 3, :detail_id => 4 |
|
56 | 96 | assert_response :success |
|
57 | 97 | assert_template 'diff' |
|
58 | 98 | |
|
59 | 99 | assert_select 'span.diff_out', :text => /removed/ |
|
60 | 100 | assert_select 'span.diff_in', :text => /added/ |
|
61 | 101 | end |
|
62 | 102 | |
|
63 | 103 | def test_diff_for_custom_field |
|
64 | 104 | field = IssueCustomField.create!(:name => "Long field", :field_format => 'text') |
|
65 | 105 | journal = Journal.create!(:journalized => Issue.find(2), :notes => 'Notes', :user_id => 1) |
|
66 | 106 | detail = JournalDetail.create!(:journal => journal, :property => 'cf', :prop_key => field.id, |
|
67 | 107 | :old_value => 'Foo', :value => 'Bar') |
|
68 | 108 | |
|
69 | 109 | get :diff, :id => journal.id, :detail_id => detail.id |
|
70 | 110 | assert_response :success |
|
71 | 111 | assert_template 'diff' |
|
72 | 112 | |
|
73 | 113 | assert_select 'span.diff_out', :text => /Foo/ |
|
74 | 114 | assert_select 'span.diff_in', :text => /Bar/ |
|
75 | 115 | end |
|
76 | 116 | |
|
77 | 117 | def test_diff_for_custom_field_should_be_denied_if_custom_field_is_not_visible |
|
78 | 118 | field = IssueCustomField.create!(:name => "Long field", :field_format => 'text', :visible => false, :role_ids => [1]) |
|
79 | 119 | journal = Journal.create!(:journalized => Issue.find(2), :notes => 'Notes', :user_id => 1) |
|
80 | 120 | detail = JournalDetail.create!(:journal => journal, :property => 'cf', :prop_key => field.id, |
|
81 | 121 | :old_value => 'Foo', :value => 'Bar') |
|
82 | 122 | |
|
83 | 123 | get :diff, :id => journal.id, :detail_id => detail.id |
|
84 | 124 | assert_response 302 |
|
85 | 125 | end |
|
86 | 126 | |
|
87 | 127 | def test_diff_should_default_to_description_diff |
|
88 | 128 | get :diff, :id => 3 |
|
89 | 129 | assert_response :success |
|
90 | 130 | assert_template 'diff' |
|
91 | 131 | |
|
92 | 132 | assert_select 'span.diff_out', :text => /removed/ |
|
93 | 133 | assert_select 'span.diff_in', :text => /added/ |
|
94 | 134 | end |
|
95 | 135 | |
|
96 | 136 | def test_reply_to_issue |
|
97 | 137 | @request.session[:user_id] = 2 |
|
98 | 138 | xhr :get, :new, :id => 6 |
|
99 | 139 | assert_response :success |
|
100 | 140 | assert_template 'new' |
|
101 | 141 | assert_equal 'text/javascript', response.content_type |
|
102 | 142 | assert_include '> This is an issue', response.body |
|
103 | 143 | end |
|
104 | 144 | |
|
105 | 145 | def test_reply_to_issue_without_permission |
|
106 | 146 | @request.session[:user_id] = 7 |
|
107 | 147 | xhr :get, :new, :id => 6 |
|
108 | 148 | assert_response 403 |
|
109 | 149 | end |
|
110 | 150 | |
|
111 | 151 | def test_reply_to_note |
|
112 | 152 | @request.session[:user_id] = 2 |
|
113 | 153 | xhr :get, :new, :id => 6, :journal_id => 4 |
|
114 | 154 | assert_response :success |
|
115 | 155 | assert_template 'new' |
|
116 | 156 | assert_equal 'text/javascript', response.content_type |
|
117 | 157 | assert_include '> A comment with a private version', response.body |
|
118 | 158 | end |
|
119 | 159 | |
|
120 | 160 | def test_reply_to_private_note_should_fail_without_permission |
|
121 | 161 | journal = Journal.create!(:journalized => Issue.find(2), :notes => 'Privates notes', :private_notes => true) |
|
122 | 162 | @request.session[:user_id] = 2 |
|
123 | 163 | |
|
124 | 164 | xhr :get, :new, :id => 2, :journal_id => journal.id |
|
125 | 165 | assert_response :success |
|
126 | 166 | assert_template 'new' |
|
127 | 167 | assert_equal 'text/javascript', response.content_type |
|
128 | 168 | assert_include '> Privates notes', response.body |
|
129 | 169 | |
|
130 | 170 | Role.find(1).remove_permission! :view_private_notes |
|
131 | 171 | xhr :get, :new, :id => 2, :journal_id => journal.id |
|
132 | 172 | assert_response 404 |
|
133 | 173 | end |
|
134 | 174 | |
|
135 | 175 | def test_edit_xhr |
|
136 | 176 | @request.session[:user_id] = 1 |
|
137 | 177 | xhr :get, :edit, :id => 2 |
|
138 | 178 | assert_response :success |
|
139 | 179 | assert_template 'edit' |
|
140 | 180 | assert_equal 'text/javascript', response.content_type |
|
141 | 181 | assert_include 'textarea', response.body |
|
142 | 182 | end |
|
143 | 183 | |
|
144 | 184 | def test_edit_private_note_should_fail_without_permission |
|
145 | 185 | journal = Journal.create!(:journalized => Issue.find(2), :notes => 'Privates notes', :private_notes => true) |
|
146 | 186 | @request.session[:user_id] = 2 |
|
147 | 187 | Role.find(1).add_permission! :edit_issue_notes |
|
148 | 188 | |
|
149 | 189 | xhr :get, :edit, :id => journal.id |
|
150 | 190 | assert_response :success |
|
151 | 191 | assert_template 'edit' |
|
152 | 192 | assert_equal 'text/javascript', response.content_type |
|
153 | 193 | assert_include 'textarea', response.body |
|
154 | 194 | |
|
155 | 195 | Role.find(1).remove_permission! :view_private_notes |
|
156 | 196 | xhr :get, :edit, :id => journal.id |
|
157 | 197 | assert_response 404 |
|
158 | 198 | end |
|
159 | 199 | |
|
160 | 200 | def test_update_xhr |
|
161 | 201 | @request.session[:user_id] = 1 |
|
162 | 202 | xhr :post, :edit, :id => 2, :notes => 'Updated notes' |
|
163 | 203 | assert_response :success |
|
164 | 204 | assert_template 'update' |
|
165 | 205 | assert_equal 'text/javascript', response.content_type |
|
166 | 206 | assert_equal 'Updated notes', Journal.find(2).notes |
|
167 | 207 | assert_include 'journal-2-notes', response.body |
|
168 | 208 | end |
|
169 | 209 | |
|
170 | 210 | def test_update_xhr_with_empty_notes_should_delete_the_journal |
|
171 | 211 | @request.session[:user_id] = 1 |
|
172 | 212 | assert_difference 'Journal.count', -1 do |
|
173 | 213 | xhr :post, :edit, :id => 2, :notes => '' |
|
174 | 214 | assert_response :success |
|
175 | 215 | assert_template 'update' |
|
176 | 216 | assert_equal 'text/javascript', response.content_type |
|
177 | 217 | end |
|
178 | 218 | assert_nil Journal.find_by_id(2) |
|
179 | 219 | assert_include 'change-2', response.body |
|
180 | 220 | end |
|
181 | 221 | end |
General Comments 0
You need to be logged in to leave comments.
Login now