@@ -1,105 +1,106 | |||
|
1 | 1 | # redMine - project management software |
|
2 | 2 | # Copyright (C) 2006-2008 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] |
|
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] |
|
23 | 23 | accept_key_auth :index |
|
24 | 24 | |
|
25 | 25 | helper :issues |
|
26 | helper :custom_fields | |
|
26 | 27 | helper :queries |
|
27 | 28 | include QueriesHelper |
|
28 | 29 | helper :sort |
|
29 | 30 | include SortHelper |
|
30 | 31 | |
|
31 | 32 | def index |
|
32 | 33 | retrieve_query |
|
33 | 34 | sort_init 'id', 'desc' |
|
34 | 35 | sort_update(@query.sortable_columns) |
|
35 | 36 | |
|
36 | 37 | if @query.valid? |
|
37 | 38 | @journals = @query.journals(:order => "#{Journal.table_name}.created_on DESC", |
|
38 | 39 | :limit => 25) |
|
39 | 40 | end |
|
40 | 41 | @title = (@project ? @project.name : Setting.app_title) + ": " + (@query.new_record? ? l(:label_changes_details) : @query.name) |
|
41 | 42 | render :layout => false, :content_type => 'application/atom+xml' |
|
42 | 43 | rescue ActiveRecord::RecordNotFound |
|
43 | 44 | render_404 |
|
44 | 45 | end |
|
45 | 46 | |
|
46 | 47 | def new |
|
47 | 48 | journal = Journal.find(params[:journal_id]) if params[:journal_id] |
|
48 | 49 | if journal |
|
49 | 50 | user = journal.user |
|
50 | 51 | text = journal.notes |
|
51 | 52 | else |
|
52 | 53 | user = @issue.author |
|
53 | 54 | text = @issue.description |
|
54 | 55 | end |
|
55 | 56 | # Replaces pre blocks with [...] |
|
56 | 57 | text = text.to_s.strip.gsub(%r{<pre>((.|\s)*?)</pre>}m, '[...]') |
|
57 | 58 | content = "#{ll(Setting.default_language, :text_user_wrote, user)}\n> " |
|
58 | 59 | content << text.gsub(/(\r?\n|\r\n?)/, "\n> ") + "\n\n" |
|
59 | 60 | |
|
60 | 61 | render(:update) { |page| |
|
61 | 62 | page.<< "$('notes').value = \"#{escape_javascript content}\";" |
|
62 | 63 | page.show 'update' |
|
63 | 64 | page << "Form.Element.focus('notes');" |
|
64 | 65 | page << "Element.scrollTo('update');" |
|
65 | 66 | page << "$('notes').scrollTop = $('notes').scrollHeight - $('notes').clientHeight;" |
|
66 | 67 | } |
|
67 | 68 | end |
|
68 | 69 | |
|
69 | 70 | def edit |
|
70 | 71 | if request.post? |
|
71 | 72 | @journal.update_attributes(:notes => params[:notes]) if params[:notes] |
|
72 | 73 | @journal.destroy if @journal.details.empty? && @journal.notes.blank? |
|
73 | 74 | call_hook(:controller_journals_edit_post, { :journal => @journal, :params => params}) |
|
74 | 75 | respond_to do |format| |
|
75 | 76 | format.html { redirect_to :controller => 'issues', :action => 'show', :id => @journal.journalized_id } |
|
76 | 77 | format.js { render :action => 'update' } |
|
77 | 78 | end |
|
78 | 79 | else |
|
79 | 80 | respond_to do |format| |
|
80 | 81 | format.html { |
|
81 | 82 | # TODO: implement non-JS journal update |
|
82 | 83 | render :nothing => true |
|
83 | 84 | } |
|
84 | 85 | format.js |
|
85 | 86 | end |
|
86 | 87 | end |
|
87 | 88 | end |
|
88 | 89 | |
|
89 | 90 | private |
|
90 | 91 | def find_journal |
|
91 | 92 | @journal = Journal.find(params[:id]) |
|
92 | 93 | (render_403; return false) unless @journal.editable_by?(User.current) |
|
93 | 94 | @project = @journal.journalized.project |
|
94 | 95 | rescue ActiveRecord::RecordNotFound |
|
95 | 96 | render_404 |
|
96 | 97 | end |
|
97 | 98 | |
|
98 | 99 | # TODO: duplicated in IssuesController |
|
99 | 100 | def find_issue |
|
100 | 101 | @issue = Issue.find(params[:id], :include => [:project, :tracker, :status, :author, :priority, :category]) |
|
101 | 102 | @project = @issue.project |
|
102 | 103 | rescue ActiveRecord::RecordNotFound |
|
103 | 104 | render_404 |
|
104 | 105 | end |
|
105 | 106 | end |
@@ -1,22 +1,29 | |||
|
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 | journal_details_005: | |
|
24 | old_value: Old value | |
|
25 | property: cf | |
|
26 | id: 5 | |
|
27 | value: New value | |
|
28 | prop_key: 2 | |
|
29 | journal_id: 3 |
@@ -1,86 +1,87 | |||
|
1 | 1 | # redMine - project management software |
|
2 | 2 | # Copyright (C) 2006-2008 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_reply_to_issue |
|
42 | 43 | @request.session[:user_id] = 2 |
|
43 | 44 | get :new, :id => 6 |
|
44 | 45 | assert_response :success |
|
45 | 46 | assert_select_rjs :show, "update" |
|
46 | 47 | end |
|
47 | 48 | |
|
48 | 49 | def test_reply_to_issue_without_permission |
|
49 | 50 | @request.session[:user_id] = 7 |
|
50 | 51 | get :new, :id => 6 |
|
51 | 52 | assert_response 403 |
|
52 | 53 | end |
|
53 | 54 | |
|
54 | 55 | def test_reply_to_note |
|
55 | 56 | @request.session[:user_id] = 2 |
|
56 | 57 | get :new, :id => 6, :journal_id => 4 |
|
57 | 58 | assert_response :success |
|
58 | 59 | assert_select_rjs :show, "update" |
|
59 | 60 | end |
|
60 | 61 | |
|
61 | 62 | def test_get_edit |
|
62 | 63 | @request.session[:user_id] = 1 |
|
63 | 64 | xhr :get, :edit, :id => 2 |
|
64 | 65 | assert_response :success |
|
65 | 66 | assert_select_rjs :insert, :after, 'journal-2-notes' do |
|
66 | 67 | assert_select 'form[id=journal-2-form]' |
|
67 | 68 | assert_select 'textarea' |
|
68 | 69 | end |
|
69 | 70 | end |
|
70 | 71 | |
|
71 | 72 | def test_post_edit |
|
72 | 73 | @request.session[:user_id] = 1 |
|
73 | 74 | xhr :post, :edit, :id => 2, :notes => 'Updated notes' |
|
74 | 75 | assert_response :success |
|
75 | 76 | assert_select_rjs :replace, 'journal-2-notes' |
|
76 | 77 | assert_equal 'Updated notes', Journal.find(2).notes |
|
77 | 78 | end |
|
78 | 79 | |
|
79 | 80 | def test_post_edit_with_empty_notes |
|
80 | 81 | @request.session[:user_id] = 1 |
|
81 | 82 | xhr :post, :edit, :id => 2, :notes => '' |
|
82 | 83 | assert_response :success |
|
83 | 84 | assert_select_rjs :remove, 'change-2' |
|
84 | 85 | assert_nil Journal.find_by_id(2) |
|
85 | 86 | end |
|
86 | 87 | end |
General Comments 0
You need to be logged in to leave comments.
Login now