Store relation type instead of i18n key in journals (#15704).

git-svn-id: http://svn.redmine.org/redmine/trunk@12416 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
Jean-Philippe Lang 2013-12-15 11:02:24 +00:00
parent 13756eb3a8
commit 77665b5252
5 changed files with 42 additions and 15 deletions

View File

@ -340,7 +340,8 @@ module IssuesHelper
old_value = rel_issue.nil? ? "#{l(:label_issue)} ##{detail.old_value}" :
(no_html ? rel_issue : link_to_issue(rel_issue, :only_path => options[:only_path]))
end
label = l(detail.prop_key.to_sym)
relation_type = IssueRelation::TYPES[detail.prop_key]
label = l(relation_type[:name]) if relation_type
end
call_hook(:helper_issues_show_detail_after_setting,
{:detail => detail, :label => label, :value => value, :old_value => old_value })

View File

@ -185,12 +185,12 @@ class IssueRelation < ActiveRecord::Base
def create_journal_after_create
journal = issue_from.init_journal(User.current)
journal.details << JournalDetail.new(:property => 'relation',
:prop_key => label_for(issue_from).to_s,
:prop_key => relation_type_for(issue_from),
:value => issue_to.id)
journal.save
journal = issue_to.init_journal(User.current)
journal.details << JournalDetail.new(:property => 'relation',
:prop_key => label_for(issue_to).to_s,
:prop_key => relation_type_for(issue_to),
:value => issue_from.id)
journal.save
end
@ -198,12 +198,12 @@ class IssueRelation < ActiveRecord::Base
def create_journal_after_delete
journal = issue_from.init_journal(User.current)
journal.details << JournalDetail.new(:property => 'relation',
:prop_key => label_for(issue_from).to_s,
:prop_key => relation_type_for(issue_from),
:old_value => issue_to.id)
journal.save
journal = issue_to.init_journal(User.current)
journal.details << JournalDetail.new(:property => 'relation',
:prop_key => label_for(issue_to).to_s,
:prop_key => relation_type_for(issue_to),
:old_value => issue_from.id)
journal.save
end

View File

@ -0,0 +1,26 @@
class StoreRelationTypeInJournalDetails < ActiveRecord::Migration
MAPPING = {
"label_relates_to" => "relates",
"label_duplicates" => "duplicates",
"label_duplicated_by" => "duplicated",
"label_blocks" => "blocks",
"label_blocked_by" => "blocked",
"label_precedes" => "precedes",
"label_follows" => "follows",
"label_copied_to" => "copied_to",
"label_copied_from" => "copied_from"
}
def up
StoreRelationTypeInJournalDetails::MAPPING.each do |prop_key, replacement|
JournalDetail.where(:property => 'relation', :prop_key => prop_key).update_all(:prop_key => replacement)
end
end
def down
StoreRelationTypeInJournalDetails::MAPPING.each do |prop_key, replacement|
JournalDetail.where(:property => 'relation', :prop_key => replacement).update_all(:prop_key => prop_key)
end
end
end

View File

@ -213,7 +213,7 @@ class IssuesHelperTest < ActionView::TestCase
def test_show_detail_relation_added
detail = JournalDetail.new(:property => 'relation',
:prop_key => 'label_precedes',
:prop_key => 'precedes',
:value => 1)
assert_equal "Precedes Bug #1: Can't print recipes added", show_detail(detail, true)
assert_match %r{<strong>Precedes</strong> <i><a href="/issues/1" class=".+">Bug #1</a>: Can&#x27;t print recipes</i> added},
@ -224,7 +224,7 @@ class IssuesHelperTest < ActionView::TestCase
inexistant_issue_number = 9999
assert_nil Issue.find_by_id(inexistant_issue_number)
detail = JournalDetail.new(:property => 'relation',
:prop_key => 'label_precedes',
:prop_key => 'precedes',
:value => inexistant_issue_number)
assert_equal "Precedes Issue ##{inexistant_issue_number} added", show_detail(detail, true)
assert_equal "<strong>Precedes</strong> <i>Issue ##{inexistant_issue_number}</i> added", show_detail(detail, false)
@ -233,7 +233,7 @@ class IssuesHelperTest < ActionView::TestCase
def test_show_detail_relation_added_should_not_disclose_issue_that_is_not_visible
issue = Issue.generate!(:is_private => true)
detail = JournalDetail.new(:property => 'relation',
:prop_key => 'label_precedes',
:prop_key => 'precedes',
:value => issue.id)
assert_equal "Precedes Issue ##{issue.id} added", show_detail(detail, true)
@ -242,7 +242,7 @@ class IssuesHelperTest < ActionView::TestCase
def test_show_detail_relation_deleted
detail = JournalDetail.new(:property => 'relation',
:prop_key => 'label_precedes',
:prop_key => 'precedes',
:old_value => 1)
assert_equal "Precedes deleted (Bug #1: Can't print recipes)", show_detail(detail, true)
assert_match %r{<strong>Precedes</strong> deleted \(<i><a href="/issues/1" class=".+">Bug #1</a>: Can&#x27;t print recipes</i>\)},
@ -253,7 +253,7 @@ class IssuesHelperTest < ActionView::TestCase
inexistant_issue_number = 9999
assert_nil Issue.find_by_id(inexistant_issue_number)
detail = JournalDetail.new(:property => 'relation',
:prop_key => 'label_precedes',
:prop_key => 'precedes',
:old_value => inexistant_issue_number)
assert_equal "Precedes deleted (Issue #9999)", show_detail(detail, true)
assert_equal "<strong>Precedes</strong> deleted (<i>Issue #9999</i>)", show_detail(detail, false)
@ -262,7 +262,7 @@ class IssuesHelperTest < ActionView::TestCase
def test_show_detail_relation_deleted_should_not_disclose_issue_that_is_not_visible
issue = Issue.generate!(:is_private => true)
detail = JournalDetail.new(:property => 'relation',
:prop_key => 'label_precedes',
:prop_key => 'precedes',
:old_value => issue.id)
assert_equal "Precedes deleted (Issue ##{issue.id})", show_detail(detail, true)

View File

@ -183,11 +183,11 @@ class IssueRelationTest < ActiveSupport::TestCase
assert_equal from.journals.size, (from_journals + 1)
assert_equal to.journals.size, (to_journals + 1)
assert_equal 'relation', from.journals.last.details.last.property
assert_equal 'label_precedes', from.journals.last.details.last.prop_key
assert_equal 'precedes', from.journals.last.details.last.prop_key
assert_equal '2', from.journals.last.details.last.value
assert_nil from.journals.last.details.last.old_value
assert_equal 'relation', to.journals.last.details.last.property
assert_equal 'label_follows', to.journals.last.details.last.prop_key
assert_equal 'follows', to.journals.last.details.last.prop_key
assert_equal '1', to.journals.last.details.last.value
assert_nil to.journals.last.details.last.old_value
end
@ -205,11 +205,11 @@ class IssueRelationTest < ActiveSupport::TestCase
assert_equal from.journals.size, (from_journals + 1)
assert_equal to.journals.size, (to_journals + 1)
assert_equal 'relation', from.journals.last.details.last.property
assert_equal 'label_blocks', from.journals.last.details.last.prop_key
assert_equal 'blocks', from.journals.last.details.last.prop_key
assert_equal '9', from.journals.last.details.last.old_value
assert_nil from.journals.last.details.last.value
assert_equal 'relation', to.journals.last.details.last.property
assert_equal 'label_blocked_by', to.journals.last.details.last.prop_key
assert_equal 'blocked', to.journals.last.details.last.prop_key
assert_equal '10', to.journals.last.details.last.old_value
assert_nil to.journals.last.details.last.value
end