From 08454ab7fa82e79d1b80063657f576713701fd4d Mon Sep 17 00:00:00 2001 From: Eric Davis Date: Wed, 28 Dec 2011 15:15:56 -0800 Subject: [PATCH] [#808] Truncate and show a link to the full journal diff in the issue history --- test/integration/journals_test.rb | 47 +++++++++++++++++++ test/integration_test_helpers.rb | 2 +- .../lib/journal_formatter.rb | 14 ++++++ 3 files changed, 62 insertions(+), 1 deletion(-) create mode 100644 test/integration/journals_test.rb diff --git a/test/integration/journals_test.rb b/test/integration/journals_test.rb new file mode 100644 index 00000000..3bd067e8 --- /dev/null +++ b/test/integration/journals_test.rb @@ -0,0 +1,47 @@ +#-- encoding: UTF-8 +#-- copyright +# ChiliProject is a project management system. +# +# Copyright (C) 2010-2011 the ChiliProject Team +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License +# as published by the Free Software Foundation; either version 2 +# of the License, or (at your option) any later version. +# +# See doc/COPYRIGHT.rdoc for more details. +#++ +require File.expand_path('../../test_helper', __FILE__) +require 'capybara/rails' + +class JournalsTest < ActionController::IntegrationTest + fixtures :all + + include IntegrationTestHelpers::CapybaraHelpers + include Capybara::DSL + + test "showing issue description changes as a diff" do + # Description change + @issue = Issue.find(1) + @issue.recreate_initial_journal! + @issue.reload + assert_difference("Journal.count") do + @issue.journal_user = User.find_by_login('jsmith') + @issue.description = "A new description" + assert @issue.save + end + + log_user('jsmith', 'jsmith') + + # Issue page + visit_issue_page(@issue) + assert has_selector?("#history .journal-attributes li i", :text => 'A new description') + within("#history .journal-attributes li") do + find_link("More").click + end + + # Diff page + assert_response :success + assert has_selector?("#content .text-diff", :text => /A new description/) + end +end diff --git a/test/integration_test_helpers.rb b/test/integration_test_helpers.rb index 9e20efef..2e9b0c2d 100644 --- a/test/integration_test_helpers.rb +++ b/test/integration_test_helpers.rb @@ -51,7 +51,7 @@ module IntegrationTestHelpers visit "/login" fill_in 'Login', :with => user fill_in 'Password', :with => password - click_button 'login' + click_button 'Login' assert_response :success assert User.current.logged? end diff --git a/vendor/plugins/acts_as_journalized/lib/journal_formatter.rb b/vendor/plugins/acts_as_journalized/lib/journal_formatter.rb index 44c6bf36..dddf4d8c 100644 --- a/vendor/plugins/acts_as_journalized/lib/journal_formatter.rb +++ b/vendor/plugins/acts_as_journalized/lib/journal_formatter.rb @@ -28,6 +28,7 @@ module JournalFormatter include CustomFieldsHelper include ActionView::Helpers::TagHelper include ActionView::Helpers::UrlHelper + include ActionView::Helpers::TextHelper include ActionController::UrlWriter extend Redmine::I18n @@ -122,6 +123,16 @@ module JournalFormatter [label, old_value, value] end + # Formats a detail to be used with a Journal diff + # + # Truncates the content. Adds a link to view a diff. + def format_html_diff_detail(key, label, old_value, value) + link = link_to(l(:label_more), {:controller => 'journals', :action => 'diff', :id => id, :field => key.to_s}) + old_value = truncate(old_value, :length => 80) + value = truncate(value, :length => 80) + " " + link + [old_value, value] + end + def property(detail) key = prop_key(detail) if key.start_with? "custom_values" @@ -186,6 +197,9 @@ module JournalFormatter unless no_html label, old_value, value = *format_html_detail(label, old_value, value) value = format_html_attachment_detail(key.sub("attachments", ""), value) if attachment_detail + if property(detail) == :attribute && key == "description" + old_value, value = *format_html_diff_detail(key, label, old_value, value) + end end unless value.blank?