##// END OF EJS Templates
Removed unimplemented JournalsController#edit html response and added some tests....
Jean-Philippe Lang -
r13322:a942c1c25ec9
parent child
Show More
@@ -1,104 +1,101
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 class JournalsController < ApplicationController
18 class JournalsController < ApplicationController
19 before_filter :find_journal, :only => [:edit, :diff]
19 before_filter :find_journal, :only => [:edit, :diff]
20 before_filter :find_issue, :only => [:new]
20 before_filter :find_issue, :only => [:new]
21 before_filter :find_optional_project, :only => [:index]
21 before_filter :find_optional_project, :only => [:index]
22 before_filter :authorize, :only => [:new, :edit, :diff]
22 before_filter :authorize, :only => [:new, :edit, :diff]
23 accept_rss_auth :index
23 accept_rss_auth :index
24 menu_item :issues
24 menu_item :issues
25
25
26 helper :issues
26 helper :issues
27 helper :custom_fields
27 helper :custom_fields
28 helper :queries
28 helper :queries
29 include QueriesHelper
29 include QueriesHelper
30 helper :sort
30 helper :sort
31 include SortHelper
31 include SortHelper
32
32
33 def index
33 def index
34 retrieve_query
34 retrieve_query
35 sort_init 'id', 'desc'
35 sort_init 'id', 'desc'
36 sort_update(@query.sortable_columns)
36 sort_update(@query.sortable_columns)
37 if @query.valid?
37 if @query.valid?
38 @journals = @query.journals(:order => "#{Journal.table_name}.created_on DESC",
38 @journals = @query.journals(:order => "#{Journal.table_name}.created_on DESC",
39 :limit => 25)
39 :limit => 25)
40 end
40 end
41 @title = (@project ? @project.name : Setting.app_title) + ": " + (@query.new_record? ? l(:label_changes_details) : @query.name)
41 @title = (@project ? @project.name : Setting.app_title) + ": " + (@query.new_record? ? l(:label_changes_details) : @query.name)
42 render :layout => false, :content_type => 'application/atom+xml'
42 render :layout => false, :content_type => 'application/atom+xml'
43 rescue ActiveRecord::RecordNotFound
43 rescue ActiveRecord::RecordNotFound
44 render_404
44 render_404
45 end
45 end
46
46
47 def diff
47 def diff
48 @issue = @journal.issue
48 @issue = @journal.issue
49 if params[:detail_id].present?
49 if params[:detail_id].present?
50 @detail = @journal.details.find_by_id(params[:detail_id])
50 @detail = @journal.details.find_by_id(params[:detail_id])
51 else
51 else
52 @detail = @journal.details.detect {|d| d.prop_key == 'description'}
52 @detail = @journal.details.detect {|d| d.prop_key == 'description'}
53 end
53 end
54 (render_404; return false) unless @issue && @detail
54 (render_404; return false) unless @issue && @detail
55 @diff = Redmine::Helpers::Diff.new(@detail.value, @detail.old_value)
55 @diff = Redmine::Helpers::Diff.new(@detail.value, @detail.old_value)
56 end
56 end
57
57
58 def new
58 def new
59 @journal = Journal.visible.find(params[:journal_id]) if params[:journal_id]
59 @journal = Journal.visible.find(params[:journal_id]) if params[:journal_id]
60 if @journal
60 if @journal
61 user = @journal.user
61 user = @journal.user
62 text = @journal.notes
62 text = @journal.notes
63 else
63 else
64 user = @issue.author
64 user = @issue.author
65 text = @issue.description
65 text = @issue.description
66 end
66 end
67 # Replaces pre blocks with [...]
67 # Replaces pre blocks with [...]
68 text = text.to_s.strip.gsub(%r{<pre>(.*?)</pre>}m, '[...]')
68 text = text.to_s.strip.gsub(%r{<pre>(.*?)</pre>}m, '[...]')
69 @content = "#{ll(Setting.default_language, :text_user_wrote, user)}\n> "
69 @content = "#{ll(Setting.default_language, :text_user_wrote, user)}\n> "
70 @content << text.gsub(/(\r?\n|\r\n?)/, "\n> ") + "\n\n"
70 @content << text.gsub(/(\r?\n|\r\n?)/, "\n> ") + "\n\n"
71 rescue ActiveRecord::RecordNotFound
71 rescue ActiveRecord::RecordNotFound
72 render_404
72 render_404
73 end
73 end
74
74
75 def edit
75 def edit
76 (render_403; return false) unless @journal.editable_by?(User.current)
76 (render_403; return false) unless @journal.editable_by?(User.current)
77 if request.post?
77 if request.post?
78 @journal.update_attributes(:notes => params[:notes]) if params[:notes]
78 @journal.update_attributes(:notes => params[:notes]) if params[:notes]
79 @journal.destroy if @journal.details.empty? && @journal.notes.blank?
79 @journal.destroy if @journal.details.empty? && @journal.notes.blank?
80 call_hook(:controller_journals_edit_post, { :journal => @journal, :params => params})
80 call_hook(:controller_journals_edit_post, { :journal => @journal, :params => params})
81 respond_to do |format|
81 respond_to do |format|
82 format.html { redirect_to issue_path(@journal.journalized) }
82 format.html { redirect_to issue_path(@journal.journalized) }
83 format.js { render :action => 'update' }
83 format.js { render :action => 'update' }
84 end
84 end
85 else
85 else
86 respond_to do |format|
86 respond_to do |format|
87 format.html {
87 # TODO: implement non-JS journal update
88 # TODO: implement non-JS journal update
89 render :nothing => true
90 }
91 format.js
88 format.js
92 end
89 end
93 end
90 end
94 end
91 end
95
92
96 private
93 private
97
94
98 def find_journal
95 def find_journal
99 @journal = Journal.visible.find(params[:id])
96 @journal = Journal.visible.find(params[:id])
100 @project = @journal.journalized.project
97 @project = @journal.journalized.project
101 rescue ActiveRecord::RecordNotFound
98 rescue ActiveRecord::RecordNotFound
102 render_404
99 render_404
103 end
100 end
104 end
101 end
@@ -1,143 +1,157
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 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
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_with_invalid_query_id
36 get :index, :project_id => 1, :query_id => 999
37 assert_response 404
38 end
39
35 def test_index_should_return_privates_notes_with_permission_only
40 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)
41 journal = Journal.create!(:journalized => Issue.find(2), :notes => 'Privates notes', :private_notes => true, :user_id => 1)
37 @request.session[:user_id] = 2
42 @request.session[:user_id] = 2
38
43
39 get :index, :project_id => 1
44 get :index, :project_id => 1
40 assert_response :success
45 assert_response :success
41 assert_include journal, assigns(:journals)
46 assert_include journal, assigns(:journals)
42
47
43 Role.find(1).remove_permission! :view_private_notes
48 Role.find(1).remove_permission! :view_private_notes
44 get :index, :project_id => 1
49 get :index, :project_id => 1
45 assert_response :success
50 assert_response :success
46 assert_not_include journal, assigns(:journals)
51 assert_not_include journal, assigns(:journals)
47 end
52 end
48
53
49 def test_diff
54 def test_diff
50 get :diff, :id => 3, :detail_id => 4
55 get :diff, :id => 3, :detail_id => 4
51 assert_response :success
56 assert_response :success
52 assert_template 'diff'
57 assert_template 'diff'
53
58
54 assert_select 'span.diff_out', :text => /removed/
59 assert_select 'span.diff_out', :text => /removed/
55 assert_select 'span.diff_in', :text => /added/
60 assert_select 'span.diff_in', :text => /added/
56 end
61 end
57
62
63 def test_diff_should_default_to_description_diff
64 get :diff, :id => 3
65 assert_response :success
66 assert_template 'diff'
67
68 assert_select 'span.diff_out', :text => /removed/
69 assert_select 'span.diff_in', :text => /added/
70 end
71
58 def test_reply_to_issue
72 def test_reply_to_issue
59 @request.session[:user_id] = 2
73 @request.session[:user_id] = 2
60 xhr :get, :new, :id => 6
74 xhr :get, :new, :id => 6
61 assert_response :success
75 assert_response :success
62 assert_template 'new'
76 assert_template 'new'
63 assert_equal 'text/javascript', response.content_type
77 assert_equal 'text/javascript', response.content_type
64 assert_include '> This is an issue', response.body
78 assert_include '> This is an issue', response.body
65 end
79 end
66
80
67 def test_reply_to_issue_without_permission
81 def test_reply_to_issue_without_permission
68 @request.session[:user_id] = 7
82 @request.session[:user_id] = 7
69 xhr :get, :new, :id => 6
83 xhr :get, :new, :id => 6
70 assert_response 403
84 assert_response 403
71 end
85 end
72
86
73 def test_reply_to_note
87 def test_reply_to_note
74 @request.session[:user_id] = 2
88 @request.session[:user_id] = 2
75 xhr :get, :new, :id => 6, :journal_id => 4
89 xhr :get, :new, :id => 6, :journal_id => 4
76 assert_response :success
90 assert_response :success
77 assert_template 'new'
91 assert_template 'new'
78 assert_equal 'text/javascript', response.content_type
92 assert_equal 'text/javascript', response.content_type
79 assert_include '> A comment with a private version', response.body
93 assert_include '> A comment with a private version', response.body
80 end
94 end
81
95
82 def test_reply_to_private_note_should_fail_without_permission
96 def test_reply_to_private_note_should_fail_without_permission
83 journal = Journal.create!(:journalized => Issue.find(2), :notes => 'Privates notes', :private_notes => true)
97 journal = Journal.create!(:journalized => Issue.find(2), :notes => 'Privates notes', :private_notes => true)
84 @request.session[:user_id] = 2
98 @request.session[:user_id] = 2
85
99
86 xhr :get, :new, :id => 2, :journal_id => journal.id
100 xhr :get, :new, :id => 2, :journal_id => journal.id
87 assert_response :success
101 assert_response :success
88 assert_template 'new'
102 assert_template 'new'
89 assert_equal 'text/javascript', response.content_type
103 assert_equal 'text/javascript', response.content_type
90 assert_include '> Privates notes', response.body
104 assert_include '> Privates notes', response.body
91
105
92 Role.find(1).remove_permission! :view_private_notes
106 Role.find(1).remove_permission! :view_private_notes
93 xhr :get, :new, :id => 2, :journal_id => journal.id
107 xhr :get, :new, :id => 2, :journal_id => journal.id
94 assert_response 404
108 assert_response 404
95 end
109 end
96
110
97 def test_edit_xhr
111 def test_edit_xhr
98 @request.session[:user_id] = 1
112 @request.session[:user_id] = 1
99 xhr :get, :edit, :id => 2
113 xhr :get, :edit, :id => 2
100 assert_response :success
114 assert_response :success
101 assert_template 'edit'
115 assert_template 'edit'
102 assert_equal 'text/javascript', response.content_type
116 assert_equal 'text/javascript', response.content_type
103 assert_include 'textarea', response.body
117 assert_include 'textarea', response.body
104 end
118 end
105
119
106 def test_edit_private_note_should_fail_without_permission
120 def test_edit_private_note_should_fail_without_permission
107 journal = Journal.create!(:journalized => Issue.find(2), :notes => 'Privates notes', :private_notes => true)
121 journal = Journal.create!(:journalized => Issue.find(2), :notes => 'Privates notes', :private_notes => true)
108 @request.session[:user_id] = 2
122 @request.session[:user_id] = 2
109 Role.find(1).add_permission! :edit_issue_notes
123 Role.find(1).add_permission! :edit_issue_notes
110
124
111 xhr :get, :edit, :id => journal.id
125 xhr :get, :edit, :id => journal.id
112 assert_response :success
126 assert_response :success
113 assert_template 'edit'
127 assert_template 'edit'
114 assert_equal 'text/javascript', response.content_type
128 assert_equal 'text/javascript', response.content_type
115 assert_include 'textarea', response.body
129 assert_include 'textarea', response.body
116
130
117 Role.find(1).remove_permission! :view_private_notes
131 Role.find(1).remove_permission! :view_private_notes
118 xhr :get, :edit, :id => journal.id
132 xhr :get, :edit, :id => journal.id
119 assert_response 404
133 assert_response 404
120 end
134 end
121
135
122 def test_update_xhr
136 def test_update_xhr
123 @request.session[:user_id] = 1
137 @request.session[:user_id] = 1
124 xhr :post, :edit, :id => 2, :notes => 'Updated notes'
138 xhr :post, :edit, :id => 2, :notes => 'Updated notes'
125 assert_response :success
139 assert_response :success
126 assert_template 'update'
140 assert_template 'update'
127 assert_equal 'text/javascript', response.content_type
141 assert_equal 'text/javascript', response.content_type
128 assert_equal 'Updated notes', Journal.find(2).notes
142 assert_equal 'Updated notes', Journal.find(2).notes
129 assert_include 'journal-2-notes', response.body
143 assert_include 'journal-2-notes', response.body
130 end
144 end
131
145
132 def test_update_xhr_with_empty_notes_should_delete_the_journal
146 def test_update_xhr_with_empty_notes_should_delete_the_journal
133 @request.session[:user_id] = 1
147 @request.session[:user_id] = 1
134 assert_difference 'Journal.count', -1 do
148 assert_difference 'Journal.count', -1 do
135 xhr :post, :edit, :id => 2, :notes => ''
149 xhr :post, :edit, :id => 2, :notes => ''
136 assert_response :success
150 assert_response :success
137 assert_template 'update'
151 assert_template 'update'
138 assert_equal 'text/javascript', response.content_type
152 assert_equal 'text/javascript', response.content_type
139 end
153 end
140 assert_nil Journal.find_by_id(2)
154 assert_nil Journal.find_by_id(2)
141 assert_include 'change-2', response.body
155 assert_include 'change-2', response.body
142 end
156 end
143 end
157 end
General Comments 0
You need to be logged in to leave comments. Login now