##// END OF EJS Templates
Merged r14913 (#21419)....
Jean-Philippe Lang -
r14541:a75b0e9cbfa9
parent child
Show More
@@ -1,31 +1,31
1 xml.instruct!
1 xml.instruct!
2 xml.feed "xmlns" => "http://www.w3.org/2005/Atom" do
2 xml.feed "xmlns" => "http://www.w3.org/2005/Atom" do
3 xml.title @title
3 xml.title @title
4 xml.link "rel" => "self", "href" => url_for(:format => 'atom', :key => User.current.rss_key, :only_path => false)
4 xml.link "rel" => "self", "href" => url_for(:format => 'atom', :key => User.current.rss_key, :only_path => false)
5 xml.link "rel" => "alternate", "href" => home_url(:only_path => false)
5 xml.link "rel" => "alternate", "href" => home_url(:only_path => false)
6 xml.id url_for(:controller => 'welcome', :only_path => false)
6 xml.id url_for(:controller => 'welcome', :only_path => false)
7 xml.icon favicon_url
7 xml.icon favicon_url
8 xml.updated((@journals.first ? @journals.first.event_datetime : Time.now).xmlschema)
8 xml.updated((@journals.first ? @journals.first.event_datetime : Time.now).xmlschema)
9 xml.author { xml.name "#{Setting.app_title}" }
9 xml.author { xml.name "#{Setting.app_title}" }
10 @journals.each do |change|
10 @journals.each do |change|
11 issue = change.issue
11 issue = change.issue
12 xml.entry do
12 xml.entry do
13 xml.title "#{issue.project.name} - #{issue.tracker.name} ##{issue.id}: #{issue.subject}"
13 xml.title "#{issue.project.name} - #{issue.tracker.name} ##{issue.id}: #{issue.subject}"
14 xml.link "rel" => "alternate", "href" => url_for(:controller => 'issues' , :action => 'show', :id => issue, :only_path => false)
14 xml.link "rel" => "alternate", "href" => url_for(:controller => 'issues' , :action => 'show', :id => issue, :only_path => false)
15 xml.id url_for(:controller => 'issues' , :action => 'show', :id => issue, :journal_id => change, :only_path => false)
15 xml.id url_for(:controller => 'issues' , :action => 'show', :id => issue, :journal_id => change, :only_path => false)
16 xml.updated change.created_on.xmlschema
16 xml.updated change.created_on.xmlschema
17 xml.author do
17 xml.author do
18 xml.name change.user.name
18 xml.name change.user.name
19 xml.email(change.user.mail) if change.user.is_a?(User) && !change.user.mail.blank? && !change.user.pref.hide_mail
19 xml.email(change.user.mail) if change.user.is_a?(User) && !change.user.mail.blank? && !change.user.pref.hide_mail
20 end
20 end
21 xml.content "type" => "html" do
21 xml.content "type" => "html" do
22 xml.text! '<ul>'
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 xml.text! '<li>' + string + '</li>'
24 xml.text! '<li>' + string + '</li>'
25 end
25 end
26 xml.text! '</ul>'
26 xml.text! '</ul>'
27 xml.text! textilizable(change, :notes, :only_path => false) unless change.notes.blank?
27 xml.text! textilizable(change, :notes, :only_path => false) unless change.notes.blank?
28 end
28 end
29 end
29 end
30 end
30 end
31 end
31 end
@@ -1,147 +1,187
1 # Redmine - project management software
1 # Redmine - project management software
2 # Copyright (C) 2006-2015 Jean-Philippe Lang
2 # Copyright (C) 2006-2015 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 JournalsControllerTest < ActionController::TestCase
20 class JournalsControllerTest < ActionController::TestCase
21 fixtures :projects, :users, :members, :member_roles, :roles, :issues, :journals, :journal_details, :enabled_modules,
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 def setup
24 def setup
25 User.current = nil
25 User.current = nil
26 end
26 end
27
27
28 def test_index
28 def test_index
29 get :index, :project_id => 1
29 get :index, :project_id => 1
30 assert_response :success
30 assert_response :success
31 assert_not_nil assigns(:journals)
31 assert_not_nil assigns(:journals)
32 assert_equal 'application/atom+xml', @response.content_type
32 assert_equal 'application/atom+xml', @response.content_type
33 end
33 end
34
34
35 def test_index_should_return_privates_notes_with_permission_only
35 def test_index_should_return_privates_notes_with_permission_only
36 journal = Journal.create!(:journalized => Issue.find(2), :notes => 'Privates notes', :private_notes => true, :user_id => 1)
36 journal = Journal.create!(:journalized => Issue.find(2), :notes => 'Privates notes', :private_notes => true, :user_id => 1)
37 @request.session[:user_id] = 2
37 @request.session[:user_id] = 2
38
38
39 get :index, :project_id => 1
39 get :index, :project_id => 1
40 assert_response :success
40 assert_response :success
41 assert_include journal, assigns(:journals)
41 assert_include journal, assigns(:journals)
42
42
43 Role.find(1).remove_permission! :view_private_notes
43 Role.find(1).remove_permission! :view_private_notes
44 get :index, :project_id => 1
44 get :index, :project_id => 1
45 assert_response :success
45 assert_response :success
46 assert_not_include journal, assigns(:journals)
46 assert_not_include journal, assigns(:journals)
47 end
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 def test_diff
89 def test_diff
50 get :diff, :id => 3, :detail_id => 4
90 get :diff, :id => 3, :detail_id => 4
51 assert_response :success
91 assert_response :success
52 assert_template 'diff'
92 assert_template 'diff'
53
93
54 assert_tag 'span',
94 assert_tag 'span',
55 :attributes => {:class => 'diff_out'},
95 :attributes => {:class => 'diff_out'},
56 :content => /removed/
96 :content => /removed/
57 assert_tag 'span',
97 assert_tag 'span',
58 :attributes => {:class => 'diff_in'},
98 :attributes => {:class => 'diff_in'},
59 :content => /added/
99 :content => /added/
60 end
100 end
61
101
62 def test_reply_to_issue
102 def test_reply_to_issue
63 @request.session[:user_id] = 2
103 @request.session[:user_id] = 2
64 xhr :get, :new, :id => 6
104 xhr :get, :new, :id => 6
65 assert_response :success
105 assert_response :success
66 assert_template 'new'
106 assert_template 'new'
67 assert_equal 'text/javascript', response.content_type
107 assert_equal 'text/javascript', response.content_type
68 assert_include '> This is an issue', response.body
108 assert_include '> This is an issue', response.body
69 end
109 end
70
110
71 def test_reply_to_issue_without_permission
111 def test_reply_to_issue_without_permission
72 @request.session[:user_id] = 7
112 @request.session[:user_id] = 7
73 xhr :get, :new, :id => 6
113 xhr :get, :new, :id => 6
74 assert_response 403
114 assert_response 403
75 end
115 end
76
116
77 def test_reply_to_note
117 def test_reply_to_note
78 @request.session[:user_id] = 2
118 @request.session[:user_id] = 2
79 xhr :get, :new, :id => 6, :journal_id => 4
119 xhr :get, :new, :id => 6, :journal_id => 4
80 assert_response :success
120 assert_response :success
81 assert_template 'new'
121 assert_template 'new'
82 assert_equal 'text/javascript', response.content_type
122 assert_equal 'text/javascript', response.content_type
83 assert_include '> A comment with a private version', response.body
123 assert_include '> A comment with a private version', response.body
84 end
124 end
85
125
86 def test_reply_to_private_note_should_fail_without_permission
126 def test_reply_to_private_note_should_fail_without_permission
87 journal = Journal.create!(:journalized => Issue.find(2), :notes => 'Privates notes', :private_notes => true)
127 journal = Journal.create!(:journalized => Issue.find(2), :notes => 'Privates notes', :private_notes => true)
88 @request.session[:user_id] = 2
128 @request.session[:user_id] = 2
89
129
90 xhr :get, :new, :id => 2, :journal_id => journal.id
130 xhr :get, :new, :id => 2, :journal_id => journal.id
91 assert_response :success
131 assert_response :success
92 assert_template 'new'
132 assert_template 'new'
93 assert_equal 'text/javascript', response.content_type
133 assert_equal 'text/javascript', response.content_type
94 assert_include '> Privates notes', response.body
134 assert_include '> Privates notes', response.body
95
135
96 Role.find(1).remove_permission! :view_private_notes
136 Role.find(1).remove_permission! :view_private_notes
97 xhr :get, :new, :id => 2, :journal_id => journal.id
137 xhr :get, :new, :id => 2, :journal_id => journal.id
98 assert_response 404
138 assert_response 404
99 end
139 end
100
140
101 def test_edit_xhr
141 def test_edit_xhr
102 @request.session[:user_id] = 1
142 @request.session[:user_id] = 1
103 xhr :get, :edit, :id => 2
143 xhr :get, :edit, :id => 2
104 assert_response :success
144 assert_response :success
105 assert_template 'edit'
145 assert_template 'edit'
106 assert_equal 'text/javascript', response.content_type
146 assert_equal 'text/javascript', response.content_type
107 assert_include 'textarea', response.body
147 assert_include 'textarea', response.body
108 end
148 end
109
149
110 def test_edit_private_note_should_fail_without_permission
150 def test_edit_private_note_should_fail_without_permission
111 journal = Journal.create!(:journalized => Issue.find(2), :notes => 'Privates notes', :private_notes => true)
151 journal = Journal.create!(:journalized => Issue.find(2), :notes => 'Privates notes', :private_notes => true)
112 @request.session[:user_id] = 2
152 @request.session[:user_id] = 2
113 Role.find(1).add_permission! :edit_issue_notes
153 Role.find(1).add_permission! :edit_issue_notes
114
154
115 xhr :get, :edit, :id => journal.id
155 xhr :get, :edit, :id => journal.id
116 assert_response :success
156 assert_response :success
117 assert_template 'edit'
157 assert_template 'edit'
118 assert_equal 'text/javascript', response.content_type
158 assert_equal 'text/javascript', response.content_type
119 assert_include 'textarea', response.body
159 assert_include 'textarea', response.body
120
160
121 Role.find(1).remove_permission! :view_private_notes
161 Role.find(1).remove_permission! :view_private_notes
122 xhr :get, :edit, :id => journal.id
162 xhr :get, :edit, :id => journal.id
123 assert_response 404
163 assert_response 404
124 end
164 end
125
165
126 def test_update_xhr
166 def test_update_xhr
127 @request.session[:user_id] = 1
167 @request.session[:user_id] = 1
128 xhr :post, :edit, :id => 2, :notes => 'Updated notes'
168 xhr :post, :edit, :id => 2, :notes => 'Updated notes'
129 assert_response :success
169 assert_response :success
130 assert_template 'update'
170 assert_template 'update'
131 assert_equal 'text/javascript', response.content_type
171 assert_equal 'text/javascript', response.content_type
132 assert_equal 'Updated notes', Journal.find(2).notes
172 assert_equal 'Updated notes', Journal.find(2).notes
133 assert_include 'journal-2-notes', response.body
173 assert_include 'journal-2-notes', response.body
134 end
174 end
135
175
136 def test_update_xhr_with_empty_notes_should_delete_the_journal
176 def test_update_xhr_with_empty_notes_should_delete_the_journal
137 @request.session[:user_id] = 1
177 @request.session[:user_id] = 1
138 assert_difference 'Journal.count', -1 do
178 assert_difference 'Journal.count', -1 do
139 xhr :post, :edit, :id => 2, :notes => ''
179 xhr :post, :edit, :id => 2, :notes => ''
140 assert_response :success
180 assert_response :success
141 assert_template 'update'
181 assert_template 'update'
142 assert_equal 'text/javascript', response.content_type
182 assert_equal 'text/javascript', response.content_type
143 end
183 end
144 assert_nil Journal.find_by_id(2)
184 assert_nil Journal.find_by_id(2)
145 assert_include 'change-2', response.body
185 assert_include 'change-2', response.body
146 end
186 end
147 end
187 end
General Comments 0
You need to be logged in to leave comments. Login now