From 77665b52523d13532c16c97090b83c7ef88e2b62 Mon Sep 17 00:00:00 2001 From: Jean-Philippe Lang Date: Sun, 15 Dec 2013 11:02:24 +0000 Subject: [PATCH] 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 --- app/helpers/issues_helper.rb | 3 ++- app/models/issue_relation.rb | 8 +++--- ..._store_relation_type_in_journal_details.rb | 26 +++++++++++++++++++ test/unit/helpers/issues_helper_test.rb | 12 ++++----- test/unit/issue_relation_test.rb | 8 +++--- 5 files changed, 42 insertions(+), 15 deletions(-) create mode 100644 db/migrate/20131215104612_store_relation_type_in_journal_details.rb diff --git a/app/helpers/issues_helper.rb b/app/helpers/issues_helper.rb index ed1d243fb..05cc84471 100644 --- a/app/helpers/issues_helper.rb +++ b/app/helpers/issues_helper.rb @@ -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 }) diff --git a/app/models/issue_relation.rb b/app/models/issue_relation.rb index 1de565011..90a660436 100644 --- a/app/models/issue_relation.rb +++ b/app/models/issue_relation.rb @@ -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 diff --git a/db/migrate/20131215104612_store_relation_type_in_journal_details.rb b/db/migrate/20131215104612_store_relation_type_in_journal_details.rb new file mode 100644 index 000000000..3fa6b1f11 --- /dev/null +++ b/db/migrate/20131215104612_store_relation_type_in_journal_details.rb @@ -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 diff --git a/test/unit/helpers/issues_helper_test.rb b/test/unit/helpers/issues_helper_test.rb index ce27e6afe..0f87d45bc 100644 --- a/test/unit/helpers/issues_helper_test.rb +++ b/test/unit/helpers/issues_helper_test.rb @@ -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{Precedes Bug #1: Can't print recipes 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 "Precedes Issue ##{inexistant_issue_number} 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{Precedes deleted \(Bug #1: Can't print recipes\)}, @@ -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 "Precedes deleted (Issue #9999)", 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) diff --git a/test/unit/issue_relation_test.rb b/test/unit/issue_relation_test.rb index 6fc408353..7da6147fd 100644 --- a/test/unit/issue_relation_test.rb +++ b/test/unit/issue_relation_test.rb @@ -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