##// END OF EJS Templates
Merged r14913 (#21419)....
Jean-Philippe Lang -
r14541:a75b0e9cbfa9
parent child
Show More
@@ -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(:only_path => false)
6 6 xml.id url_for(:controller => 'welcome', :only_path => false)
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" => url_for(:controller => 'issues' , :action => 'show', :id => issue, :only_path => false)
15 15 xml.id url_for(:controller => 'issues' , :action => 'show', :id => issue, :journal_id => change, :only_path => false)
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,147 +1,187
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_should_return_privates_notes_with_permission_only
36 36 journal = Journal.create!(:journalized => Issue.find(2), :notes => 'Privates notes', :private_notes => true, :user_id => 1)
37 37 @request.session[:user_id] = 2
38 38
39 39 get :index, :project_id => 1
40 40 assert_response :success
41 41 assert_include journal, assigns(:journals)
42 42
43 43 Role.find(1).remove_permission! :view_private_notes
44 44 get :index, :project_id => 1
45 45 assert_response :success
46 46 assert_not_include journal, assigns(:journals)
47 47 end
48 48
49 def test_index_should_show_visible_custom_fields_only
50 Issue.destroy_all
51 field_attributes = {:field_format => 'string', :is_for_all => true, :is_filter => true, :trackers => Tracker.all}
52 @fields = []
53 @fields << (@field1 = IssueCustomField.create!(field_attributes.merge(:name => 'Field 1', :visible => true)))
54 @fields << (@field2 = IssueCustomField.create!(field_attributes.merge(:name => 'Field 2', :visible => false, :role_ids => [1, 2])))
55 @fields << (@field3 = IssueCustomField.create!(field_attributes.merge(:name => 'Field 3', :visible => false, :role_ids => [1, 3])))
56 @issue = Issue.generate!(
57 :author_id => 1,
58 :project_id => 1,
59 :tracker_id => 1,
60 :custom_field_values => {@field1.id => 'Value0', @field2.id => 'Value1', @field3.id => 'Value2'}
61 )
62 @issue.init_journal(User.find(1))
63 @issue.update_attribute :custom_field_values, {@field1.id => 'NewValue0', @field2.id => 'NewValue1', @field3.id => 'NewValue2'}
64
65
66 user_with_role_on_other_project = User.generate!
67 User.add_to_project(user_with_role_on_other_project, Project.find(2), Role.find(3))
68 users_to_test = {
69 User.find(1) => [@field1, @field2, @field3],
70 User.find(3) => [@field1, @field2],
71 user_with_role_on_other_project => [@field1], # should see field1 only on Project 1
72 User.generate! => [@field1],
73 User.anonymous => [@field1]
74 }
75
76 users_to_test.each do |user, visible_fields|
77 get :index, :format => 'atom', :key => user.rss_key
78 @fields.each_with_index do |field, i|
79 if visible_fields.include?(field)
80 assert_select "content[type=html]", { :text => /NewValue#{i}/, :count => 1 }, "User #{user.id} was not able to view #{field.name} in API"
81 else
82 assert_select "content[type=html]", { :text => /NewValue#{i}/, :count => 0 }, "User #{user.id} was able to view #{field.name} in API"
83 end
84 end
85 end
86
87 end
88
49 89 def test_diff
50 90 get :diff, :id => 3, :detail_id => 4
51 91 assert_response :success
52 92 assert_template 'diff'
53 93
54 94 assert_tag 'span',
55 95 :attributes => {:class => 'diff_out'},
56 96 :content => /removed/
57 97 assert_tag 'span',
58 98 :attributes => {:class => 'diff_in'},
59 99 :content => /added/
60 100 end
61 101
62 102 def test_reply_to_issue
63 103 @request.session[:user_id] = 2
64 104 xhr :get, :new, :id => 6
65 105 assert_response :success
66 106 assert_template 'new'
67 107 assert_equal 'text/javascript', response.content_type
68 108 assert_include '> This is an issue', response.body
69 109 end
70 110
71 111 def test_reply_to_issue_without_permission
72 112 @request.session[:user_id] = 7
73 113 xhr :get, :new, :id => 6
74 114 assert_response 403
75 115 end
76 116
77 117 def test_reply_to_note
78 118 @request.session[:user_id] = 2
79 119 xhr :get, :new, :id => 6, :journal_id => 4
80 120 assert_response :success
81 121 assert_template 'new'
82 122 assert_equal 'text/javascript', response.content_type
83 123 assert_include '> A comment with a private version', response.body
84 124 end
85 125
86 126 def test_reply_to_private_note_should_fail_without_permission
87 127 journal = Journal.create!(:journalized => Issue.find(2), :notes => 'Privates notes', :private_notes => true)
88 128 @request.session[:user_id] = 2
89 129
90 130 xhr :get, :new, :id => 2, :journal_id => journal.id
91 131 assert_response :success
92 132 assert_template 'new'
93 133 assert_equal 'text/javascript', response.content_type
94 134 assert_include '> Privates notes', response.body
95 135
96 136 Role.find(1).remove_permission! :view_private_notes
97 137 xhr :get, :new, :id => 2, :journal_id => journal.id
98 138 assert_response 404
99 139 end
100 140
101 141 def test_edit_xhr
102 142 @request.session[:user_id] = 1
103 143 xhr :get, :edit, :id => 2
104 144 assert_response :success
105 145 assert_template 'edit'
106 146 assert_equal 'text/javascript', response.content_type
107 147 assert_include 'textarea', response.body
108 148 end
109 149
110 150 def test_edit_private_note_should_fail_without_permission
111 151 journal = Journal.create!(:journalized => Issue.find(2), :notes => 'Privates notes', :private_notes => true)
112 152 @request.session[:user_id] = 2
113 153 Role.find(1).add_permission! :edit_issue_notes
114 154
115 155 xhr :get, :edit, :id => journal.id
116 156 assert_response :success
117 157 assert_template 'edit'
118 158 assert_equal 'text/javascript', response.content_type
119 159 assert_include 'textarea', response.body
120 160
121 161 Role.find(1).remove_permission! :view_private_notes
122 162 xhr :get, :edit, :id => journal.id
123 163 assert_response 404
124 164 end
125 165
126 166 def test_update_xhr
127 167 @request.session[:user_id] = 1
128 168 xhr :post, :edit, :id => 2, :notes => 'Updated notes'
129 169 assert_response :success
130 170 assert_template 'update'
131 171 assert_equal 'text/javascript', response.content_type
132 172 assert_equal 'Updated notes', Journal.find(2).notes
133 173 assert_include 'journal-2-notes', response.body
134 174 end
135 175
136 176 def test_update_xhr_with_empty_notes_should_delete_the_journal
137 177 @request.session[:user_id] = 1
138 178 assert_difference 'Journal.count', -1 do
139 179 xhr :post, :edit, :id => 2, :notes => ''
140 180 assert_response :success
141 181 assert_template 'update'
142 182 assert_equal 'text/javascript', response.content_type
143 183 end
144 184 assert_nil Journal.find_by_id(2)
145 185 assert_include 'change-2', response.body
146 186 end
147 187 end
General Comments 0
You need to be logged in to leave comments. Login now