From 2bbc948e06ef802588b25cf02f0de816f6fa0cc6 Mon Sep 17 00:00:00 2001 From: Jean-Philippe Lang Date: Sun, 28 Mar 2010 15:17:46 +0000 Subject: [PATCH] Preview description if it was edited while updating an issue (#741). git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@3623 e93f8b46-1217-0410-a6f0-8f06a7374b81 --- app/controllers/issues_controller.rb | 14 +++++++++++--- app/views/issues/preview.html.erb | 11 +++++++++++ test/functional/issues_controller_test.rb | 16 ++++++++++++++++ 3 files changed, 38 insertions(+), 3 deletions(-) create mode 100644 app/views/issues/preview.html.erb diff --git a/app/controllers/issues_controller.rb b/app/controllers/issues_controller.rb index 10c8aebc1..b97937a48 100644 --- a/app/controllers/issues_controller.rb +++ b/app/controllers/issues_controller.rb @@ -453,9 +453,17 @@ class IssuesController < ApplicationController def preview @issue = @project.issues.find_by_id(params[:id]) unless params[:id].blank? - @attachements = @issue.attachments if @issue - @text = params[:notes] || (params[:issue] ? params[:issue][:description] : nil) - render :partial => 'common/preview' + if @issue + @attachements = @issue.attachments + @description = params[:issue] && params[:issue][:description] + if @description && @description.gsub(/(\r?\n|\n\r?)/, "\n") == @issue.description.to_s.gsub(/(\r?\n|\n\r?)/, "\n") + @description = nil + end + @notes = params[:notes] + else + @description = (params[:issue] ? params[:issue][:description] : nil) + end + render :layout => false end def auto_complete diff --git a/app/views/issues/preview.html.erb b/app/views/issues/preview.html.erb new file mode 100644 index 000000000..23772859e --- /dev/null +++ b/app/views/issues/preview.html.erb @@ -0,0 +1,11 @@ +<% if @notes %> +
<%= l(:field_notes) %> + <%= textilizable @notes, :attachments => @attachements, :object => @issue %> +
+<% end %> + +<% if @description %> +
<%= l(:field_description) %> + <%= textilizable @description, :attachments => @attachements, :object => @issue %> +
+<% end %> diff --git a/test/functional/issues_controller_test.rb b/test/functional/issues_controller_test.rb index 23d09152c..757f36c19 100644 --- a/test/functional/issues_controller_test.rb +++ b/test/functional/issues_controller_test.rb @@ -1271,6 +1271,22 @@ class IssuesControllerTest < ActionController::TestCase :attributes => { :href => '#', :class => 'icon-del disabled' } end + + def test_preview_new_issue + @request.session[:user_id] = 2 + post :preview, :project_id => '1', :issue => {:description => 'Foo'} + assert_response :success + assert_template 'preview' + assert_not_nil assigns(:description) + end + + def test_preview_notes + @request.session[:user_id] = 2 + post :preview, :project_id => '1', :id => 1, :issue => {:description => Issue.find(1).description}, :notes => 'Foo' + assert_response :success + assert_template 'preview' + assert_not_nil assigns(:notes) + end def test_auto_complete_routing assert_routing(