[#808] Truncate and show a link to the full journal diff in the issue history

This commit is contained in:
Eric Davis 2011-12-28 15:15:56 -08:00
parent 5ad97a4ea3
commit 08454ab7fa
3 changed files with 62 additions and 1 deletions

View File

@ -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

View File

@ -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

View File

@ -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?