##// END OF EJS Templates
Fixed: error on JournalsController#index when custom fields are present (#7795)....
Jean-Philippe Lang -
r4901:334132289ca9
parent child
Show More
@@ -1,118 +1,119
1 1 # Redmine - project management software
2 2 # Copyright (C) 2006-2011 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 class JournalsController < ApplicationController
19 19 before_filter :find_journal, :only => [:edit, :diff]
20 20 before_filter :find_issue, :only => [:new]
21 21 before_filter :find_optional_project, :only => [:index]
22 22 before_filter :authorize, :only => [:new, :edit, :diff]
23 23 accept_key_auth :index
24 24 menu_item :issues
25 25
26 26 helper :issues
27 helper :custom_fields
27 28 helper :queries
28 29 include QueriesHelper
29 30 helper :sort
30 31 include SortHelper
31 32
32 33 def index
33 34 retrieve_query
34 35 sort_init 'id', 'desc'
35 36 sort_update(@query.sortable_columns)
36 37
37 38 if @query.valid?
38 39 @journals = @query.journals(:order => "#{Journal.table_name}.created_on DESC",
39 40 :limit => 25)
40 41 end
41 42 @title = (@project ? @project.name : Setting.app_title) + ": " + (@query.new_record? ? l(:label_changes_details) : @query.name)
42 43 render :layout => false, :content_type => 'application/atom+xml'
43 44 rescue ActiveRecord::RecordNotFound
44 45 render_404
45 46 end
46 47
47 48 def diff
48 49 @issue = @journal.issue
49 50 if params[:detail_id].present?
50 51 @detail = @journal.details.find_by_id(params[:detail_id])
51 52 else
52 53 @detail = @journal.details.detect {|d| d.prop_key == 'description'}
53 54 end
54 55 (render_404; return false) unless @issue && @detail
55 56 @diff = Redmine::Helpers::Diff.new(@detail.value, @detail.old_value)
56 57 end
57 58
58 59 def new
59 60 journal = Journal.find(params[:journal_id]) if params[:journal_id]
60 61 if journal
61 62 user = journal.user
62 63 text = journal.notes
63 64 else
64 65 user = @issue.author
65 66 text = @issue.description
66 67 end
67 68 # Replaces pre blocks with [...]
68 69 text = text.to_s.strip.gsub(%r{<pre>((.|\s)*?)</pre>}m, '[...]')
69 70 content = "#{ll(Setting.default_language, :text_user_wrote, user)}\n> "
70 71 content << text.gsub(/(\r?\n|\r\n?)/, "\n> ") + "\n\n"
71 72
72 73 render(:update) { |page|
73 74 page.<< "$('notes').value = \"#{escape_javascript content}\";"
74 75 page.show 'update'
75 76 page << "Form.Element.focus('notes');"
76 77 page << "Element.scrollTo('update');"
77 78 page << "$('notes').scrollTop = $('notes').scrollHeight - $('notes').clientHeight;"
78 79 }
79 80 end
80 81
81 82 def edit
82 83 (render_403; return false) unless @journal.editable_by?(User.current)
83 84 if request.post?
84 85 @journal.update_attributes(:notes => params[:notes]) if params[:notes]
85 86 @journal.destroy if @journal.details.empty? && @journal.notes.blank?
86 87 call_hook(:controller_journals_edit_post, { :journal => @journal, :params => params})
87 88 respond_to do |format|
88 89 format.html { redirect_to :controller => 'issues', :action => 'show', :id => @journal.journalized_id }
89 90 format.js { render :action => 'update' }
90 91 end
91 92 else
92 93 respond_to do |format|
93 94 format.html {
94 95 # TODO: implement non-JS journal update
95 96 render :nothing => true
96 97 }
97 98 format.js
98 99 end
99 100 end
100 101 end
101 102
102 103 private
103 104
104 105 def find_journal
105 106 @journal = Journal.find(params[:id])
106 107 @project = @journal.journalized.project
107 108 rescue ActiveRecord::RecordNotFound
108 109 render_404
109 110 end
110 111
111 112 # TODO: duplicated in IssuesController
112 113 def find_issue
113 114 @issue = Issue.find(params[:id], :include => [:project, :tracker, :status, :author, :priority, :category])
114 115 @project = @issue.project
115 116 rescue ActiveRecord::RecordNotFound
116 117 render_404
117 118 end
118 119 end
@@ -1,29 +1,36
1 1 ---
2 2 journal_details_001:
3 3 old_value: "1"
4 4 property: attr
5 5 id: 1
6 6 value: "2"
7 7 prop_key: status_id
8 8 journal_id: 1
9 9 journal_details_002:
10 10 old_value: "40"
11 11 property: attr
12 12 id: 2
13 13 value: "30"
14 14 prop_key: done_ratio
15 15 journal_id: 1
16 16 journal_details_003:
17 17 old_value: nil
18 18 property: attr
19 19 id: 3
20 20 value: "6"
21 21 prop_key: fixed_version_id
22 22 journal_id: 4
23 23 journal_details_004:
24 24 old_value: "This word was removed and an other was"
25 25 property: attr
26 26 id: 4
27 27 value: "This word was and an other was added"
28 28 prop_key: description
29 29 journal_id: 3
30 journal_details_005:
31 old_value: Old value
32 property: cf
33 id: 5
34 value: New value
35 prop_key: 2
36 journal_id: 3
@@ -1,99 +1,100
1 1 # Redmine - project management software
2 2 # Copyright (C) 2006-2011 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 require 'journals_controller'
20 20
21 21 # Re-raise errors caught by the controller.
22 22 class JournalsController; def rescue_action(e) raise e end; end
23 23
24 24 class JournalsControllerTest < ActionController::TestCase
25 fixtures :projects, :users, :members, :member_roles, :roles, :issues, :journals, :journal_details, :enabled_modules
25 fixtures :projects, :users, :members, :member_roles, :roles, :issues, :journals, :journal_details, :enabled_modules,
26 :trackers, :issue_statuses, :enumerations, :custom_fields, :custom_values, :custom_fields_projects
26 27
27 28 def setup
28 29 @controller = JournalsController.new
29 30 @request = ActionController::TestRequest.new
30 31 @response = ActionController::TestResponse.new
31 32 User.current = nil
32 33 end
33 34
34 35 def test_index
35 36 get :index, :project_id => 1
36 37 assert_response :success
37 38 assert_not_nil assigns(:journals)
38 39 assert_equal 'application/atom+xml', @response.content_type
39 40 end
40 41
41 42 def test_diff
42 43 get :diff, :id => 3, :detail_id => 4
43 44 assert_response :success
44 45 assert_template 'diff'
45 46
46 47 assert_tag 'span',
47 48 :attributes => {:class => 'diff_out'},
48 49 :content => /removed/
49 50 assert_tag 'span',
50 51 :attributes => {:class => 'diff_in'},
51 52 :content => /added/
52 53 end
53 54
54 55 def test_reply_to_issue
55 56 @request.session[:user_id] = 2
56 57 get :new, :id => 6
57 58 assert_response :success
58 59 assert_select_rjs :show, "update"
59 60 end
60 61
61 62 def test_reply_to_issue_without_permission
62 63 @request.session[:user_id] = 7
63 64 get :new, :id => 6
64 65 assert_response 403
65 66 end
66 67
67 68 def test_reply_to_note
68 69 @request.session[:user_id] = 2
69 70 get :new, :id => 6, :journal_id => 4
70 71 assert_response :success
71 72 assert_select_rjs :show, "update"
72 73 end
73 74
74 75 def test_get_edit
75 76 @request.session[:user_id] = 1
76 77 xhr :get, :edit, :id => 2
77 78 assert_response :success
78 79 assert_select_rjs :insert, :after, 'journal-2-notes' do
79 80 assert_select 'form[id=journal-2-form]'
80 81 assert_select 'textarea'
81 82 end
82 83 end
83 84
84 85 def test_post_edit
85 86 @request.session[:user_id] = 1
86 87 xhr :post, :edit, :id => 2, :notes => 'Updated notes'
87 88 assert_response :success
88 89 assert_select_rjs :replace, 'journal-2-notes'
89 90 assert_equal 'Updated notes', Journal.find(2).notes
90 91 end
91 92
92 93 def test_post_edit_with_empty_notes
93 94 @request.session[:user_id] = 1
94 95 xhr :post, :edit, :id => 2, :notes => ''
95 96 assert_response :success
96 97 assert_select_rjs :remove, 'change-2'
97 98 assert_nil Journal.find_by_id(2)
98 99 end
99 100 end
General Comments 0
You need to be logged in to leave comments. Login now