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